Skip to content

Commit 9df5484

Browse files
authored
Merge pull request #2180 from OneSignal/fix-empty-permissions
[Fix] Permissions returned by onRequestPermissionResult is empty
2 parents b218b01 + a8624e3 commit 9df5484

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/activities/PermissionsActivity.kt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,31 @@ class PermissionsActivity : Activity() {
9898
// We need to wait for other activity to show
9999
if (requestCode == ONESIGNAL_PERMISSION_REQUEST_CODE) {
100100
Handler().postDelayed({
101-
val permission = permissions[0]
102-
val granted =
103-
grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
104101
val callback =
105102
requestPermissionService!!.getCallback(permissionRequestType!!)
106103
?: throw RuntimeException("Missing handler for permissionRequestType: $permissionRequestType")
107-
if (granted) {
108-
callback.onAccept()
109-
preferenceService!!.saveBool(
110-
PreferenceStores.ONESIGNAL,
111-
"${PreferenceOneSignalKeys.PREFS_OS_USER_RESOLVED_PERMISSION_PREFIX}$permission",
112-
true,
113-
)
104+
105+
// It is possible that the permissions request interaction with the user is interrupted. In this case
106+
// we will receive empty permissions which should be treated as a cancellation and will not prompt
107+
// for the permission setting
108+
val defaultFallbackSetting = false
109+
if (permissions.isEmpty()) {
110+
callback.onReject(defaultFallbackSetting)
114111
} else {
115-
callback.onReject(shouldShowSettings(permission))
112+
val permission = permissions[0]
113+
val granted =
114+
grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
115+
116+
if (granted) {
117+
callback.onAccept()
118+
preferenceService!!.saveBool(
119+
PreferenceStores.ONESIGNAL,
120+
"${PreferenceOneSignalKeys.PREFS_OS_USER_RESOLVED_PERMISSION_PREFIX}$permission",
121+
true,
122+
)
123+
} else {
124+
callback.onReject(shouldShowSettings(permission))
125+
}
116126
}
117127
}, DELAY_TIME_CALLBACK_CALL.toLong())
118128
}

0 commit comments

Comments
 (0)