diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-12-07 14:25:15 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-12-13 11:33:16 +0000 |
| commit | bdbd3d107eeb3472513a3ce790e81022b151c607 (patch) | |
| tree | 6c2301fe973a3dffd00fa769b0845f5242551032 /android/src/main | |
| parent | bf513dd8f7e297da4dab8ba1a6cfd8837b69caa2 (diff) | |
| download | mullvadvpn-bdbd3d107eeb3472513a3ce790e81022b151c607.tar.xz mullvadvpn-bdbd3d107eeb3472513a3ce790e81022b151c607.zip | |
Add `ServiceInstance` notifier to the service
Diffstat (limited to 'android/src/main')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 7b3bfaea8e..7423b91586 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking import net.mullvad.mullvadvpn.dataproxy.ConnectionProxy import net.mullvad.talpid.TalpidVpnService +import net.mullvad.talpid.util.EventNotifier class MullvadVpnService : TalpidVpnService() { private val binder = LocalBinder() @@ -21,6 +22,8 @@ class MullvadVpnService : TalpidVpnService() { private lateinit var connectionProxy: ConnectionProxy private lateinit var notificationManager: ForegroundNotificationManager + private var serviceNotifier = EventNotifier<ServiceInstance?>(null) + override fun onCreate() { super.onCreate() setUp() @@ -51,6 +54,8 @@ class MullvadVpnService : TalpidVpnService() { inner class LocalBinder : Binder() { val daemon get() = this@MullvadVpnService.daemon + val serviceNotifier + get() = this@MullvadVpnService.serviceNotifier val connectionProxy get() = this@MullvadVpnService.connectionProxy val connectivityListener @@ -72,11 +77,15 @@ class MullvadVpnService : TalpidVpnService() { private fun startDaemon() = GlobalScope.async(Dispatchers.Default) { ApiRootCaFile().extract(application) - MullvadDaemon(this@MullvadVpnService).apply { + val daemon = MullvadDaemon(this@MullvadVpnService).apply { onSettingsChange.subscribe { settings -> notificationManager.loggedIn = settings?.accountToken != null } } + + serviceNotifier.notify(ServiceInstance(daemon, connectionProxy, connectivityListener)) + + daemon } private fun startNotificationManager(): ForegroundNotificationManager { @@ -89,6 +98,8 @@ class MullvadVpnService : TalpidVpnService() { private fun stop() { resetComplete = CompletableDeferred() + serviceNotifier.notify(null) + if (daemon.isCompleted) { runBlocking { daemon.await().shutdown() } } else { |
