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.helpers.LockscreenUtils.LockscreenType 20 import android.platform.helpers.LockscreenUtils.LockscreenType.PASSWORD 21 import android.platform.helpers.LockscreenUtils.LockscreenType.PIN 22 import android.platform.systemui_tapl.utils.DeviceUtils.androidResSelector 23 import android.platform.systemui_tapl.utils.DeviceUtils.settingsResSelector 24 import android.platform.test.scenario.tapl_common.Gestures 25 import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible 26 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 27 import android.platform.uiautomatorhelpers.DeviceHelpers.shell 28 import android.platform.uiautomatorhelpers.DeviceHelpers.uiDevice 29 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj 30 import androidx.test.uiautomator.By 31 import androidx.test.uiautomator.BySelector 32 import java.time.Duration 33 34 /** 35 * System UI test automation object representing the setup screen of screen lock. 36 * 37 * https://hsv.googleplex.com/6685423272198144 38 */ 39 class ChooseScreenLock internal constructor() { 40 41 init { 42 CHOOSE_A_SCREEN_LOCK_SELECTOR.assertVisible(timeout = LONG_WAIT_TIME) 43 } 44 45 /** 46 * Choose one screen lock. 47 * 48 * @param screenLockType type of screen lock set. 49 */ chooseScreenLocknull50 fun chooseScreenLock(screenLockType: LockscreenType) { 51 waitForObj(androidResSelector("title").text(screenLockType.toString())).click() 52 } 53 54 /** 55 * Entering the given code on the setup page of screen lock. 56 * 57 * If using the setLockscreenPin method to set a 6 digit PIN lock, it will not trigger the auto 58 * unlock feature, so add the functionality to set PIN lock. 59 * 60 * @param screenLockType type of screen lock set. 61 * @param screenLockCode screen lock code. 62 */ enterCodeOnSetupPageOfScreenLocknull63 fun enterCodeOnSetupPageOfScreenLock(screenLockType: LockscreenType, screenLockCode: String) { 64 when (screenLockType) { 65 PIN, 66 PASSWORD -> { 67 waitForObj(PASSWORD_ENTRY, LONG_WAIT_TIME).click() 68 uiDevice.shell("input keyboard text $screenLockCode") 69 Gestures.click(waitForObj(NEXT_BUTTON_SELECTOR, LONG_WAIT_TIME), "Next button") 70 uiDevice.shell("input keyboard text $screenLockCode") 71 Gestures.click( 72 waitForObj(CONFIRM_BUTTON_SELECTOR, LONG_WAIT_TIME), 73 "Confirm button", 74 ) 75 Gestures.click(waitForObj(DONE_BUTTON_SELECTOR, LONG_WAIT_TIME), "Done button") 76 DONE_BUTTON_SELECTOR.assertInvisible(timeout = LONG_WAIT_TIME) 77 } 78 else -> throw AssertionError("Non-supported Lockscreen Type: $screenLockType") 79 } 80 } 81 82 private companion object { 83 @JvmField val LONG_WAIT_TIME: Duration = Duration.ofSeconds(15) 84 85 const val BUTTON_CLASS = "android.widget.Button" 86 87 // https://hsv.googleplex.com/6685423272198144?node=7 88 val CHOOSE_A_SCREEN_LOCK_SELECTOR: BySelector = 89 settingsResSelector("collapsing_toolbar").desc("Choose a screen lock") 90 91 val PASSWORD_ENTRY: BySelector = settingsResSelector("password_entry") 92 93 val NEXT_BUTTON_SELECTOR: BySelector = By.clazz(BUTTON_CLASS).text("Next") 94 95 val CONFIRM_BUTTON_SELECTOR: BySelector = By.clazz(BUTTON_CLASS).text("Confirm") 96 97 // https://hsv.googleplex.com/5618542457126912?node=26 98 val DONE_BUTTON_SELECTOR: BySelector = By.clazz(BUTTON_CLASS).text("Done") 99 } 100 } 101