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.kt58
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt7
2 files changed, 36 insertions, 29 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 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()