From d18d91550f352e8cd8f63090c2ae7e5c3fc57a88 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 1 Feb 2016 19:43:17 +0100 Subject: [PATCH] Display number of hosts Fixes #248 --- .../eu/faircode/netguard/SinkholeService.java | 15 +++++++++------ app/src/main/res/values/strings.xml | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index 9ba7aaf1..c680adf9 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -339,7 +339,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS Log.d(TAG, "Stop foreground state=" + state.toString()); stopForeground(true); } - startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0)); + startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0, 0)); state = State.enforcing; Log.d(TAG, "Start foreground state=" + state.toString()); @@ -370,7 +370,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS Log.d(TAG, "Stop foreground state=" + state.toString()); stopForeground(true); } - startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0)); + startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0, 0)); state = State.enforcing; Log.d(TAG, "Start foreground state=" + state.toString()); } @@ -1334,7 +1334,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS stopForeground(true); } if (state == State.enforcing) - startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0)); + startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0, 0)); else if (state != State.none) startForeground(NOTIFY_WAITING, getWaitingNotification()); Log.d(TAG, "Start foreground state=" + state.toString()); @@ -1436,7 +1436,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS super.onDestroy(); } - private Notification getEnforcingNotification(int allowed, int blocked) { + private Notification getEnforcingNotification(int allowed, int blocked, int hosts) { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); @@ -1459,13 +1459,16 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_started)); - notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked)); + if (Util.isPlayStoreInstall(this)) + notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked)); + else + notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts)); return notification.build(); } private void updateEnforcingNotification(int allowed, int total) { // Update notification - Notification notification = getEnforcingNotification(allowed, total - allowed); + Notification notification = getEnforcingNotification(allowed, total - allowed, mapHostsBlocked.size()); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(NOTIFY_ENFORCING, notification); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c54f7c3..c3f9dda2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,6 +101,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi Are you sure? Enforcing rules %1$d allowed, %2$d blocked + %1$d allowed, %2$d blocked, %3$d hosts Waiting for event NetGuard is disabled, use the switch above to enable NetGuard NetGuard has been disabled, likely by using another VPN based application