• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Point
19 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector
20 import android.platform.uiautomatorhelpers.BetterSwipe
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.waitForObj
25 import android.platform.uiautomatorhelpers.PRECISE_GESTURE_INTERPOLATOR
26 import android.view.WindowManager
27 
28 /**
29  * Provides an API for interacting with the expanded bubble view when bubble bar is used in UI
30  * automation tests.
31  *
32  * @see [ExpandedBubbleBar]
33  */
34 class ExpandedBubbleBarBubble internal constructor() {
35 
36     init {
37         BUBBLE_EXPANDED_VIEW.assertVisible()
38         HANDLE_VIEW.assertVisible()
39     }
40 
41     /** Dismisses expanded view by dragging it into the dismiss area */
dragToDismissnull42     fun dragToDismiss() {
43         val windowMetrics =
44             DeviceHelpers.context.getSystemService(WindowManager::class.java)!!.currentWindowMetrics
45         val displayCenter = Point(windowMetrics.bounds.centerX(), windowMetrics.bounds.centerY())
46 
47         BetterSwipe.swipe(waitForObj(HANDLE_VIEW).visibleCenter) {
48             // First drag to the center of the display, dismiss view only shows up after drag starts
49             to(displayCenter, interpolator = PRECISE_GESTURE_INTERPOLATOR)
50             to(waitForObj(DISMISS_VIEW).visibleCenter, interpolator = PRECISE_GESTURE_INTERPOLATOR)
51         }
52         BUBBLE_EXPANDED_VIEW.assertInvisible {
53             "Failed while waiting for expanded bubble to become invisible"
54         }
55     }
56 
57     private companion object {
58         val BUBBLE_EXPANDED_VIEW = sysuiResSelector("bubble_expanded_view")
59         val HANDLE_VIEW = sysuiResSelector("bubble_bar_handle_view")
60         val DISMISS_VIEW = sysuiResSelector("dismiss_view")
61     }
62 }
63