fix speed info
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
<!-- notification category -->
|
||||
<string name="forward_success">Shadowsocks started.</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="service_stopped">Shadowsocks stopped.</string>
|
||||
<string name="forward_stop">Shadowsocks stopped.</string>
|
||||
|
||||
@@ -95,6 +95,7 @@ class ShadowsocksService extends Service {
|
||||
var config: Config = null
|
||||
var hasRedirectSupport = false
|
||||
var apps: Array[ProxiedApp] = null
|
||||
val uid = Process.myUid()
|
||||
|
||||
private var mSetForeground: Method = null
|
||||
private var mStartForeground: Method = null
|
||||
@@ -200,8 +201,8 @@ class ShadowsocksService extends Service {
|
||||
val task = new TimerTask {
|
||||
def run() {
|
||||
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
|
||||
val now = new TrafficStat(TrafficStats.getTotalTxBytes,
|
||||
TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis())
|
||||
val now = new TrafficStat(TrafficStats.getUidTxBytes(uid),
|
||||
TrafficStats.getUidRxBytes(uid), java.lang.System.currentTimeMillis())
|
||||
val txRate = ((now.tx - last.tx) / 1024 / TIMER_INTERVAL).toInt
|
||||
val rxRate = ((now.rx - last.rx) / 1024 / TIMER_INTERVAL).toInt
|
||||
last = now
|
||||
@@ -213,12 +214,12 @@ class ShadowsocksService extends Service {
|
||||
}
|
||||
if (pm.isScreenOn && state == State.CONNECTED) {
|
||||
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,
|
||||
TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis())
|
||||
last = new TrafficStat(TrafficStats.getUidTxBytes(uid),
|
||||
TrafficStats.getUidRxBytes(uid), java.lang.System.currentTimeMillis())
|
||||
timer = new Timer(true)
|
||||
timer.schedule(task, TIMER_INTERVAL * 1000, TIMER_INTERVAL * 1000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user