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 17 package android.platform.helpers.features.common; 18 19 import static android.platform.helpers.ui.UiAutomatorUtils.getUiDevice; 20 21 import static com.android.systemui.Flags.migrateClocksToBlueprint; 22 import static com.android.systemui.Flags.sceneContainer; 23 24 import static com.google.common.truth.Truth.assertWithMessage; 25 26 import static java.util.concurrent.TimeUnit.SECONDS; 27 28 import android.os.RemoteException; 29 import android.platform.helpers.features.Page; 30 import android.util.Log; 31 32 import androidx.test.uiautomator.By; 33 import androidx.test.uiautomator.BySelector; 34 import androidx.test.uiautomator.Direction; 35 import androidx.test.uiautomator.UiObject2; 36 import androidx.test.uiautomator.Until; 37 38 /** 39 * Helper class for Lock screen Home page. This contains the all the possible helper methods for the 40 * page. 41 * 42 * HSV: 43 * - Android 11: http://go/hsv/4836673386971136 44 * - Android 12: http://go/hsv/5398171133935616 45 * - Android 12 (big clock): http://go/hsv/4759092784529408 46 * @deprecated use classes from the "systemui-tapl" library instead 47 */ 48 @Deprecated 49 public class HomeLockscreenPage implements Page { 50 51 // https://hsv.googleplex.com/4836673386971136?node=68 52 public static final BySelector SWIPEABLE_AREA = 53 By.res( 54 "com.android.systemui", 55 com.android.systemui.Flags.sceneContainer() 56 ? "shared_notification_container" 57 : "notification_panel"); 58 // https://hsv.googleplex.com/5130837462876160?node=117 59 60 public static final String PAGE_TITLE_ID = 61 migrateClocksToBlueprint() ? "keyguard_indication_area" : "keyguard_clock_container"; 62 private static final BySelector PAGE_TITLE_SELECTOR = 63 sceneContainer() 64 ? By.res("element:lockscreen") 65 : By.res("com.android.systemui", PAGE_TITLE_ID); 66 private static final int SHORT_SLEEP_IN_SECONDS = 2; 67 private static final int WAIT_TIME_MILLIS = 5000; 68 69 @Override open()70 public void open() { 71 try { 72 // Turning off the screen for lockscreen to enable 73 getUiDevice().sleep(); 74 // Immediately waking up the device after sleep acts weird. 75 SECONDS.sleep(SHORT_SLEEP_IN_SECONDS); 76 // Waking up the device. 77 getUiDevice().wakeUp(); 78 } catch (RemoteException | InterruptedException e) { 79 Log.e(getPageName(), String.format("Exception Occurred: %s", e)); 80 throw new RuntimeException(e); 81 } 82 } 83 84 /** 85 * To get page selector used for determining the given page 86 * 87 * @return an instance of given page selector identifier. 88 */ 89 @Override getPageTitleSelector()90 public BySelector getPageTitleSelector() { 91 return PAGE_TITLE_SELECTOR; 92 } 93 94 /** If we're currently on the lock screen. */ isVisible()95 public boolean isVisible() { 96 return getUiDevice().findObject(PAGE_TITLE_SELECTOR) != null; 97 } 98 99 /** 100 * To swipe the keyguard ui element up. 101 * HSV: https://hsv.googleplex.com/4836673386971136?node=68 102 */ swipeUp()103 public void swipeUp() { 104 UiObject2 swipeableArea = getUiDevice().wait(Until.findObject(SWIPEABLE_AREA), 105 WAIT_TIME_MILLIS); 106 assertWithMessage("Swipeable area not found").that(swipeableArea).isNotNull(); 107 // shift swipe gesture over to left so we don't begin the gesture on the lock icon 108 // this can be removed if b/229696938 gets resolved to allow for swiping on the icon 109 swipeableArea.setGestureMargins( 110 /* left= */ 0, /* top= */ 0, swipeableArea.getVisibleCenter().x, /* bottom= */ 1); 111 swipeableArea.swipe(Direction.UP, /* percent= */ 0.7f, /* speed= */ 1000); 112 } 113 } 114