Search in sources :

Example 6 with LauncherInstrumentation

use of com.android.launcher3.tapl.LauncherInstrumentation in project android_packages_apps_Launcher3 by ProtonAOSP.

the class NavigationModeSwitchRule method setActiveOverlay.

public static boolean setActiveOverlay(LauncherInstrumentation launcher, String overlayPackage, LauncherInstrumentation.NavigationModel expectedMode, Description description) throws Exception {
    if (!packageExists(overlayPackage)) {
        Log.d(TAG, "setActiveOverlay: " + overlayPackage + " pkg does not exist");
        return false;
    }
    Log.d(TAG, "setActiveOverlay: " + overlayPackage + "...");
    UiDevice.getInstance(getInstrumentation()).executeShellCommand("cmd overlay enable-exclusive --category " + overlayPackage);
    if (currentSysUiNavigationMode() != expectedMode) {
        final CountDownLatch latch = new CountDownLatch(1);
        final Context targetContext = getInstrumentation().getTargetContext();
        final SysUINavigationMode.NavigationModeChangeListener listener = newMode -> {
            if (LauncherInstrumentation.getNavigationModel(newMode.resValue) == expectedMode) {
                latch.countDown();
            }
        };
        targetContext.getMainExecutor().execute(() -> SYS_UI_NAVIGATION_MODE.addModeChangeListener(listener));
        latch.await(60, TimeUnit.SECONDS);
        targetContext.getMainExecutor().execute(() -> SYS_UI_NAVIGATION_MODE.removeModeChangeListener(listener));
        assertTrue(launcher, "Navigation mode didn't change to " + expectedMode, currentSysUiNavigationMode() == expectedMode, description);
    }
    Wait.atMost("Couldn't switch to " + overlayPackage, () -> launcher.getNavigationModel() == expectedMode, WAIT_TIME_MS, launcher);
    Wait.atMost(() -> "Switching nav mode: " + launcher.getNavigationModeMismatchError(false), () -> launcher.getNavigationModeMismatchError(false) == null, WAIT_TIME_MS, launcher);
    AbstractLauncherUiTest.checkDetectedLeaks(launcher);
    return true;
}
Also used : Context(android.content.Context) Context(android.content.Context) FailureWatcher(com.android.launcher3.util.rule.FailureWatcher) Statement(org.junit.runners.model.Statement) ZERO_BUTTON(com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON) NAV_BAR_MODE_3BUTTON_OVERLAY(com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_3BUTTON_OVERLAY) TWO_BUTTON(com.android.quickstep.NavigationModeSwitchRule.Mode.TWO_BUTTON) PackageManager(android.content.pm.PackageManager) TestRule(org.junit.rules.TestRule) QuickStepContract(com.android.systemui.shared.system.QuickStepContract) NAV_BAR_MODE_GESTURAL_OVERLAY(com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY) TestHelpers(com.android.launcher3.tapl.TestHelpers) Retention(java.lang.annotation.Retention) InstrumentationRegistry.getInstrumentation(androidx.test.InstrumentationRegistry.getInstrumentation) THREE_BUTTON(com.android.quickstep.NavigationModeSwitchRule.Mode.THREE_BUTTON) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) ALL(com.android.quickstep.NavigationModeSwitchRule.Mode.ALL) Log(android.util.Log) UiDevice(androidx.test.uiautomator.UiDevice) LauncherInstrumentation(com.android.launcher3.tapl.LauncherInstrumentation) NAV_BAR_MODE_2BUTTON_OVERLAY(com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_2BUTTON_OVERLAY) Description(org.junit.runner.Description) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Wait(com.android.launcher3.util.Wait) RetentionPolicy(java.lang.annotation.RetentionPolicy) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Context (android.content.Context)6 PackageManager (android.content.pm.PackageManager)6 Log (android.util.Log)6 InstrumentationRegistry.getInstrumentation (androidx.test.InstrumentationRegistry.getInstrumentation)6 UiDevice (androidx.test.uiautomator.UiDevice)6 LauncherInstrumentation (com.android.launcher3.tapl.LauncherInstrumentation)6 TestHelpers (com.android.launcher3.tapl.TestHelpers)6 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)6 Wait (com.android.launcher3.util.Wait)6 FailureWatcher (com.android.launcher3.util.rule.FailureWatcher)6 ALL (com.android.quickstep.NavigationModeSwitchRule.Mode.ALL)6 THREE_BUTTON (com.android.quickstep.NavigationModeSwitchRule.Mode.THREE_BUTTON)6 TWO_BUTTON (com.android.quickstep.NavigationModeSwitchRule.Mode.TWO_BUTTON)6 ZERO_BUTTON (com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON)6 QuickStepContract (com.android.systemui.shared.system.QuickStepContract)6 NAV_BAR_MODE_2BUTTON_OVERLAY (com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_2BUTTON_OVERLAY)6 NAV_BAR_MODE_3BUTTON_OVERLAY (com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_3BUTTON_OVERLAY)6 NAV_BAR_MODE_GESTURAL_OVERLAY (com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY)6 ElementType (java.lang.annotation.ElementType)6 Retention (java.lang.annotation.Retention)6