Skip to content

Commit

Permalink
annotate resourceIds with specific Android API versions they appear in
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Sep 15, 2023
1 parent be37250 commit 8080c95
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ class Automator private constructor() {

fun allowPermissionWhileUsingApp() {
val identifiers = arrayOf(
"com.android.packageinstaller:id/permission_allow_button",
"com.android.permissioncontroller:id/permission_allow_button",
"com.android.permissioncontroller:id/permission_allow_foreground_only_button"
"com.android.packageinstaller:id/permission_allow_button", // API <= 28
"com.android.permissioncontroller:id/permission_allow_button", // API 29
"com.android.permissioncontroller:id/permission_allow_foreground_only_button" // API >= 30 + API 29 (only for location permission)
)

val uiObject = waitForUiObjectByResourceId(*identifiers, timeout = timeoutMillis)
Expand All @@ -421,16 +421,14 @@ class Automator private constructor() {

fun allowPermissionOnce() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
// One-time permissions are available only on Android 11 (R) and above.
// One-time permissions are available only on API 30 (R) and above.
// See: https://developer.android.com/training/permissions/requesting#one-time
allowPermissionWhileUsingApp()
return
}

val identifiers = arrayOf(
"com.android.packageinstaller:id/permission_allow_button",
"com.android.permissioncontroller:id/permission_allow_button",
"com.android.permissioncontroller:id/permission_allow_one_time_button"
"com.android.permissioncontroller:id/permission_allow_one_time_button" // API >= 30
)

val uiObject = waitForUiObjectByResourceId(*identifiers, timeout = timeoutMillis)
Expand All @@ -441,8 +439,8 @@ class Automator private constructor() {

fun denyPermission() {
val identifiers = arrayOf(
"com.android.packageinstaller:id/permission_deny_button",
"com.android.permissioncontroller:id/permission_deny_button"
"com.android.packageinstaller:id/permission_deny_button", // API <= 28
"com.android.permissioncontroller:id/permission_deny_button" // API >= 29
)

val uiObject = waitForUiObjectByResourceId(*identifiers, timeout = timeoutMillis)
Expand Down

0 comments on commit 8080c95

Please sign in to comment.