mirror of
https://github.com/M66B/NetGuard.git
synced 2025-03-16 16:55:55 +00:00
Workaround Android issue
Some Android versions report network events on a background thread
This commit is contained in:
parent
5961b6daad
commit
1919aa0e28
1 changed files with 50 additions and 5 deletions
|
@ -3293,14 +3293,32 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
Intent intent = new Intent(context, ServiceSinkhole.class);
|
Intent intent = new Intent(context, ServiceSinkhole.class);
|
||||||
intent.putExtra(EXTRA_COMMAND, Command.run);
|
intent.putExtra(EXTRA_COMMAND, Command.run);
|
||||||
intent.putExtra(EXTRA_REASON, reason);
|
intent.putExtra(EXTRA_REASON, reason);
|
||||||
|
try {
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
// ForegroundServiceStartNotAllowedException
|
||||||
|
try {
|
||||||
|
context.startService(intent);
|
||||||
|
} catch (Throwable exex) {
|
||||||
|
Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start(String reason, Context context) {
|
public static void start(String reason, Context context) {
|
||||||
Intent intent = new Intent(context, ServiceSinkhole.class);
|
Intent intent = new Intent(context, ServiceSinkhole.class);
|
||||||
intent.putExtra(EXTRA_COMMAND, Command.start);
|
intent.putExtra(EXTRA_COMMAND, Command.start);
|
||||||
intent.putExtra(EXTRA_REASON, reason);
|
intent.putExtra(EXTRA_REASON, reason);
|
||||||
|
try {
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
// ForegroundServiceStartNotAllowedException
|
||||||
|
try {
|
||||||
|
context.startService(intent);
|
||||||
|
} catch (Throwable exex) {
|
||||||
|
Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload(String reason, Context context, boolean interactive) {
|
public static void reload(String reason, Context context, boolean interactive) {
|
||||||
|
@ -3310,7 +3328,16 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
intent.putExtra(EXTRA_COMMAND, Command.reload);
|
intent.putExtra(EXTRA_COMMAND, Command.reload);
|
||||||
intent.putExtra(EXTRA_REASON, reason);
|
intent.putExtra(EXTRA_REASON, reason);
|
||||||
intent.putExtra(EXTRA_INTERACTIVE, interactive);
|
intent.putExtra(EXTRA_INTERACTIVE, interactive);
|
||||||
|
try {
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
// ForegroundServiceStartNotAllowedException
|
||||||
|
try {
|
||||||
|
context.startService(intent);
|
||||||
|
} catch (Throwable exex) {
|
||||||
|
Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3319,13 +3346,31 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
intent.putExtra(EXTRA_COMMAND, Command.stop);
|
intent.putExtra(EXTRA_COMMAND, Command.stop);
|
||||||
intent.putExtra(EXTRA_REASON, reason);
|
intent.putExtra(EXTRA_REASON, reason);
|
||||||
intent.putExtra(EXTRA_TEMPORARY, vpnonly);
|
intent.putExtra(EXTRA_TEMPORARY, vpnonly);
|
||||||
|
try {
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
// ForegroundServiceStartNotAllowedException
|
||||||
|
try {
|
||||||
|
context.startService(intent);
|
||||||
|
} catch (Throwable exex) {
|
||||||
|
Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadStats(String reason, Context context) {
|
public static void reloadStats(String reason, Context context) {
|
||||||
Intent intent = new Intent(context, ServiceSinkhole.class);
|
Intent intent = new Intent(context, ServiceSinkhole.class);
|
||||||
intent.putExtra(EXTRA_COMMAND, Command.stats);
|
intent.putExtra(EXTRA_COMMAND, Command.stats);
|
||||||
intent.putExtra(EXTRA_REASON, reason);
|
intent.putExtra(EXTRA_REASON, reason);
|
||||||
|
try {
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
// ForegroundServiceStartNotAllowedException
|
||||||
|
try {
|
||||||
|
context.startService(intent);
|
||||||
|
} catch (Throwable exex) {
|
||||||
|
Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue