summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-07-30 17:39:25 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-07-31 13:08:41 +0200
commit595e5199bcafdd80ff60714c4bd70dbecb97436a (patch)
tree0d1dc1e9fb84253ce314a497bf576fcf5a84cc79
parentc7f81f5aad8b20f94bb8cc43cdc06065086c78d1 (diff)
downloadmullvadvpn-android/permissions-fix-1-1214.tar.xz
mullvadvpn-android/permissions-fix-1-1214.zip
Fix crash in request vpn permissionandroid/permissions-fix-1-1214
This crash could occur if create intent in request vpn permission was called while vpn permission was already approved Fixed by returning true immediately in those cases
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RequestVpnPermission.kt16
1 files changed, 12 insertions, 4 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RequestVpnPermission.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RequestVpnPermission.kt
index 13817db4bc..f198a3159c 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RequestVpnPermission.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RequestVpnPermission.kt
@@ -8,13 +8,21 @@ import androidx.activity.result.contract.ActivityResultContract
class RequestVpnPermission : ActivityResultContract<Unit, Boolean>() {
override fun createIntent(context: Context, input: Unit): Intent {
- // We expect this permission to only be requested when the permission is missing, however,
- // if it for some reason is called incorrectly we should return an empty intent so we avoid
- // a crash.
- return VpnService.prepare(context) ?: Intent()
+ return VpnService.prepare(context)!!
}
override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
return resultCode == Activity.RESULT_OK
}
+
+ // We expect this permission to only be requested when the permission is missing. However,
+ // if it for some reason is called incorrectly we will skip the call to create intent
+ // to avoid crashing. The app will then proceed as the user accepted the permission.
+ override fun getSynchronousResult(context: Context, input: Unit): SynchronousResult<Boolean>? {
+ return if (VpnService.prepare(context) == null) {
+ SynchronousResult(true)
+ } else {
+ null
+ }
+ }
}