1 /*
2  * 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.utils
18 
19 import androidx.test.uiautomator.By
20 import androidx.test.uiautomator.BySelector
21 import java.time.Duration
22 
23 const val SYSUI_PACKAGE = "com.android.systemui"
24 const val SETTINGS_PACKAGE = "com.android.settings"
25 private const val LAUNCHER_PACKAGE = "com.google.android.apps.nexuslauncher"
26 private const val ANDROID_PACKAGE = "android"
27 
28 object DeviceUtils {
29     @JvmField val SHORT_WAIT: Duration = Duration.ofMillis(1_500)
30     @JvmField val LONG_WAIT: Duration = Duration.ofMillis(10_000)
31 
32     /** Returns a [BySelector] of a resource in sysui package. */
33     @JvmStatic
sysuiResSelectornull34     fun sysuiResSelector(resourceId: String): BySelector =
35         By.pkg(SYSUI_PACKAGE).res(SYSUI_PACKAGE, resourceId)
36 
37     /** Returns a [BySelector] of a resource in settings package. */
38     @JvmStatic
39     fun settingsResSelector(resourceId: String): BySelector =
40         By.pkg(SETTINGS_PACKAGE).res(SETTINGS_PACKAGE, resourceId)
41 
42     /** Returns a [BySelector] of a resource in launcher package. */
43     @JvmStatic
44     fun launcherResSelector(resourceId: String): BySelector =
45         By.pkg(LAUNCHER_PACKAGE).res(LAUNCHER_PACKAGE, resourceId)
46 
47     /** Returns a [BySelector] of a resource with the given content description in sysui package. */
48     @JvmStatic
49     fun sysuiDescSelector(contentDescription: String): BySelector =
50         By.pkg(SYSUI_PACKAGE).desc(contentDescription)
51 
52     /**
53      * Returns a [BySelector] of a resource with the given content description in launcher package.
54      */
55     @JvmStatic
56     fun launcherDescSelector(contentDescription: String): BySelector =
57         By.pkg(LAUNCHER_PACKAGE).desc(contentDescription)
58 
59     /** Returns a [BySelector] of a resource in android package. */
60     @JvmStatic
61     fun androidResSelector(resourceId: String): BySelector = By.res(ANDROID_PACKAGE, resourceId)
62 }
63