Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in request vpn permission #6547

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Loading