summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-04-24 19:29:01 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-04-29 11:43:06 +0000
commit67f152a49e83c32490e89bb490aa024e7bd06557 (patch)
tree64e6502edce447f95729dbdc248faf73f69a6c9d /android
parent5e3c2e40d4a01457f0dbe43c0eff54a1d0262bd6 (diff)
downloadmullvadvpn-67f152a49e83c32490e89bb490aa024e7bd06557.tar.xz
mullvadvpn-67f152a49e83c32490e89bb490aa024e7bd06557.zip
Use an IPC connection for the tile service
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt34
1 files changed, 29 insertions, 5 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt
index 61c9c0e196..db9662f5d6 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt
@@ -1,31 +1,52 @@
package net.mullvad.mullvadvpn.service
+import android.content.ComponentName
import android.content.Intent
import android.graphics.drawable.Icon
import android.os.Build
+import android.os.IBinder
+import android.os.Messenger
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.model.TunnelState
-import net.mullvad.mullvadvpn.service.tunnelstate.TunnelStateListener
+import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnection
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
class MullvadTileService : TileService() {
+ private val serviceConnectionManager = object : android.content.ServiceConnection {
+ override fun onServiceConnected(className: ComponentName, binder: IBinder) {
+ serviceConnection = ServiceConnection(Messenger(binder))
+ }
+
+ override fun onServiceDisconnected(className: ComponentName) {
+ serviceConnection = null
+ }
+ }
+
+ private var serviceConnection by observable<ServiceConnection?>(
+ null
+ ) { _, oldConnection, newConnection ->
+ oldConnection?.onDestroy()
+
+ newConnection?.connectionProxy?.run {
+ onStateChange.subscribe(this@MullvadTileService, ::updateTunnelState)
+ }
+ }
+
private var secured by observable(false) { _, wasSecured, isSecured ->
if (wasSecured != isSecured) {
updateTileState()
}
}
- private lateinit var listener: TunnelStateListener
private lateinit var securedIcon: Icon
private lateinit var unsecuredIcon: Icon
override fun onCreate() {
super.onCreate()
- listener = TunnelStateListener(this)
securedIcon = Icon.createWithResource(this, R.drawable.small_logo_white)
unsecuredIcon = Icon.createWithResource(this, R.drawable.small_logo_black)
}
@@ -33,7 +54,9 @@ class MullvadTileService : TileService() {
override fun onStartListening() {
super.onStartListening()
- listener.onStateChange = ::updateTunnelState
+ val intent = Intent(this, MullvadVpnService::class.java)
+
+ bindService(intent, serviceConnectionManager, BIND_IMPORTANT)
updateTileState()
}
@@ -57,7 +80,8 @@ class MullvadTileService : TileService() {
}
override fun onStopListening() {
- listener.onStateChange = null
+ unbindService(serviceConnectionManager)
+ serviceConnection = null
super.onStopListening()
}