diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-12-17 12:17:48 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-12-17 15:54:36 +0000 |
| commit | 09359615cda666c841f3a64183dbbdc31ac2b70e (patch) | |
| tree | 1968b92b348d7460d9c4d98873add1847a6a4333 /android/src | |
| parent | 4ab8371abe991bed692b50378455f7d794fb1cbc (diff) | |
| download | mullvadvpn-09359615cda666c841f3a64183dbbdc31ac2b70e.tar.xz mullvadvpn-09359615cda666c841f3a64183dbbdc31ac2b70e.zip | |
Add a service connection event notifier
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt index 914188a8ab..4780433223 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -23,6 +23,7 @@ import net.mullvad.mullvadvpn.dataproxy.RelayListListener import net.mullvad.mullvadvpn.dataproxy.WwwAuthTokenRetriever import net.mullvad.mullvadvpn.service.MullvadDaemon import net.mullvad.mullvadvpn.service.MullvadVpnService +import net.mullvad.talpid.util.EventNotifier class MainActivity : FragmentActivity() { companion object { @@ -38,6 +39,7 @@ class MainActivity : FragmentActivity() { private set val problemReport = MullvadProblemReport() + val serviceNotifier = EventNotifier<ServiceConnection?>(null) val appVersionInfoCache: AppVersionInfoCache get() = serviceConnection!!.appVersionInfoCache @@ -65,9 +67,12 @@ class MainActivity : FragmentActivity() { serviceConnectionSubscription = localBinder.serviceNotifier.subscribe { service -> serviceConnection?.onDestroy() - serviceConnection = service?.let { service -> + val newConnection = service?.let { service -> ServiceConnection(service, this@MainActivity) } + + serviceConnection = newConnection + serviceNotifier.notify(newConnection) } waitForDaemonJob = GlobalScope.launch(Dispatchers.Default) { @@ -93,6 +98,8 @@ class MainActivity : FragmentActivity() { service = CompletableDeferred<MullvadVpnService.LocalBinder>() daemon = CompletableDeferred<MullvadDaemon>() + + serviceNotifier.notify(null) } } @@ -125,6 +132,8 @@ class MainActivity : FragmentActivity() { override fun onStop() { quitJob?.cancel() + serviceNotifier.unsubscribeAll() + serviceToStop?.apply { stop() } unbindService(serviceConnectionManager) |
