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 org.junit.Assert.assertFalse; 20 import static org.junit.Assert.assertTrue; 21 import static org.junit.Assume.assumeTrue; 22 23 import android.content.Intent; 24 25 import androidx.test.ext.junit.runners.AndroidJUnit4; 26 import androidx.test.filters.LargeTest; 27 import androidx.test.platform.app.InstrumentationRegistry; 28 29 import com.android.launcher3.tapl.Overview; 30 import com.android.launcher3.tapl.Taskbar; 31 import com.android.launcher3.tapl.TaskbarAppIcon; 32 import com.android.quickstep.util.SplitScreenTestUtils; 33 34 import org.junit.After; 35 import org.junit.Before; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 39 @LargeTest 40 @RunWith(AndroidJUnit4.class) 41 public class TaplTestsSplitscreen extends AbstractQuickStepTest { 42 private static final String CALCULATOR_APP_NAME = "Calculator"; 43 private static final String CALCULATOR_APP_PACKAGE = 44 resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); 45 46 private static final String READ_DEVICE_CONFIG_PERMISSION = 47 "android.permission.READ_DEVICE_CONFIG"; 48 49 @Override 50 @Before setUp()51 public void setUp() throws Exception { 52 super.setUp(); 53 54 if (mLauncher.isTablet()) { 55 mLauncher.enableBlockTimeout(true); 56 mLauncher.showTaskbarIfHidden(); 57 } 58 InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity( 59 READ_DEVICE_CONFIG_PERMISSION); 60 } 61 62 @After tearDown()63 public void tearDown() { 64 if (mLauncher.isTablet()) { 65 mLauncher.enableBlockTimeout(false); 66 } 67 } 68 69 @Test testSplitAppFromHomeWithItself()70 public void testSplitAppFromHomeWithItself() throws Exception { 71 // Currently only tablets have Taskbar in Overview, so test is only active on tablets 72 assumeTrue(mLauncher.isTablet()); 73 74 mLauncher.getWorkspace() 75 .deleteAppIcon(mLauncher.getWorkspace().getHotseatAppIcon(0)) 76 .switchToAllApps() 77 .getAppIcon(CALCULATOR_APP_NAME) 78 .dragToHotseat(0); 79 80 startAppFast(CALCULATOR_APP_PACKAGE); 81 82 mLauncher.goHome() 83 .switchToAllApps() 84 .getAppIcon(CALCULATOR_APP_NAME) 85 .openMenu() 86 .getSplitScreenMenuItem() 87 .click(); 88 89 // We're staying in all apps, use same instance 90 mLauncher.getAllApps() 91 .getAppIcon(CALCULATOR_APP_NAME) 92 .launchIntoSplitScreen(); 93 } 94 95 @Test testSaveAppPairMenuItemOrActionExistsOnSplitPair()96 public void testSaveAppPairMenuItemOrActionExistsOnSplitPair() { 97 Overview overview = SplitScreenTestUtils.createAndLaunchASplitPairInOverview(mLauncher); 98 99 if (mLauncher.isGridOnlyOverviewEnabled() || !mLauncher.isTablet()) { 100 assertTrue("Save app pair menu item is missing", 101 overview.getCurrentTask() 102 .tapMenu() 103 .hasMenuItem("Save app pair")); 104 } 105 } 106 107 @Test testSaveAppPairMenuItemDoesNotExistOnSingleTask()108 public void testSaveAppPairMenuItemDoesNotExistOnSingleTask() throws Exception { 109 startAppFast(CALCULATOR_APP_PACKAGE); 110 111 assertFalse("Save app pair menu item is erroneously appearing on single task", 112 mLauncher.goHome() 113 .switchToOverview() 114 .getCurrentTask() 115 .tapMenu() 116 .hasMenuItem("Save app pair")); 117 } 118 119 @Test testSplitSingleTaskFromTaskbar()120 public void testSplitSingleTaskFromTaskbar() { 121 // Currently only tablets have Taskbar in Overview, so test is only active on tablets 122 assumeTrue(mLauncher.isTablet()); 123 124 clearAllRecentTasks(); 125 startAppFast(getAppPackageName()); 126 127 Overview overview = mLauncher.goHome().switchToOverview(); 128 if (mLauncher.isGridOnlyOverviewEnabled()) { 129 overview.getCurrentTask().tapMenu().tapSplitMenuItem(); 130 } else { 131 overview.getOverviewActions().clickSplit(); 132 } 133 134 Taskbar taskbar = overview.getTaskbar(); 135 String firstAppName = taskbar.getIconNames().get(0); 136 TaskbarAppIcon firstApp = taskbar.getAppIcon(firstAppName); 137 firstApp.launchIntoSplitScreen(); 138 } 139 } 140