summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-05 14:45:17 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-04-12 13:19:37 +0000
commit4d74d26765c57e70716329ec1cb20b2dbf5bca68 (patch)
treef40ad94bafe07e9e99791a4bbee8bc387e7f56a8 /android/src
parent0080af7e7854f4b806202c509d5468b9b459f97b (diff)
downloadmullvadvpn-4d74d26765c57e70716329ec1cb20b2dbf5bca68.tar.xz
mullvadvpn-4d74d26765c57e70716329ec1cb20b2dbf5bca68.zip
Use `ConnectionProxy` in notification manager
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt21
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt2
2 files changed, 7 insertions, 16 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 7138e0ebae..f1221fa307 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
@@ -14,13 +14,13 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.sendBlocking
import net.mullvad.mullvadvpn.model.TunnelState
+import net.mullvad.mullvadvpn.service.endpoint.ConnectionProxy
import net.mullvad.mullvadvpn.service.notifications.TunnelStateNotification
-import net.mullvad.talpid.util.EventNotifier
import net.mullvad.talpid.util.autoSubscribable
class ForegroundNotificationManager(
val service: MullvadVpnService,
- val serviceNotifier: EventNotifier<ServiceInstance?>,
+ val connectionProxy: ConnectionProxy,
val keyguardManager: KeyguardManager
) {
private sealed class UpdaterMessage {
@@ -43,13 +43,6 @@ class ForegroundNotificationManager(
}
}
- private var tunnelStateEvents by autoSubscribable<TunnelState>(
- this,
- TunnelState.Disconnected
- ) { newState ->
- updater.sendBlocking(UpdaterMessage.NewTunnelState(newState))
- }
-
private var deviceIsUnlocked by observable(!keyguardManager.isDeviceLocked) { _, _, _ ->
updater.sendBlocking(UpdaterMessage.UpdateAction())
}
@@ -59,7 +52,7 @@ class ForegroundNotificationManager(
}
private val tunnelState
- get() = tunnelStateEvents?.latestEvent ?: TunnelState.Disconnected
+ get() = connectionProxy.onStateChange.latestEvent
private val shouldBeOnForeground
get() = lockedToForeground || !(tunnelState is TunnelState.Disconnected)
@@ -76,8 +69,8 @@ class ForegroundNotificationManager(
}
init {
- serviceNotifier.subscribe(this) { newServiceInstance ->
- tunnelStateEvents = newServiceInstance?.connectionProxy?.onStateChange
+ connectionProxy.onStateChange.subscribe(this) { newState ->
+ updater.sendBlocking(UpdaterMessage.NewTunnelState(newState))
}
service.apply {
@@ -94,11 +87,9 @@ class ForegroundNotificationManager(
}
fun onDestroy() {
- serviceNotifier.unsubscribe(this)
-
accountNumberEvents = null
- tunnelStateEvents = null
+ connectionProxy.onStateChange.unsubscribe(this)
service.unregisterReceiver(deviceLockListener)
updater.close()
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 3665a2b7e2..0988fcf035 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -112,7 +112,7 @@ class MullvadVpnService : TalpidVpnService() {
)
notificationManager =
- ForegroundNotificationManager(this, serviceNotifier, keyguardManager).apply {
+ ForegroundNotificationManager(this, connectionProxy, keyguardManager).apply {
acknowledgeStartForegroundService()
accountNumberEvents = endpoint.settingsListener.accountNumberNotifier
}