1 /* 2 * Copyright (C) 2024 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 20 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector 21 import android.platform.systemui_tapl.utils.SYSUI_PACKAGE 22 import android.platform.systemui_tapl.utils.UserUtils.runThenWaitUntilSwitchCompleted 23 import android.platform.test.scenario.tapl_common.TaplUiDevice 24 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 25 import android.platform.uiautomatorhelpers.DeviceHelpers.uiDevice 26 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj 27 import androidx.test.uiautomator.By 28 import androidx.test.uiautomator.BySelector 29 import androidx.test.uiautomator.Until 30 31 /** 32 * List that shows up from the bouncer user switcher. 33 * 34 * https://hsv.googleplex.com/6537215275433984?node=3 35 */ 36 class UserSelectionExpandedList internal constructor() { 37 38 init { <lambda>null39 USERS_LIST_SELECTOR.assertVisible { "User selection list didn't appear" } 40 } 41 42 /** Opens add user prompt. */ openAddUserPromptnull43 fun openAddUserPrompt(): AddUserPrompt { 44 TaplUiDevice.waitForObject(ADD_USER_SELECTOR, "Add user menu item").click() 45 return AddUserPrompt() 46 } 47 48 /** Selects switching to an existing user or a new guest user. */ switchToUsernull49 fun switchToUser(userName: String) { 50 runThenWaitUntilSwitchCompleted { 51 // (b/265080418): The clickable attribute of these items are always false. 52 uiDevice.waitForObj(By.pkg(SYSUI_PACKAGE).text(userName)).click() 53 } 54 } 55 56 /** 57 * The number of options on the user selector list. 58 * https://hsv.googleplex.com/6542084124180480?node=3 59 */ 60 val numberOfUsers: Int 61 get() { 62 return uiDevice 63 .wait( 64 Until.findObjects(sysuiResSelector(USER_SWITCHER_ITEM_ID)), 65 DeviceUtils.SHORT_WAIT.toMillis(), 66 ) 67 ?.size ?: error("Can't find any user option.") 68 } 69 70 /** Asserts that user name exists on the expanded list. */ assertUserNameInExpandedListnull71 fun assertUserNameInExpandedList(userName: String) { 72 waitForObj(sysuiResSelector(USER_SWITCHER_ITEM_ID).hasDescendant(By.text(userName))) 73 } 74 75 private companion object { 76 val IS_COMPOSE_BOUNCER_ENABLED = 77 com.android.systemui.Flags.composeBouncer() || 78 com.android.systemui.Flags.sceneContainer() 79 const val USER_SWITCHER_ITEM_ID = "user_switcher_item" 80 81 // https://hsv.googleplex.com/6213668812357632?node=8 82 val ADD_USER_SELECTOR: BySelector = 83 sysuiResSelector(USER_SWITCHER_ITEM_ID).hasDescendant(By.text("Add user")) 84 85 // https://hsv.googleplex.com/6542084124180480?node=6 86 val OWNER_SELECTOR: BySelector = 87 sysuiResSelector(USER_SWITCHER_ITEM_ID).hasDescendant(By.text("Owner")) 88 89 // https://hsv.googleplex.com/6542084124180480?node=3 90 val USERS_LIST_SELECTOR: BySelector = 91 if (IS_COMPOSE_BOUNCER_ENABLED) sysuiResSelector("user_list_dropdown") 92 else 93 By.clazz("android.widget.ListView").pkg(SYSUI_PACKAGE).hasDescendant(OWNER_SELECTOR) 94 } 95 } 96