1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-25 15:42:53 +00:00

Display number of hosts

Fixes #248
This commit is contained in:
M66B 2016-02-01 19:43:17 +01:00
parent cf031885a2
commit d18d91550f
2 changed files with 10 additions and 6 deletions

View file

@ -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));
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);
}

View file

@ -101,6 +101,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="msg_sure">Are you sure?</string>
<string name="msg_started">Enforcing rules</string>
<string name="msg_packages">%1$d allowed, %2$d blocked</string>
<string name="msg_hosts">%1$d allowed, %2$d blocked, %3$d hosts</string>
<string name="msg_waiting">Waiting for event</string>
<string name="msg_disabled">NetGuard is disabled, use the switch above to enable NetGuard</string>
<string name="msg_revoked">NetGuard has been disabled, likely by using another VPN based application</string>