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

[Permissions] MutableMultiplePermissionsState.shouldShowRationale returns true despite some permissions being Denied(shouldShowRationale=false) #1781

Open
FelixZY opened this issue Jul 5, 2024 · 4 comments · May be fixed by #1783
Assignees

Comments

@FelixZY
Copy link

FelixZY commented Jul 5, 2024

Description

The current implementation of MutableMultiplePermissionsState.shouldShowRationale does not consider cases where one or more permissions are Denied(shouldShowRationale=false). This causes issues in statements such as

val permissions = rememberMultiplePermissionsState(listOf(ACCESS_FINE_LOCATION, ACCESS_BACKGROUND_LOCATION))

when {
  // Granted
  permissions.allPermissionsGranted -> Unit,
  // Denied, but I can ask the user
  permissions.shouldShowRationale -> 
    // ERROR: Does not trigger!
    permissions.launchMultiplePermissionRequest()
  // Denied and I may not ask the user.
  else -> Unit
}

The issue is located at

Suggested fix:

    override val shouldShowRationale: Boolean by derivedStateOf {
-       permissions.any { it.status.shouldShowRationale }
+       permissions.any { it.status.shouldShowRationale } && permissions.none { !it.status.isGranted && !it.status.shouldShowRationale }
    }
@bentrengrove
Copy link
Collaborator

That does make sense. PR's welcome!

FelixZY added a commit to FelixZY/accompanist that referenced this issue Jul 12, 2024
…`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`.
@BobbyESP
Copy link

I'm also having this issue

@hafiz013
Copy link

hafiz013 commented Aug 1, 2024

However I have issue with this in which shouldShowRationale is never being trigger even I already click don't allow. Check report bugs I have made.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale Stale issues which are marked for closure label Sep 16, 2024
@bentrengrove bentrengrove removed the stale Stale issues which are marked for closure label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants