minor: disable stats job when app is closed
Adds a slight battery performance improvement #437
This commit is contained in:
parent
f79f922838
commit
9a2d77c8bf
|
@ -273,7 +273,7 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val STATS_START_DELAY = 5_000L
|
const val STATS_START_DELAY = 1_000L
|
||||||
const val VPN_STATISTIC_CHECK_INTERVAL = 1_000L
|
const val VPN_STATISTIC_CHECK_INTERVAL = 1_000L
|
||||||
const val VPN_RESTART_DELAY = 1_000L
|
const val VPN_RESTART_DELAY = 1_000L
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun initTunnel() {
|
private suspend fun initTunnel() {
|
||||||
|
if (tunnelService.get().getState() == TunnelState.UP) tunnelService.get().startStatsJob()
|
||||||
val activeTunnels = appDataRepository.tunnels.getActive()
|
val activeTunnels = appDataRepository.tunnels.getActive()
|
||||||
if (activeTunnels.isNotEmpty() &&
|
if (activeTunnels.isNotEmpty() &&
|
||||||
tunnelService.get().getState() == TunnelState.DOWN
|
tunnelService.get().getState() == TunnelState.DOWN
|
||||||
|
|
|
@ -215,4 +215,9 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
// save battery by not polling stats while app is closed
|
||||||
|
tunnelService.cancelStatsJob()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,8 +182,7 @@ object LogcatCollector {
|
||||||
clear()
|
clear()
|
||||||
logcatProc = Runtime.getRuntime().exec(command)
|
logcatProc = Runtime.getRuntime().exec(command)
|
||||||
reader = BufferedReader(InputStreamReader(logcatProc!!.inputStream), 1024)
|
reader = BufferedReader(InputStreamReader(logcatProc!!.inputStream), 1024)
|
||||||
var line: String? = null
|
var line: String?
|
||||||
|
|
||||||
while (!stopped) {
|
while (!stopped) {
|
||||||
if (paused) continue
|
if (paused) continue
|
||||||
line = reader?.readLine()
|
line = reader?.readLine()
|
||||||
|
|
Loading…
Reference in New Issue