summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt)19
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/VpnServiceModule.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/VpnServiceModule.kt)2
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AppVersionInfoCache.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AppVersionInfoCache.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt)2
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VoucherRedeemer.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VoucherRedeemer.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt)6
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt)18
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt)2
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt)25
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt)9
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/persistence/SplitTunnelingPersistence.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/persistence/SplitTunnelingPersistence.kt)0
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ExponentialBackoff.kt52
24 files changed, 105 insertions, 30 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt
index 4e121bc693..4e121bc693 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
index 36d640c719..36d640c719 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
index 089e13ef31..089e13ef31 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
index 0058b09e4f..9024eaad18 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -1,5 +1,6 @@
package net.mullvad.mullvadvpn.service
+import android.annotation.SuppressLint
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
@@ -12,16 +13,19 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
-import net.mullvad.mullvadvpn.BuildConfig
-import net.mullvad.mullvadvpn.di.vpnServiceModule
+import net.mullvad.mullvadvpn.lib.common.constant.KEY_CONNECT_ACTION
+import net.mullvad.mullvadvpn.lib.common.constant.KEY_DISCONNECT_ACTION
+import net.mullvad.mullvadvpn.lib.common.constant.KEY_QUIT_ACTION
+import net.mullvad.mullvadvpn.lib.common.constant.MAIN_ACTIVITY_CLASS
+import net.mullvad.mullvadvpn.lib.common.constant.MULLVAD_PACKAGE_NAME
import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration
import net.mullvad.mullvadvpn.lib.endpoint.DefaultApiEndpointConfiguration
import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras
import net.mullvad.mullvadvpn.model.Settings
import net.mullvad.mullvadvpn.model.TunnelState
+import net.mullvad.mullvadvpn.service.di.vpnServiceModule
import net.mullvad.mullvadvpn.service.endpoint.ServiceEndpoint
import net.mullvad.mullvadvpn.service.notifications.AccountExpiryNotification
-import net.mullvad.mullvadvpn.ui.MainActivity
import net.mullvad.talpid.TalpidVpnService
import org.koin.core.context.loadKoinModules
@@ -29,10 +33,6 @@ class MullvadVpnService : TalpidVpnService() {
companion object {
private val TAG = "mullvad"
- val KEY_CONNECT_ACTION = "net.mullvad.mullvadvpn.connect_action"
- val KEY_DISCONNECT_ACTION = "net.mullvad.mullvadvpn.disconnect_action"
- val KEY_QUIT_ACTION = "net.mullvad.mullvadvpn.quit_action"
-
init {
System.loadLibrary("mullvad_jni")
}
@@ -70,6 +70,8 @@ class MullvadVpnService : TalpidVpnService() {
private var apiEndpointConfiguration: ApiEndpointConfiguration =
DefaultApiEndpointConfiguration()
+ // Suppressing since the tunnel state pref should be writted immediately.
+ @SuppressLint("ApplySharedPref")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "Initializing service")
@@ -265,7 +267,8 @@ class MullvadVpnService : TalpidVpnService() {
private fun openUi() {
val intent =
- Intent(this, MainActivity::class.java).apply {
+ Intent().apply {
+ setClassName(MULLVAD_PACKAGE_NAME, MAIN_ACTIVITY_CLASS)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/VpnServiceModule.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/VpnServiceModule.kt
index 431023caa2..0a7d3dec39 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/VpnServiceModule.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/VpnServiceModule.kt
@@ -1,4 +1,4 @@
-package net.mullvad.mullvadvpn.di
+package net.mullvad.mullvadvpn.service.di
import androidx.core.app.NotificationManagerCompat
import org.koin.android.ext.koin.androidContext
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
index ad8b96f9a5..ad8b96f9a5 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AppVersionInfoCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AppVersionInfoCache.kt
index 767ac3e251..767ac3e251 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AppVersionInfoCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AppVersionInfoCache.kt
diff --git a/android/app/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..6506c0469d 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AuthTokenCache.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt
index a2c97a05bd..a2c97a05bd 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt
index fe8f55a66d..fe8f55a66d 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt
index db264ed1fe..db264ed1fe 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
index 68d6b56f6e..fb3a8637f6 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt
@@ -18,7 +18,7 @@ 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.util.ExponentialBackoff
+import net.mullvad.mullvadvpn.service.util.ExponentialBackoff
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
class LocationInfoCache(private val endpoint: ServiceEndpoint) {
diff --git a/android/app/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..1abf64907c 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
index 1d6cb9f9a7..1d6cb9f9a7 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt
index 2863594cb9..2863594cb9 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt
index a683b1e4bf..a683b1e4bf 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VoucherRedeemer.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VoucherRedeemer.kt
index a7003d6888..a7003d6888 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VoucherRedeemer.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VoucherRedeemer.kt
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt
index d94d1d6b60..c753c13b36 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt
@@ -3,10 +3,11 @@ package net.mullvad.mullvadvpn.service.endpoint
import android.content.Context
import android.content.Intent
import android.net.VpnService
+import net.mullvad.mullvadvpn.lib.common.constant.MAIN_ACTIVITY_CLASS
+import net.mullvad.mullvadvpn.lib.common.constant.MULLVAD_PACKAGE_NAME
import net.mullvad.mullvadvpn.lib.common.util.Intermittent
import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.Request
-import net.mullvad.mullvadvpn.ui.MainActivity
class VpnPermission(private val context: Context, private val endpoint: ServiceEndpoint) {
private val isGranted = Intermittent<Boolean>()
@@ -28,7 +29,8 @@ class VpnPermission(private val context: Context, private val endpoint: ServiceE
isGranted.update(true)
} else {
val activityIntent =
- Intent(context, MainActivity::class.java).apply {
+ Intent().apply {
+ setClassName(MULLVAD_PACKAGE_NAME, MAIN_ACTIVITY_CLASS)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
index b66c668972..dcc97e8b11 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
@@ -1,5 +1,6 @@
package net.mullvad.mullvadvpn.service.notifications
+import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
@@ -9,17 +10,18 @@ import android.net.Uri
import androidx.core.app.NotificationCompat
import kotlin.properties.Delegates.observable
import kotlinx.coroutines.delay
-import net.mullvad.mullvadvpn.BuildConfig
-import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.lib.common.constant.BuildTypes
+import net.mullvad.mullvadvpn.lib.common.constant.MAIN_ACTIVITY_CLASS
+import net.mullvad.mullvadvpn.lib.common.constant.MULLVAD_PACKAGE_NAME
import net.mullvad.mullvadvpn.lib.common.util.Intermittent
import net.mullvad.mullvadvpn.lib.common.util.JobTracker
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.isNotificationPermissionGranted
import net.mullvad.mullvadvpn.model.AccountExpiry
+import net.mullvad.mullvadvpn.service.BuildConfig
import net.mullvad.mullvadvpn.service.MullvadDaemon
+import net.mullvad.mullvadvpn.service.R
import net.mullvad.mullvadvpn.service.endpoint.AccountCache
-import net.mullvad.mullvadvpn.ui.MainActivity
import org.joda.time.DateTime
import org.joda.time.Duration
@@ -66,6 +68,8 @@ class AccountExpiryNotification(
accountCache.onAccountExpiryChange.unsubscribe(this)
}
+ // Suppressing since the permission check is done by calling a common util in another module.
+ @SuppressLint("MissingPermission")
private suspend fun update(expiry: AccountExpiry) {
val expiryDate = expiry.date()
val durationUntilExpiry = expiryDate?.remainingTime()
@@ -102,9 +106,11 @@ class AccountExpiryNotification(
}
val intent =
if (BuildTypes.RELEASE == BuildConfig.BUILD_TYPE) {
- Intent(context, MainActivity::class.java)
- .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
- .setAction(Intent.ACTION_MAIN)
+ Intent().apply {
+ setClassName(MULLVAD_PACKAGE_NAME, MAIN_ACTIVITY_CLASS)
+ setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
+ setAction(Intent.ACTION_MAIN)
+ }
} else {
Intent(Intent.ACTION_VIEW, url)
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt
index de557aaf22..d6e904e6ca 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt
@@ -6,7 +6,7 @@ import android.content.Context
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
-import net.mullvad.mullvadvpn.R
+import net.mullvad.mullvadvpn.service.R
class NotificationChannel(
val context: Context,
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
index b25d1a2056..b9691b6fa9 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
@@ -1,5 +1,6 @@
package net.mullvad.mullvadvpn.service.notifications
+import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
@@ -7,11 +8,13 @@ import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import kotlin.properties.Delegates.observable
-import net.mullvad.mullvadvpn.R
+import net.mullvad.mullvadvpn.lib.common.constant.MAIN_ACTIVITY_CLASS
+import net.mullvad.mullvadvpn.lib.common.constant.MULLVAD_PACKAGE_NAME
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils
+import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.isNotificationPermissionGranted
import net.mullvad.mullvadvpn.lib.common.util.getErrorNotificationResources
import net.mullvad.mullvadvpn.model.TunnelState
-import net.mullvad.mullvadvpn.ui.MainActivity
+import net.mullvad.mullvadvpn.service.R
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
import net.mullvad.talpid.tunnel.ErrorStateCause
@@ -97,17 +100,25 @@ class TunnelStateNotification(val context: Context) {
}
}
+ // Suppressing since the permission check is done by calling a common util in another module.
+ @SuppressLint("MissingPermission")
private fun update() {
- if (visible && (!reconnecting || !showingReconnecting)) {
+ if (
+ context.isNotificationPermissionGranted() &&
+ visible &&
+ (!reconnecting || !showingReconnecting)
+ ) {
channel.notificationManager.notify(NOTIFICATION_ID, build())
}
}
fun build(): Notification {
val intent =
- Intent(context, MainActivity::class.java)
- .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
- .setAction(Intent.ACTION_MAIN)
+ Intent().apply {
+ setClassName(MULLVAD_PACKAGE_NAME, MAIN_ACTIVITY_CLASS)
+ setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
+ setAction(Intent.ACTION_MAIN)
+ }
val pendingIntent =
PendingIntent.getActivity(context, 1, intent, SdkUtils.getSupportedPendingIntentFlags())
val actions =
@@ -128,7 +139,7 @@ class TunnelStateNotification(val context: Context) {
private fun buildAction(): NotificationCompat.Action {
val action = TunnelStateNotificationAction.from(tunnelState)
val label = context.getString(action.text)
- val intent = Intent(action.key).setPackage("net.mullvad.mullvadvpn")
+ val intent = Intent(action.key).setPackage(MULLVAD_PACKAGE_NAME)
val pendingIntent =
PendingIntent.getForegroundService(
context,
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt
index 9ed9998054..c415940ea8 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotificationAction.kt
@@ -1,8 +1,9 @@
package net.mullvad.mullvadvpn.service.notifications
-import net.mullvad.mullvadvpn.R
+import net.mullvad.mullvadvpn.lib.common.constant.KEY_CONNECT_ACTION
+import net.mullvad.mullvadvpn.lib.common.constant.KEY_DISCONNECT_ACTION
import net.mullvad.mullvadvpn.model.TunnelState
-import net.mullvad.mullvadvpn.service.MullvadVpnService
+import net.mullvad.mullvadvpn.service.R
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
enum class TunnelStateNotificationAction {
@@ -45,8 +46,8 @@ enum class TunnelStateNotificationAction {
val key
get() =
when (this) {
- Connect -> MullvadVpnService.KEY_CONNECT_ACTION
- else -> MullvadVpnService.KEY_DISCONNECT_ACTION
+ Connect -> KEY_CONNECT_ACTION
+ else -> KEY_DISCONNECT_ACTION
}
val icon
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/persistence/SplitTunnelingPersistence.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/persistence/SplitTunnelingPersistence.kt
index 264304ab3f..264304ab3f 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/persistence/SplitTunnelingPersistence.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/persistence/SplitTunnelingPersistence.kt
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ExponentialBackoff.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ExponentialBackoff.kt
new file mode 100644
index 0000000000..12e94a9241
--- /dev/null
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ExponentialBackoff.kt
@@ -0,0 +1,52 @@
+package net.mullvad.mullvadvpn.service.util
+
+// Calculates a series of delays that increase exponentially.
+//
+// The delays follow the formula:
+//
+// (base ^ retryAttempt) * scale
+//
+// but it is never larger than the specified cap value.
+class ExponentialBackoff : Iterator<Long> {
+ private var unscaledValue = 1L
+ private var current = 1L
+
+ var iteration = 1
+ private set
+
+ var base = 2L
+ var scale = 1000L
+ var cap = Long.MAX_VALUE
+ var count: Int? = null
+
+ override fun hasNext(): Boolean {
+ val maxIterations = count
+
+ if (maxIterations != null) {
+ return iteration < maxIterations
+ } else {
+ return true
+ }
+ }
+
+ override fun next(): Long {
+ iteration += 1
+
+ if (current >= cap) {
+ return cap
+ } else {
+ val value = current
+
+ unscaledValue *= base
+ current = Math.min(cap, scale * unscaledValue)
+
+ return value
+ }
+ }
+
+ fun reset() {
+ unscaledValue = 1L
+ current = 1L
+ iteration = 1
+ }
+}