summaryrefslogtreecommitdiffhomepage
path: root/android/tile/src
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson@mullvad.net>2024-11-18 14:23:05 +0100
committerDavid Göransson <david.goransson@mullvad.net>2024-11-27 09:00:18 +0100
commit1bb7fc7ebaa2837ed9f9d28c2bb5a6fd91033988 (patch)
treea83565926fb753a2dd9fd24f0e2bd07262e4507e /android/tile/src
parent0d155385e1cb7075012bd270de0398d83a438bc5 (diff)
downloadmullvadvpn-1bb7fc7ebaa2837ed9f9d28c2bb5a6fd91033988.tar.xz
mullvadvpn-1bb7fc7ebaa2837ed9f9d28c2bb5a6fd91033988.zip
Handle legacy always-on vpn profiles
Co-authored-by: Jonatan Rhodin <jonatan.rhodin@mullvad.net>
Diffstat (limited to 'android/tile/src')
-rw-r--r--android/tile/src/main/kotlin/net/mullvad/mullvadvpn/tile/MullvadTileService.kt40
1 files changed, 20 insertions, 20 deletions
diff --git a/android/tile/src/main/kotlin/net/mullvad/mullvadvpn/tile/MullvadTileService.kt b/android/tile/src/main/kotlin/net/mullvad/mullvadvpn/tile/MullvadTileService.kt
index b1fa9ae311..9fe3c06dfc 100644
--- a/android/tile/src/main/kotlin/net/mullvad/mullvadvpn/tile/MullvadTileService.kt
+++ b/android/tile/src/main/kotlin/net/mullvad/mullvadvpn/tile/MullvadTileService.kt
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Intent
import android.graphics.drawable.Icon
-import android.net.VpnService
import android.os.Build
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
@@ -26,6 +25,7 @@ import net.mullvad.mullvadvpn.lib.common.constant.MAIN_ACTIVITY_CLASS
import net.mullvad.mullvadvpn.lib.common.constant.VPN_SERVICE_CLASS
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.setSubtitleIfSupported
+import net.mullvad.mullvadvpn.lib.common.util.prepareVpnSafe
import net.mullvad.mullvadvpn.lib.daemon.grpc.GrpcConnectivityState
import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService
import net.mullvad.mullvadvpn.lib.model.ActionAfterDisconnect
@@ -88,9 +88,26 @@ class MullvadTileService : TileService() {
@SuppressLint("StartActivityAndCollapseDeprecated")
private fun toggleTunnel() {
- val isSetup = VpnService.prepare(applicationContext) == null
+ val isSetup = applicationContext.prepareVpnSafe().isRight()
// TODO This logic should be more advanced, we should ensure user has an account setup etc.
- if (!isSetup) {
+ if (isSetup) {
+ Logger.i("TileService: VPN service is setup")
+
+ val intent =
+ Intent().apply {
+ setClassName(applicationContext.packageName, VPN_SERVICE_CLASS)
+ action =
+ if (qsTile.state == Tile.STATE_INACTIVE) {
+ KEY_CONNECT_ACTION
+ } else {
+ KEY_DISCONNECT_ACTION
+ }
+ }
+
+ // Always start as foreground, e.g if app is dead we won't be allowed to start if not
+ // in foreground.
+ startForegroundService(intent)
+ } else {
Logger.i("TileService: VPN service not setup, starting main activity")
val intent =
@@ -103,24 +120,7 @@ class MullvadTileService : TileService() {
action = Intent.ACTION_MAIN
}
startActivityAndCollapseCompat(intent)
- return
- } else {
- Logger.i("TileService: VPN service is setup")
}
- val intent =
- Intent().apply {
- setClassName(applicationContext.packageName, VPN_SERVICE_CLASS)
- action =
- if (qsTile.state == Tile.STATE_INACTIVE) {
- KEY_CONNECT_ACTION
- } else {
- KEY_DISCONNECT_ACTION
- }
- }
-
- // Always start as foreground, e.g if app is dead we won't be allowed to start if not
- // in foreground.
- startForegroundService(intent)
}
@SuppressLint("StartActivityAndCollapseDeprecated")