mirror of https://github.com/M66B/NetGuard.git
Another attempt to workaround start at boot issues
This commit is contained in:
parent
06f213594c
commit
242ec83248
|
@ -84,10 +84,9 @@ public class Receiver extends BroadcastReceiver {
|
|||
SinkholeService.start("receiver", context);
|
||||
|
||||
} else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
|
||||
if (prefs.getBoolean("enabled", false)) {
|
||||
if (VpnService.prepare(context) == null)
|
||||
if (prefs.getBoolean("enabled", false))
|
||||
SinkholeService.start("receiver", context);
|
||||
} else if (prefs.getBoolean("show_stats", false))
|
||||
else if (prefs.getBoolean("show_stats", false))
|
||||
SinkholeService.run("receiver", context);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
|
|
|
@ -183,6 +183,13 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
String reason = intent.getStringExtra(EXTRA_REASON);
|
||||
Log.i(TAG, "Executing intent=" + intent + " command=" + cmd + " reason=" + reason + " vpn=" + (vpn != null));
|
||||
|
||||
// Check if prepared
|
||||
if (cmd == Command.start || cmd == Command.reload)
|
||||
if (VpnService.prepare(SinkholeService.this) != null) {
|
||||
Log.w(TAG, "VPN not prepared");
|
||||
return;
|
||||
}
|
||||
|
||||
// Listen for phone state changes
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (tm != null && !phone_state &&
|
||||
|
@ -306,13 +313,12 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
|
||||
if (Util.isConnected(SinkholeService.this)) {
|
||||
if (!(ex instanceof IllegalStateException)) {
|
||||
// Disable firewall
|
||||
prefs.edit().putBoolean("enabled", false).apply();
|
||||
Widget.updateWidgets(SinkholeService.this);
|
||||
|
||||
// Report exception
|
||||
if (!(ex instanceof IllegalStateException))
|
||||
Util.sendCrashReport(ex, SinkholeService.this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,10 +76,8 @@ public class Widget extends AppWidgetProvider {
|
|||
|
||||
} else if (INTENT_ON.equals(intent.getAction()))
|
||||
try {
|
||||
if (VpnService.prepare(context) == null) {
|
||||
prefs.edit().putBoolean("enabled", true).apply();
|
||||
SinkholeService.start("widget", context);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Util.sendCrashReport(ex, context);
|
||||
|
@ -91,14 +89,12 @@ public class Widget extends AppWidgetProvider {
|
|||
boolean enabled = prefs.getBoolean("enabled", false);
|
||||
|
||||
try {
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, ActivityMain.class), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
try {
|
||||
PendingIntent pi;
|
||||
if (VpnService.prepare(context) == null)
|
||||
pi = PendingIntent.getBroadcast(context, 0, new Intent(enabled ? INTENT_OFF : INTENT_ON), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Util.sendCrashReport(ex, context);
|
||||
}
|
||||
else
|
||||
pi = PendingIntent.getActivity(context, 0, new Intent(context, ActivityMain.class), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
for (int id : appWidgetIds) {
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||
|
@ -110,6 +106,10 @@ public class Widget extends AppWidgetProvider {
|
|||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Util.sendCrashReport(ex, context);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Util.sendCrashReport(ex, context);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateWidgets(Context context) {
|
||||
|
|
Loading…
Reference in New Issue