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.allowViaDialog() only works for PERMISSIONS.Button.ALLOW #649

Open
TTC1018 opened this issue Jun 13, 2024 · 0 comments · May be fixed by #667
Open

Permissions.allowViaDialog() only works for PERMISSIONS.Button.ALLOW #649

TTC1018 opened this issue Jun 13, 2024 · 0 comments · May be fixed by #667
Labels
enhancement New feature or request

Comments

@TTC1018
Copy link
Contributor

TTC1018 commented Jun 13, 2024

In PermissionImpl, allowViaDialog() code is shown below.

override fun allowViaDialog() {
    wait(
        timeoutMs = DIALOG_TIMEOUT_MS,
        logger = logger
    ) {
        handlePermissionRequest(Permissions.Button.ALLOW)
    }
    logger.i("Allow permission via dialog")
}

But since Android 11, the ALLOW_FOREGROUND option was added.
It's OK with Permissions.clickOn(Permissions.Button.ALLOW_FOREGROUND)
but developers may consider allowViaDialog() as a silver bullet for granting runtime permissions.
So I hope this function to be able to handle both situations.

Maybe we could add a conditional to the handlePermissionRequest function?
like this

private fun handlePermissionRequest(button: Permissions.Button) {
    val uiObjectButton = getPermissionDialogButtonAsUiObject(button).let { 
        if (it == null && button == Permissions.Button.ALLOW) {
            getPermissionDialogButtonAsUiObject(Permissions.Button.ALLOW_FOREGROUND)
        } else {
            it
        }
    }
        
    if (uiObjectButton != null && uiObjectButton.exists()) {
        uiObjectButton.click()
    } else {
        logger.e("In method handlePermissionRequest button=$button is not exist or is not found.")
    }
}

It's a simple approach, and I'm sure there's another better way.
Thank you

@TTC1018 TTC1018 added the enhancement New feature or request label Jun 13, 2024
@Nikitae57 Nikitae57 linked a pull request Aug 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant