1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.android.quickstep; 18 19 import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE; 20 21 import static org.junit.Assert.assertTrue; 22 23 import com.android.launcher3.Launcher; 24 import com.android.launcher3.tapl.LauncherInstrumentation; 25 import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType; 26 import com.android.launcher3.ui.AbstractLauncherUiTest; 27 import com.android.quickstep.views.RecentsView; 28 29 import org.junit.rules.RuleChain; 30 import org.junit.rules.TestRule; 31 32 /** 33 * Base class for all instrumentation tests that deal with Quickstep. 34 */ 35 public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest { 36 @Override getRulesInsideActivityMonitor()37 protected TestRule getRulesInsideActivityMonitor() { 38 return RuleChain. 39 outerRule(new NavigationModeSwitchRule(mLauncher)). 40 around(super.getRulesInsideActivityMonitor()); 41 } 42 43 @Override onLauncherActivityClose(Launcher launcher)44 protected void onLauncherActivityClose(Launcher launcher) { 45 RecentsView recentsView = launcher.getOverviewPanel(); 46 if (recentsView != null) { 47 recentsView.finishRecentsAnimation(false /* toRecents */, null); 48 } 49 } 50 51 @Override checkLauncherState(Launcher launcher, ContainerType expectedContainerType, boolean isResumed, boolean isStarted)52 protected void checkLauncherState(Launcher launcher, ContainerType expectedContainerType, 53 boolean isResumed, boolean isStarted) { 54 if (!isInLiveTileMode(launcher, expectedContainerType)) { 55 super.checkLauncherState(launcher, expectedContainerType, isResumed, isStarted); 56 } else { 57 assertTrue("[Live Tile] hasBeenResumed() == isStarted(), hasBeenResumed(): " 58 + isResumed, isResumed != isStarted); 59 } 60 } 61 62 @Override checkLauncherStateInOverview(Launcher launcher, ContainerType expectedContainerType, boolean isStarted, boolean isResumed)63 protected void checkLauncherStateInOverview(Launcher launcher, 64 ContainerType expectedContainerType, boolean isStarted, boolean isResumed) { 65 if (!isInLiveTileMode(launcher, expectedContainerType)) { 66 super.checkLauncherStateInOverview(launcher, expectedContainerType, isStarted, 67 isResumed); 68 } else { 69 assertTrue( 70 "[Live Tile] Launcher is not started or has been resumed in state: " 71 + expectedContainerType, 72 isStarted && !isResumed); 73 } 74 } 75 isInLiveTileMode(Launcher launcher, LauncherInstrumentation.ContainerType expectedContainerType)76 private boolean isInLiveTileMode(Launcher launcher, 77 LauncherInstrumentation.ContainerType expectedContainerType) { 78 if (!ENABLE_QUICKSTEP_LIVE_TILE.get() 79 || expectedContainerType != LauncherInstrumentation.ContainerType.OVERVIEW) { 80 return false; 81 } 82 83 RecentsView recentsView = launcher.getOverviewPanel(); 84 return recentsView.getSizeStrategy().isInLiveTileMode() 85 && recentsView.getRunningTaskViewId() != -1; 86 } 87 } 88