summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt33
1 files changed, 13 insertions, 20 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 1a6d19e3a0..c376a726aa 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
@@ -30,34 +30,27 @@ class ForegroundNotificationManager(
service.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private val listenerId = serviceNotifier.subscribe { newServiceInstance ->
- serviceInstance = newServiceInstance
+ connectionProxy = newServiceInstance?.connectionProxy
}
- 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 {
- connectionListenerId = 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 connectionListenerId: Int? = null
- private var connectionProxy: ConnectionProxy? = null
-
private var onForeground = false
private var reconnecting = false
private var showingReconnecting = false
@@ -197,7 +190,7 @@ class ForegroundNotificationManager(
fun onDestroy() {
serviceNotifier.unsubscribe(listenerId)
- serviceInstance = null
+ connectionProxy = null
service.apply {
unregisterReceiver(connectReceiver)