Skip to content

Comments

[Permissions] fix(gh-1781): check for Denied(shouldShowRationale=false) in MutableMultiplePermissionsState.shouldShowRationale#1783

Merged
bentrengrove merged 1 commit intogoogle:mainfrom
FelixZY:fzy/1781/1
Nov 25, 2024
Merged

[Permissions] fix(gh-1781): check for Denied(shouldShowRationale=false) in MutableMultiplePermissionsState.shouldShowRationale#1783
bentrengrove merged 1 commit intogoogle:mainfrom
FelixZY:fzy/1781/1

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
@lafamiliadedios1521-spec

/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants