diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index 255e05ff..3a47a4a5 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -286,7 +286,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere SinkholeService.reload("other", "setting changed", this); } else if ("show_stats".equals(name)) - ; + SinkholeService.reloadStats("setting changed", this); else if ("stats_base".equals(name)) getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_base, prefs.getString(name, "5"))); diff --git a/app/src/main/java/eu/faircode/netguard/Receiver.java b/app/src/main/java/eu/faircode/netguard/Receiver.java index b27ed590..3038a185 100644 --- a/app/src/main/java/eu/faircode/netguard/Receiver.java +++ b/app/src/main/java/eu/faircode/netguard/Receiver.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.VpnService; +import android.os.PowerManager; import android.preference.PreferenceManager; import android.util.Log; @@ -63,6 +64,10 @@ public class Receiver extends BroadcastReceiver { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Util.sendCrashReport(ex, context); } + + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + if (pm.isInteractive()) + SinkholeService.reloadStats("receiver", context); } } diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index 63cca858..25eeb55a 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -93,7 +93,7 @@ public class SinkholeService extends VpnService { private static final int MSG_STATS_STOP = 2; private static final int MSG_STATS_UPDATE = 3; - private enum Command {start, reload, stop} + private enum Command {start, reload, stop, stats} private static volatile PowerManager.WakeLock wlInstance = null; @@ -222,6 +222,11 @@ public class SinkholeService extends VpnService { stopForeground(true); } break; + + case stats: + stopStats(); + startStats(); + break; } // Update main view @@ -867,4 +872,11 @@ public class SinkholeService extends VpnService { intent.putExtra(EXTRA_REASON, reason); context.startService(intent); } + + public static void reloadStats(String reason, Context context) { + Intent intent = new Intent(context, SinkholeService.class); + intent.putExtra(EXTRA_COMMAND, Command.stats); + intent.putExtra(EXTRA_REASON, reason); + context.startService(intent); + } } diff --git a/app/src/main/res/layout/traffic.xml b/app/src/main/res/layout/traffic.xml index 4a797d15..607ff125 100644 --- a/app/src/main/res/layout/traffic.xml +++ b/app/src/main/res/layout/traffic.xml @@ -18,7 +18,6 @@ android:layout_alignParentTop="true" android:gravity="center_horizontal"> -