summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-02 19:32:26 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-03-25 18:19:59 +0000
commitcc0132942473975ce1e95420841efec6c9c181f0 (patch)
tree3808abb724904c07d769e7d2ca733118e8f53f2c /android/src/main
parent04be7025554d441490a751eb3cdb042f8f270585 (diff)
downloadmullvadvpn-cc0132942473975ce1e95420841efec6c9c181f0.tar.xz
mullvadvpn-cc0132942473975ce1e95420841efec6c9c181f0.zip
Move `LocationInfoCache` into `ServiceEndpoint`
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt10
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt9
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt (renamed from android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt)22
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt7
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt2
5 files changed, 26 insertions, 24 deletions
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 3e3b81bad2..bcd9df4128 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -105,7 +105,11 @@ class MullvadVpnService : TalpidVpnService() {
notificationManager = ForegroundNotificationManager(this, serviceNotifier, keyguardManager)
tunnelStateUpdater = TunnelStateUpdater(this, serviceNotifier)
- endpoint = ServiceEndpoint(Looper.getMainLooper(), daemonInstance.intermittentDaemon)
+ endpoint = ServiceEndpoint(
+ Looper.getMainLooper(),
+ daemonInstance.intermittentDaemon,
+ connectivityListener
+ )
notificationManager.acknowledgeStartForegroundService()
@@ -243,14 +247,16 @@ class MullvadVpnService : TalpidVpnService() {
handlePendingAction(connectionProxy, settings)
+ endpoint.locationInfoCache.stateEvents = connectionProxy.onStateChange
+
if (state == State.Running) {
instance = ServiceInstance(
endpoint.messenger,
daemon,
daemonInstance.intermittentDaemon,
connectionProxy,
- connectivityListener,
customDns,
+ endpoint.locationInfoCache,
endpoint.settingsListener,
splitTunneling
)
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt
index cc6e3fdbb5..4101ce604f 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt
@@ -1,28 +1,23 @@
package net.mullvad.mullvadvpn.service
import android.os.Messenger
+import net.mullvad.mullvadvpn.service.endpoint.LocationInfoCache
import net.mullvad.mullvadvpn.service.endpoint.SettingsListener
import net.mullvad.mullvadvpn.util.Intermittent
-import net.mullvad.talpid.ConnectivityListener
class ServiceInstance(
val messenger: Messenger,
val daemon: MullvadDaemon,
val intermittentDaemon: Intermittent<MullvadDaemon>,
val connectionProxy: ConnectionProxy,
- val connectivityListener: ConnectivityListener,
val customDns: CustomDns,
+ val locationInfoCache: LocationInfoCache,
val settingsListener: SettingsListener,
val splitTunneling: SplitTunneling
) {
val accountCache = AccountCache(daemon, settingsListener)
val keyStatusListener = KeyStatusListener(daemon)
- val locationInfoCache =
- LocationInfoCache(connectivityListener, settingsListener, intermittentDaemon).apply {
- stateEvents = connectionProxy.onStateChange
- }
-
fun onDestroy() {
accountCache.onDestroy()
connectionProxy.onDestroy()
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
index e8136ce5ed..ce1edd1b3f 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
@@ -1,4 +1,4 @@
-package net.mullvad.mullvadvpn.service
+package net.mullvad.mullvadvpn.service.endpoint
import kotlin.properties.Delegates.observable
import kotlinx.coroutines.Dispatchers
@@ -14,18 +14,11 @@ import net.mullvad.mullvadvpn.model.Constraint
import net.mullvad.mullvadvpn.model.GeoIpLocation
import net.mullvad.mullvadvpn.model.RelaySettings
import net.mullvad.mullvadvpn.model.TunnelState
-import net.mullvad.mullvadvpn.service.endpoint.SettingsListener
import net.mullvad.mullvadvpn.util.ExponentialBackoff
-import net.mullvad.mullvadvpn.util.Intermittent
-import net.mullvad.talpid.ConnectivityListener
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
import net.mullvad.talpid.util.autoSubscribable
-class LocationInfoCache(
- val connectivityListener: ConnectivityListener,
- val settingsListener: SettingsListener,
- val daemon: Intermittent<MullvadDaemon>
-) {
+class LocationInfoCache(private val endpoint: ServiceEndpoint) {
companion object {
private enum class RequestFetch {
ForRealLocation,
@@ -35,6 +28,9 @@ class LocationInfoCache(
private val fetchRequestChannel = runFetcher()
+ private val daemon
+ get() = endpoint.intermittentDaemon
+
private var lastKnownRealLocation: GeoIpLocation? = null
private var selectedRelayLocation: GeoIpLocation? = null
@@ -73,18 +69,18 @@ class LocationInfoCache(
}
init {
- connectivityListener.connectivityNotifier.subscribe(this) { isConnected ->
+ endpoint.connectivityListener.connectivityNotifier.subscribe(this) { isConnected ->
if (isConnected && state is TunnelState.Disconnected) {
fetchRequestChannel.sendBlocking(RequestFetch.ForRealLocation)
}
}
- settingsListener.relaySettingsNotifier.subscribe(this, ::updateSelectedLocation)
+ endpoint.settingsListener.relaySettingsNotifier.subscribe(this, ::updateSelectedLocation)
}
fun onDestroy() {
- connectivityListener.connectivityNotifier.unsubscribe(this)
- settingsListener.relaySettingsNotifier.unsubscribe(this)
+ endpoint.connectivityListener.connectivityNotifier.unsubscribe(this)
+ endpoint.settingsListener.relaySettingsNotifier.unsubscribe(this)
stateEvents = null
fetchRequestChannel.close()
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
index b9258c50ac..043afe4cfe 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
@@ -15,10 +15,12 @@ import net.mullvad.mullvadvpn.ipc.Event
import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.mullvadvpn.service.MullvadDaemon
import net.mullvad.mullvadvpn.util.Intermittent
+import net.mullvad.talpid.ConnectivityListener
class ServiceEndpoint(
looper: Looper,
- internal val intermittentDaemon: Intermittent<MullvadDaemon>
+ internal val intermittentDaemon: Intermittent<MullvadDaemon>,
+ val connectivityListener: ConnectivityListener
) {
private val listeners = mutableSetOf<Messenger>()
private val registrationQueue: SendChannel<Messenger> = startRegistrator()
@@ -31,6 +33,8 @@ class ServiceEndpoint(
val settingsListener = SettingsListener(this)
+ val locationInfoCache = LocationInfoCache(this)
+
init {
dispatcher.registerHandler(Request.RegisterListener::class) { request ->
registrationQueue.sendBlocking(request.listener)
@@ -41,6 +45,7 @@ class ServiceEndpoint(
dispatcher.onDestroy()
registrationQueue.close()
+ locationInfoCache.onDestroy()
settingsListener.onDestroy()
}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt
index 6ff8b8c488..3d5d8e8a28 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt
@@ -11,9 +11,9 @@ import net.mullvad.mullvadvpn.service.AccountCache
import net.mullvad.mullvadvpn.service.ConnectionProxy
import net.mullvad.mullvadvpn.service.CustomDns
import net.mullvad.mullvadvpn.service.KeyStatusListener
-import net.mullvad.mullvadvpn.service.LocationInfoCache
import net.mullvad.mullvadvpn.service.MullvadDaemon
import net.mullvad.mullvadvpn.service.SplitTunneling
+import net.mullvad.mullvadvpn.service.endpoint.LocationInfoCache
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnection
import net.mullvad.mullvadvpn.ui.serviceconnection.SettingsListener