From 3e0cfcda31301e53c92cb2f91ed8be1cd6efd8bc Mon Sep 17 00:00:00 2001 From: RoboErik Date: Tue, 4 Nov 2014 14:47:44 -0800 Subject: [PATCH 1/2] skip MediaController callbacks if it's been unregistered This gives slightly better gaurantees around when an app will receive a callback. As long as they remove a callback on the same thread calls get posted on they won't receive any callbacks after the remove. bug:18104724 Change-Id: Id9878186f005bf0b35c0380cd35f8fd7e67d1d90 --- media/java/android/media/session/MediaController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java index e490c2be8f9c8..dd6bd208d5915 100644 --- a/media/java/android/media/session/MediaController.java +++ b/media/java/android/media/session/MediaController.java @@ -449,6 +449,7 @@ public final class MediaController { } MessageHandler holder = new MessageHandler(handler.getLooper(), cb); mCallbacks.add(holder); + holder.mRegistered = true; if (!mCbRegistered) { try { @@ -467,6 +468,7 @@ public final class MediaController { if (cb == handler.mCallback) { mCallbacks.remove(i); success = true; + handler.mRegistered = false; } } if (mCbRegistered && mCallbacks.size() == 0) { @@ -956,6 +958,7 @@ public final class MediaController { private final static class MessageHandler extends Handler { private final MediaController.Callback mCallback; + private boolean mRegistered = false; public MessageHandler(Looper looper, MediaController.Callback cb) { super(looper, null, true); @@ -964,6 +967,9 @@ public final class MediaController { @Override public void handleMessage(Message msg) { + if (!mRegistered) { + return; + } switch (msg.what) { case MSG_EVENT: mCallback.onSessionEvent((String) msg.obj, msg.getData()); From a13846ddf34e4e237f698279a120abd2fe01e486 Mon Sep 17 00:00:00 2001 From: RoboErik Date: Thu, 6 Nov 2014 10:55:06 -0800 Subject: [PATCH 2/2] Update metadata artwork and uri docs This updates the Javadoc on the bitmap and uri fields to strongly suggest Uris be used for high res artwork and strongly suggest Uris use the content: style and support EXTRA_SIZE. Change-Id: If4c38bfec20d049473457784b1b56fa4d78abe5e --- media/java/android/media/MediaMetadata.java | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/media/java/android/media/MediaMetadata.java b/media/java/android/media/MediaMetadata.java index b4e603394c2d1..924078c455fdc 100644 --- a/media/java/android/media/MediaMetadata.java +++ b/media/java/android/media/MediaMetadata.java @@ -122,6 +122,10 @@ public final class MediaMetadata implements Parcelable { /** * The artwork for the media as a {@link Bitmap}. + *

+ * The artwork should be relatively small and may be scaled down by the + * system if it is too large. For higher resolution artwork + * {@link #METADATA_KEY_ART_URI} should be used instead. */ public static final String METADATA_KEY_ART = "android.media.metadata.ART"; @@ -129,12 +133,20 @@ public final class MediaMetadata implements Parcelable { * The artwork for the media as a Uri formatted String. The artwork can be * loaded using a combination of {@link ContentResolver#openInputStream} and * {@link BitmapFactory#decodeStream}. + *

+ * For the best results, Uris should use the content:// style and support + * {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork through + * {@link ContentResolver#openTypedAssetFileDescriptor(Uri, String, Bundle)}. */ public static final String METADATA_KEY_ART_URI = "android.media.metadata.ART_URI"; /** * The artwork for the album of the media's original source as a * {@link Bitmap}. + *

+ * The artwork should be relatively small and may be scaled down by the + * system if it is too large. For higher resolution artwork + * {@link #METADATA_KEY_ALBUM_ART_URI} should be used instead. */ public static final String METADATA_KEY_ALBUM_ART = "android.media.metadata.ALBUM_ART"; @@ -143,6 +155,10 @@ public final class MediaMetadata implements Parcelable { * formatted String. The artwork can be loaded using a combination of * {@link ContentResolver#openInputStream} and * {@link BitmapFactory#decodeStream}. + *

+ * For the best results, Uris should use the content:// style and support + * {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork through + * {@link ContentResolver#openTypedAssetFileDescriptor(Uri, String, Bundle)}. */ public static final String METADATA_KEY_ALBUM_ART_URI = "android.media.metadata.ALBUM_ART_URI"; @@ -188,6 +204,10 @@ public final class MediaMetadata implements Parcelable { * An icon or thumbnail that is suitable for display to the user. When * displaying an icon for media described by this metadata this should be * preferred to other fields if present. This must be a {@link Bitmap}. + *

+ * The icon should be relatively small and may be scaled down by the system + * if it is too large. For higher resolution artwork + * {@link #METADATA_KEY_DISPLAY_ICON_URI} should be used instead. */ public static final String METADATA_KEY_DISPLAY_ICON = "android.media.metadata.DISPLAY_ICON"; @@ -199,6 +219,10 @@ public final class MediaMetadata implements Parcelable { * fields when present. The icon can be loaded using a combination of * {@link ContentResolver#openInputStream} and * {@link BitmapFactory#decodeStream}. + *

+ * For the best results, Uris should use the content:// style and support + * {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork through + * {@link ContentResolver#openTypedAssetFileDescriptor(Uri, String, Bundle)}. */ public static final String METADATA_KEY_DISPLAY_ICON_URI = "android.media.metadata.DISPLAY_ICON_URI"; @@ -602,6 +626,11 @@ public final class MediaMetadata implements Parcelable { *

  • {@link #METADATA_KEY_DISPLAY_DESCRIPTION}
  • *
  • {@link #METADATA_KEY_DISPLAY_ICON_URI}
  • * + *

    + * Uris for artwork should use the content:// style and support + * {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork + * through {@link ContentResolver#openTypedAssetFileDescriptor(Uri, + * String, Bundle)}. * * @param key The key for referencing this value * @param value The String value to store