diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 98360ce9..8b9f7224 100755 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -44,7 +44,7 @@ Shadowsocks started. Running in the background. - Upload: %d KB/s, Download: %d KB/s + Upload: %d KB/s\t|\tDownload: %d KB/s Shadowsocks failed to start. Shadowsocks stopped. Shadowsocks stopped. diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksService.scala index 02ff385e..f0fcd329 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksService.scala @@ -120,8 +120,10 @@ class ShadowsocksService extends Service { private var state = State.INIT private var last = new TrafficStat(TrafficStats.getTotalTxBytes, TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis()) + private var lastTxRate = 0 + private var lastRxRate = 0 private val timer = new Timer(true) - private val TIMER_INTERVAL = 5 + private val TIMER_INTERVAL = 1 private def changeState(s: Int) { if (state != s) { @@ -412,13 +414,19 @@ class ShadowsocksService extends Service { def run() { val now = new TrafficStat(TrafficStats.getTotalTxBytes, TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis()) - val txRate = (now.tx - last.tx) / 1024 / TIMER_INTERVAL - val rxRate = (now.rx - last.rx) / 1024 / TIMER_INTERVAL + val txRate = ((now.tx - last.tx) / 1024 / TIMER_INTERVAL).toInt + val rxRate = ((now.rx - last.rx) / 1024 / TIMER_INTERVAL).toInt last = now + if (lastTxRate == txRate && lastRxRate == rxRate) { + return + } else { + lastTxRate = txRate + lastRxRate = rxRate + } if (state == State.CONNECTED) { Log.d(TAG, getString(R.string.service_status).format(txRate, rxRate)) notifyForegroundAlert(getString(R.string.forward_success), - getString(R.string.service_status).format(txRate, rxRate), txRate.toInt + rxRate.toInt) + getString(R.string.service_status).format(txRate, rxRate), txRate + rxRate) } } }