1 /* 2 * Copyright (C) 2023 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 package android.platform.systemui_tapl.ui 17 18 import android.graphics.Rect 19 import android.platform.systemui_tapl.ui.NotificationShade.Companion.waitForShadeToClose 20 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector 21 import android.platform.uiautomatorhelpers.DeviceHelpers 22 import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible 23 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 24 import android.platform.uiautomatorhelpers.DeviceHelpers.betterSwipe 25 import android.view.WindowInsets 26 import android.view.WindowManager 27 import android.view.WindowMetrics 28 29 /** 30 * System UI test automation object representing swipe down screen bottom to trigger one-handed mode 31 * triggered, the whole screen translate down and tutorial shown on top area. 32 * HSV:https://hsv.googleplex.com/4846680840077312 Lastly, swipe down gesture to close one-handed 33 * mode, and ensure the display area recovered. Swipe gesture 34 * region:https://screenshot.googleplex.com/q83UXMidE2PUFDq) 35 */ 36 class OneHandModeTutorial internal constructor() { 37 38 init { 39 waitForShadeToClose() 40 TUTORIAL_SELECTOR.assertVisible() 41 } 42 43 /** 44 * Closes the one-handed mode by swipe up gesture at screen bottom area. Gesture region: 45 * https://screenshot.googleplex.com/q83UXMidE2PUFDq, and make sure the tutorial invisible from 46 * screen at the end. 47 */ closenull48 fun close() { 49 val windowMetrics: WindowMetrics = 50 DeviceHelpers.context.getSystemService(WindowManager::class.java)!!.currentWindowMetrics 51 val insets: WindowInsets = windowMetrics.windowInsets 52 val displayBounds: Rect = windowMetrics.bounds 53 val bottomMandatoryGestureHeight: Int = 54 insets 55 .getInsetsIgnoringVisibility( 56 WindowInsets.Type.navigationBars() or WindowInsets.Type.displayCutout() 57 ) 58 .bottom 59 60 // Swipe up from screen bottom exiting one-handed mode in System Gesture mandatory region. 61 betterSwipe( 62 displayBounds.width() / 2, 63 displayBounds.height(), 64 displayBounds.width() / 2, 65 displayBounds.height() - Math.round(bottomMandatoryGestureHeight * 2.5f), 66 ) 67 68 TUTORIAL_SELECTOR.assertInvisible() 69 } 70 71 companion object { 72 private val TUTORIAL_SELECTOR = sysuiResSelector("one_handed_tutorial_layout") 73 private const val TRANSITION_TIMEOUT = 20000 74 } 75 } 76