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 17 package android.platform.systemui_tapl.ui 18 19 import android.graphics.Point 20 import android.platform.systemui_tapl.utils.DeviceUtils.launcherResSelector 21 import android.platform.uiautomatorhelpers.BetterSwipe 22 import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible 23 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 24 import android.platform.uiautomatorhelpers.DeviceHelpers.click 25 import android.platform.uiautomatorhelpers.DeviceHelpers.uiDevice 26 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj 27 import android.platform.uiautomatorhelpers.PRECISE_GESTURE_INTERPOLATOR 28 import com.google.common.truth.Truth.assertThat 29 import java.time.Duration 30 import java.time.temporal.ChronoUnit 31 32 /** 33 * Provides an API for interacting with the collapsed bubble bar within launcher in UI automation 34 * tests. 35 * 36 * Note that this class does not represent the state of the bubble bar being stashed. 37 * 38 * @see [ExpandedBubbleBar] 39 */ 40 class BubbleBar { 41 42 init { <lambda>null43 BUBBLE_BAR_VIEW.assertVisible { "Failed while waiting for bubble bar to become visible" } 44 assertThat(bubbles).isNotEmpty() 45 } 46 47 /** 48 * Returns the selected bubble in the bubble bar. 49 * 50 * Bubbles in the collapsed bubble bar are reversed. The selected bubble is the last bubble in 51 * the view hierarchy. 52 */ 53 val selectedBubble: BubbleBarItem 54 get() = bubbles.last() 55 56 /** 57 * Returns all the bubbles in the bubble bar. 58 * 59 * Note that the overflow bubble is not included in the result because it is never visible when 60 * the bubble bar is collapsed. 61 */ 62 val bubbles: List<BubbleBarItem> <lambda>null63 get() = waitForObj(BUBBLE_BAR_VIEW).children.map { BubbleBarItem(it) } 64 65 /** Expands the bubble bar by clicking on it and returns [ExpandedBubbleBar]. */ expandnull66 fun expand(): ExpandedBubbleBar { 67 BUBBLE_BAR_VIEW.click() 68 return ExpandedBubbleBar(selectedBubble) 69 } 70 71 /** Expands the bubble bar by swiping up on it and returns [ExpandedBubbleBar]. */ swipeUpToExpandnull72 fun swipeUpToExpand(): ExpandedBubbleBar { 73 val bubbleBarCenter = waitForObj(BUBBLE_BAR_VIEW).visibleCenter 74 val windowHeight = uiDevice.displayHeight 75 // we want to swipe to the point that is twice as far from the bottom of the screen as the 76 // bubble bar center Y coordinate 77 val destinationY = 2 * bubbleBarCenter.y - windowHeight 78 BetterSwipe.swipe( 79 Point(bubbleBarCenter.x, windowHeight), 80 Point(bubbleBarCenter.x, destinationY), 81 ) 82 return ExpandedBubbleBar(selectedBubble) 83 } 84 85 /** 86 * Drags the bubble bar to the dismiss target. At the end of the gesture the bubble bar will be 87 * gone. 88 */ dragToDismissnull89 fun dragToDismiss() { 90 BetterSwipe.swipe(waitForObj(BUBBLE_BAR_VIEW).visibleCenter) { 91 pause() 92 to( 93 waitForObj(DISMISS_VIEW).visibleCenter, 94 Duration.of(500, ChronoUnit.MILLIS), 95 PRECISE_GESTURE_INTERPOLATOR, 96 ) 97 } 98 99 BUBBLE_BAR_VIEW.assertInvisible { 100 "Failed while waiting for bubble bar to become invisible" 101 } 102 } 103 104 companion object { 105 internal val BUBBLE_BAR_VIEW = launcherResSelector("taskbar_bubbles") 106 private val DISMISS_VIEW = launcherResSelector("dismiss_view") 107 } 108 } 109