From e5a1b89220b4c61a543265db2ad8da0cd0ee3e37 Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Tue, 7 Nov 2023 14:35:17 -0800 Subject: [PATCH] Making keyguard dismissal a permanent solution Before, it was considered to be a workaround while System UI has keyguard bugs. But these bugs will happen in future, and they are unlikely to be prevented by presubmit tests since they are usually flakes. The solution that this CL makes permanent is: in presubmit attempt to unlock SysUI if it's locked. In postsubmit, just make sure it's unlocked. This way, in postsubmit, we'll know whether tere are active keyguard bugs. Bug: 187761685 Test: presubmit Flag: N/A Change-Id: Ia9602bc6e9cc8400e939051c45aba92bc197d428 --- .../quickstep/FallbackRecentsTest.java | 2 +- .../launcher3/ui/AbstractLauncherUiTest.java | 43 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 12568ea85d..281516ce8c 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -163,7 +163,7 @@ public class FallbackRecentsTest { public void setUp() { mLauncher.onTestStart(); AbstractLauncherUiTest.waitForSetupWizardDismissal(); - AbstractLauncherUiTest.verifyKeyguardInvisible(); + AbstractLauncherUiTest.onTestStart(); } @After diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 9bfafcfddb..4f01794d51 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -45,6 +45,7 @@ import android.platform.test.flag.junit.SetFlagsRule; import android.system.OsConstants; import android.util.Log; +import androidx.annotation.NonNull; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; @@ -108,7 +109,7 @@ public abstract class AbstractLauncherUiTest { private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; protected LooperExecutor mMainThreadExecutor = MAIN_EXECUTOR; - protected final UiDevice mDevice = UiDevice.getInstance(getInstrumentation()); + protected final UiDevice mDevice = getUiDevice(); protected final LauncherInstrumentation mLauncher = new LauncherInstrumentation(); protected Context mTargetContext; protected String mTargetPackage; @@ -160,7 +161,7 @@ public abstract class AbstractLauncherUiTest { if (TestHelpers.isInLauncherProcess()) { Debug.dumpHprofData(fileName); } else { - final UiDevice device = UiDevice.getInstance(getInstrumentation()); + final UiDevice device = getUiDevice(); device.executeShellCommand( "am dumpheap " + device.getLauncherPackageName() + " " + fileName); } @@ -249,11 +250,6 @@ public abstract class AbstractLauncherUiTest { mLauncher.onTestStart(); waitForSetupWizardDismissal(); - if (TestStabilityRule.isPresubmit()) { - aggressivelyUnlockSysUi(); - } else { - verifyKeyguardInvisible(); - } final String launcherPackageName = mDevice.getLauncherPackageName(); try { @@ -285,23 +281,38 @@ public abstract class AbstractLauncherUiTest { } } - verifyKeyguardInvisible(); + onTestStart(); } - private boolean hasSystemUiObject(String resId) { - return mDevice.hasObject(By.res(SYSTEMUI_PACKAGE, resId)); + /** Method that should be called when a test starts. */ + public static void onTestStart() { + if (TestStabilityRule.isPresubmit()) { + aggressivelyUnlockSysUi(); + } else { + verifyKeyguardInvisible(); + } } - // Seeing if this will decrease: b/303755862 - void aggressivelyUnlockSysUi() { + private static boolean hasSystemUiObject(String resId) { + return getUiDevice().hasObject( + By.res(SYSTEMUI_PACKAGE, resId)); + } + + @NonNull + private static UiDevice getUiDevice() { + return UiDevice.getInstance(getInstrumentation()); + } + + private static void aggressivelyUnlockSysUi() { + final UiDevice device = getUiDevice(); for (int i = 0; i < 10 && hasSystemUiObject("keyguard_status_view"); ++i) { Log.d(TAG, "Before attempting to unlock the phone"); try { - mDevice.executeShellCommand("input keyevent 82"); + device.executeShellCommand("input keyevent 82"); } catch (IOException e) { throw new RuntimeException(e); } - mDevice.waitForIdle(); + device.waitForIdle(); } Assert.assertTrue("Keyguard still visible", TestHelpers.wait( @@ -323,7 +334,7 @@ public abstract class AbstractLauncherUiTest { public static void waitForSetupWizardDismissal() { if (sFirstTimeWaitingForWizard && TestStabilityRule.isPresubmit()) { try { - UiDevice.getInstance(getInstrumentation()).executeShellCommand( + getUiDevice().executeShellCommand( "am force-stop com.google.android.setupwizard"); } catch (IOException e) { throw new RuntimeException(e); @@ -339,7 +350,7 @@ public abstract class AbstractLauncherUiTest { // wizardDismissed); } - public static void verifyKeyguardInvisible() { + private static void verifyKeyguardInvisible() { final boolean keyguardAlreadyVisible = sSeenKeyguard; sSeenKeyguard = sSeenKeyguard