1 /* 2 * Copyright (C) 2022 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.launcher3.tapl; 17 18 import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL; 19 20 import androidx.annotation.NonNull; 21 import androidx.test.uiautomator.UiObject2; 22 23 import com.android.launcher3.testing.shared.TestProtocol; 24 25 public class HomeAllApps extends AllApps { 26 private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background"; 27 HomeAllApps(LauncherInstrumentation launcher)28 HomeAllApps(LauncherInstrumentation launcher) { 29 super(launcher); 30 } 31 32 /** 33 * Swipes up or down to dismiss to Workspace. 34 * @param swipeDown Swipe all apps down to dismiss, otherwise swipe up to dismiss by going home. 35 * 36 * @return the Workspace object. 37 */ 38 @NonNull switchToWorkspace(boolean swipeDown)39 public Workspace switchToWorkspace(boolean swipeDown) { 40 try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); 41 LauncherInstrumentation.Closable c = 42 mLauncher.addContextLayer("want to switch from all apps to workspace")) { 43 UiObject2 allAppsContainer = verifyActiveContainer(); 44 45 final int startX = allAppsContainer.getVisibleCenter().x; 46 final int startY = swipeDown ? getTopVisibleIconBounds(allAppsContainer).centerY() 47 : mLauncher.getDevice().getDisplayHeight(); 48 final int endY = 49 swipeDown ? mLauncher.getDevice().getDisplayHeight() : getTopVisibleIconBounds( 50 allAppsContainer).centerY(); 51 LauncherInstrumentation.log( 52 "switchToWorkspace: startY = " + startY + ", endY = " + endY 53 + ", slop = " + mLauncher.getTouchSlop() 54 + ", swipeDown = " + swipeDown); 55 56 mLauncher.swipeToState( 57 startX, 58 startY, 59 startX, 60 endY, 61 5 /* steps */, 62 NORMAL_STATE_ORDINAL, 63 swipeDown ? LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER 64 : LauncherInstrumentation.GestureScope.EXPECT_PILFER); 65 66 try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( 67 "swiped to workspace")) { 68 return mLauncher.getWorkspace(); 69 } 70 } 71 } 72 73 @Override getContainerType()74 protected LauncherInstrumentation.ContainerType getContainerType() { 75 return LauncherInstrumentation.ContainerType.HOME_ALL_APPS; 76 } 77 78 @NonNull 79 @Override getAppIcon(String appName)80 public HomeAppIcon getAppIcon(String appName) { 81 return (AllAppsAppIcon) super.getAppIcon(appName); 82 } 83 84 @NonNull 85 @Override createAppIcon(UiObject2 icon)86 protected HomeAppIcon createAppIcon(UiObject2 icon) { 87 return new AllAppsAppIcon(mLauncher, icon); 88 } 89 90 @Override hasSearchBox()91 protected boolean hasSearchBox() { 92 return true; 93 } 94 95 @Override getAppsListRecyclerTopPadding()96 protected int getAppsListRecyclerTopPadding() { 97 return mLauncher.getTestInfo(TestProtocol.REQUEST_ALL_APPS_TOP_PADDING) 98 .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); 99 } 100 101 /** 102 * Taps outside bottom sheet to dismiss and return to workspace. Available on tablets only. 103 * @param tapRight Tap on the right of bottom sheet if true, or left otherwise. 104 */ dismissByTappingOutsideForTablet(boolean tapRight)105 public Workspace dismissByTappingOutsideForTablet(boolean tapRight) { 106 try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); 107 LauncherInstrumentation.Closable c = mLauncher.addContextLayer( 108 "want to tap outside AllApps bottom sheet on the " 109 + (tapRight ? "right" : "left"))) { 110 final UiObject2 allAppsBottomSheet = 111 mLauncher.waitForLauncherObject(BOTTOM_SHEET_RES_ID); 112 mLauncher.touchOutsideContainer(allAppsBottomSheet, tapRight); 113 try (LauncherInstrumentation.Closable tapped = mLauncher.addContextLayer( 114 "tapped outside AllApps bottom sheet")) { 115 return mLauncher.getWorkspace(); 116 } 117 } 118 } 119 120 @NonNull 121 @Override getQsb()122 public Qsb getQsb() { 123 return new AllAppsQsb(mLauncher, verifyActiveContainer()); 124 } 125 126 @Override getAllAppsScroll()127 protected int getAllAppsScroll() { 128 return mLauncher.getTestInfo(TestProtocol.REQUEST_APPS_LIST_SCROLL_Y) 129 .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); 130 } 131 } 132