Commit 95952f0f authored by Mygod's avatar Mygod

Fix division by zero

parent eed2f47c
package com.github.shadowsocks.utils
import java.lang.{Math, System}
import java.util.Locale
import android.net.TrafficStats
import android.os.Process
import java.lang.{String, System, Math}
import java.util.Locale
case class Traffic(tx: Long, rx: Long, timestamp: Long)
......@@ -40,8 +41,11 @@ object TrafficMonitor {
def update() {
val now = getTraffic
txRate = (now.tx - last.tx) / (now.timestamp - last.timestamp)
rxRate = (now.rx - last.rx) / (now.timestamp - last.timestamp)
val delta = now.timestamp - last.timestamp
if (delta != 0) {
txRate = (now.tx - last.tx) / delta
rxRate = (now.rx - last.rx) / delta
}
txTotal += (now.tx - last.tx) / 1024
rxTotal += (now.rx - last.rx) / 1024
last = now
......
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