MediaRouteProviderProtocol.java revision 3efa63d3b896244713e84acbb5945562dce41d77
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
17package android.support.v7.media;
18
19import android.content.Intent;
20import android.os.Messenger;
21
22/**
23 * Defines the communication protocol for media route provider services.
24 * @hide
25 */
26abstract 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_VOLUME = "volume";
124
125    /*
126     * Messages sent from the service to the client.
127     * DO NOT RENUMBER THESE!
128     */
129
130    /** (service v1)
131     * Generic failure sent in response to any unrecognized or malformed request.
132     * - arg1    : request id
133     */
134    public static final int SERVICE_MSG_GENERIC_FAILURE = 0;
135
136    /** (service v1)
137     * Generic failure sent in response to a successful message.
138     * - arg1    : request id
139     */
140    public static final int SERVICE_MSG_GENERIC_SUCCESS = 1;
141
142    /** (service v1)
143     * Registration succeeded.
144     * - arg1    : request id
145     * - arg2    : server version
146     * - obj     : route provider descriptor bundle, or null
147     */
148    public static final int SERVICE_MSG_REGISTERED = 2;
149
150    /** (service v1)
151     * Route control request success result.
152     * - arg1    : request id
153     * - obj     : result data bundle, or null
154     */
155    public static final int SERVICE_MSG_CONTROL_REQUEST_SUCCEEDED = 3;
156
157    /** (service v1)
158     * Route control request failure result.
159     * - arg1    : request id
160     * - obj     : result data bundle, or null
161     * - SERVICE_DATA_ERROR: error message
162     */
163    public static final int SERVICE_MSG_CONTROL_REQUEST_FAILED = 4;
164
165    /** (service v1)
166     * Route provider descriptor changed.  (unsolicited event)
167     * - arg1    : reserved (0)
168     * - obj     : route provider descriptor bundle, or null
169     */
170    public static final int SERVICE_MSG_DESCRIPTOR_CHANGED = 5;
171
172    public static final String SERVICE_DATA_ERROR = "error";
173
174    /*
175     * Recognized client version numbers.  (Reserved for future use.)
176     * DO NOT RENUMBER THESE!
177     */
178
179    public static final int CLIENT_VERSION_1 = 1;
180    public static final int CLIENT_VERSION_CURRENT = CLIENT_VERSION_1;
181
182    /*
183     * Recognized server version numbers.  (Reserved for future use.)
184     * DO NOT RENUMBER THESE!
185     */
186
187    public static final int SERVICE_VERSION_1 = 1;
188    public static final int SERVICE_VERSION_CURRENT = SERVICE_VERSION_1;
189
190    /**
191     * Returns true if the messenger object is valid.
192     * <p>
193     * The messenger constructor and unparceling code does not check whether the
194     * provided IBinder is a valid IMessenger object.  As a result, it's possible
195     * for a peer to send an invalid IBinder that will result in crashes downstream.
196     * This method checks that the messenger is in a valid state.
197     * </p>
198     */
199    public static boolean isValidRemoteMessenger(Messenger messenger) {
200        try {
201            return messenger != null && messenger.getBinder() != null;
202        } catch (NullPointerException ex) {
203            // If the messenger was constructed with a binder interface other than
204            // IMessenger then the call to getBinder() will crash with an NPE.
205            return false;
206        }
207    }
208}
209