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] fix(gh-1781): check for Denied(shouldShowRationale=false) in MutableMultiplePermissionsState.shouldShowRationale #1783

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

FelixZY
Copy link
Contributor

@FelixZY FelixZY commented Jul 12, 2024

Adding the fix I proposed in #1781

Fixes #1781


Additional complication:

I have indications that ACCESS_BACKGROUND_LOCATION may be Denied(shouldShowRationale=false) while ACCESS_FINE_LOCATION is Denied(shouldShowRationale=true). It then seems like ACCESS_BACKGROUND_LOCATION shifts to Denied(shouldShowRationale=true) once ACCESS_FINE_LOCATION is granted.

I have not yet confirmed this but something seems to be acting strange with these two. If the above description is correct, the proposed solution in this PR is insufficient (though covering an unexpected gap that exists today).

I think someone should take a closer look and disprove the above theory before merging this (that'll probably be a few months out on my end - if even then).

@bentrengrove
Copy link
Collaborator

Sorry for the slow response here, I am planning to get to this. Just trying to get the beta release out first

Copy link
Collaborator

@bentrengrove bentrengrove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this and sorry for the slow review. Could you please rebase this to main just to kick the CI?

@FelixZY
Copy link
Contributor Author

FelixZY commented Nov 24, 2024

Sure! It will be a day or two but I'll do so asap.

…`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`.
@FelixZY
Copy link
Contributor Author

FelixZY commented Nov 25, 2024

@bentrengrove rebase completed 🚀

@bentrengrove bentrengrove merged commit b019980 into google:main Nov 25, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants