diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 6c8a19c281..e57913f338 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -55,6 +55,9 @@ * Fix issue where the current position jumps back when the controller replaces the current item ([#951](https://github.com/androidx/media/issues/951)). + * Fix issue where `MediaMetadata` with just non-null `extras` is not + transmitted between media controllers and sessions + ([#1176](https://github.com/androidx/media/issues/1176)). * UI: * Fallback to include audio track language name if `Locale` cannot identify a display name diff --git a/libraries/common/src/main/java/androidx/media3/common/MediaItem.java b/libraries/common/src/main/java/androidx/media3/common/MediaItem.java index d6368c0104..3d7ae4cc98 100644 --- a/libraries/common/src/main/java/androidx/media3/common/MediaItem.java +++ b/libraries/common/src/main/java/androidx/media3/common/MediaItem.java @@ -2267,8 +2267,9 @@ public RequestMetadata build() { /** * Optional extras {@link Bundle}. * - *

Given the complexities of checking the equality of two {@link Bundle}s, the contents of - * these extras are not considered in the {@link #equals(Object)} or {@link #hashCode()}. + *

Given the complexities of checking the equality of two {@link Bundle} instances, the + * contents of these extras are not considered in the {@link #equals(Object)} or {@link + * #hashCode()} implementation. */ @Nullable public final Bundle extras; diff --git a/libraries/common/src/main/java/androidx/media3/common/MediaMetadata.java b/libraries/common/src/main/java/androidx/media3/common/MediaMetadata.java index 0078334d63..ede0858e8b 100644 --- a/libraries/common/src/main/java/androidx/media3/common/MediaMetadata.java +++ b/libraries/common/src/main/java/androidx/media3/common/MediaMetadata.java @@ -1085,8 +1085,9 @@ public MediaMetadata build() { /** * Optional extras {@link Bundle}. * - *

Given the complexities of checking the equality of two {@link Bundle}s, this is not - * considered in the {@link #equals(Object)} or {@link #hashCode()}. + *

Given the complexities of checking the equality of two {@link Bundle} instances, the + * contents of these extras are not considered in the {@link #equals(Object)} and {@link + * #hashCode()} implementation. */ @Nullable public final Bundle extras; @@ -1191,7 +1192,8 @@ public boolean equals(@Nullable Object obj) { && Util.areEqual(genre, that.genre) && Util.areEqual(compilation, that.compilation) && Util.areEqual(station, that.station) - && Util.areEqual(mediaType, that.mediaType); + && Util.areEqual(mediaType, that.mediaType) + && ((extras == null) == (that.extras == null)); } @SuppressWarnings("deprecation") // Hashing deprecated fields. @@ -1229,7 +1231,8 @@ public int hashCode() { genre, compilation, station, - mediaType); + mediaType, + extras == null); } // Bundleable implementation. diff --git a/libraries/common/src/test/java/androidx/media3/common/MediaMetadataTest.java b/libraries/common/src/test/java/androidx/media3/common/MediaMetadataTest.java index 5a247d5d8a..416773f800 100644 --- a/libraries/common/src/test/java/androidx/media3/common/MediaMetadataTest.java +++ b/libraries/common/src/test/java/androidx/media3/common/MediaMetadataTest.java @@ -163,6 +163,20 @@ public void createFullyPopulatedMediaMetadata_roundTripViaBundle_yieldsEqualInst assertThat(mediaMetadataFromBundle.extras.getString(EXTRAS_KEY)).isEqualTo(EXTRAS_VALUE); } + /** Regression test for https://github.com/androidx/media/issues/1176. */ + @Test + public void roundTripViaBundle_withJustNonNullExtras_restoresAllData() { + Bundle extras = new Bundle(); + extras.putString("key", "value"); + MediaMetadata mediaMetadata = new MediaMetadata.Builder().setExtras(extras).build(); + + MediaMetadata restoredMetadata = MediaMetadata.fromBundle(mediaMetadata.toBundle()); + + assertThat(restoredMetadata).isEqualTo(mediaMetadata); + assertThat(restoredMetadata.extras).isNotNull(); + assertThat(restoredMetadata.extras.get("key")).isEqualTo("value"); + } + @SuppressWarnings("deprecation") // Testing deprecated setter. @Test public void builderSetFolderType_toNone_setsIsBrowsableToFalse() {