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