1 /*
2  * Copyright (C) 2017 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.media.cts;
18 
19 /**
20  * Defines constants for controlling the media session test helper app, which can start media
21  * playback and create the media session for test.
22  * <p>Any change in these constants should also be applied to the media session test helper app.
23  * <p>Don't add Android specific imports because this will be used by the both host-side and
24  * device-side.
25  */
26 public class MediaSessionTestHelperConstants {
27     /**
28      * Package name of the media session test helper.
29      */
30     public static final String MEDIA_SESSION_TEST_HELPER_PKG =
31             "android.media.app.media_session_test_helper";
32     /**
33      * Package binary file name of the media session test helper`.
34      */
35     public static final String MEDIA_SESSION_TEST_HELPER_APK = "CtsMediaSessionTestHelper.apk";
36 
37     /**
38      * Intent action name to control media sesion test helper.
39      */
40     public static final String ACTION_CONTROL =
41             "android.media.app.media_session_test_helper.ACTION_CONTROL";
42     /**
43      * Intent extra key name to control media session test helper.
44      */
45     public static final String EXTRA_CONTROL_COMMAND =
46             "android.media.app.media_session_test_helper.EXTRA_CONTROL_COMMAND";
47 
48     /**
49      * Intent extra value for the key {@link #EXTRA_CONTROL_COMMAND} to create the media session
50      * if it doesn't exist.
51      * @see #buildControlCommand
52      */
53     public static final int FLAG_CREATE_MEDIA_SESSION = 0x01;
54     /**
55      * Intent extra value for the key {@link #EXTRA_CONTROL_COMMAND} to set the media session active
56      * if it exists.
57      * @see #buildControlCommand
58      */
59     public static final int FLAG_SET_MEDIA_SESSION_ACTIVE = 0x02;
60     /**
61      * Intent extra value for the key {@link #EXTRA_CONTROL_COMMAND} to set the media session
62      * inactive if it exists.
63      * @see #buildControlCommand
64      */
65     public static final int FLAG_SET_MEDIA_SESSION_INACTIVE = 0x04;
66     /**
67      * Intent extra value for the key {@link #EXTRA_CONTROL_COMMAND} to release both media session1
68      * and session2 if created.
69      * @see #buildControlCommand
70      */
71     public static final int FLAG_RELEASE_ALL_MEDIA_SESSION = 0x08;
72 
73     /**
74      * Intent extra value for the key {@link #EXTRA_CONTROL_COMMAND} to create the media session2
75      * if it doesn't exist.
76      * @see #buildControlCommand
77      */
78     public static final int FLAG_CREATE_MEDIA_SESSION2 = 0x10;
79 
80 
MediaSessionTestHelperConstants()81     private MediaSessionTestHelperConstants() {
82         // Prevent from the instantiation.
83     }
84 
85     /**
86      * Builds the control command for the media session test helper app.
87      *
88      * @param userId user id to send the command
89      * @param flag bit masked flag among {@link #FLAG_CREATE_MEDIA_SESSION},
90      *            {@link #FLAG_SET_MEDIA_SESSION_ACTIVE}, {@link #FLAG_SET_MEDIA_SESSION_INACTIVE},
91      *            and {@link #FLAG_RELEASE_ALL_MEDIA_SESSION}. If multiple flags are specificed,
92      *            operations will be exceuted in order.
93      **/
buildControlCommand(int userId, int flag)94     public static String buildControlCommand(int userId, int flag) {
95         return "am start-foreground-service --user " + userId + " -a " + ACTION_CONTROL + " --ei "
96                 + EXTRA_CONTROL_COMMAND + " " + flag + " " + MEDIA_SESSION_TEST_HELPER_PKG;
97     }
98 }
99