diff options
author | RoboErik <epastern@google.com> | 2014-09-02 16:58:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-02 16:58:30 +0000 |
commit | 17a1b48629138c177106a21d4350a3be0e74aad7 (patch) | |
tree | f457e137c6a7f1a5bd41fc04c80a012d5ce51b16 /media | |
parent | 65899b10929dca755fbc43161fe5017e1fd0f0cc (diff) | |
parent | c692d05951561e1d9fde952cc5389ec167bdb7bb (diff) | |
download | frameworks_base-17a1b48629138c177106a21d4350a3be0e74aad7.zip frameworks_base-17a1b48629138c177106a21d4350a3be0e74aad7.tar.gz frameworks_base-17a1b48629138c177106a21d4350a3be0e74aad7.tar.bz2 |
Merge "Update MediaBrowser to use String ids instead of Uris" into lmp-dev
Diffstat (limited to 'media')
4 files changed, 103 insertions, 112 deletions
diff --git a/media/java/android/media/browse/MediaBrowser.java b/media/java/android/media/browse/MediaBrowser.java index debaf45..338c711 100644 --- a/media/java/android/media/browse/MediaBrowser.java +++ b/media/java/android/media/browse/MediaBrowser.java @@ -25,8 +25,8 @@ import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.ParceledListSlice; import android.media.MediaDescription; +import android.media.session.MediaController; import android.media.session.MediaSession; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -67,14 +67,14 @@ public final class MediaBrowser { private final ConnectionCallback mCallback; private final Bundle mRootHints; private final Handler mHandler = new Handler(); - private final ArrayMap<Uri,Subscription> mSubscriptions = - new ArrayMap<Uri, MediaBrowser.Subscription>(); + private final ArrayMap<String,Subscription> mSubscriptions = + new ArrayMap<String, MediaBrowser.Subscription>(); private int mState = CONNECT_STATE_DISCONNECTED; private MediaServiceConnection mServiceConnection; private IMediaBrowserService mServiceBinder; private IMediaBrowserServiceCallbacks mServiceCallbacks; - private Uri mRootUri; + private String mRootId; private MediaSession.Token mMediaSessionToken; private Bundle mExtras; @@ -85,7 +85,7 @@ public final class MediaBrowser { * @param serviceComponent The component name of the media browse service. * @param callback The connection callback. * @param rootHints An optional bundle of service-specific arguments to send - * to the media browse service when connecting and retrieving the root uri + * to the media browse service when connecting and retrieving the root id * for browsing, or null if none. The contents of this bundle may affect * the information returned when browsing. */ @@ -212,7 +212,7 @@ public final class MediaBrowser { mServiceConnection = null; mServiceBinder = null; mServiceCallbacks = null; - mRootUri = null; + mRootId = null; mMediaSessionToken = null; } @@ -235,20 +235,20 @@ public final class MediaBrowser { } /** - * Gets the root Uri. + * Gets the root id. * <p> - * Note that the root uri may become invalid or change when when the + * Note that the root id may become invalid or change when when the * browser is disconnected. * </p> * * @throws IllegalStateException if not connected. */ - public @NonNull Uri getRoot() { + public @NonNull String getRoot() { if (!isConnected()) { throw new IllegalStateException("getSessionToken() called while not connected (state=" + getStateLabel(mState) + ")"); } - return mRootUri; + return mRootId; } /** @@ -285,35 +285,35 @@ public final class MediaBrowser { /** * Queries for information about the media items that are contained within - * the specified Uri and subscribes to receive updates when they change. + * the specified id and subscribes to receive updates when they change. * <p> * The list of subscriptions is maintained even when not connected and is * restored after reconnection. It is ok to subscribe while not connected * but the results will not be returned until the connection completes. * </p><p> - * If the uri is already subscribed with a different callback then the new + * If the id is already subscribed with a different callback then the new * callback will replace the previous one. * </p> * - * @param parentUri The uri of the parent media item whose list of children + * @param parentId The id of the parent media item whose list of children * will be subscribed. * @param callback The callback to receive the list of children. */ - public void subscribe(@NonNull Uri parentUri, @NonNull SubscriptionCallback callback) { + public void subscribe(@NonNull String parentId, @NonNull SubscriptionCallback callback) { // Check arguments. - if (parentUri == null) { - throw new IllegalArgumentException("parentUri is null"); + if (parentId == null) { + throw new IllegalArgumentException("parentId is null"); } if (callback == null) { throw new IllegalArgumentException("callback is null"); } // Update or create the subscription. - Subscription sub = mSubscriptions.get(parentUri); + Subscription sub = mSubscriptions.get(parentId); boolean newSubscription = sub == null; if (newSubscription) { - sub = new Subscription(parentUri); - mSubscriptions.put(parentUri, sub); + sub = new Subscription(parentId); + mSubscriptions.put(parentId, sub); } sub.callback = callback; @@ -321,42 +321,42 @@ public final class MediaBrowser { // connected, the service will be told when we connect. if (mState == CONNECT_STATE_CONNECTED && newSubscription) { try { - mServiceBinder.addSubscription(parentUri, mServiceCallbacks); + mServiceBinder.addSubscription(parentId, mServiceCallbacks); } catch (RemoteException ex) { // Process is crashing. We will disconnect, and upon reconnect we will // automatically reregister. So nothing to do here. - Log.d(TAG, "addSubscription failed with RemoteException parentUri=" + parentUri); + Log.d(TAG, "addSubscription failed with RemoteException parentId=" + parentId); } } } /** - * Unsubscribes for changes to the children of the specified Uri. + * Unsubscribes for changes to the children of the specified media id. * <p> * The query callback will no longer be invoked for results associated with - * this Uri once this method returns. + * this id once this method returns. * </p> * - * @param parentUri The uri of the parent media item whose list of children + * @param parentId The id of the parent media item whose list of children * will be unsubscribed. */ - public void unsubscribe(@NonNull Uri parentUri) { + public void unsubscribe(@NonNull String parentId) { // Check arguments. - if (parentUri == null) { - throw new IllegalArgumentException("parentUri is null"); + if (parentId == null) { + throw new IllegalArgumentException("parentId is null"); } // Remove from our list. - final Subscription sub = mSubscriptions.remove(parentUri); + final Subscription sub = mSubscriptions.remove(parentId); // Tell the service if necessary. if (mState == CONNECT_STATE_CONNECTED && sub != null) { try { - mServiceBinder.removeSubscription(parentUri, mServiceCallbacks); + mServiceBinder.removeSubscription(parentId, mServiceCallbacks); } catch (RemoteException ex) { // Process is crashing. We will disconnect, and upon reconnect we will // automatically reregister. So nothing to do here. - Log.d(TAG, "removeSubscription failed with RemoteException parentUri=" + parentUri); + Log.d(TAG, "removeSubscription failed with RemoteException parentId=" + parentId); } } } @@ -380,7 +380,7 @@ public final class MediaBrowser { } private final void onServiceConnected(final IMediaBrowserServiceCallbacks callback, - final Uri root, final MediaSession.Token session, final Bundle extra) { + final String root, final MediaSession.Token session, final Bundle extra) { mHandler.post(new Runnable() { @Override public void run() { @@ -395,7 +395,7 @@ public final class MediaBrowser { + getStateLabel(mState) + "... ignoring"); return; } - mRootUri = root; + mRootId = root; mMediaSessionToken = session; mExtras = extra; mState = CONNECT_STATE_CONNECTED; @@ -408,13 +408,13 @@ public final class MediaBrowser { // we may receive some subscriptions before we are connected, so re-subscribe // everything now - for (Uri uri : mSubscriptions.keySet()) { + for (String id : mSubscriptions.keySet()) { try { - mServiceBinder.addSubscription(uri, mServiceCallbacks); + mServiceBinder.addSubscription(id, mServiceCallbacks); } catch (RemoteException ex) { // Process is crashing. We will disconnect, and upon reconnect we will // automatically reregister. So nothing to do here. - Log.d(TAG, "addSubscription failed with RemoteException parentUri=" + uri); + Log.d(TAG, "addSubscription failed with RemoteException parentId=" + id); } } } @@ -448,8 +448,8 @@ public final class MediaBrowser { }); } - private final void onLoadChildren(final IMediaBrowserServiceCallbacks callback, final Uri uri, - final ParceledListSlice list) { + private final void onLoadChildren(final IMediaBrowserServiceCallbacks callback, + final String parentId, final ParceledListSlice list) { mHandler.post(new Runnable() { @Override public void run() { @@ -461,24 +461,24 @@ public final class MediaBrowser { List<MediaItem> data = list.getList(); if (DBG) { - Log.d(TAG, "onLoadChildren for " + mServiceComponent + " uri=" + uri); + Log.d(TAG, "onLoadChildren for " + mServiceComponent + " id=" + parentId); } if (data == null) { data = Collections.emptyList(); } // Check that the subscription is still subscribed. - final Subscription subscription = mSubscriptions.get(uri); + final Subscription subscription = mSubscriptions.get(parentId); if (subscription == null) { if (DBG) { - Log.d(TAG, "onLoadChildren for uri that isn't subscribed uri=" - + uri); + Log.d(TAG, "onLoadChildren for id that isn't subscribed id=" + + parentId); } return; } // Tell the app. - subscription.callback.onChildrenLoaded(uri, data); + subscription.callback.onChildrenLoaded(parentId, data); } }); } @@ -514,7 +514,7 @@ public final class MediaBrowser { Log.d(TAG, " mServiceConnection=" + mServiceConnection); Log.d(TAG, " mServiceBinder=" + mServiceBinder); Log.d(TAG, " mServiceCallbacks=" + mServiceCallbacks); - Log.d(TAG, " mRootUri=" + mRootUri); + Log.d(TAG, " mRootId=" + mRootId); Log.d(TAG, " mMediaSessionToken=" + mMediaSessionToken); } @@ -535,7 +535,8 @@ public final class MediaBrowser { /** * Flag: Indicates that the item is playable. * <p> - * The Uri of this item may be passed to link android.media.session.MediaController#play(Uri) + * The id of this item may be passed to + * {@link MediaController.TransportControls#playFromMediaId(String, Bundle)} * to start playing it. * </p> */ @@ -669,18 +670,18 @@ public final class MediaBrowser { /** * Called when the list of children is loaded or updated. */ - public void onChildrenLoaded(@NonNull Uri parentUri, + public void onChildrenLoaded(@NonNull String parentId, @NonNull List<MediaItem> children) { } /** - * Called when the Uri doesn't exist or other errors in subscribing. + * Called when the id doesn't exist or other errors in subscribing. * <p> * If this is called, the subscription remains until {@link MediaBrowser#unsubscribe} * called, because some errors may heal themselves. * </p> */ - public void onError(@NonNull Uri uri) { + public void onError(@NonNull String id) { } } @@ -783,7 +784,7 @@ public final class MediaBrowser { * are the initial data as requested. */ @Override - public void onConnect(final Uri root, final MediaSession.Token session, + public void onConnect(final String root, final MediaSession.Token session, final Bundle extras) { MediaBrowser mediaBrowser = mMediaBrowser.get(); if (mediaBrowser != null) { @@ -803,20 +804,20 @@ public final class MediaBrowser { } @Override - public void onLoadChildren(final Uri uri, final ParceledListSlice list) { + public void onLoadChildren(final String parentId, final ParceledListSlice list) { MediaBrowser mediaBrowser = mMediaBrowser.get(); if (mediaBrowser != null) { - mediaBrowser.onLoadChildren(this, uri, list); + mediaBrowser.onLoadChildren(this, parentId, list); } } } private static class Subscription { - final Uri uri; + final String id; SubscriptionCallback callback; - Subscription(Uri u) { - this.uri = u; + Subscription(String id) { + this.id = id; } } } diff --git a/media/java/android/service/media/IMediaBrowserService.aidl b/media/java/android/service/media/IMediaBrowserService.aidl index 2631ddd..01285ee 100644 --- a/media/java/android/service/media/IMediaBrowserService.aidl +++ b/media/java/android/service/media/IMediaBrowserService.aidl @@ -16,6 +16,6 @@ oneway interface IMediaBrowserService { void connect(String pkg, in Bundle rootHints, IMediaBrowserServiceCallbacks callbacks); void disconnect(IMediaBrowserServiceCallbacks callbacks); - void addSubscription(in Uri uri, IMediaBrowserServiceCallbacks callbacks); - void removeSubscription(in Uri uri, IMediaBrowserServiceCallbacks callbacks); + void addSubscription(String uri, IMediaBrowserServiceCallbacks callbacks); + void removeSubscription(String uri, IMediaBrowserServiceCallbacks callbacks); }
\ No newline at end of file diff --git a/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl b/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl index 7702a50..2a37ada 100644 --- a/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl +++ b/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl @@ -5,7 +5,6 @@ package android.service.media; import android.content.pm.ParceledListSlice; import android.graphics.Bitmap; import android.media.session.MediaSession; -import android.net.Uri; import android.os.Bundle; /** @@ -16,12 +15,12 @@ import android.os.Bundle; oneway interface IMediaBrowserServiceCallbacks { /** * Invoked when the connected has been established. - * @param root The root Uri for browsing. + * @param root The root media id for browsing. * @param session The {@link MediaSession.Token media session token} that can be used to control * the playback of the media app. * @param extra Extras returned by the media service. */ - void onConnect(in Uri root, in MediaSession.Token session, in Bundle extras); + void onConnect(String root, in MediaSession.Token session, in Bundle extras); void onConnectFailed(); - void onLoadChildren(in Uri uri, in ParceledListSlice list); + void onLoadChildren(String mediaId, in ParceledListSlice list); } diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java index 4d6fd7b..317cb96 100644 --- a/media/java/android/service/media/MediaBrowserService.java +++ b/media/java/android/service/media/MediaBrowserService.java @@ -25,12 +25,8 @@ import android.app.Service; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; -import android.content.res.Configuration; -import android.graphics.Bitmap; import android.media.browse.MediaBrowser; -import android.media.browse.MediaBrowser.MediaItem; import android.media.session.MediaSession; -import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; @@ -38,18 +34,13 @@ import android.os.Handler; import android.os.RemoteException; import android.service.media.IMediaBrowserService; import android.service.media.IMediaBrowserServiceCallbacks; -import android.service.media.IMediaBrowserService.Stub; import android.util.ArrayMap; import android.util.Log; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Set; /** * Base class for media browse services. @@ -96,7 +87,7 @@ public abstract class MediaBrowserService extends Service { Bundle rootHints; IMediaBrowserServiceCallbacks callbacks; BrowserRoot root; - HashSet<Uri> subscriptions = new HashSet(); + HashSet<String> subscriptions = new HashSet(); } /** @@ -199,7 +190,7 @@ public abstract class MediaBrowserService extends Service { } else { try { mConnections.put(b, connection); - callbacks.onConnect(connection.root.getRootUri(), + callbacks.onConnect(connection.root.getRootId(), mSession, connection.root.getExtras()); } catch (RemoteException ex) { Log.w(TAG, "Calling onConnect() failed. Dropping client. " @@ -229,7 +220,7 @@ public abstract class MediaBrowserService extends Service { @Override - public void addSubscription(final Uri uri, final IMediaBrowserServiceCallbacks callbacks) { + public void addSubscription(final String id, final IMediaBrowserServiceCallbacks callbacks) { mHandler.post(new Runnable() { @Override public void run() { @@ -238,18 +229,18 @@ public abstract class MediaBrowserService extends Service { // Get the record for the connection final ConnectionRecord connection = mConnections.get(b); if (connection == null) { - Log.w(TAG, "addSubscription for callback that isn't registered uri=" - + uri); + Log.w(TAG, "addSubscription for callback that isn't registered id=" + + id); return; } - MediaBrowserService.this.addSubscription(uri, connection); + MediaBrowserService.this.addSubscription(id, connection); } }); } @Override - public void removeSubscription(final Uri uri, + public void removeSubscription(final String id, final IMediaBrowserServiceCallbacks callbacks) { mHandler.post(new Runnable() { @Override @@ -258,12 +249,12 @@ public abstract class MediaBrowserService extends Service { ConnectionRecord connection = mConnections.get(b); if (connection == null) { - Log.w(TAG, "removeSubscription for callback that isn't registered uri=" - + uri); + Log.w(TAG, "removeSubscription for callback that isn't registered id=" + + id); return; } - if (!connection.subscriptions.remove(uri)) { - Log.w(TAG, "removeSubscription called for " + uri + if (!connection.subscriptions.remove(id)) { + Log.w(TAG, "removeSubscription called for " + id + " which is not subscribed"); } } @@ -294,7 +285,7 @@ public abstract class MediaBrowserService extends Service { * <p> * The implementation should verify that the client package has * permission to access browse media information before returning - * the root uri; it should return null if the client is not + * the root id; it should return null if the client is not * allowed to access this information. * </p> * @@ -303,7 +294,7 @@ public abstract class MediaBrowserService extends Service { * @param clientUid The uid of the application which is requesting * access to browse media. * @param rootHints An optional bundle of service-specific arguments to send - * to the media browse service when connecting and retrieving the root uri + * to the media browse service when connecting and retrieving the root id * for browsing, or null if none. The contents of this bundle may affect * the information returned when browsing. */ @@ -319,11 +310,11 @@ public abstract class MediaBrowserService extends Service { * from this function, and then {@link Result#sendResult result.sendResult} called when * the loading is complete. * - * @param parentUri The uri of the parent media item whose + * @param parentId The id of the parent media item whose * children are to be queried. - * @return The list of children, or null if the uri is invalid. + * @return The list of children, or null if the id is invalid. */ - public abstract void onLoadChildren(@NonNull Uri parentUri, + public abstract void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowser.MediaItem>> result); /** @@ -351,23 +342,23 @@ public abstract class MediaBrowserService extends Service { /** * Notifies all connected media browsers that the children of - * the specified Uri have changed in some way. + * the specified parent id have changed in some way. * This will cause browsers to fetch subscribed content again. * - * @param parentUri The uri of the parent media item whose + * @param parentId The id of the parent media item whose * children changed. */ - public void notifyChildrenChanged(@NonNull final Uri parentUri) { - if (parentUri == null) { - throw new IllegalArgumentException("parentUri cannot be null in notifyChildrenChanged"); + public void notifyChildrenChanged(@NonNull final String parentId) { + if (parentId == null) { + throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged"); } mHandler.post(new Runnable() { @Override public void run() { for (IBinder binder : mConnections.keySet()) { ConnectionRecord connection = mConnections.get(binder); - if (connection.subscriptions.contains(parentUri)) { - performLoadChildren(parentUri, connection); + if (connection.subscriptions.contains(parentId)) { + performLoadChildren(parentId, connection); } } } @@ -395,13 +386,13 @@ public abstract class MediaBrowserService extends Service { /** * Save the subscription and if it is a new subscription send the results. */ - private void addSubscription(Uri uri, ConnectionRecord connection) { + private void addSubscription(String id, ConnectionRecord connection) { // Save the subscription - final boolean added = connection.subscriptions.add(uri); + final boolean added = connection.subscriptions.add(id); // If this is a new subscription, send the results if (added) { - performLoadChildren(uri, connection); + performLoadChildren(id, connection); } } @@ -410,39 +401,39 @@ public abstract class MediaBrowserService extends Service { * <p> * Callers must make sure that this connection is still connected. */ - private void performLoadChildren(final Uri uri, final ConnectionRecord connection) { + private void performLoadChildren(final String parentId, final ConnectionRecord connection) { final Result<List<MediaBrowser.MediaItem>> result - = new Result<List<MediaBrowser.MediaItem>>( - uri) { + = new Result<List<MediaBrowser.MediaItem>>(parentId) { @Override void onResultSent(List<MediaBrowser.MediaItem> list) { if (list == null) { - throw new IllegalStateException("onLoadChildren sent null list for uri " + uri); + throw new IllegalStateException("onLoadChildren sent null list for id " + + parentId); } if (mConnections.get(connection.callbacks.asBinder()) != connection) { if (DBG) { Log.d(TAG, "Not sending onLoadChildren result for connection that has" - + " been disconnected. pkg=" + connection.pkg + " uri=" + uri); + + " been disconnected. pkg=" + connection.pkg + " id=" + parentId); } return; } final ParceledListSlice<MediaBrowser.MediaItem> pls = new ParceledListSlice(list); try { - connection.callbacks.onLoadChildren(uri, pls); + connection.callbacks.onLoadChildren(parentId, pls); } catch (RemoteException ex) { // The other side is in the process of crashing. - Log.w(TAG, "Calling onLoadChildren() failed for uri=" + uri + Log.w(TAG, "Calling onLoadChildren() failed for id=" + parentId + " package=" + connection.pkg); } } }; - onLoadChildren(uri, result); + onLoadChildren(parentId, result); if (!result.isDone()) { throw new IllegalStateException("onLoadChildren must call detach() or sendResult()" - + " before returning for package=" + connection.pkg + " uri=" + uri); + + " before returning for package=" + connection.pkg + " id=" + parentId); } } @@ -451,28 +442,28 @@ public abstract class MediaBrowserService extends Service { * when first connected. */ public static final class BrowserRoot { - final private Uri mUri; + final private String mRootId; final private Bundle mExtras; /** * Constructs a browser root. - * @param uri The root Uri for browsing. + * @param rootId The root id for browsing. * @param extras Any extras about the browser service. */ - public BrowserRoot(@NonNull Uri uri, @Nullable Bundle extras) { - if (uri == null) { - throw new IllegalArgumentException("The root uri in BrowserRoot cannot be null. " + + public BrowserRoot(@NonNull String rootId, @Nullable Bundle extras) { + if (rootId == null) { + throw new IllegalArgumentException("The root id in BrowserRoot cannot be null. " + "Use null for BrowserRoot instead."); } - mUri = uri; + mRootId = rootId; mExtras = extras; } /** - * Gets the root uri for browsing. + * Gets the root id for browsing. */ - public Uri getRootUri() { - return mUri; + public String getRootId() { + return mRootId; } /** |