Skip to content

Commit

Permalink
fix(googlegh-1781): check for Denied(shouldShowRationale=false) in …
Browse files Browse the repository at this point in the history
…`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`.
  • Loading branch information
FelixZY committed Nov 25, 2024
1 parent 52a660d commit b80c533
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b80c533

Please sign in to comment.