From 06fdd20f32f954e8ea8750eca3c06656b0238032 Mon Sep 17 00:00:00 2001 From: Ovsyannikov_M Date: Wed, 14 Aug 2024 22:48:00 +0300 Subject: [PATCH 1/3] ISSUE-656: add flag to remove PermissionController --- .../kaspresso/params/SystemDialogsSafetyParams.kt | 8 ++++++-- .../systemsafety/SystemDialogSafetyProviderImpl.kt | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt index e04cc6ea7..ea71857c7 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt @@ -1,9 +1,13 @@ package com.kaspersky.kaspresso.params data class SystemDialogsSafetyParams( - val shouldIgnoreKeyboard: Boolean + val shouldIgnoreKeyboard: Boolean, + val shouldIgnorePermissionController: Boolean ) { companion object { - fun default() = SystemDialogsSafetyParams(shouldIgnoreKeyboard = false) + fun default() = SystemDialogsSafetyParams( + shouldIgnoreKeyboard = false, + shouldIgnorePermissionController = false + ) } } diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt index 52cbdec5c..19cd6fd9c 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt @@ -32,9 +32,9 @@ class SystemDialogSafetyProviderImpl( private val attemptsToSuppress: List<(UiDevice, AdbServer) -> Unit> = listOf( { _, adbServer -> - adbServer.performShell("input keyevent KEYCODE_BACK") - adbServer.performShell("input keyevent KEYCODE_ENTER") - adbServer.performShell("input keyevent KEYCODE_ENTER") + adbServer.performShell("input", listOf("keyevent", "KEYCODE_BACK")) + adbServer.performShell("input", listOf("keyevent", "KEYCODE_ENTER")) + adbServer.performShell("input", listOf("keyevent", "KEYCODE_ENTER")) }, { uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("android:id/button1")), DEFAULT_TIMEOUT).click() }, { uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("android:id/closeButton")), DEFAULT_TIMEOUT).click() }, @@ -111,7 +111,11 @@ class SystemDialogSafetyProviderImpl( */ private fun isAndroidSystemDetected(): Boolean { with(uiDevice) { - var isSystemDialogVisible = SystemDialogSafetyPattern.values().any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } + var isSystemDialogVisible = if (systemDialogsSafetyParams.shouldIgnorePermissionController) { + SystemDialogSafetyPattern.values().filter { it != SystemDialogSafetyPattern.PERMISSION_API30 }.any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } + } else { + SystemDialogSafetyPattern.values().any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } + } if (systemDialogsSafetyParams.shouldIgnoreKeyboard) { val isKeyboardVisible = isVisible(By.pkg(Pattern.compile("\\S*google.android.inputmethod\\S*")).clazz(FrameLayout::class.java)) From 8a79a7e2c519b3db433e4f3a74231d4be054e3d5 Mon Sep 17 00:00:00 2001 From: Ovsyannikov_M Date: Fri, 16 Aug 2024 18:11:42 +0300 Subject: [PATCH 2/3] ISSUE-656: fix comments --- .../kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt | 4 ++-- .../kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt index ea71857c7..6ba974678 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/SystemDialogsSafetyParams.kt @@ -2,12 +2,12 @@ package com.kaspersky.kaspresso.params data class SystemDialogsSafetyParams( val shouldIgnoreKeyboard: Boolean, - val shouldIgnorePermissionController: Boolean + val shouldIgnorePermissionDialogs: Boolean ) { companion object { fun default() = SystemDialogsSafetyParams( shouldIgnoreKeyboard = false, - shouldIgnorePermissionController = false + shouldIgnorePermissionDialogs = false ) } } diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt index 19cd6fd9c..9805acc1e 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt @@ -111,8 +111,9 @@ class SystemDialogSafetyProviderImpl( */ private fun isAndroidSystemDetected(): Boolean { with(uiDevice) { - var isSystemDialogVisible = if (systemDialogsSafetyParams.shouldIgnorePermissionController) { - SystemDialogSafetyPattern.values().filter { it != SystemDialogSafetyPattern.PERMISSION_API30 }.any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } + var isSystemDialogVisible = if (systemDialogsSafetyParams.shouldIgnorePermissionDialogs) { + SystemDialogSafetyPattern.values().filter { it != SystemDialogSafetyPattern.PERMISSION_API30 && it != SystemDialogSafetyPattern.PERMISSION_API23} + .any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } } else { SystemDialogSafetyPattern.values().any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } } From 9dc005216c819bfcd02a7150d2f6ed4a4695cd2a Mon Sep 17 00:00:00 2001 From: Ovsyannikov_M Date: Tue, 20 Aug 2024 19:30:06 +0300 Subject: [PATCH 3/3] ISSUE-656: fix detekt --- .../kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt index 9805acc1e..394bd3ed8 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt @@ -112,7 +112,7 @@ class SystemDialogSafetyProviderImpl( private fun isAndroidSystemDetected(): Boolean { with(uiDevice) { var isSystemDialogVisible = if (systemDialogsSafetyParams.shouldIgnorePermissionDialogs) { - SystemDialogSafetyPattern.values().filter { it != SystemDialogSafetyPattern.PERMISSION_API30 && it != SystemDialogSafetyPattern.PERMISSION_API23} + SystemDialogSafetyPattern.values().filter { it != SystemDialogSafetyPattern.PERMISSION_API30 && it != SystemDialogSafetyPattern.PERMISSION_API23 } .any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) } } else { SystemDialogSafetyPattern.values().any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) }