diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index 3a47a4a5..84065b07 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -106,6 +106,12 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere EditTextPreference pref_stats_base = (EditTextPreference) screen.findPreference("stats_base"); pref_stats_base.setTitle(getString(R.string.setting_stats_base, prefs.getString("stats_base", "5"))); + EditTextPreference pref_stats_frequency = (EditTextPreference) screen.findPreference("stats_frequency"); + pref_stats_frequency.setTitle(getString(R.string.setting_stats_frequency, prefs.getString("stats_frequency", "1000"))); + + EditTextPreference pref_stats_samples = (EditTextPreference) screen.findPreference("stats_samples"); + pref_stats_samples.setTitle(getString(R.string.setting_stats_samples, prefs.getString("stats_samples", "90"))); + // Wi-Fi home MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) screen.findPreference("wifi_homes"); Set ssid = prefs.getStringSet("wifi_homes", new HashSet()); @@ -291,6 +297,12 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else if ("stats_base".equals(name)) getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_base, prefs.getString(name, "5"))); + else if ("stats_frequency".equals(name)) + getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000"))); + + else if ("stats_samples".equals(name)) + getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90"))); + else if ("auto_enable".equals(name)) getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_auto, prefs.getString(name, "0"))); diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index 65d1aa30..7bbf4b15 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -266,9 +266,6 @@ public class SinkholeService extends VpnService { private HashMap app = new HashMap<>(); - private final static int STATS_POINTS = 100; - private final static int STATS_FREQUENCY = 1000; - private void startStats() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this); boolean enabled = (!stats && prefs.getBoolean("show_stats", false)); @@ -296,12 +293,17 @@ public class SinkholeService extends VpnService { private void updateStats() { RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.traffic); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this); + int frequency = Integer.parseInt(prefs.getString("stats_frequency", "1000")); + int samples = Integer.parseInt(prefs.getString("stats_samples", "90")); + float base = Integer.parseInt(prefs.getString("stats_base", "5")) * 1000f; // Schedule next update - mServiceHandler.sendEmptyMessageDelayed(MSG_STATS_UPDATE, STATS_FREQUENCY); + mServiceHandler.sendEmptyMessageDelayed(MSG_STATS_UPDATE, frequency); + + long ct = SystemClock.elapsedRealtime(); // Cleanup - while (gt.size() >= STATS_POINTS) { + while (gt.size() > 0 && ct - gt.get(0) > samples * 1000) { gt.remove(0); gtx.remove(0); grx.remove(0); @@ -310,7 +312,6 @@ public class SinkholeService extends VpnService { // Calculate network speed float txsec = 0; float rxsec = 0; - long ct = SystemClock.elapsedRealtime(); long ctx = TrafficStats.getTotalTxBytes(); long rtx = TrafficStats.getTotalRxBytes(); if (t > 0 && tx > 0 && rx > 0) { @@ -377,8 +378,6 @@ public class SinkholeService extends VpnService { Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.TRANSPARENT); - float base = Integer.parseInt(prefs.getString("stats_base", "5")) * 1000f; - // Determine max long xmax = 0; float ymax = base * 1.5f; @@ -398,7 +397,7 @@ public class SinkholeService extends VpnService { Path ptx = new Path(); Path prx = new Path(); for (int i = 0; i < gtx.size(); i++) { - float x = width - width * (xmax - gt.get(i)) / 1000f / STATS_POINTS; + float x = width - width * (xmax - gt.get(i)) / 1000f / samples; float ytx = height - height * gtx.get(i) / ymax; float yrx = height - height * grx.get(i) / ymax; if (i == 0) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7581614d..44204dd7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,9 +24,6 @@ These issues are caused by bugs in Android, or in the software provided by the m Options Manage system applications - Show speed notification - Speed baseline: %s KB/s - Show top network using applications Auto enable after %1$s minutes Use dark theme Wi-Fi home networks: %1$s @@ -36,6 +33,13 @@ These issues are caused by bugs in Android, or in the software provided by the m Consider LTE unmetered Ignore national roaming + Speed notification + Show speed notification + Show top applications + Speed baseline: %s KB/s + Sample frequency: %s ms + Number of samples: %s s + Backup Export settings Import settings diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e7e16e38..fb5e71ae 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -32,21 +32,6 @@ android:key="manage_system" android:summary="@string/summary_system" android:title="@string/setting_system" /> - - - + + + + + + +