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

PermissionGranter should click *foreground* grant button for location #356

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.schibsted.spain.barista.interaction

import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
Expand All @@ -19,6 +21,11 @@ object PermissionGranter {
} else {
"com.android.packageinstaller:id/permission_allow_button"
}
private val PERMISSIONS_DIALOG_ALLOW_FOREGROUND_ID = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
"com.android.permissioncontroller:id/permission_allow_foreground_only_button"
} else {
PERMISSIONS_DIALOG_ALLOW_ID
}
// private static final String PERMISSIONS_DIALOG_DENY_ID = "com.android.packageinstaller:id/permission_deny_button";

@JvmStatic
Expand All @@ -28,10 +35,16 @@ object PermissionGranter {
permissionNeeded)) {
sleepThread(PERMISSIONS_DIALOG_DELAY.toLong())
val device = UiDevice.getInstance(getInstrumentation())

val resourceId = if (permissionNeeded == ACCESS_FINE_LOCATION || permissionNeeded == ACCESS_COARSE_LOCATION) {
PERMISSIONS_DIALOG_ALLOW_FOREGROUND_ID
} else {
PERMISSIONS_DIALOG_ALLOW_ID
}
val allowPermissions = device.findObject(UiSelector()
.clickable(true)
.checkable(false)
.resourceId(PERMISSIONS_DIALOG_ALLOW_ID))
.resourceId(resourceId))
if (allowPermissions.exists()) {
allowPermissions.click()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.schibsted.spain.barista.interaction.PermissionGranter
import org.junit.Assert.assertEquals
import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Ignore
import org.junit.Test

class PermissionGranterTest {
Expand All @@ -36,7 +35,6 @@ class PermissionGranterTest {
* Since Android Q the Location permission dialog is different to the others
*/
@Test
@Ignore("Won't pass without the fix in https://github.com/AdevintaSpain/Barista/pull/356")
fun grants_location_permission() {
launchActivity {
verifyPermissionNotGranted(LOCATION_PERMISSION)
Expand Down