Add Builder for DeviceInfo

This simplifies the addition of new fields in the future.

Also do some misc clean up for the volume limit values:
 - Add some documentation to mention assumed defaults
 - Add the IntRange annotations to match the ones we have in Player
   already
 - Mention the limits in the relevant Player methods
 - Avoid bundling default values
 - Improve range checks for masking in MediaController

PiperOrigin-RevId: 526029619
This commit is contained in:
tonihei 2023-04-21 15:30:42 +01:00 committed by Rohit Singh
parent 186f3d5c77
commit d9fd8f4310
18 changed files with 155 additions and 67 deletions

View File

@ -36,6 +36,7 @@
* Fix issue where last frame may not be rendered if the last sample with * Fix issue where last frame may not be rendered if the last sample with
frames is dequeued without reading the 'end of stream' sample. frames is dequeued without reading the 'end of stream' sample.
([#11079](https://github.com/google/ExoPlayer/issues/11079)). ([#11079](https://github.com/google/ExoPlayer/issues/11079)).
* Add `Builder` for `DeviceInfo` and deprecate existing constructor.
* Session: * Session:
* Deprecate 4 volume-controlling methods in `Player` and add overloaded * Deprecate 4 volume-controlling methods in `Player` and add overloaded
methods which allow users to specify volume flags: methods which allow users to specify volume flags:

11
api.txt
View File

@ -178,11 +178,18 @@ package androidx.media3.common {
field public static final int PLAYBACK_TYPE_LOCAL = 0; // 0x0 field public static final int PLAYBACK_TYPE_LOCAL = 0; // 0x0
field public static final int PLAYBACK_TYPE_REMOTE = 1; // 0x1 field public static final int PLAYBACK_TYPE_REMOTE = 1; // 0x1
field public static final androidx.media3.common.DeviceInfo UNKNOWN; field public static final androidx.media3.common.DeviceInfo UNKNOWN;
field public final int maxVolume; field @IntRange(from=0) public final int maxVolume;
field public final int minVolume; field @IntRange(from=0) public final int minVolume;
field @androidx.media3.common.DeviceInfo.PlaybackType public final int playbackType; field @androidx.media3.common.DeviceInfo.PlaybackType public final int playbackType;
} }
public static final class DeviceInfo.Builder {
ctor public DeviceInfo.Builder(@androidx.media3.common.DeviceInfo.PlaybackType int);
method public androidx.media3.common.DeviceInfo build();
method public androidx.media3.common.DeviceInfo.Builder setMaxVolume(@IntRange(from=0) int);
method public androidx.media3.common.DeviceInfo.Builder setMinVolume(@IntRange(from=0) int);
}
@IntDef({androidx.media3.common.DeviceInfo.PLAYBACK_TYPE_LOCAL, androidx.media3.common.DeviceInfo.PLAYBACK_TYPE_REMOTE}) @java.lang.annotation.Documented @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) public static @interface DeviceInfo.PlaybackType { @IntDef({androidx.media3.common.DeviceInfo.PLAYBACK_TYPE_LOCAL, androidx.media3.common.DeviceInfo.PLAYBACK_TYPE_REMOTE}) @java.lang.annotation.Documented @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) public static @interface DeviceInfo.PlaybackType {
} }

View File

@ -85,7 +85,7 @@ public final class CastPlayer extends BasePlayer {
/** The {@link DeviceInfo} returned by {@link #getDeviceInfo() this player}. */ /** The {@link DeviceInfo} returned by {@link #getDeviceInfo() this player}. */
public static final DeviceInfo DEVICE_INFO = public static final DeviceInfo DEVICE_INFO =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 0); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).build();
static { static {
MediaLibraryInfo.registerModule("media3.cast"); MediaLibraryInfo.registerModule("media3.cast");

View File

@ -19,9 +19,12 @@ import static java.lang.annotation.ElementType.TYPE_USE;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.IntRange;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -45,22 +48,83 @@ public final class DeviceInfo implements Bundleable {
public static final int PLAYBACK_TYPE_REMOTE = 1; public static final int PLAYBACK_TYPE_REMOTE = 1;
/** Unknown DeviceInfo. */ /** Unknown DeviceInfo. */
public static final DeviceInfo UNKNOWN = public static final DeviceInfo UNKNOWN = new Builder(PLAYBACK_TYPE_LOCAL).build();
new DeviceInfo(PLAYBACK_TYPE_LOCAL, /* minVolume= */ 0, /* maxVolume= */ 0);
/** Builder for {@link DeviceInfo}. */
public static final class Builder {
private final @PlaybackType int playbackType;
private int minVolume;
private int maxVolume;
/**
* Creates the builder.
*
* @param playbackType The {@link PlaybackType}.
*/
public Builder(@PlaybackType int playbackType) {
this.playbackType = playbackType;
}
/**
* Sets the minimum supported device volume.
*
* <p>The minimum will be set to {@code 0} if not specified.
*
* @param minVolume The minimum device volume.
* @return This builder.
*/
@CanIgnoreReturnValue
public Builder setMinVolume(@IntRange(from = 0) int minVolume) {
this.minVolume = minVolume;
return this;
}
/**
* Sets the maximum supported device volume.
*
* @param maxVolume The maximum device volume, or {@code 0} to leave the maximum unspecified.
* @return This builder.
*/
@CanIgnoreReturnValue
public Builder setMaxVolume(@IntRange(from = 0) int maxVolume) {
this.maxVolume = maxVolume;
return this;
}
/** Builds the {@link DeviceInfo}. */
public DeviceInfo build() {
Assertions.checkArgument(minVolume <= maxVolume);
return new DeviceInfo(this);
}
}
/** The type of playback. */ /** The type of playback. */
public final @PlaybackType int playbackType; public final @PlaybackType int playbackType;
/** The minimum volume that the device supports. */ /** The minimum volume that the device supports. */
@IntRange(from = 0)
public final int minVolume; public final int minVolume;
/** The maximum volume that the device supports. */ /** The maximum volume that the device supports, or {@code 0} if unspecified. */
@IntRange(from = 0)
public final int maxVolume; public final int maxVolume;
/** Creates device information. */ /**
* @deprecated Use {@link Builder} instead.
*/
@UnstableApi @UnstableApi
public DeviceInfo(@PlaybackType int playbackType, int minVolume, int maxVolume) { @Deprecated
this.playbackType = playbackType; public DeviceInfo(
this.minVolume = minVolume; @PlaybackType int playbackType,
this.maxVolume = maxVolume; @IntRange(from = 0) int minVolume,
@IntRange(from = 0) int maxVolume) {
this(new Builder(playbackType).setMinVolume(minVolume).setMaxVolume(maxVolume));
}
private DeviceInfo(Builder builder) {
this.playbackType = builder.playbackType;
this.minVolume = builder.minVolume;
this.maxVolume = builder.maxVolume;
} }
@Override @Override
@ -96,9 +160,15 @@ public final class DeviceInfo implements Bundleable {
@Override @Override
public Bundle toBundle() { public Bundle toBundle() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(FIELD_PLAYBACK_TYPE, playbackType); if (playbackType != PLAYBACK_TYPE_LOCAL) {
bundle.putInt(FIELD_MIN_VOLUME, minVolume); bundle.putInt(FIELD_PLAYBACK_TYPE, playbackType);
bundle.putInt(FIELD_MAX_VOLUME, maxVolume); }
if (minVolume != 0) {
bundle.putInt(FIELD_MIN_VOLUME, minVolume);
}
if (maxVolume != 0) {
bundle.putInt(FIELD_MAX_VOLUME, maxVolume);
}
return bundle; return bundle;
} }
@ -110,6 +180,9 @@ public final class DeviceInfo implements Bundleable {
bundle.getInt(FIELD_PLAYBACK_TYPE, /* defaultValue= */ PLAYBACK_TYPE_LOCAL); bundle.getInt(FIELD_PLAYBACK_TYPE, /* defaultValue= */ PLAYBACK_TYPE_LOCAL);
int minVolume = bundle.getInt(FIELD_MIN_VOLUME, /* defaultValue= */ 0); int minVolume = bundle.getInt(FIELD_MIN_VOLUME, /* defaultValue= */ 0);
int maxVolume = bundle.getInt(FIELD_MAX_VOLUME, /* defaultValue= */ 0); int maxVolume = bundle.getInt(FIELD_MAX_VOLUME, /* defaultValue= */ 0);
return new DeviceInfo(playbackType, minVolume, maxVolume); return new DeviceInfo.Builder(playbackType)
.setMinVolume(minVolume)
.setMaxVolume(maxVolume)
.build();
}; };
} }

View File

@ -3135,6 +3135,9 @@ public interface Player {
/** /**
* Increases the volume of the device. * Increases the volume of the device.
* *
* <p>The {@link #getDeviceVolume()} device volume cannot be increased above {@link
* DeviceInfo#maxVolume}, if defined.
*
* <p>This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS} is * <p>This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS} is
* {@linkplain #getAvailableCommands() available}. * {@linkplain #getAvailableCommands() available}.
* *
@ -3151,6 +3154,9 @@ public interface Player {
/** /**
* Decreases the volume of the device. * Decreases the volume of the device.
* *
* <p>The {@link #getDeviceVolume()} device volume cannot be decreased below {@link
* DeviceInfo#minVolume}.
*
* <p>This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS} is * <p>This method must only be called if {@link #COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS} is
* {@linkplain #getAvailableCommands() available}. * {@linkplain #getAvailableCommands() available}.
* *

View File

@ -28,7 +28,10 @@ public class DeviceInfoTest {
@Test @Test
public void roundTripViaBundle_yieldsEqualInstance() { public void roundTripViaBundle_yieldsEqualInstance() {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 1, /* maxVolume= */ 9); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE)
.setMinVolume(1)
.setMaxVolume(9)
.build();
assertThat(DeviceInfo.CREATOR.fromBundle(deviceInfo.toBundle())).isEqualTo(deviceInfo); assertThat(DeviceInfo.CREATOR.fromBundle(deviceInfo.toBundle())).isEqualTo(deviceInfo);
} }

View File

@ -109,8 +109,7 @@ public class SimpleBasePlayerTest {
ImmutableList.of(new Cue.Builder().setText("text").build()), ImmutableList.of(new Cue.Builder().setText("text").build()),
/* presentationTimeUs= */ 123)) /* presentationTimeUs= */ 123))
.setDeviceInfo( .setDeviceInfo(
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(7).build())
DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 3, /* maxVolume= */ 7))
.setIsDeviceMuted(true) .setIsDeviceMuted(true)
.setSurfaceSize(new Size(480, 360)) .setSurfaceSize(new Size(480, 360))
.setNewlyRenderedFirstFrame(true) .setNewlyRenderedFirstFrame(true)
@ -225,7 +224,7 @@ public class SimpleBasePlayerTest {
Metadata timedMetadata = new Metadata(new FakeMetadataEntry("data")); Metadata timedMetadata = new Metadata(new FakeMetadataEntry("data"));
Size surfaceSize = new Size(480, 360); Size surfaceSize = new Size(480, 360);
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 3, /* maxVolume= */ 7); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(7).build();
ImmutableList<SimpleBasePlayer.MediaItemData> playlist = ImmutableList<SimpleBasePlayer.MediaItemData> playlist =
ImmutableList.of( ImmutableList.of(
new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(),
@ -811,7 +810,7 @@ public class SimpleBasePlayerTest {
ImmutableList.of(new Cue.Builder().setText("text").build()), ImmutableList.of(new Cue.Builder().setText("text").build()),
/* presentationTimeUs= */ 123); /* presentationTimeUs= */ 123);
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 3, /* maxVolume= */ 7); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(7).build();
MediaMetadata playlistMetadata = new MediaMetadata.Builder().setArtist("artist").build(); MediaMetadata playlistMetadata = new MediaMetadata.Builder().setArtist("artist").build();
SimpleBasePlayer.PositionSupplier contentPositionSupplier = () -> 456; SimpleBasePlayer.PositionSupplier contentPositionSupplier = () -> 456;
SimpleBasePlayer.PositionSupplier contentBufferedPositionSupplier = () -> 499; SimpleBasePlayer.PositionSupplier contentBufferedPositionSupplier = () -> 499;
@ -1276,7 +1275,7 @@ public class SimpleBasePlayerTest {
new Metadata(/* presentationTimeUs= */ 42, new FakeMetadataEntry("data")); new Metadata(/* presentationTimeUs= */ 42, new FakeMetadataEntry("data"));
Size surfaceSize = new Size(480, 360); Size surfaceSize = new Size(480, 360);
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 3, /* maxVolume= */ 7); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(7).build();
MediaMetadata playlistMetadata = new MediaMetadata.Builder().setArtist("artist").build(); MediaMetadata playlistMetadata = new MediaMetadata.Builder().setArtist("artist").build();
State state2 = State state2 =
new State.Builder() new State.Builder()

View File

@ -2791,10 +2791,10 @@ import java.util.concurrent.TimeoutException;
} }
private static DeviceInfo createDeviceInfo(StreamVolumeManager streamVolumeManager) { private static DeviceInfo createDeviceInfo(StreamVolumeManager streamVolumeManager) {
return new DeviceInfo( return new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL)
DeviceInfo.PLAYBACK_TYPE_LOCAL, .setMinVolume(streamVolumeManager.getMinVolume())
streamVolumeManager.getMinVolume(), .setMaxVolume(streamVolumeManager.getMaxVolume())
streamVolumeManager.getMaxVolume()); .build();
} }
private static int getPlayWhenReadyChangeReason(boolean playWhenReady, int playerCommand) { private static int getPlayWhenReadyChangeReason(boolean playWhenReady, int playerCommand) {

View File

@ -1399,7 +1399,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
(iSession, seq) -> iSession.setDeviceVolume(controllerStub, seq, volume)); (iSession, seq) -> iSession.setDeviceVolume(controllerStub, seq, volume));
if (playerInfo.deviceVolume != volume) { DeviceInfo deviceInfo = getDeviceInfo();
if (playerInfo.deviceVolume != volume
&& deviceInfo.minVolume <= volume
&& (deviceInfo.maxVolume == 0 || volume <= deviceInfo.maxVolume)) {
playerInfo = playerInfo.copyWithDeviceVolume(volume, playerInfo.deviceMuted); playerInfo = playerInfo.copyWithDeviceVolume(volume, playerInfo.deviceMuted);
listeners.queueEvent( listeners.queueEvent(
@ -1418,7 +1421,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
(iSession, seq) -> iSession.setDeviceVolumeWithFlags(controllerStub, seq, volume, flags)); (iSession, seq) -> iSession.setDeviceVolumeWithFlags(controllerStub, seq, volume, flags));
if (playerInfo.deviceVolume != volume) { DeviceInfo deviceInfo = getDeviceInfo();
if (playerInfo.deviceVolume != volume
&& deviceInfo.minVolume <= volume
&& (deviceInfo.maxVolume == 0 || volume <= deviceInfo.maxVolume)) {
playerInfo = playerInfo.copyWithDeviceVolume(volume, playerInfo.deviceMuted); playerInfo = playerInfo.copyWithDeviceVolume(volume, playerInfo.deviceMuted);
listeners.queueEvent( listeners.queueEvent(
@ -1442,7 +1448,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
(iSession, seq) -> iSession.increaseDeviceVolume(controllerStub, seq)); (iSession, seq) -> iSession.increaseDeviceVolume(controllerStub, seq));
int newDeviceVolume = playerInfo.deviceVolume + 1; int newDeviceVolume = playerInfo.deviceVolume + 1;
if (newDeviceVolume <= getDeviceInfo().maxVolume) { int maxVolume = getDeviceInfo().maxVolume;
if (maxVolume == 0 || newDeviceVolume <= maxVolume) {
playerInfo = playerInfo.copyWithDeviceVolume(newDeviceVolume, playerInfo.deviceMuted); playerInfo = playerInfo.copyWithDeviceVolume(newDeviceVolume, playerInfo.deviceMuted);
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ Player.EVENT_DEVICE_VOLUME_CHANGED, /* eventFlag= */ Player.EVENT_DEVICE_VOLUME_CHANGED,
@ -1461,7 +1468,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
(iSession, seq) -> iSession.increaseDeviceVolumeWithFlags(controllerStub, seq, flags)); (iSession, seq) -> iSession.increaseDeviceVolumeWithFlags(controllerStub, seq, flags));
int newDeviceVolume = playerInfo.deviceVolume + 1; int newDeviceVolume = playerInfo.deviceVolume + 1;
if (newDeviceVolume <= getDeviceInfo().maxVolume) { int maxVolume = getDeviceInfo().maxVolume;
if (maxVolume == 0 || newDeviceVolume <= maxVolume) {
playerInfo = playerInfo.copyWithDeviceVolume(newDeviceVolume, playerInfo.deviceMuted); playerInfo = playerInfo.copyWithDeviceVolume(newDeviceVolume, playerInfo.deviceMuted);
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ Player.EVENT_DEVICE_VOLUME_CHANGED, /* eventFlag= */ Player.EVENT_DEVICE_VOLUME_CHANGED,

View File

@ -1063,7 +1063,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
DeviceInfo deviceInfo = getDeviceInfo(); DeviceInfo deviceInfo = getDeviceInfo();
int minVolume = deviceInfo.minVolume; int minVolume = deviceInfo.minVolume;
int maxVolume = deviceInfo.maxVolume; int maxVolume = deviceInfo.maxVolume;
if (minVolume <= volume && volume <= maxVolume) { if (minVolume <= volume && (maxVolume == 0 || volume <= maxVolume)) {
boolean isDeviceMuted = isDeviceMuted(); boolean isDeviceMuted = isDeviceMuted();
ControllerInfo maskedControllerInfo = ControllerInfo maskedControllerInfo =
new ControllerInfo( new ControllerInfo(
@ -1093,7 +1093,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
public void increaseDeviceVolume(@C.VolumeFlags int flags) { public void increaseDeviceVolume(@C.VolumeFlags int flags) {
int volume = getDeviceVolume(); int volume = getDeviceVolume();
int maxVolume = getDeviceInfo().maxVolume; int maxVolume = getDeviceInfo().maxVolume;
if (volume + 1 <= maxVolume) { if (maxVolume == 0 || volume + 1 <= maxVolume) {
boolean isDeviceMuted = isDeviceMuted(); boolean isDeviceMuted = isDeviceMuted();
ControllerInfo maskedControllerInfo = ControllerInfo maskedControllerInfo =

View File

@ -1335,13 +1335,13 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
if (playbackInfoCompat == null) { if (playbackInfoCompat == null) {
return DeviceInfo.UNKNOWN; return DeviceInfo.UNKNOWN;
} }
return new DeviceInfo( return new DeviceInfo.Builder(
playbackInfoCompat.getPlaybackType() playbackInfoCompat.getPlaybackType()
== MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE == MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE
? DeviceInfo.PLAYBACK_TYPE_REMOTE ? DeviceInfo.PLAYBACK_TYPE_REMOTE
: DeviceInfo.PLAYBACK_TYPE_LOCAL, : DeviceInfo.PLAYBACK_TYPE_LOCAL)
/* minVolume= */ 0, .setMaxVolume(playbackInfoCompat.getMaxVolume())
playbackInfoCompat.getMaxVolume()); .build();
} }
/** Converts {@link MediaControllerCompat.PlaybackInfo} to device volume. */ /** Converts {@link MediaControllerCompat.PlaybackInfo} to device volume. */

View File

@ -136,8 +136,7 @@ public class PlayerInfoTest {
new int[] {C.FORMAT_EXCEEDS_CAPABILITIES}, new int[] {C.FORMAT_EXCEEDS_CAPABILITIES},
/* trackSelected= */ new boolean[] {true})))) /* trackSelected= */ new boolean[] {true}))))
.setDeviceInfo( .setDeviceInfo(
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(10).build())
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 4, /* maxVolume= */ 10))
.setDiscontinuityReason(Player.DISCONTINUITY_REASON_REMOVE) .setDiscontinuityReason(Player.DISCONTINUITY_REASON_REMOVE)
.setIsLoading(true) .setIsLoading(true)
.setIsPlaying(true) .setIsPlaying(true)

View File

@ -411,7 +411,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
@Test @Test
public void setPlayer_playbackTypeChangedToRemote() throws Exception { public void setPlayer_playbackTypeChangedToRemote() throws Exception {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 25); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(25).build();
int legacyPlaybackType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE; int legacyPlaybackType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE;
int deviceVolume = 10; int deviceVolume = 10;
CountDownLatch playbackInfoNotified = new CountDownLatch(1); CountDownLatch playbackInfoNotified = new CountDownLatch(1);
@ -445,12 +445,12 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
@Test @Test
public void setPlayer_playbackTypeChangedToLocal() throws Exception { public void setPlayer_playbackTypeChangedToLocal() throws Exception {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 10); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(10).build();
Bundle playerConfig = Bundle playerConfig =
new RemoteMediaSession.MockPlayerConfigBuilder().setDeviceInfo(deviceInfo).build(); new RemoteMediaSession.MockPlayerConfigBuilder().setDeviceInfo(deviceInfo).build();
session.setPlayer(playerConfig); session.setPlayer(playerConfig);
DeviceInfo deviceInfoToUpdate = DeviceInfo deviceInfoToUpdate =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 0, /* maxVolume= */ 10); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(10).build();
int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL; int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
int legacyStream = AudioManager.STREAM_RING; int legacyStream = AudioManager.STREAM_RING;
AudioAttributesCompat attrsCompat = AudioAttributesCompat attrsCompat =
@ -496,7 +496,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
@Test @Test
public void setPlayer_playbackTypeNotChanged_local() throws Exception { public void setPlayer_playbackTypeNotChanged_local() throws Exception {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 0, /* maxVolume= */ 10); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(10).build();
int legacyPlaybackType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL; int legacyPlaybackType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
int legacyStream = AudioManager.STREAM_RING; int legacyStream = AudioManager.STREAM_RING;
AudioAttributesCompat attrsCompat = AudioAttributesCompat attrsCompat =
@ -542,7 +542,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
@Test @Test
public void setPlayer_playbackTypeNotChanged_remote() throws Exception { public void setPlayer_playbackTypeNotChanged_remote() throws Exception {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 10); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(10).build();
Bundle playerConfig = Bundle playerConfig =
new RemoteMediaSession.MockPlayerConfigBuilder() new RemoteMediaSession.MockPlayerConfigBuilder()
.setDeviceInfo(deviceInfo) .setDeviceInfo(deviceInfo)
@ -550,7 +550,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
.build(); .build();
session.setPlayer(playerConfig); session.setPlayer(playerConfig);
DeviceInfo deviceInfoToUpdate = DeviceInfo deviceInfoToUpdate =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 25); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(25).build();
int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE; int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_REMOTE;
int deviceVolumeToUpdate = 10; int deviceVolumeToUpdate = 10;
CountDownLatch playbackInfoNotified = new CountDownLatch(1); CountDownLatch playbackInfoNotified = new CountDownLatch(1);
@ -1316,7 +1316,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
@Test @Test
public void onAudioInfoChanged_isCalledByVolumeChange() throws Exception { public void onAudioInfoChanged_isCalledByVolumeChange() throws Exception {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 10); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(10).build();
Bundle playerConfig = Bundle playerConfig =
new RemoteMediaSession.MockPlayerConfigBuilder() new RemoteMediaSession.MockPlayerConfigBuilder()
.setDeviceInfo(deviceInfo) .setDeviceInfo(deviceInfo)

View File

@ -2767,7 +2767,7 @@ public class MediaControllerListenerTest {
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
Bundle playerConfig = Bundle playerConfig =
new RemoteMediaSession.MockPlayerConfigBuilder().setDeviceInfo(deviceInfo).build(); new RemoteMediaSession.MockPlayerConfigBuilder().setDeviceInfo(deviceInfo).build();
remoteSession.setPlayer(playerConfig); remoteSession.setPlayer(playerConfig);
@ -2806,7 +2806,7 @@ public class MediaControllerListenerTest {
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 1, /* maxVolume= */ 23); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(23).build();
remoteSession.getMockPlayer().notifyDeviceInfoChanged(deviceInfo); remoteSession.getMockPlayer().notifyDeviceInfoChanged(deviceInfo);
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
@ -2819,7 +2819,7 @@ public class MediaControllerListenerTest {
@Test @Test
public void onDeviceVolumeChanged_isCalledByDeviceVolumeChange() throws Exception { public void onDeviceVolumeChanged_isCalledByDeviceVolumeChange() throws Exception {
DeviceInfo deviceInfo = DeviceInfo deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
Bundle playerConfig = Bundle playerConfig =
new RemoteMediaSession.MockPlayerConfigBuilder() new RemoteMediaSession.MockPlayerConfigBuilder()
.setDeviceInfo(deviceInfo) .setDeviceInfo(deviceInfo)

View File

@ -486,8 +486,7 @@ public class MediaControllerStateMaskingTest {
new RemoteMediaSession.MockPlayerConfigBuilder() new RemoteMediaSession.MockPlayerConfigBuilder()
.setDeviceVolume(1) .setDeviceVolume(1)
.setDeviceInfo( .setDeviceInfo(
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(2).build())
DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 0, /* maxVolume= */ 2))
.build(); .build();
remoteSession.setPlayer(playerConfig); remoteSession.setPlayer(playerConfig);

View File

@ -673,8 +673,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
handler.postAndSync( handler.postAndSync(
() -> { () -> {
remotePlayer.deviceInfo = remotePlayer.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
remotePlayer.deviceVolume = 23; remotePlayer.deviceVolume = 23;
session.setPlayer(remotePlayer); session.setPlayer(remotePlayer);
}); });
@ -702,8 +701,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
handler.postAndSync( handler.postAndSync(
() -> { () -> {
remotePlayer.deviceInfo = remotePlayer.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
remotePlayer.deviceVolume = 23; remotePlayer.deviceVolume = 23;
session.setPlayer(remotePlayer); session.setPlayer(remotePlayer);
}); });
@ -735,8 +733,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
handler.postAndSync( handler.postAndSync(
() -> { () -> {
remotePlayer.deviceInfo = remotePlayer.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
remotePlayer.deviceVolume = 23; remotePlayer.deviceVolume = 23;
session.setPlayer(remotePlayer); session.setPlayer(remotePlayer);
}); });
@ -761,8 +758,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
handler.postAndSync( handler.postAndSync(
() -> { () -> {
remotePlayer.deviceInfo = remotePlayer.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
remotePlayer.deviceVolume = 23; remotePlayer.deviceVolume = 23;
session.setPlayer(remotePlayer); session.setPlayer(remotePlayer);
}); });
@ -792,8 +788,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
handler.postAndSync( handler.postAndSync(
() -> { () -> {
remotePlayer.deviceInfo = remotePlayer.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
remotePlayer.deviceVolume = 23; remotePlayer.deviceVolume = 23;
session.setPlayer(remotePlayer); session.setPlayer(remotePlayer);
}); });
@ -819,8 +814,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
handler.postAndSync( handler.postAndSync(
() -> { () -> {
remotePlayer.deviceInfo = remotePlayer.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
remotePlayer.deviceVolume = 23; remotePlayer.deviceVolume = 23;
session.setPlayer(remotePlayer); session.setPlayer(remotePlayer);
}); });

View File

@ -279,7 +279,7 @@ public class MediaSessionPermissionTest {
.build(); .build();
// Set remote device info to ensure we also cover the volume provider compat setup. // Set remote device info to ensure we also cover the volume provider compat setup.
mockPlayer.deviceInfo = mockPlayer.deviceInfo =
new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100); new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
Player player = Player player =
new ForwardingPlayer(mockPlayer) { new ForwardingPlayer(mockPlayer) {
@Override @Override

View File

@ -842,8 +842,7 @@ public class MediaSessionPlayerTest {
.postAndSync( .postAndSync(
() -> { () -> {
player.deviceInfo = player.deviceInfo =
new DeviceInfo( new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(100).build();
DeviceInfo.PLAYBACK_TYPE_REMOTE, /* minVolume= */ 0, /* maxVolume= */ 100);
player.notifyDeviceInfoChanged(); player.notifyDeviceInfoChanged();
}); });
} }