Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5a1b892 authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

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
parent 38dc539f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ public class FallbackRecentsTest {
    public void setUp() {
        mLauncher.onTestStart();
        AbstractLauncherUiTest.waitForSetupWizardDismissal();
        AbstractLauncherUiTest.verifyKeyguardInvisible();
        AbstractLauncherUiTest.onTestStart();
    }

    @After
+27 −16
Original line number Diff line number Diff line
@@ -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 {
            }
        }

        onTestStart();
    }

    /** Method that should be called when a test starts. */
    public static void onTestStart() {
        if (TestStabilityRule.isPresubmit()) {
            aggressivelyUnlockSysUi();
        } else {
            verifyKeyguardInvisible();
        }
    }

    private static boolean hasSystemUiObject(String resId) {
        return getUiDevice().hasObject(
                By.res(SYSTEMUI_PACKAGE, resId));
    }

    private boolean hasSystemUiObject(String resId) {
        return mDevice.hasObject(By.res(SYSTEMUI_PACKAGE, resId));
    @NonNull
    private static UiDevice getUiDevice() {
        return UiDevice.getInstance(getInstrumentation());
    }

    // Seeing if this will decrease: b/303755862
    void aggressivelyUnlockSysUi() {
    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