Permissionsdispatcher: [ktx] Issue: on denied permission callback called immediately before showing rationale

Created on 3 Sep 2020  路  5Comments  路  Source: permissions-dispatcher/PermissionsDispatcher

Overview

ViewModel unexpectedly re-emits the previous decision (deny) when running the fragment for the second time immediately after denying for the first time.

Setup:

  • A permission that returns true shouldShowRationale (in my case, Camera)
  • create constructPermissionsRequest with Camera permission in Fragment.onCreate()
  • launch request in onViewCreated

Expected

  • What is the expected behavior?

Deny callback is not triggered immediately on re-enter of fragment with permission.
Should be same behavior as reentering the Fragment after relaunching the app.

Actual

Deny callback is triggered immediately. And then
Rationale callback is called as well.
Since deny callback has been called, the fragment is already removed in the backstack.
If I proceed with the rationale and press the Deny again, it will call the on deny callback again.
Deny callback will be called twice in total.

If I re-launch the app fresh the deny callback will only be called on press of deny button.

Environment

  • Which library version are you using? ktx 1.0.0
  • On which devices do you observe the issue? Pixel 2 API 29 Emulator
  • Note any other information that might be useful

I am trying to migrate my kapt permissions code into ktx, and encountered this issue (don't have this issue with kapt).

As for the fix, I think for fragments we should be passing the fragment as the lifecycle owner, and then observe with the Fragment.viewLifecycleOwner for the permissionRequestResult

Reproducible steps

  1. Open the fragment requiring permission
  2. permission dialog shows up*
  3. Press deny
  4. Deny callback is triggered, in my case I exit the fragment (popBackStack) *
  5. Attempt to open the fragment again
  • While it's not required, it'd be perfect to add a link to a sample project where you encounter the issue
bug ktx

All 5 comments

let us check, thx!

The issue has been resolved in 1.0.1 I guess 馃檹 Let us know if it has not been addressed 馃檱

Let me close the issue.

Hello! I hadn't checked this in a while. Glad it's resolved! I'll update the version and confirm.

Was this page helpful?
0 / 5 - 0 ratings