summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-07-30 17:39:25 +0200
committerDavid Göransson <david.goransson@mullvad.net>2024-07-31 14:20:57 +0200
commit84fbae1489cb578f8e03f38643493cbb11d59e97 (patch)
tree5758696c3bcbd816ab963960c0dd33ed7e9cf8bf
parent6aa0f47316d939b2c981051ccaf28fbdaba96a08 (diff)
downloadmullvadvpn-84fbae1489cb578f8e03f38643493cbb11d59e97.tar.xz
mullvadvpn-84fbae1489cb578f8e03f38643493cbb11d59e97.zip
Fix crash in request vpn permission
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
+ }
+ }
}