• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2022 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.systemui_tapl.ui.ComposeQuickSettingsTile.Companion.assertIsTile
20 import android.platform.systemui_tapl.utils.DeviceUtils.LONG_WAIT
21 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector
22 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisibility
23 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible
24 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForFirstObj
25 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj
26 import androidx.test.uiautomator.UiObject2
27 import com.android.systemui.Flags
28 
29 /**
30  * System UI test automation object representing quick quick settings in the notification shade.
31  *
32  * This is the area that contains a few tiles and doesn't have pages, appearing on top of the
33  * Notification space.
34  *
35  * https://hsv.googleplex.com/4814389392703488?node=15#
36  */
37 class QuickQuickSettings internal constructor() {
38 
39     private val qqsTilesContainer: UiObject2
40 
41     init {
42         UI_QUICK_QUICK_SETTINGS_CONTAINER_SELECTOR.assertVisible(timeout = LONG_WAIT) {
43             "Quick quick settings not visible"
44         }
45         qqsTilesContainer =
46             waitForObj(UI_QQS_TILE_LAYOUT_SELECTOR) {
47                 "Quick quick settings does not have a tile layout"
48             }
49     }
50 
51     /**
52      * Get a list of [QuickSettingsTile] objects, each representing one of the tiles visible in the
53      * QuickQuickSettings container. Will fail if there's an element that's not a tile (i.e.,
54      * doesn't have the label view as https://hsv.googleplex.com/4814389392703488?node=22#), only
55      * when the [qsUiRefactorComposeFragment] flag is false.
56      */
57     fun getVisibleTiles(): List<QuickQuickSettingsTile> {
58         val uiTiles = qqsTilesContainer.children
59         if (!Flags.qsUiRefactorComposeFragment()) {
60             uiTiles.forEach { tile ->
61                 tile.assertVisibility(UI_TILE_LABEL_SELECTOR, visible = true)
62             }
63         }
64         return uiTiles.map { QuickQuickSettingsTile(it) }
65     }
66 
67     fun getVisibleComposeTiles(): List<ComposeQuickSettingsTile> {
68         val uiChildren = qqsTilesContainer.children
69         val largeTileSelector = sysuiResSelector(ComposeQuickSettingsTile.LARGE_TILE_TAG)
70         val smallTileSelector = sysuiResSelector(ComposeQuickSettingsTile.SMALL_TILE_TAG)
71         val uiTiles =
72             uiChildren.map { child ->
73                 val (tile, _) =
74                     child.waitForFirstObj(smallTileSelector, largeTileSelector) {
75                         "No tile object found in child $child"
76                     }
77                 tile.assertIsTile()
78                 tile
79             }
80         return uiTiles.map { ComposeQuickSettingsTile.createFrom(it) }
81     }
82 
83     companion object {
84         @JvmField
85         val UI_QUICK_QUICK_SETTINGS_CONTAINER_SELECTOR = sysuiResSelector("quick_qs_panel")
86         // https://hsv.googleplex.com/4814389392703488?node=16#
87         private val UI_QQS_TILE_LAYOUT_SELECTOR = sysuiResSelector("qqs_tile_layout")
88         @JvmField
89         // https://hsv.googleplex.com/4814389392703488?node=22#
90         val UI_TILE_LABEL_SELECTOR = sysuiResSelector("tile_label")
91     }
92 }
93