Changes to reduce flakiness of TrustTests
Use AndroidTest.xml to disable the double-click on power for turning on
Camera.
While trying to dismiss keyguard, use the back button instead of trying to power cycle the phone in order
to dismiss bouncer. As part of this, also wake the device if it's asleep
since you cannot dismiss keyguard if the display is off.
Bug: 226652325
Test: atest --iterations TrustTests
Change-Id: I7eb920f220dbc8d28d7c2035252365277d51421a
diff --git a/tests/TrustTests/AndroidTest.xml b/tests/TrustTests/AndroidTest.xml
index 61b711e..7ed19f5 100644
--- a/tests/TrustTests/AndroidTest.xml
+++ b/tests/TrustTests/AndroidTest.xml
@@ -16,6 +16,13 @@
-->
<configuration description="TrustTests configuration">
<option name="test-tag" value="TrustTests" />
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <!-- Disable the double-tap power button for camera -->
+ <option name="run-command"
+ value="settings put secure camera_double_tap_power_gesture_disabled 1" />
+ <option name="teardown-command"
+ value="settings delete secure camera_double_tap_power_gesture_disabled" />
+ </target_preparer>
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="TrustTests.apk" />
diff --git a/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt b/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt
index 8bd8340..6a8752a 100644
--- a/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt
+++ b/tests/TrustTests/src/android/trust/test/UserUnlockRequestTest.kt
@@ -38,7 +38,7 @@
*/
@RunWith(AndroidJUnit4::class)
class UserUnlockRequestTest {
- private val context: Context = getApplicationContext()
+ private val context = getApplicationContext<Context>()
private val trustManager = context.getSystemService(TrustManager::class.java) as TrustManager
private val userId = context.userId
private val activityScenarioRule = ActivityScenarioRule(TrustTestActivity::class.java)
diff --git a/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt b/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
index 7eb8157..4189baa 100644
--- a/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
+++ b/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
@@ -18,6 +18,7 @@
import android.content.Context
import android.util.Log
+import android.view.KeyEvent
import android.view.WindowManagerGlobal
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
@@ -64,17 +65,19 @@
fun dismissKeyguard() {
wait("keyguard dismissed") { count ->
- windowManager.dismissKeyguard(null, null)
-
- // Sometimes, bouncer gets shown due to a race, so we have to put display to sleep
- // and wake it back up to get it to go away
- if (count >= 10 && count % 5 == 0) {
- Log.i(TAG, "Escalation: attempting screen off/on to get rid of bouncer")
- uiDevice.sleep()
- Thread.sleep(250)
+ if (!uiDevice.isScreenOn) {
+ Log.i(TAG, "Waking device, +500ms")
uiDevice.wakeUp()
}
+ // Bouncer may be shown due to a race; back dismisses it
+ if (count >= 10) {
+ Log.i(TAG, "Pressing back to dismiss Bouncer")
+ uiDevice.pressKeyCode(KeyEvent.KEYCODE_BACK)
+ }
+
+ windowManager.dismissKeyguard(null, null)
+
!windowManager.isKeyguardLocked
}
}