• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.support.v7.media;
18 
19 import android.content.Intent;
20 import android.os.Messenger;
21 
22 /**
23  * Defines the communication protocol for media route provider services.
24  * @hide
25  */
26 abstract class MediaRouteProviderProtocol {
27     /**
28      * The {@link Intent} that must be declared as handled by the service.
29      * Put this in your manifest.
30      */
31     public static final String SERVICE_INTERFACE =
32             "android.media.MediaRouteProviderService";
33 
34     /*
35      * Messages sent from the client to the service.
36      * DO NOT RENUMBER THESE!
37      */
38 
39     /** (client v1)
40      * Register client.
41      * - replyTo : client messenger
42      * - arg1    : request id
43      * - arg2    : client version
44      */
45     public static final int CLIENT_MSG_REGISTER = 1;
46 
47     /** (client v1)
48      * Unregister client.
49      * - replyTo : client messenger
50      * - arg1    : request id
51      */
52     public static final int CLIENT_MSG_UNREGISTER = 2;
53 
54     /** (client v1)
55      * Create route controller.
56      * - replyTo : client messenger
57      * - arg1    : request id
58      * - arg2    : route controller id
59      * - CLIENT_DATA_ROUTE_ID : route id string
60      */
61     public static final int CLIENT_MSG_CREATE_ROUTE_CONTROLLER = 3;
62 
63     /** (client v1)
64      * Release route controller.
65      * - replyTo : client messenger
66      * - arg1    : request id
67      * - arg2    : route controller id
68      */
69     public static final int CLIENT_MSG_RELEASE_ROUTE_CONTROLLER = 4;
70 
71     /** (client v1)
72      * Select route.
73      * - replyTo : client messenger
74      * - arg1    : request id
75      * - arg2    : route controller id
76      */
77     public static final int CLIENT_MSG_SELECT_ROUTE = 5;
78 
79     /** (client v1)
80      * Unselect route.
81      * - replyTo : client messenger
82      * - arg1    : request id
83      * - arg2    : route controller id
84      */
85     public static final int CLIENT_MSG_UNSELECT_ROUTE = 6;
86 
87     /** (client v1)
88      * Set route volume.
89      * - replyTo : client messenger
90      * - arg1    : request id
91      * - arg2    : route controller id
92      * - CLIENT_DATA_VOLUME : volume integer
93      */
94     public static final int CLIENT_MSG_SET_ROUTE_VOLUME = 7;
95 
96     /** (client v1)
97      * Update route volume.
98      * - replyTo : client messenger
99      * - arg1    : request id
100      * - arg2    : route controller id
101      * - CLIENT_DATA_VOLUME : volume delta integer
102      */
103     public static final int CLIENT_MSG_UPDATE_ROUTE_VOLUME = 8;
104 
105     /** (client v1)
106      * Route control request.
107      * - replyTo : client messenger
108      * - arg1    : request id
109      * - arg2    : route controller id
110      * - obj     : media control intent
111      */
112     public static final int CLIENT_MSG_ROUTE_CONTROL_REQUEST = 9;
113 
114     /** (client v1)
115      * Sets the discovery request.
116      * - replyTo : client messenger
117      * - arg1    : request id
118      * - obj     : discovery request bundle, or null if none
119      */
120     public static final int CLIENT_MSG_SET_DISCOVERY_REQUEST = 10;
121 
122     public static final String CLIENT_DATA_ROUTE_ID = "routeId";
123     public static final String CLIENT_DATA_ROUTE_GROUP_ID = "routeGroupId";
124     public static final String CLIENT_DATA_VOLUME = "volume";
125     public static final String CLIENT_DATA_UNSELECT_REASON = "unselectReason";
126 
127     /*
128      * Messages sent from the service to the client.
129      * DO NOT RENUMBER THESE!
130      */
131 
132     /** (service v1)
133      * Generic failure sent in response to any unrecognized or malformed request.
134      * - arg1    : request id
135      */
136     public static final int SERVICE_MSG_GENERIC_FAILURE = 0;
137 
138     /** (service v1)
139      * Generic failure sent in response to a successful message.
140      * - arg1    : request id
141      */
142     public static final int SERVICE_MSG_GENERIC_SUCCESS = 1;
143 
144     /** (service v1)
145      * Registration succeeded.
146      * - arg1    : request id
147      * - arg2    : server version
148      * - obj     : route provider descriptor bundle, or null
149      */
150     public static final int SERVICE_MSG_REGISTERED = 2;
151 
152     /** (service v1)
153      * Route control request success result.
154      * - arg1    : request id
155      * - obj     : result data bundle, or null
156      */
157     public static final int SERVICE_MSG_CONTROL_REQUEST_SUCCEEDED = 3;
158 
159     /** (service v1)
160      * Route control request failure result.
161      * - arg1    : request id
162      * - obj     : result data bundle, or null
163      * - SERVICE_DATA_ERROR: error message
164      */
165     public static final int SERVICE_MSG_CONTROL_REQUEST_FAILED = 4;
166 
167     /** (service v1)
168      * Route provider descriptor changed.  (unsolicited event)
169      * - arg1    : reserved (0)
170      * - obj     : route provider descriptor bundle, or null
171      */
172     public static final int SERVICE_MSG_DESCRIPTOR_CHANGED = 5;
173 
174     public static final String SERVICE_DATA_ERROR = "error";
175 
176     /*
177      * Recognized client version numbers.  (Reserved for future use.)
178      * DO NOT RENUMBER THESE!
179      */
180 
181     /**
182      * The client version used from the beginning.
183      */
184     public static final int CLIENT_VERSION_1 = 1;
185 
186     /**
187      * The client version used from support library v24.1.0.
188      */
189     public static final int CLIENT_VERSION_2 = 2;
190 
191     /**
192      * The current client version.
193      */
194     public static final int CLIENT_VERSION_CURRENT = CLIENT_VERSION_2;
195 
196     /*
197      * Recognized server version numbers.  (Reserved for future use.)
198      * DO NOT RENUMBER THESE!
199      */
200 
201     /**
202      * The service version used from the beginning.
203      */
204     public static final int SERVICE_VERSION_1 = 1;
205 
206     /**
207      * The current service version.
208      */
209     public static final int SERVICE_VERSION_CURRENT = SERVICE_VERSION_1;
210 
211     static final int CLIENT_VERSION_START = CLIENT_VERSION_1;
212 
213     /**
214      * Returns true if the messenger object is valid.
215      * <p>
216      * The messenger constructor and unparceling code does not check whether the
217      * provided IBinder is a valid IMessenger object.  As a result, it's possible
218      * for a peer to send an invalid IBinder that will result in crashes downstream.
219      * This method checks that the messenger is in a valid state.
220      * </p>
221      */
isValidRemoteMessenger(Messenger messenger)222     public static boolean isValidRemoteMessenger(Messenger messenger) {
223         try {
224             return messenger != null && messenger.getBinder() != null;
225         } catch (NullPointerException ex) {
226             // If the messenger was constructed with a binder interface other than
227             // IMessenger then the call to getBinder() will crash with an NPE.
228             return false;
229         }
230     }
231 }
232