Commit 07b9cfa7 authored by Max Lv's avatar Max Lv

refine the traffic stat

parent e667a77b
...@@ -471,7 +471,11 @@ class Shadowsocks ...@@ -471,7 +471,11 @@ class Shadowsocks
// initialize timer // initialize timer
val task = new TimerTask { val task = new TimerTask {
def run() { def run() {
if (state == State.CONNECTED) {
TrafficMonitor.update() TrafficMonitor.update()
} else {
TrafficMonitor.reset()
}
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager] val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
if (pm.isScreenOn) { if (pm.isScreenOn) {
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH, val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
......
...@@ -20,8 +20,8 @@ object TrafficMonitor { ...@@ -20,8 +20,8 @@ object TrafficMonitor {
var rxTotal: Long = 0 var rxTotal: Long = 0
def getTraffic(): Traffic = { def getTraffic(): Traffic = {
new Traffic(TrafficStats.getUidTxBytes(uid), new Traffic(TrafficStats.getTotalTxBytes - TrafficStats.getUidTxBytes(uid),
TrafficStats.getUidRxBytes(uid), System.currentTimeMillis()) TrafficStats.getTotalRxBytes - TrafficStats.getUidRxBytes(uid), System.currentTimeMillis())
} }
def formatTraffic(n: Long): String = { def formatTraffic(n: Long): String = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment