1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-24 15:21:19 +00:00

Network speed improvements

This commit is contained in:
M66B 2015-12-09 17:57:10 +01:00
parent b9f59e60b3
commit 0488361937
2 changed files with 17 additions and 4 deletions

View file

@ -285,7 +285,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
} else } else
SinkholeService.reload("other", "setting changed", this); SinkholeService.reload("other", "setting changed", this);
} else if ("stats_base".equals(name)) } else if ("show_stats".equals(name))
SinkholeService.reload(null, "setting changed", this);
else if ("stats_base".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_base, prefs.getString(name, "5"))); getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_base, prefs.getString(name, "5")));
else if ("auto_enable".equals(name)) else if ("auto_enable".equals(name))

View file

@ -210,6 +210,10 @@ public class SinkholeService extends VpnService {
startDebug(vpn); startDebug(vpn);
if (prev != null) if (prev != null)
stopVPN(prev); stopVPN(prev);
// Restart stats
stopStats();
startStats();
break; break;
case stop: case stop:
@ -272,6 +276,7 @@ public class SinkholeService extends VpnService {
private void stopStats() { private void stopStats() {
Log.i(TAG, "Stats stop"); Log.i(TAG, "Stats stop");
stats = false; stats = false;
mServiceHandler.removeMessages(MSG_STATS_UPDATE);
NotificationManagerCompat.from(SinkholeService.this).cancel(NOTIFY_TRAFFIC); NotificationManagerCompat.from(SinkholeService.this).cancel(NOTIFY_TRAFFIC);
} }
@ -297,14 +302,14 @@ public class SinkholeService extends VpnService {
long ct = SystemClock.elapsedRealtime(); long ct = SystemClock.elapsedRealtime();
long ctx = TrafficStats.getTotalTxBytes(); long ctx = TrafficStats.getTotalTxBytes();
long rtx = TrafficStats.getTotalRxBytes(); long rtx = TrafficStats.getTotalRxBytes();
if (ct > 0 && (rx > 0 || tx > 0)) { if (t > 0 && tx > 0 && rx > 0) {
float dt = (ct - t) / 1000f; float dt = (ct - t) / 1000f;
txsec = (ctx - tx) / dt; txsec = (ctx - tx) / dt;
rxsec = (rtx - rx) / dt; rxsec = (rtx - rx) / dt;
Log.i(TAG, "tx=" + txsec + " rx=" + rxsec);
gt.add(ct); gt.add(ct);
gtx.add(txsec); gtx.add(txsec);
grx.add(rxsec); grx.add(rxsec);
Log.i(TAG, "tx=" + txsec + " rx=" + rxsec);
} }
t = ct; t = ct;
tx = ctx; tx = ctx;
@ -373,7 +378,12 @@ public class SinkholeService extends VpnService {
// Update remote view // Update remote view
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.traffic); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.traffic);
remoteViews.setImageViewBitmap(R.id.ivTraffic, bitmap); remoteViews.setImageViewBitmap(R.id.ivTraffic, bitmap);
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.0f/%.0f B/sec", txsec, rxsec)); if (txsec < 1024 && rxsec < 1024)
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.0f / %.0f B/sec", txsec, rxsec));
else if (txsec < 1024 * 1024 && rxsec < 1024 * 1024)
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.1f / %.1f KiB/sec", txsec / 1024, rxsec / 1024));
else
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.1f / %.1f MiB/sec", txsec / 1024 / 1024, rxsec / 1024 / 1024));
// Show notification // Show notification
Intent main = new Intent(SinkholeService.this, ActivityMain.class); Intent main = new Intent(SinkholeService.this, ActivityMain.class);