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.graphics.PointF 20 import android.platform.uiautomatorhelpers.BetterSwipe 21 import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible 22 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 23 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj 24 import androidx.test.uiautomator.By 25 26 /** System UI test automation object representing the communal hub. */ 27 class CommunalHub internal constructor() { 28 init { <lambda>null29 COMMUNAL_SELECTOR.assertVisible { "Communal Hub is not visible" } 30 } 31 32 /** Swipes right on the communal hub to exit the surface. */ swipeRightToExitnull33 fun swipeRightToExit() { 34 COMMUNAL_SELECTOR.assertVisible { "Communal Hub is not visible for swiping right" } 35 swipeRight() 36 COMMUNAL_SELECTOR.assertInvisible { "Communal Hub is still visible after swiping right" } 37 } 38 swipeRightnull39 private fun swipeRight() { 40 val bounds = waitForObj(COMMUNAL_SELECTOR).visibleBounds 41 val swipeY = bounds.top + bounds.height() / 2f 42 BetterSwipe.swipe( 43 PointF(bounds.left + 1f, swipeY), 44 PointF(bounds.left + bounds.width() / 2f, swipeY), 45 ) 46 } 47 48 companion object { 49 const val NAMESPACE_COMMUNAL = "communal" 50 const val FLAG_COMMUNAL_HUB = "com.android.systemui.communal_hub" 51 52 private const val COMMUNAL_HUB_RESOURCE_ID = "communal_hub" 53 val COMMUNAL_SELECTOR = By.res(COMMUNAL_HUB_RESOURCE_ID) 54 } 55 } 56