Skip to content

Commit e3de3f4

Browse files
committed
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
1 parent 563f107 commit e3de3f4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RequestVpnPermission.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ import androidx.activity.result.contract.ActivityResultContract
88

99
class RequestVpnPermission : ActivityResultContract<Unit, Boolean>() {
1010
override fun createIntent(context: Context, input: Unit): Intent {
11-
// We expect this permission to only be requested when the permission is missing, however,
12-
// if it for some reason is called incorrectly we should return an empty intent so we avoid
13-
// a crash.
14-
return VpnService.prepare(context) ?: Intent()
11+
return VpnService.prepare(context)!!
1512
}
1613

1714
override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
1815
return resultCode == Activity.RESULT_OK
1916
}
17+
18+
// We expect this permission to only be requested when the permission is missing. However,
19+
// if it for some reason is called incorrectly we will skip the call to create intent
20+
// to avoid crashing. The app will then proceed as the user accepted the permission.
21+
override fun getSynchronousResult(context: Context, input: Unit): SynchronousResult<Boolean>? {
22+
return if (VpnService.prepare(context) == null) {
23+
SynchronousResult(true)
24+
} else {
25+
null
26+
}
27+
}
2028
}

0 commit comments

Comments
 (0)