diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-05-06 14:12:10 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-05-06 14:12:10 +0200 |
| commit | fdf3b1a8bf8c5c095c3da257fb6094e58004b8cd (patch) | |
| tree | 0f3a5bdd8697f91c92672bbc79f526d2c33fd9bd /android/lib/common/src | |
| parent | c228ff918ac023c1c76bb4cf4f3d595a181cea63 (diff) | |
| parent | ca2010cec00fb53a444776094047d45dbfc01b22 (diff) | |
| download | mullvadvpn-fdf3b1a8bf8c5c095c3da257fb6094e58004b8cd.tar.xz mullvadvpn-fdf3b1a8bf8c5c095c3da257fb6094e58004b8cd.zip | |
Merge branch 'fix-tv-crash-on-go-to-vpn-settings-droid-1981'
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 } |
