diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-05-05 23:29:22 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-05-06 12:39:13 +0200 |
| commit | 2ea5bf3bff4a68b04ee805419b952917cd15ce59 (patch) | |
| tree | bea1dd4405b5d4345f23f9bbf9b504d72491378b /android/lib/common/src | |
| parent | c228ff918ac023c1c76bb4cf4f3d595a181cea63 (diff) | |
| download | mullvadvpn-2ea5bf3bff4a68b04ee805419b952917cd15ce59.tar.xz mullvadvpn-2ea5bf3bff4a68b04ee805419b952917cd15ce59.zip | |
Fix go to vpn settings on TV devices
- Do not show the action on devices without vpn settings
- Handle exceptions when starting vpn settings activity
Diffstat (limited to 'android/lib/common/src')
| -rw-r--r-- | android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt index bf275c4f53..2d82bc56f4 100644 --- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt @@ -1,9 +1,12 @@ package net.mullvad.mullvadvpn.lib.common.util +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.net.Uri import androidx.core.net.toUri +import arrow.core.Either +import co.touchlab.kermit.Logger import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken fun createAccountUri(accountUri: String, websiteAuthToken: WebsiteAuthToken?): Uri { @@ -17,7 +20,14 @@ fun createAccountUri(accountUri: String, websiteAuthToken: WebsiteAuthToken?): U return urlString.toUri() } -fun Context.openVpnSettings() { - val intent = Intent("android.settings.VPN_SETTINGS") - startActivity(intent) -} +// Activity not found can be return if the device does not have system vpn settings available. +// This is the case for Android TV devices. In normal cases, this action should not be available +// for those devices (see SystemVpnSettingsAvailableUseCase). This is an extra safety check. + +fun Context.openVpnSettings(): Either<ActivityNotFoundException, Unit> = + Either.catch { + val intent = Intent("android.settings.VPN_SETTINGS") + startActivity(intent) + } + .onLeft { Logger.e("Failed to open VPN settings", it) } + .mapLeft { it as? ActivityNotFoundException ?: throw it } |
