diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-09 19:28:36 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-11 12:54:16 +0000 |
| commit | e513479c9514bd8428cfffcc88b192a092fd2c6b (patch) | |
| tree | 2c40c62036aff4a57f782861cc65d1a691c3b334 /android/src/main | |
| parent | 08fb72d28d60f866478be3eb8df2ea8aebff4554 (diff) | |
| download | mullvadvpn-e513479c9514bd8428cfffcc88b192a092fd2c6b.tar.xz mullvadvpn-e513479c9514bd8428cfffcc88b192a092fd2c6b.zip | |
Handle login listener separately
Diffstat (limited to 'android/src/main')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt | 30 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 7 |
2 files changed, 25 insertions, 12 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt index c376a726aa..449f62aa6c 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt @@ -31,6 +31,7 @@ class ForegroundNotificationManager( private val listenerId = serviceNotifier.subscribe { newServiceInstance -> connectionProxy = newServiceInstance?.connectionProxy + settingsListener = newServiceInstance?.settingsListener } private val badgeColor = service.resources.getColor(R.color.colorPrimary) @@ -51,6 +52,22 @@ class ForegroundNotificationManager( } } + private var loginListenerId: Int? = null + private var settingsListener: SettingsListener? = null + set(value) { + if (field != value) { + loginListenerId?.let { listenerId -> + field?.accountNumberNotifier?.unsubscribe(listenerId) + } + + loginListenerId = value?.accountNumberNotifier?.subscribe { accountNumber -> + loggedIn = accountNumber != null + } + + field = value + } + } + private var onForeground = false private var reconnecting = false private var showingReconnecting = false @@ -67,6 +84,12 @@ class ForegroundNotificationManager( updateNotification() } + private var loggedIn = false + set(value) { + field = value + updateNotification() + } + private val shouldBeOnForeground get() = lockedToForeground || !(tunnelState is TunnelState.Disconnected) @@ -163,12 +186,6 @@ class ForegroundNotificationManager( } } - var loggedIn = false - set(value) { - field = value - updateNotification() - } - var lockedToForeground = false set(value) { field = value @@ -191,6 +208,7 @@ class ForegroundNotificationManager( fun onDestroy() { serviceNotifier.unsubscribe(listenerId) connectionProxy = null + settingsListener = null service.apply { unregisterReceiver(connectReceiver) 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 ae44ed7e8f..44cbf5ae6f 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -27,6 +27,7 @@ class MullvadVpnService : TalpidVpnService() { private val serviceNotifier = EventNotifier<ServiceInstance?>(null) private var isStopping = false + private var loggedIn = false private var startDaemonJob: Job? = null @@ -69,12 +70,6 @@ class MullvadVpnService : TalpidVpnService() { notificationManager.lockedToForeground = value } - private var loggedIn = false - set(value) { - field = value - notificationManager.loggedIn = value - } - override fun onCreate() { super.onCreate() |
