Commit 02fc0b88 authored by Max Lv's avatar Max Lv

fix speed info

parent 6139e52a
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<!-- notification category --> <!-- notification category -->
<string name="forward_success">Shadowsocks started.</string> <string name="forward_success">Shadowsocks started.</string>
<string name="service_running">Running in the background.</string> <string name="service_running">Running in the background.</string>
<string name="service_status" formatted="false">Upload: %d KB/s\t|\tDownload: %d KB/s</string> <string name="service_status" formatted="false">Current Speed: %d KB/s</string>
<string name="forward_fail">Shadowsocks failed to start.</string> <string name="forward_fail">Shadowsocks failed to start.</string>
<string name="service_stopped">Shadowsocks stopped.</string> <string name="service_stopped">Shadowsocks stopped.</string>
<string name="forward_stop">Shadowsocks stopped.</string> <string name="forward_stop">Shadowsocks stopped.</string>
......
...@@ -95,6 +95,7 @@ class ShadowsocksService extends Service { ...@@ -95,6 +95,7 @@ class ShadowsocksService extends Service {
var config: Config = null var config: Config = null
var hasRedirectSupport = false var hasRedirectSupport = false
var apps: Array[ProxiedApp] = null var apps: Array[ProxiedApp] = null
val uid = Process.myUid()
private var mSetForeground: Method = null private var mSetForeground: Method = null
private var mStartForeground: Method = null private var mStartForeground: Method = null
...@@ -200,8 +201,8 @@ class ShadowsocksService extends Service { ...@@ -200,8 +201,8 @@ class ShadowsocksService extends Service {
val task = new TimerTask { val task = new TimerTask {
def run() { def run() {
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager] val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
val now = new TrafficStat(TrafficStats.getTotalTxBytes, val now = new TrafficStat(TrafficStats.getUidTxBytes(uid),
TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis()) TrafficStats.getUidRxBytes(uid), java.lang.System.currentTimeMillis())
val txRate = ((now.tx - last.tx) / 1024 / TIMER_INTERVAL).toInt val txRate = ((now.tx - last.tx) / 1024 / TIMER_INTERVAL).toInt
val rxRate = ((now.rx - last.rx) / 1024 / TIMER_INTERVAL).toInt val rxRate = ((now.rx - last.rx) / 1024 / TIMER_INTERVAL).toInt
last = now last = now
...@@ -213,12 +214,12 @@ class ShadowsocksService extends Service { ...@@ -213,12 +214,12 @@ class ShadowsocksService extends Service {
} }
if (pm.isScreenOn && state == State.CONNECTED) { if (pm.isScreenOn && state == State.CONNECTED) {
notifyForegroundAlert(getString(R.string.forward_success), notifyForegroundAlert(getString(R.string.forward_success),
getString(R.string.service_status).format(txRate, rxRate), txRate + rxRate) getString(R.string.service_status).format(math.max(txRate, rxRate)), math.max(txRate, rxRate))
} }
} }
} }
last = new TrafficStat(TrafficStats.getTotalTxBytes, last = new TrafficStat(TrafficStats.getUidTxBytes(uid),
TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis()) TrafficStats.getUidRxBytes(uid), java.lang.System.currentTimeMillis())
timer = new Timer(true) timer = new Timer(true)
timer.schedule(task, TIMER_INTERVAL * 1000, TIMER_INTERVAL * 1000) timer.schedule(task, TIMER_INTERVAL * 1000, TIMER_INTERVAL * 1000)
} }
......
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