summaryrefslogtreecommitdiffhomepage
path: root/android/lib/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'android/lib/common/src')
-rw-r--r--android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt18
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 }