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

Case when permission is canceled was not handled #125

Closed
arifrgilang opened this issue Jun 16, 2023 · 5 comments
Closed

Case when permission is canceled was not handled #125

arifrgilang opened this issue Jun 16, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@arifrgilang
Copy link

Library version: 1.4.0
OS version: Android 13
Device model: Redmi Note 10 Pro

Describe the bug
Based on this documentation: https://developer.android.com/training/permissions/requesting#manage-request-code-yourself
There are certain cases where the permission interaction is canceled, resulting empty result.
image
When cancelation occured and returns empty result, the callback.onPermissionChecked() (callback for granted permission) was called. This is unexpected (or at least isn't quite right) because no permisison is granted, yet the callback for granted permission is triggered.
image

To Reproduce
I don't have the steps to reproduce it, but hope this screenshot when I debug it will help
image
In that screenshot, the result is empty and the callback.onPermissionChecked() block code is executed

@arifrgilang
Copy link
Author

Since this cancelation behavior is quite rare, I suggest to add a callback too when onPermissionIsCanceledOrInterrupted() and have the default callback to call the onShouldRedirectToSystemSettings() if the method isn't provided by the developer that used the library

@anggrayudi
Copy link
Owner

anggrayudi commented Jun 16, 2023

I'm unable to get empty result on emulator, either by pressing back button nor tapping outside the permission request dialog. Please provide the steps to reproduce that empty map, so that I can proceed the bugfixing. I wonder if it's a device specific issue, like it is only happens on Xiaomi.

BTW, what is the permission name that you're using on the screenshot?

@arifrgilang
Copy link
Author

arifrgilang commented Jun 18, 2023

@anggrayudi I am using camera permission inside Fragment.
Unfortunately, I still can't find the steps to reproduce it until now, since you know, it's kinda hard to trace legacy code😅. But for sure all I did was this

  1. Open Activity with Fragment
  2. Request permission camera, then showed system camera permission request
  3. Deny the camera permission
  4. Automatically showed system camera permission request
  5. Deny again the camera permission

My hypothesis is, the cancelation happened when you request permission while requesting permission.

val cameraPermission = FragmentPermissionRequest.Builder(this)
            .withPermissions(ManifestPermission.CAMERA)
            .withCallback((permissionResult, b) -> {
                if (permissionResult.getAreAllPermissionsGranted()) {
                    ScannerFragment.this.onPermissionGranted();
                } else {
                    onBack();
                }
            }).build();

cameraPermission.check();

@anggrayudi
Copy link
Owner

Yes, I can reproduce it too, by using this snippet:

    private val cameraPermissionRequest = FragmentPermissionRequest.Builder(this)
        .withPermissions(Manifest.permission.CAMERA)
        .withCallback(object : PermissionCallback {
            override fun onPermissionsChecked(result: PermissionResult, fromSystemDialog: Boolean) {
                Toast.makeText(requireContext(), result.areAllPermissionsGranted.toString(), Toast.LENGTH_SHORT).show()
            }
        })
        .build()

    @SuppressLint("NewApi")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        btnRequestCamera.setOnClickListener {
            cameraPermissionRequest.check()
            it.handler.postDelayed({
                // this will trigger empty "result"
                cameraPermissionRequest.check()
            }, 5000L)
        }

anggrayudi added a commit that referenced this issue Jun 19, 2023
@anggrayudi anggrayudi added the bug Something isn't working label Jun 19, 2023
anggrayudi added a commit that referenced this issue Jun 19, 2023
@anggrayudi
Copy link
Owner

Released v1.5.5, and I've added onPermissionRequestInterrupted()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants