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 | |
| 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')
| -rw-r--r-- | android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt | 18 | ||||
| -rw-r--r-- | android/lib/resource/src/main/res/values/strings.xml | 2 |
2 files changed, 16 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 } diff --git a/android/lib/resource/src/main/res/values/strings.xml b/android/lib/resource/src/main/res/values/strings.xml index 401e57e566..d9fe661a21 100644 --- a/android/lib/resource/src/main/res/values/strings.xml +++ b/android/lib/resource/src/main/res/values/strings.xml @@ -416,4 +416,6 @@ <string name="device_ip_info_first_paragraph">This feature allows you to choose whether to use only IPv4, only IPv6, or allow the app to automatically decide the best option when connecting to a server.</string> <string name="device_ip_info_second_paragraph">It can be useful when you are aware of problems caused by a certain IP version.</string> <string name="daita_multihop">%s: Multihop</string> + <string name="vpn_permission_denied_error_no_vpn_settings">VPN permission was denied</string> + <string name="vpn_settings_not_available">VPN Settings not available on device</string> </resources> |
