aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRoger Chuang <lchuang@mozilla.com>2019-11-29 02:16:54 +0800
committerRoger Chuang <lchuang@mozilla.com>2019-11-29 02:16:54 +0800
commit8e3651d800811879a7035d4d2bae0920cb495b6f (patch)
tree3f3fcdfbce730edece5b5cd39edf66280235c8d0
parentClear tunnel's tunnelHandle once it's down, so tunnel.state can return correct tunnel state (diff)
downloadwireguard-android-8e3651d800811879a7035d4d2bae0920cb495b6f.tar.xz
wireguard-android-8e3651d800811879a7035d4d2bae0920cb495b6f.zip
Add up duration interface to TunnelManager.kt
Signed-off-by: Roger Chuang <lchuang@mozilla.com>
-rw-r--r--libwg/src/main/java/com/wireguard/android/backend/TunnelManager.kt15
1 files changed, 14 insertions, 1 deletions
diff --git a/libwg/src/main/java/com/wireguard/android/backend/TunnelManager.kt b/libwg/src/main/java/com/wireguard/android/backend/TunnelManager.kt
index 35f8140a..4d3e2e14 100644
--- a/libwg/src/main/java/com/wireguard/android/backend/TunnelManager.kt
+++ b/libwg/src/main/java/com/wireguard/android/backend/TunnelManager.kt
@@ -33,6 +33,16 @@ class TunnelManager(
var currentTunnel: Tunnel? = null
var currentService: VpnService? = null
+ private var upTime = 0L
+ val upDuration: Long
+ get() {
+ return if (isConnected()) {
+ SystemClock.elapsedRealtime() - upTime
+ } else {
+ 0L
+ }
+ }
+
interface VpnBuilderProvider {
fun patchBuilder(builder: android.net.VpnService.Builder): android.net.VpnService.Builder
}
@@ -40,6 +50,7 @@ class TunnelManager(
fun tunnelDown() {
currentTunnel?.let { backend.tunnelDown(it) }
currentService = null
+ upTime = 0L
}
fun tunnelUp(tunnel: Tunnel) {
@@ -53,9 +64,11 @@ class TunnelManager(
applyConfig(config)
establish()?.let { fd ->
backend.tunnelUp(tunnel, fd, config.toWgUserspaceString())
+ if (upTime == 0L) {
+ upTime = SystemClock.elapsedRealtime()
+ }
}
}
-
}
appContext.startService(Intent(appContext, VpnService::class.java).apply {