• 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.systemui_tapl.ui
18 
19 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector
20 import android.platform.uiautomatorhelpers.DeviceHelpers.doubleTapAt
21 import android.platform.uiautomatorhelpers.DeviceHelpers.uiDevice
22 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForFirstObj
23 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj
24 import android.platform.uiautomatorhelpers.assertOnTheLeftSide
25 import android.platform.uiautomatorhelpers.assertOnTheRightSide
26 import java.time.Duration
27 
28 /**
29  * User switcher visible on lockscreen on large screen devices when
30  * [USER_SWITCHER_VISIBLE_FLAG_NAME] is enabled. Constructor fails if the switcher is not visible.
31  */
32 class LockscreenUserSwitcher internal constructor() {
33 
34     private val uiObject =
<lambda>null35         waitForFirstObj(*USER_SWITCHER_SELECTORS, timeout = LONG_WAIT) {
36                 "Lockscreen user switcher not found"
37             }
38             .first
39 
40     /** Check that the bouncer is on the right side of the screen. */
assertOnTheRightSidenull41     fun assertOnTheRightSide(): Unit = uiObject.assertOnTheRightSide()
42 
43     /** Check that the bouncer is on the left side of the screen. */
44     fun assertOnTheLeftSide(): Unit = uiObject.assertOnTheLeftSide()
45 
46     /**
47      * Double tap the bottom of the view. Used for large screen where user switcher is side by side
48      * with bouncer and double tapping means they should switch sides horizontally
49      */
50     fun doubleTapBelowUserSwitcher() {
51         val bounds = uiObject.visibleBounds
52         // Tap 5 pixels below the user switcher UI element.
53         val (touchX, touchY) = Pair(bounds.centerX(), bounds.bottom + 5)
54         uiDevice.doubleTapAt(touchX, touchY)
55     }
56 
57     /** Taps the user switcher anchor to expand the list. */
openUserSelectorExpandedListnull58     fun openUserSelectorExpandedList(): UserSelectionExpandedList {
59         waitForObj(USER_SWITCHER_DROPDOWN_SELECTOR) { "User switcher anchor not found" }.click()
60         return UserSelectionExpandedList()
61     }
62 
63     private companion object {
64         // Default wait used by waitForObj. waitForFirstObj uses a shorter wait.
65         private val LONG_WAIT = Duration.ofSeconds(10)
66 
67         // https://hsv.googleplex.com/6328527512141824?node=23
68         private val USER_SWITCHER_DROPDOWN_SELECTOR = sysuiResSelector("user_switcher_anchor")
69         private val USER_SWITCHER_SELECTORS =
70             arrayOf(
71                 sysuiResSelector("keyguard_bouncer_user_switcher"),
72                 sysuiResSelector("UserSwitcher"),
73             )
74     }
75 }
76