1 /*
2  * Copyright (C) 2020 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.systemui.tv.cts
18 
19 import android.content.ComponentName
20 
21 private const val pkg = "android.systemui.cts.tv.pip"
22 
23 object Components {
24 
25     @JvmStatic
activityNamenull26     fun ComponentName.activityName(): String = flattenToShortString()
27 
28     @JvmStatic
29     fun ComponentName.windowName(): String = flattenToString()
30 
31     @JvmField
32     val PIP_ACTIVITY: ComponentName = ComponentName.createRelative(pkg, ".PipTestActivity")
33 
34     @JvmField
35     val PIP_MENU_ACTIVITY: ComponentName = ComponentName.createRelative(
36         ResourceNames.SYSTEM_UI_PACKAGE,
37         ResourceNames.WM_SHELL_PACKAGE + ".pip.tv.PipMenuActivity"
38     )
39 }
40 
41 object PipActivity {
42     /** Instruct the app to go into pip mode */
43     const val ACTION_ENTER_PIP = "$pkg.PipTestActivity.enter_pip"
44     const val ACTION_SET_MEDIA_TITLE = "$pkg.PipTestActivity.set_media_title"
45 
46     /**
47      * A no-op action that the app's broadcast receiver listens to.
48      *
49      * This action can be used to apply changes passed in extras without having to
50      * launch the activity thereby moving it out of pip.
51      */
52     const val ACTION_NO_OP = "$pkg.PipTestActivity.generic_update"
53 
54     const val ACTION_MEDIA_PLAY = "$pkg.PipTestActivity.media_play"
55     const val ACTION_MEDIA_PAUSE = "$pkg.PipTestActivity.media_pause"
56 
57     /** Instruct the app to go into pip mode when set to true */
58     const val EXTRA_ENTER_PIP = "enter_pip"
59 
60     /** Provide a rect hint for entering pip in the form "left top right bottom" */
61     const val EXTRA_SOURCE_RECT_HINT = "source_rect_hint"
62 
63     /**
64      * Boolean.
65      * Make sure the app will turn on the screen (waking up the device) upon start.
66      * This is accomplished by means of
67      * https://developer.android.com/reference/android/app/Activity#setTurnScreenOn(boolean)
68      */
69     const val EXTRA_TURN_ON_SCREEN = "turn_on_screen"
70 
71     const val EXTRA_ASPECT_RATIO_DENOMINATOR = "aspect_ratio_denominator"
72     const val EXTRA_ASPECT_RATIO_NUMERATOR = "aspect_ratio_numerator"
73 
74     /** Taken from [android.server.wm.PinnedStackTests] */
75     object Ratios {
76         // Corresponds to com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio
77         const val MIN_ASPECT_RATIO_NUMERATOR = 100
78         const val MIN_ASPECT_RATIO_DENOMINATOR = 239
79 
80         // Corresponds to com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio
81         const val MAX_ASPECT_RATIO_NUMERATOR = 239
82         const val MAX_ASPECT_RATIO_DENOMINATOR = 100
83     }
84 
85     /** URL encoded string. Sets the title of the media session. */
86     const val EXTRA_MEDIA_SESSION_TITLE = "media_session_title"
87     /** Boolean. Controls the active status of the media session. */
88     const val EXTRA_MEDIA_SESSION_ACTIVE = "media_session_active"
89 
90     /**
91      * Allows to set the [android.media.session.PlaybackState.Actions] that the media
92      * session will react to. Defaults to (ACTION_PAUSE | ACTION_PLAY).
93      */
94     const val EXTRA_MEDIA_SESSION_ACTIONS = "media_session_actions"
95 
96     const val MEDIA_SESSION_TITLE = "PipTestActivity:MediaSession"
97 
98     /** Set the pip menu custom actions to this [ArrayList] of [android.app.RemoteAction]. */
99     const val EXTRA_SET_CUSTOM_ACTIONS = "set_custom_actions"
100 }
101 
102 object PipMenu {
103     const val ACTION_MENU = "PipNotification.menu"
104     const val ACTION_CLOSE = "PipNotification.close"
105 }
106 
107 object ResourceNames {
108     const val SYSTEM_UI_CTS_PACKAGE = "android.systemui.cts"
109     const val SYSTEM_UI_PACKAGE = "com.android.systemui"
110     const val WM_SHELL_PACKAGE = "com.android.wm.shell"
111 
112     const val STRING_PIP_PAUSE = "pip_pause"
113 
114     const val ID_PIP_MENU_CLOSE_BUTTON = "$SYSTEM_UI_PACKAGE:id/close_button"
115     const val ID_PIP_MENU_FULLSCREEN_BUTTON = "$SYSTEM_UI_PACKAGE:id/full_button"
116     const val ID_PIP_MENU_CUSTOM_BUTTON = "$SYSTEM_UI_PACKAGE:id/button"
117 }