1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.quickstep; 17 18 19 import static com.android.launcher3.config.FeatureFlags.enableSplitContextually; 20 import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL; 21 import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT; 22 23 import static org.junit.Assert.assertFalse; 24 import static org.junit.Assert.assertTrue; 25 import static org.junit.Assume.assumeTrue; 26 27 import android.content.Intent; 28 29 import androidx.test.ext.junit.runners.AndroidJUnit4; 30 import androidx.test.filters.LargeTest; 31 import androidx.test.platform.app.InstrumentationRegistry; 32 33 import com.android.launcher3.tapl.Overview; 34 import com.android.launcher3.tapl.Taskbar; 35 import com.android.launcher3.tapl.TaskbarAppIcon; 36 import com.android.launcher3.util.rule.TestStabilityRule; 37 import com.android.wm.shell.Flags; 38 39 import org.junit.After; 40 import org.junit.Before; 41 import org.junit.Test; 42 import org.junit.runner.RunWith; 43 44 @LargeTest 45 @RunWith(AndroidJUnit4.class) 46 public class TaplTestsSplitscreen extends AbstractQuickStepTest { 47 private static final String CALCULATOR_APP_NAME = "Calculator"; 48 private static final String CALCULATOR_APP_PACKAGE = 49 resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); 50 51 private static final String READ_DEVICE_CONFIG_PERMISSION = 52 "android.permission.READ_DEVICE_CONFIG"; 53 54 @Override 55 @Before setUp()56 public void setUp() throws Exception { 57 super.setUp(); 58 59 if (mLauncher.isTablet()) { 60 mLauncher.enableBlockTimeout(true); 61 mLauncher.showTaskbarIfHidden(); 62 } 63 InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity( 64 READ_DEVICE_CONFIG_PERMISSION); 65 } 66 67 @After tearDown()68 public void tearDown() { 69 if (mLauncher.isTablet()) { 70 mLauncher.enableBlockTimeout(false); 71 } 72 } 73 74 @Test 75 @TestStabilityRule.Stability(flavors = PLATFORM_POSTSUBMIT | LOCAL) // b/295225524 testSplitAppFromHomeWithItself()76 public void testSplitAppFromHomeWithItself() throws Exception { 77 // Currently only tablets have Taskbar in Overview, so test is only active on tablets 78 assumeTrue(mLauncher.isTablet()); 79 80 mLauncher.getWorkspace() 81 .deleteAppIcon(mLauncher.getWorkspace().getHotseatAppIcon(0)) 82 .switchToAllApps() 83 .getAppIcon(CALCULATOR_APP_NAME) 84 .dragToHotseat(0); 85 86 startAppFast(CALCULATOR_APP_PACKAGE); 87 88 mLauncher.goHome() 89 .switchToAllApps() 90 .getAppIcon(CALCULATOR_APP_NAME) 91 .openMenu() 92 .getSplitScreenMenuItem() 93 .click(); 94 95 if (enableSplitContextually()) { 96 // We're staying in all apps, use same instance 97 mLauncher.getAllApps() 98 .getAppIcon(CALCULATOR_APP_NAME) 99 .launchIntoSplitScreen(); 100 } else { 101 // We're in overview, use taskbar instance 102 mLauncher.getLaunchedAppState() 103 .getTaskbar() 104 .getAppIcon(CALCULATOR_APP_NAME) 105 .launchIntoSplitScreen(); 106 } 107 } 108 109 @Test testSaveAppPairMenuItemOrActionExistsOnSplitPair()110 public void testSaveAppPairMenuItemOrActionExistsOnSplitPair() { 111 assumeTrue("App pairs feature is currently not enabled, no test needed", 112 Flags.enableAppPairs()); 113 114 createAndLaunchASplitPair(); 115 116 Overview overview = mLauncher.goHome().switchToOverview(); 117 if (mLauncher.isGridOnlyOverviewEnabled() || !mLauncher.isTablet()) { 118 assertTrue("Save app pair menu item is missing", 119 overview.getCurrentTask() 120 .tapMenu() 121 .hasMenuItem("Save app pair")); 122 } 123 } 124 125 @Test testSaveAppPairMenuItemDoesNotExistOnSingleTask()126 public void testSaveAppPairMenuItemDoesNotExistOnSingleTask() throws Exception { 127 assumeTrue("App pairs feature is currently not enabled, no test needed", 128 Flags.enableAppPairs()); 129 130 startAppFast(CALCULATOR_APP_PACKAGE); 131 132 assertFalse("Save app pair menu item is erroneously appearing on single task", 133 mLauncher.goHome() 134 .switchToOverview() 135 .getCurrentTask() 136 .tapMenu() 137 .hasMenuItem("Save app pair")); 138 } 139 140 @Test testSplitSingleTaskFromTaskbar()141 public void testSplitSingleTaskFromTaskbar() { 142 // Currently only tablets have Taskbar in Overview, so test is only active on tablets 143 assumeTrue(mLauncher.isTablet()); 144 145 clearAllRecentTasks(); 146 startAppFast(getAppPackageName()); 147 148 Overview overview = mLauncher.goHome().switchToOverview(); 149 if (mLauncher.isGridOnlyOverviewEnabled()) { 150 overview.getCurrentTask().tapMenu().tapSplitMenuItem(); 151 } else { 152 overview.getOverviewActions().clickSplit(); 153 } 154 155 Taskbar taskbar = overview.getTaskbar(); 156 String firstAppName = taskbar.getIconNames().get(0); 157 TaskbarAppIcon firstApp = taskbar.getAppIcon(firstAppName); 158 firstApp.launchIntoSplitScreen(); 159 } 160 createAndLaunchASplitPair()161 private void createAndLaunchASplitPair() { 162 clearAllRecentTasks(); 163 164 startTestActivity(2); 165 startTestActivity(3); 166 167 if (mLauncher.isTablet() && !mLauncher.isGridOnlyOverviewEnabled()) { 168 mLauncher.goHome().switchToOverview().getOverviewActions() 169 .clickSplit() 170 .getTestActivityTask(2) 171 .open(); 172 } else { 173 mLauncher.goHome().switchToOverview().getCurrentTask() 174 .tapMenu() 175 .tapSplitMenuItem() 176 .getCurrentTask() 177 .open(); 178 } 179 } 180 } 181