mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-01 12:54:07 +00:00
parent
b968a2b595
commit
7c1e7f4845
2 changed files with 32 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -112,6 +112,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="msg_vpn">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.</string>
|
||||
<string name="msg_autostart">NetGuard could not be started automatically on boot because of a bug in your Android version</string>
|
||||
<string name="msg_try">Try NetGuard</string>
|
||||
<string name="msg_terms">By donating you agree to the <a href="http://www.netguard.me/#terms">terms & conditions</a></string>
|
||||
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>
|
||||
|
|
Loading…
Reference in a new issue