accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Permissions] "Ask every time" doesn't trigger a state change

Open pvegh opened this issue 2 years ago • 2 comments

Using something like this:

val cameraPermissionState = rememberPermissionState(Manifest.permission.CAMERA)

LaunchedEffect(cameraPermissionState.status) { cameraPermissionState.launchPermissionRequest() } if (cameraPermissionState.status.isGranted) { } else { }

works when the user chooses something from the dialog. Those result in state changes and the new state is represented correctly. Also if the user does then go to the settings and either denies or grants the permission, then returns to the app, also everything works with the new state value.

But when in the settings "ask every time" is chosen, and the app is brought to the foreground, the remembered state is not triggered at all.

What am I missing? Could be a bug since everything else seems to work correctly :)

pvegh avatar Jun 17 '22 13:06 pvegh

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[bot] avatar Jul 18 '22 03:07 github-actions[bot]

Hm, no response, but it should be autoclosed now? Not much has changed in the Android world in the last 10 years :)

pvegh avatar Jul 21 '22 06:07 pvegh

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[bot] avatar Aug 22 '22 03:08 github-actions[bot]

LOL autoclosed because nobody from the team bothered to answer :)

pvegh avatar Aug 27 '22 07:08 pvegh

@manuelvicnt @pvegh Do we have any update on this?

ForceGT avatar Nov 09 '22 14:11 ForceGT

The onPermissionResult: (Boolean) -> Unit = {} callback in Permission(s)State should be triggered every time that the user interacts with the dialog. Would that work?

manuelvicnt avatar Nov 09 '22 16:11 manuelvicnt

@manuelvicnt It is correct, that the method is triggered each time But it's a very specific edge case

Let me describe it in detail again

I have granted the permission using "Always allow" , now I go to the settings, I set the permission to "Ask every time", this works, when I relaunch the app I have granted the permission using "Ask every time", this will always allow the permission, unless I explicitly, force stop the app. Once I force stop the app (from the settings) and I come back, then the permission will be denied

I just want to know, if this is normal, and should be expected, because by "Ask every time" we expect the popup to come up again on each app launch (even though it is not force stopped and just cleared from recents)


EDIT: As per the documentation

https://developer.android.com/training/permissions/requesting#one-time

This section says that the app can access the permission when the app is in background for sometime, but I clear it from the recents, then the app is not in the background, it has been stopped, so permission prompt should happen again, since it's the one time state

ForceGT avatar Nov 10 '22 05:11 ForceGT

In which version are you seeing this behavior? I wouldn't worry too much because the behavior can vary across different Android API versions, it depends on what the platform permissions API retrieve, nothing we can control in this Accompanist wrapper.

In some OS version, they introduced the behavior that even if you say "Ask every time", they cache the user selection for some time and then it resets. So it's normal to see that even if you force close the app and open it again, the system is caching the result for you. If you force close and open it after... let's say 5 or 10 minutes, you should see the permission being requested again.

I've been testing this in API 31 and that's the behavior I saw as well

manuelvicnt avatar Nov 10 '22 06:11 manuelvicnt

@manuelvicnt Thanks for the quick response, here's something I found regarding what you and me are facing, The permissions won't be reset unless the process restarts

https://developer.android.com/guide/components/activities/tasks-and-back-stack#back-press-behavior

ForceGT avatar Nov 10 '22 09:11 ForceGT

If this is helpful, in my experience after clicking "ask every time" the permissions can be revoked while the app is in the background, even if the app isn't directly force closed by the user. So this behavior is possible:

  • Grant permission with "ask every time"
  • Background the app
  • Wait a period of time (30 minutes is probably plenty, I don't know exact time)
  • Return to the app

Because the permission was revoked, this will kill the process in a similar manner to process death.

alexvanyo avatar Nov 10 '22 11:11 alexvanyo