diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index d2ef4940..17a509a8 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -114,8 +114,9 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS private static final int NOTIFY_ENFORCING = 1; private static final int NOTIFY_WAITING = 2; private static final int NOTIFY_DISABLED = 3; - private static final int NOTIFY_ERROR = 4; - private static final int NOTIFY_TRAFFIC = 5; + private static final int NOTIFY_AUTOSTART = 4; + private static final int NOTIFY_ERROR = 5; + private static final int NOTIFY_TRAFFIC = 6; public static final String EXTRA_COMMAND = "Command"; private static final String EXTRA_REASON = "Reason"; @@ -238,6 +239,8 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS if (cmd == Command.start || cmd == Command.reload) if (VpnService.prepare(SinkholeService.this) != null) { Log.w(TAG, "VPN not prepared"); + prefs.edit().putBoolean("enabled", false).apply(); + showAutoStartNotification(); return; } @@ -1523,6 +1526,32 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build()); } + private void showAutoStartNotification() { + Intent main = new Intent(this, ActivityMain.class); + PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); + + TypedValue tv = new TypedValue(); + getTheme().resolveAttribute(R.attr.colorOff, tv, true); + NotificationCompat.Builder builder = new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_error_white_24dp) + .setContentTitle(getString(R.string.app_name)) + .setContentText(getString(R.string.msg_autostart)) + .setContentIntent(pi) + .setColor(tv.data) + .setOngoing(false) + .setAutoCancel(true); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder.setCategory(Notification.CATEGORY_STATUS) + .setVisibility(Notification.VISIBILITY_SECRET); + } + + NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); + notification.bigText(getString(R.string.msg_autostart)); + + NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build()); + } + private void showErrorNotification(String reason) { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1bad30ee..3b18c147 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,6 +112,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi NetGuard uses a local VPN to filter internet traffic. For this reason, please allow a VPN connection in the next dialog. Your internet traffic is not being sent to an remote VPN server. + NetGuard could not be started automatically on boot because of a bug in your Android version Try NetGuard By donating you agree to the terms & conditions If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.