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] Permissions returned by onRequestPermissionResult is empty #2180

Merged
merged 1 commit into from
Sep 5, 2024
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 @@ -98,21 +98,31 @@ class PermissionsActivity : Activity() {
// We need to wait for other activity to show
if (requestCode == ONESIGNAL_PERMISSION_REQUEST_CODE) {
Handler().postDelayed({
val permission = permissions[0]
val granted =
grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
val callback =
requestPermissionService!!.getCallback(permissionRequestType!!)
?: throw RuntimeException("Missing handler for permissionRequestType: $permissionRequestType")
if (granted) {
callback.onAccept()
preferenceService!!.saveBool(
PreferenceStores.ONESIGNAL,
"${PreferenceOneSignalKeys.PREFS_OS_USER_RESOLVED_PERMISSION_PREFIX}$permission",
true,
)

// It is possible that the permissions request interaction with the user is interrupted. In this case
// we will receive empty permissions which should be treated as a cancellation and will not prompt
// for the permission setting
val defaultFallbackSetting = false
if (permissions.isEmpty()) {
callback.onReject(defaultFallbackSetting)
} else {
callback.onReject(shouldShowSettings(permission))
val permission = permissions[0]
val granted =
grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED

if (granted) {
callback.onAccept()
preferenceService!!.saveBool(
PreferenceStores.ONESIGNAL,
"${PreferenceOneSignalKeys.PREFS_OS_USER_RESOLVED_PERMISSION_PREFIX}$permission",
true,
)
} else {
callback.onReject(shouldShowSettings(permission))
}
}
}, DELAY_TIME_CALLBACK_CALL.toLong())
}
Expand Down
Loading