From b80c533d1fab475dcd893b0fe3cb212bf0fa2a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Zed=C3=A9n=20Yver=C3=A5s?= Date: Fri, 12 Jul 2024 21:03:09 +0200 Subject: [PATCH] fix(gh-1781): check for `Denied(shouldShowRationale=false)` in `MutableMultiplePermissionsState.shouldShowRationale` `launchMultiplePermissionRequest` is typically called when `shouldShowRationale` returns true. However, what may not be as obvious is that `launchMultiplePermissionRequest` appears to result in a noop if one or more permissions in `MutableMultiplePermissionsState` are `Denied(shouldShowRationale=false)`. This caused issues for us in some code similar to this: ```kotlin val permissions = rememberMultiplePermissionsState( listOf( ACCESS_FINE_LOCATION, ACCESS_BACKGROUND_LOCATION, ) ) when { // Granted permissions.allPermissionsGranted -> /* ... */, // Denied, but I can ask the user permissions.shouldShowRationale -> // UNEXPECTED: Does not trigger! permissions.launchMultiplePermissionRequest() // Denied and I may not ask the user. else -> /* ... */ } ``` The fix would seem to be to additionally make sure that there are no permissions with the `Denied(shouldShowRationale=false)` status before returning a truthy value from `shouldShowRationale`. --- .../accompanist/permissions/MutableMultiplePermissionsState.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/permissions/src/main/java/com/google/accompanist/permissions/MutableMultiplePermissionsState.kt b/permissions/src/main/java/com/google/accompanist/permissions/MutableMultiplePermissionsState.kt index 4bf119ddc..e29aed007 100644 --- a/permissions/src/main/java/com/google/accompanist/permissions/MutableMultiplePermissionsState.kt +++ b/permissions/src/main/java/com/google/accompanist/permissions/MutableMultiplePermissionsState.kt @@ -127,7 +127,8 @@ internal class MutableMultiplePermissionsState( } override val shouldShowRationale: Boolean by derivedStateOf { - permissions.any { it.status.shouldShowRationale } + permissions.any { it.status.shouldShowRationale } && + permissions.none { !it.status.isGranted && !it.status.shouldShowRationale } } override fun launchMultiplePermissionRequest() {