diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-11 10:12:00 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-11 10:12:00 -0300 |
| commit | 98100c0610508326919e4cd423e1cb70d947bd05 (patch) | |
| tree | 8e214e9a6e8817d03591b6ffa5c5f82171d3ebff | |
| parent | 15c9308491b2ea0b50c3f77efd0d2861e9b6c605 (diff) | |
| parent | c6ae89be2f4f99025f4e8ac4deded600e73169fa (diff) | |
| download | mullvadvpn-98100c0610508326919e4cd423e1cb70d947bd05.tar.xz mullvadvpn-98100c0610508326919e4cd423e1cb70d947bd05.zip | |
Merge branch 'fix-leftover-notification'
3 files changed, 37 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 129fc3d48e..24be9f238c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Line wrap the file at 100 chars. Th - Fix version update notifications not appearing. - Fix UI losing any settings updates that happen after leaving the app and then coming back. - Fix account expiration date disappearing in some circumstances. +- Fix notification reappearing after quitting the application. ## [2020.4-beta4] - 2020-05-06 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 bae29762e6..449f62aa6c 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt @@ -30,33 +30,43 @@ class ForegroundNotificationManager( service.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager private val listenerId = serviceNotifier.subscribe { newServiceInstance -> - serviceInstance = newServiceInstance + connectionProxy = newServiceInstance?.connectionProxy + settingsListener = newServiceInstance?.settingsListener } - private var serviceInstance: ServiceInstance? = null + private val badgeColor = service.resources.getColor(R.color.colorPrimary) + + private var connectionListenerId: Int? = null + private var connectionProxy: ConnectionProxy? = null set(value) { - synchronized(this) { - if (value != null) { - connectionProxy = value.connectionProxy.apply { - onStateChange.subscribe { state -> - tunnelState = state - } - } - } else { - connectionProxy = null - connectionListenerId?.let { listenerId -> - field?.connectionProxy?.onStateChange?.unsubscribe(listenerId) - } + if (field != value) { + connectionListenerId?.let { listenerId -> + field?.onStateChange?.unsubscribe(listenerId) + } + + connectionListenerId = value?.onStateChange?.subscribe { state -> + tunnelState = state } field = value } } - private val badgeColor = service.resources.getColor(R.color.colorPrimary) + private var loginListenerId: Int? = null + private var settingsListener: SettingsListener? = null + set(value) { + if (field != value) { + loginListenerId?.let { listenerId -> + field?.accountNumberNotifier?.unsubscribe(listenerId) + } - private var connectionListenerId: Int? = null - private var connectionProxy: ConnectionProxy? = null + loginListenerId = value?.accountNumberNotifier?.subscribe { accountNumber -> + loggedIn = accountNumber != null + } + + field = value + } + } private var onForeground = false private var reconnecting = false @@ -74,6 +84,12 @@ class ForegroundNotificationManager( updateNotification() } + private var loggedIn = false + set(value) { + field = value + updateNotification() + } + private val shouldBeOnForeground get() = lockedToForeground || !(tunnelState is TunnelState.Disconnected) @@ -170,12 +186,6 @@ class ForegroundNotificationManager( } } - var loggedIn = false - set(value) { - field = value - updateNotification() - } - var lockedToForeground = false set(value) { field = value @@ -197,6 +207,8 @@ 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() |
