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