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

Closed
FelixZY opened this issue Jul 5, 2024 · 6 comments · Fixed by #1783
Assignees
Labels
stale Stale issues which are marked for closure

Comments

@FelixZY
Copy link
Contributor

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
Copy link

github-actions bot commented Nov 4, 2024

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 Nov 4, 2024
@FelixZY
Copy link
Contributor Author

FelixZY commented Nov 10, 2024

@bentrengrove as far as I know this has not yet been resolved? Could you please reopen?

@bentrengrove bentrengrove reopened this Nov 20, 2024
FelixZY added a commit to FelixZY/accompanist that referenced this issue Nov 25, 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`.
bentrengrove added a commit that referenced this issue Nov 25, 2024
[Permissions] fix(gh-1781): check for `Denied(shouldShowRationale=false)` in `MutableMultiplePermissionsState.shouldShowRationale`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues which are marked for closure
Projects
None yet
4 participants