Skip to content

Commit

Permalink
Include nullness of RequestMetadata.extras in equals method
Browse files Browse the repository at this point in the history
This ensures RequestMetadata with just non-null extras is not
considered equal to RequestMetadata.EMPTY. This makes sure the
contents are bundled when a controller sets the extras in a
new MediaItem.

PiperOrigin-RevId: 604632788
(cherry picked from commit 766a15a)
  • Loading branch information
tonihei authored and SheenaChhabra committed Feb 8, 2024
1 parent ad57b41 commit a294dc9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Muxers:
* IMA extension:
* Session:
* Fix issue where `MediaItem.RequestMetadata` with just non-null extras is
not sent transmitted between media controllers and sessions.
* UI:
* Downloads:
* OkHttp Extension:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2267,8 +2267,8 @@ public RequestMetadata build() {
/**
* Optional extras {@link Bundle}.
*
* <p>Given the complexities of checking the equality of two {@link Bundle}s, this is not
* considered in the {@link #equals(Object)} or {@link #hashCode()}.
* <p>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()}.
*/
@Nullable public final Bundle extras;

Expand All @@ -2292,13 +2292,16 @@ public boolean equals(@Nullable Object o) {
return false;
}
RequestMetadata that = (RequestMetadata) o;
return Util.areEqual(mediaUri, that.mediaUri) && Util.areEqual(searchQuery, that.searchQuery);
return Util.areEqual(mediaUri, that.mediaUri)
&& Util.areEqual(searchQuery, that.searchQuery)
&& ((extras == null) == (that.extras == null));
}

@Override
public int hashCode() {
int result = mediaUri == null ? 0 : mediaUri.hashCode();
result = 31 * result + (searchQuery == null ? 0 : searchQuery.hashCode());
result = 31 * result + (extras == null ? 0 : 1);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,24 @@ public void roundTripViaBundle_withoutLocalConfiguration_yieldsEqualInstance() {
assertThat(restoredMediaItem.localConfiguration).isEqualTo(mediaItem.localConfiguration);
}

/** Regression test for internal b/323302460 */
@Test
public void roundTripViaBundle_withJustNonNullRequestMetadataExtras_restoresAllData() {
Bundle extras = new Bundle();
extras.putString("key", "value");
MediaItem mediaItem =
new MediaItem.Builder()
.setMediaId("mediaId")
.setRequestMetadata(new RequestMetadata.Builder().setExtras(extras).build())
.build();

MediaItem restoredItem = MediaItem.fromBundle(mediaItem.toBundle());

assertThat(restoredItem).isEqualTo(mediaItem);
assertThat(restoredItem.requestMetadata.extras).isNotNull();
assertThat(restoredItem.requestMetadata.extras.get("key")).isEqualTo("value");
}

@Test
public void createDefaultMediaItemInstance_checksDefaultValues() {
MediaItem mediaItem = new MediaItem.Builder().build();
Expand Down

0 comments on commit a294dc9

Please sign in to comment.