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

Commit 9d706b1a authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Fix failed test in order to enable Live Tile (in the next change)

Live tile changes certain assumptions we have for tests, for example
- Launcher will not be in the resumed state after swiping up to Overview

Also, disable live tile for 3rd party launcher for now

Test: presubmit
Fixes: 169694902
Change-Id: Ifd466db0354f59290c4f66a0a2ad4c82f1169f29
parent 29c1e843
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TI

import android.content.Context;

import com.android.quickstep.OverviewComponentObserver;
import com.android.quickstep.RecentsAnimationDeviceState;
import com.android.quickstep.SysUINavigationMode;

import java.util.function.Predicate;
@@ -35,6 +37,7 @@ public class NavigationModeFeatureFlag implements
    private final Supplier<Boolean> mBasePredicate;
    private final Predicate<SysUINavigationMode.Mode> mModePredicate;
    private boolean mSupported;
    private OverviewComponentObserver mObserver;

    private NavigationModeFeatureFlag(Supplier<Boolean> basePredicate,
            Predicate<SysUINavigationMode.Mode> modePredicate) {
@@ -43,12 +46,16 @@ public class NavigationModeFeatureFlag implements
    }

    public boolean get() {
        return mBasePredicate.get() && mSupported;
        return mBasePredicate.get() && mSupported && mObserver.isHomeAndOverviewSame();
    }

    public void initialize(Context context) {
        onNavigationModeChanged(SysUINavigationMode.INSTANCE.get(context).getMode());
        SysUINavigationMode.INSTANCE.get(context).addModeChangeListener(this);

        // Temporary solution to disable live tile for the fallback launcher
        RecentsAnimationDeviceState rads = new RecentsAnimationDeviceState(context);
        mObserver = new OverviewComponentObserver(context, rads);
    }

    @Override
+53 −0
Original line number Diff line number Diff line
@@ -16,7 +16,15 @@

package com.android.quickstep;

import static com.android.quickstep.util.NavigationModeFeatureFlag.LIVE_TILE;

import static org.junit.Assert.assertTrue;

import com.android.launcher3.Launcher;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.quickstep.views.RecentsView;

import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
@@ -31,4 +39,49 @@ public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
                outerRule(new NavigationModeSwitchRule(mLauncher)).
                around(super.getRulesInsideActivityMonitor());
    }

    @Override
    protected void onLauncherActivityClose(Launcher launcher) {
        RecentsView recentsView = launcher.getOverviewPanel();
        if (recentsView != null) {
            recentsView.finishRecentsAnimation(true, null);
        }
    }

    @Override
    protected void checkLauncherState(Launcher launcher, ContainerType expectedContainerType,
            boolean isResumed, boolean isStarted) {
        if (!isInLiveTileMode(launcher, expectedContainerType)) {
            super.checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);
        } else {
            assertTrue("[Live Tile] hasBeenResumed() == isStarted(), hasBeenResumed(): "
                            + isResumed, isResumed != isStarted);
        }
    }

    @Override
    protected void checkLauncherStateInOverview(Launcher launcher,
            ContainerType expectedContainerType, boolean isStarted, boolean isResumed) {
        if (!isInLiveTileMode(launcher, expectedContainerType)) {
            super.checkLauncherStateInOverview(launcher, expectedContainerType, isStarted,
                    isResumed);
        } else {
            assertTrue(
                    "[Live Tile] Launcher is not started or has been resumed in state: "
                            + expectedContainerType,
                    isStarted && !isResumed);
        }
    }

    private boolean isInLiveTileMode(Launcher launcher,
            LauncherInstrumentation.ContainerType expectedContainerType) {
        if (!LIVE_TILE.get()
                || expectedContainerType != LauncherInstrumentation.ContainerType.OVERVIEW) {
            return false;
        }

        RecentsView recentsView = launcher.getOverviewPanel();
        return recentsView.getSizeStrategy().isInLiveTileMode()
                && recentsView.getRunningTaskId() != -1;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest {
            // The test action.
            mLauncher.getBackground().switchToOverview();
        }
        closeLauncherActivity();
        mLauncher.pressHome();
    }
}
+21 −7
Original line number Diff line number Diff line
@@ -503,6 +503,7 @@ public abstract class AbstractLauncherUiTest {
        // Destroy Launcher activity.
        executeOnLauncher(launcher -> {
            if (launcher != null) {
                onLauncherActivityClose(launcher);
                launcher.finish();
            }
        });
@@ -524,7 +525,7 @@ public abstract class AbstractLauncherUiTest {
        return launcher.getAppsView().getActiveRecyclerView().getCurrentScrollY();
    }

    private static void checkLauncherIntegrity(
    private void checkLauncherIntegrity(
            Launcher launcher, ContainerType expectedContainerType) {
        if (launcher != null) {
            final StateManager<LauncherState> stateManager = launcher.getStateManager();
@@ -535,10 +536,8 @@ public abstract class AbstractLauncherUiTest {
                    stableState == stateManager.getState());

            final boolean isResumed = launcher.hasBeenResumed();
            assertTrue("hasBeenResumed() != isStarted(), hasBeenResumed(): " + isResumed,
                    isResumed == launcher.isStarted());
            assertTrue("hasBeenResumed() != isUserActive(), hasBeenResumed(): " + isResumed,
                    isResumed == launcher.isUserActive());
            final boolean isStarted = launcher.isStarted();
            checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);

            final int ordinal = stableState.ordinal;

@@ -561,8 +560,7 @@ public abstract class AbstractLauncherUiTest {
                    break;
                }
                case OVERVIEW: {
                    assertTrue(
                            "Launcher is not resumed in state: " + expectedContainerType,
                    checkLauncherStateInOverview(launcher, expectedContainerType, isStarted,
                            isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal),
                            ordinal == TestProtocol.OVERVIEW_STATE_ORDINAL);
@@ -587,4 +585,20 @@ public abstract class AbstractLauncherUiTest {
                            expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
        }
    }

    protected void checkLauncherState(Launcher launcher, ContainerType expectedContainerType,
            boolean isResumed, boolean isStarted) {
        assertTrue("hasBeenResumed() != isStarted(), hasBeenResumed(): " + isResumed,
                isResumed == isStarted);
        assertTrue("hasBeenResumed() != isUserActive(), hasBeenResumed(): " + isResumed,
                isResumed == launcher.isUserActive());
    }

    protected void checkLauncherStateInOverview(Launcher launcher,
            ContainerType expectedContainerType, boolean isStarted, boolean isResumed) {
        assertTrue("Launcher is not resumed in state: " + expectedContainerType,
                isResumed);
    }

    protected void onLauncherActivityClose(Launcher launcher) { }
}