Skip to content

Commit 59929c1

Browse files
committed
Merge branch 'crash-on-first-connection-attempt-after-installing-latest-droid-1214'
2 parents 6aa0f47 + 84fbae1 commit 59929c1

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)