Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright 2018 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 package androidx.media;
     17 
     18 import android.os.Bundle;
     19 import android.support.v4.media.MediaBrowserCompat;
     20 
     21 import androidx.annotation.RestrictTo;
     22 
     23 /**
     24  * Defines the communication protocol for media browsers and media browser services.
     25  *
     26  * @hide
     27  */
     28 @RestrictTo(RestrictTo.Scope.LIBRARY)
     29 public class MediaBrowserProtocol {
     30 
     31     public static final String DATA_CALLBACK_TOKEN = "data_callback_token";
     32     public static final String DATA_CALLING_UID = "data_calling_uid";
     33     public static final String DATA_CALLING_PID = "data_calling_pid";
     34     public static final String DATA_MEDIA_ITEM_ID = "data_media_item_id";
     35     public static final String DATA_MEDIA_ITEM_LIST = "data_media_item_list";
     36     public static final String DATA_MEDIA_SESSION_TOKEN = "data_media_session_token";
     37     public static final String DATA_OPTIONS = "data_options";
     38     public static final String DATA_NOTIFY_CHILDREN_CHANGED_OPTIONS =
     39             "data_notify_children_changed_options";
     40     public static final String DATA_PACKAGE_NAME = "data_package_name";
     41     public static final String DATA_RESULT_RECEIVER = "data_result_receiver";
     42     public static final String DATA_ROOT_HINTS = "data_root_hints";
     43     public static final String DATA_SEARCH_EXTRAS = "data_search_extras";
     44     public static final String DATA_SEARCH_QUERY = "data_search_query";
     45     public static final String DATA_CUSTOM_ACTION = "data_custom_action";
     46     public static final String DATA_CUSTOM_ACTION_EXTRAS = "data_custom_action_extras";
     47 
     48     public static final String EXTRA_CLIENT_VERSION = "extra_client_version";
     49     public static final String EXTRA_SERVICE_VERSION = "extra_service_version";
     50     public static final String EXTRA_MESSENGER_BINDER = "extra_messenger";
     51     public static final String EXTRA_SESSION_BINDER = "extra_session_binder";
     52 
     53     /**
     54      * MediaBrowserCompat will check the version of the connected MediaBrowserServiceCompat,
     55      * and it will not send messages if they are introduced in the higher version of the
     56      * MediaBrowserServiceCompat.
     57      */
     58     public static final int SERVICE_VERSION_1 = 1;
     59 
     60     /**
     61      * To prevent ClassNotFoundException from Parcelables, MediaBrowser(Service)Compat tries to
     62      * avoid using framework code as much as possible (b/62648808). For backward compatibility,
     63      * service v2 is introduced so that the browser can distinguish whether the service supports
     64      * subscribing through compat code.
     65      */
     66     public static final int SERVICE_VERSION_2 = 2;
     67     public static final int SERVICE_VERSION_CURRENT = SERVICE_VERSION_2;
     68 
     69     /*
     70      * Messages sent from the media browser service compat to the media browser compat.
     71      * (Compat implementation for IMediaBrowserServiceCallbacks)
     72      * DO NOT RENUMBER THESE!
     73      */
     74 
     75     /** (service v1)
     76      * Sent after {@link MediaBrowserCompat#connect()} when the request has successfully
     77      * completed.
     78      * - arg1 : The service version
     79      * - data
     80      *     DATA_MEDIA_ITEM_ID : A string for the root media item id
     81      *     DATA_MEDIA_SESSION_TOKEN : Media session token
     82      *     DATA_ROOT_HINTS : An optional root hints bundle of service-specific arguments
     83      */
     84     public static final int SERVICE_MSG_ON_CONNECT = 1;
     85 
     86     /** (service v1)
     87      * Sent after {@link MediaBrowserCompat#connect()} when the connection to the media browser
     88      * failed.
     89      * - arg1 : service version
     90      */
     91     public static final int SERVICE_MSG_ON_CONNECT_FAILED = 2;
     92 
     93     /** (service v1)
     94      * Sent when the list of children is loaded or updated.
     95      * - arg1 : The service version
     96      * - data
     97      *     DATA_MEDIA_ITEM_ID : A string for the parent media item id
     98      *     DATA_MEDIA_ITEM_LIST : An array list for the media item children
     99      *     DATA_OPTIONS : A bundle of service-specific arguments sent from the media browse to
    100      *                    the media browser service
    101      *     DATA_NOTIFY_CHILDREN_CHANGED_OPTIONS : A bundle of service-specific arguments sent from
    102      *                    the media browser service to the media browser by calling
    103      *                    {@link MediaBrowserServiceCompat#notifyChildrenChanged(String, Bundle)}
    104      */
    105     public static final int SERVICE_MSG_ON_LOAD_CHILDREN = 3;
    106 
    107     /**
    108      * MediaBrowserServiceCompat will check the version of the MediaBrowserCompat, and it will not
    109      * send messages if they are introduced in the higher version of the MediaBrowserCompat.
    110      */
    111     public static final int CLIENT_VERSION_1 = 1;
    112     public static final int CLIENT_VERSION_CURRENT = CLIENT_VERSION_1;
    113 
    114     /*
    115      * Messages sent from the media browser compat to the media browser service compat.
    116      * (Compat implementation for IMediaBrowserService)
    117      * DO NOT RENUMBER THESE!
    118      */
    119 
    120     /** (client v1)
    121      * Sent to connect to the media browse service compat.
    122      * - arg1 : The client version
    123      * - data
    124      *     DATA_PACKAGE_NAME : A string for the package name of MediaBrowserCompat
    125      *     DATA_ROOT_HINTS : An optional root hints bundle of service-specific arguments
    126      * - replyTo : Callback messenger
    127      */
    128     public static final int CLIENT_MSG_CONNECT = 1;
    129 
    130     /** (client v1)
    131      * Sent to disconnect from the media browse service compat.
    132      * - arg1 : The client version
    133      * - replyTo : Callback messenger
    134      */
    135     public static final int CLIENT_MSG_DISCONNECT = 2;
    136 
    137     /** (client v1)
    138      * Sent to subscribe for changes to the children of the specified media id.
    139      * - arg1 : The client version
    140      * - data
    141      *     DATA_MEDIA_ITEM_ID : A string for a media item id
    142      *     DATA_OPTIONS : A bundle of service-specific arguments sent from the media browser to
    143      *                    the media browser service
    144      *     DATA_CALLBACK_TOKEN : An IBinder of service-specific arguments sent from the media
    145      *                           browser to the media browser service
    146      * - replyTo : Callback messenger
    147      */
    148     public static final int CLIENT_MSG_ADD_SUBSCRIPTION = 3;
    149 
    150     /** (client v1)
    151      * Sent to unsubscribe for changes to the children of the specified media id.
    152      * - arg1 : The client version
    153      * - data
    154      *     DATA_MEDIA_ITEM_ID : A string for a media item id
    155      *     DATA_CALLBACK_TOKEN : An IBinder of service-specific arguments sent from the media
    156      *                           browser to the media browser service
    157      * - replyTo : Callback messenger
    158      */
    159     public static final int CLIENT_MSG_REMOVE_SUBSCRIPTION = 4;
    160 
    161     /** (client v1)
    162      * Sent to retrieve a specific media item from the connected service.
    163      * - arg1 : The client version
    164      * - data
    165      *     DATA_MEDIA_ITEM_ID : A string for a media item id
    166      *     DATA_RESULT_RECEIVER : Result receiver to get the result
    167      * - replyTo : Callback messenger
    168      */
    169     public static final int CLIENT_MSG_GET_MEDIA_ITEM = 5;
    170 
    171     /** (client v1)
    172      * Sent to register the client messenger
    173      * - arg1 : The client version
    174      * - data
    175      *     DATA_ROOT_HINTS : An optional root hints bundle of service-specific arguments
    176      * - replyTo : Callback messenger
    177      */
    178     public static final int CLIENT_MSG_REGISTER_CALLBACK_MESSENGER = 6;
    179 
    180     /** (client v1)
    181      * Sent to unregister the client messenger
    182      * - arg1 : The client version
    183      * - replyTo : Callback messenger
    184      */
    185     public static final int CLIENT_MSG_UNREGISTER_CALLBACK_MESSENGER = 7;
    186 
    187     /** (client v1)
    188      * Sent to retrieve a specific media item from the connected service.
    189      * - arg1 : The client version
    190      * - data
    191      *     DATA_SEARCH_QUERY : A string for search query that contains keywords separated by space.
    192      *     DATA_SEARCH_EXTRAS : A bundle of service-specific arguments to send to the media browser
    193      *                          service.
    194      *     DATA_RESULT_RECEIVER : Result receiver to get the result.
    195      * - replyTo : Callback messenger
    196      */
    197     public static final int CLIENT_MSG_SEARCH = 8;
    198 
    199     /** (client v1)
    200      * Sent to request a custom action from the media browser.
    201      * - arg1 : The client version
    202      * - data
    203      *     DATA_CUSTOM_ACTION : A string for the custom action.
    204      *     DATA_CUSTOM_ACTION_EXTRAS : A bundle of service-specific arguments to send to the media
    205      *                                 browser service.
    206      *     DATA_RESULT_RECEIVER : Result receiver to get the result.
    207      * - replyTo : Callback messenger
    208      */
    209     public static final int CLIENT_MSG_SEND_CUSTOM_ACTION = 9;
    210 
    211     private MediaBrowserProtocol() {
    212     }
    213 }
    214