From a8624e32cb681beeb7412496dca1278e8f7908de Mon Sep 17 00:00:00 2001 From: jinliu9508 Date: Tue, 20 Aug 2024 12:45:09 -0400 Subject: [PATCH] Check if permissions returned by onRequestPermissionResult is empty --- .../core/activities/PermissionsActivity.kt | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/activities/PermissionsActivity.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/activities/PermissionsActivity.kt index 1404edb945..00367476fe 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/activities/PermissionsActivity.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/activities/PermissionsActivity.kt @@ -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()) }