summaryrefslogtreecommitdiffhomepage
path: root/android/service/src
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson90@gmail.com>2023-09-29 20:09:39 +0200
committerDavid Göransson <david.goransson90@gmail.com>2023-10-02 16:06:03 +0200
commit5052cdea50ce6d00a444dfd4c3811cf1dadaeb25 (patch)
treea2d916b2b8e6d715fbcd0ade05bf7d2b44785dc0 /android/service/src
parente51bb93ed06366a9922700e7bb3c8129b5974a31 (diff)
downloadmullvadvpn-5052cdea50ce6d00a444dfd4c3811cf1dadaeb25.tar.xz
mullvadvpn-5052cdea50ce6d00a444dfd4c3811cf1dadaeb25.zip
Add class test and fix issues
Diffstat (limited to 'android/service/src')
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt15
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt19
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt12
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt13
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt13
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt15
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt11
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt8
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt44
9 files changed, 78 insertions, 72 deletions
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
index 3f7149b282..cd05d5cc71 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -28,13 +28,6 @@ import net.mullvad.talpid.TalpidVpnService
import org.koin.core.context.loadKoinModules
class MullvadVpnService : TalpidVpnService() {
- companion object {
- private val TAG = "mullvad"
-
- init {
- System.loadLibrary("mullvad_jni")
- }
- }
private enum class PendingAction {
Connect,
@@ -273,4 +266,12 @@ class MullvadVpnService : TalpidVpnService() {
startActivity(intent)
}
+
+ companion object {
+ private val TAG = "mullvad"
+
+ init {
+ System.loadLibrary("mullvad_jni")
+ }
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
index d6ba237f97..ba470a6b24 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
@@ -17,15 +17,6 @@ import net.mullvad.mullvadvpn.model.GetAccountDataResult
import net.mullvad.talpid.util.EventNotifier
class AccountCache(private val endpoint: ServiceEndpoint) {
- companion object {
- private sealed class Command {
- object CreateAccount : Command()
-
- data class Login(val account: String) : Command()
-
- object Logout : Command()
- }
- }
private val commandChannel = spawnActor()
@@ -179,4 +170,14 @@ class AccountCache(private val endpoint: ServiceEndpoint) {
private suspend fun fetchAccountData(accountToken: String): GetAccountDataResult {
return daemon.await().getAccountData(accountToken)
}
+
+ companion object {
+ private sealed class Command {
+ object CreateAccount : Command()
+
+ data class Login(val account: String) : Command()
+
+ object Logout : Command()
+ }
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt
index 6506c0469d..08b0943c4d 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt
@@ -11,12 +11,6 @@ import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.Request
class AuthTokenCache(endpoint: ServiceEndpoint) {
- companion object {
- private enum class Command {
- Fetch
- }
- }
-
private val daemon = endpoint.intermittentDaemon
private val requestQueue = spawnActor()
@@ -46,4 +40,10 @@ class AuthTokenCache(endpoint: ServiceEndpoint) {
// Closed sender, so stop the actor
}
}
+
+ companion object {
+ private enum class Command {
+ Fetch
+ }
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
index e050421699..2d06cc109f 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
@@ -22,12 +22,6 @@ import net.mullvad.mullvadvpn.service.util.ExponentialBackoff
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
class LocationInfoCache(private val endpoint: ServiceEndpoint) {
- companion object {
- private enum class RequestFetch {
- ForRealLocation,
- ForRelayLocation,
- }
- }
private val fetchRetryDelays =
ExponentialBackoff().apply {
@@ -135,4 +129,11 @@ class LocationInfoCache(private val endpoint: ServiceEndpoint) {
selectedRelayLocation = constraint?.value?.toGeographicLocationConstraint()?.location
}
+
+ companion object {
+ private enum class RequestFetch {
+ ForRealLocation,
+ ForRelayLocation,
+ }
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
index 1abf64907c..09f90a44d5 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
@@ -19,12 +19,6 @@ import net.mullvad.mullvadvpn.model.WireguardConstraints
import net.mullvad.mullvadvpn.service.MullvadDaemon
class RelayListListener(endpoint: ServiceEndpoint) {
- companion object {
- private enum class Command {
- SetRelayLocation,
- SetWireguardConstraints
- }
- }
private val commandChannel = spawnActor()
private val daemon = endpoint.intermittentDaemon
@@ -105,4 +99,11 @@ class RelayListListener(endpoint: ServiceEndpoint) {
daemon.await().updateRelaySettings(update)
}
+
+ companion object {
+ private enum class Command {
+ SetRelayLocation,
+ SetWireguardConstraints
+ }
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
index e9aa8d4328..fe7ddb75e9 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
@@ -27,13 +27,6 @@ class ServiceEndpoint(
val connectivityListener: ConnectivityListener,
context: Context
) {
- companion object {
- sealed class Command {
- data class RegisterListener(val listener: Messenger) : Command()
-
- data class UnregisterListener(val listenerId: Int) : Command()
- }
- }
private val listeners = mutableMapOf<Int, Messenger>()
private val commands: SendChannel<Command> = startRegistrator()
@@ -165,4 +158,12 @@ class ServiceEndpoint(
return listenerId
}
+
+ companion object {
+ sealed class Command {
+ data class RegisterListener(val listener: Messenger) : Command()
+
+ data class UnregisterListener(val listenerId: Int) : Command()
+ }
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
index b6085221f1..6ed6a5b72e 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
@@ -28,11 +28,6 @@ class AccountExpiryNotification(
val daemon: Intermittent<MullvadDaemon>,
val accountCache: AccountCache
) {
- companion object {
- val NOTIFICATION_ID: Int = 2
- val REMAINING_TIME_FOR_REMINDERS = Duration.standardDays(2)
- val TIME_BETWEEN_CHECKS: Long = 12 /* h */ * 60 /* min */ * 60 /* s */ * 1000 /* ms */
- }
private val jobTracker = JobTracker()
private val resources = context.resources
@@ -143,4 +138,10 @@ class AccountExpiryNotification(
private fun getRemainingText(pluralId: Int, quantity: Int): String {
return resources.getQuantityString(pluralId, quantity, quantity)
}
+
+ companion object {
+ val NOTIFICATION_ID: Int = 2
+ val REMAINING_TIME_FOR_REMINDERS = Duration.standardDays(2)
+ val TIME_BETWEEN_CHECKS: Long = 12 /* h */ * 60 /* min */ * 60 /* s */ * 1000 /* ms */
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
index a19358f95e..97bddc8608 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
@@ -18,10 +18,6 @@ import net.mullvad.talpid.tunnel.ActionAfterDisconnect
import net.mullvad.talpid.tunnel.ErrorStateCause
class TunnelStateNotification(val context: Context) {
- companion object {
- val NOTIFICATION_ID: Int = 1
- }
-
private val channel =
NotificationChannel(
context,
@@ -149,4 +145,8 @@ class TunnelStateNotification(val context: Context) {
return NotificationCompat.Action(action.icon, label, pendingIntent)
}
+
+ companion object {
+ val NOTIFICATION_ID: Int = 1
+ }
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt
index c415940ea8..c836c765f6 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt
@@ -12,28 +12,6 @@ enum class TunnelStateNotificationAction {
Cancel,
Dismiss;
- companion object {
- fun from(tunnelState: TunnelState) =
- when (tunnelState) {
- is TunnelState.Disconnected -> Connect
- is TunnelState.Connecting -> Cancel
- is TunnelState.Connected -> Disconnect
- is TunnelState.Disconnecting -> {
- when (tunnelState.actionAfterDisconnect) {
- ActionAfterDisconnect.Reconnect -> Cancel
- else -> Connect
- }
- }
- is TunnelState.Error -> {
- if (tunnelState.errorState.isBlocking) {
- Disconnect
- } else {
- Dismiss
- }
- }
- }
- }
-
val text
get() =
when (this) {
@@ -56,4 +34,26 @@ enum class TunnelStateNotificationAction {
Connect -> R.drawable.icon_notification_connect
else -> R.drawable.icon_notification_disconnect
}
+
+ companion object {
+ fun from(tunnelState: TunnelState) =
+ when (tunnelState) {
+ is TunnelState.Disconnected -> Connect
+ is TunnelState.Connecting -> Cancel
+ is TunnelState.Connected -> Disconnect
+ is TunnelState.Disconnecting -> {
+ when (tunnelState.actionAfterDisconnect) {
+ ActionAfterDisconnect.Reconnect -> Cancel
+ else -> Connect
+ }
+ }
+ is TunnelState.Error -> {
+ if (tunnelState.errorState.isBlocking) {
+ Disconnect
+ } else {
+ Dismiss
+ }
+ }
+ }
+ }
}