Make remote process bundle method less error-prone

The toBundle method should only be used for remote processes,
because there is a separate method for in-process bundling.
Renaming the method makes this more explicit and less error-prone.

PiperOrigin-RevId: 578456532
This commit is contained in:
tonihei 2023-11-01 03:06:07 -07:00 committed by Copybara-Service
parent 4f99000ba1
commit 1a09430182
4 changed files with 15 additions and 12 deletions

View File

@ -98,10 +98,10 @@ import java.util.List;
@Override @Override
public Bundle toBundle() { public Bundle toBundle() {
return toBundle(Integer.MAX_VALUE); return toBundleForRemoteProcess(Integer.MAX_VALUE);
} }
public Bundle toBundle(int controllerInterfaceVersion) { public Bundle toBundleForRemoteProcess(int controllerInterfaceVersion) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(FIELD_LIBRARY_VERSION, libraryVersion); bundle.putInt(FIELD_LIBRARY_VERSION, libraryVersion);
BundleCompat.putBinder(bundle, FIELD_SESSION_BINDER, sessionBinder.asBinder()); BundleCompat.putBinder(bundle, FIELD_SESSION_BINDER, sessionBinder.asBinder());
@ -121,7 +121,7 @@ import java.util.List;
playerInfo playerInfo
.filterByAvailableCommands( .filterByAvailableCommands(
intersectedCommands, /* excludeTimeline= */ false, /* excludeTracks= */ false) intersectedCommands, /* excludeTimeline= */ false, /* excludeTracks= */ false)
.toBundle(controllerInterfaceVersion)); .toBundleForRemoteProcess(controllerInterfaceVersion));
bundle.putInt(FIELD_SESSION_INTERFACE_VERSION, sessionInterfaceVersion); bundle.putInt(FIELD_SESSION_INTERFACE_VERSION, sessionInterfaceVersion);
return bundle; return bundle;
} }

View File

@ -540,7 +540,7 @@ import java.util.concurrent.ExecutionException;
sequencedFutureManager.obtainNextSequenceNumber(), sequencedFutureManager.obtainNextSequenceNumber(),
caller instanceof MediaControllerStub caller instanceof MediaControllerStub
? state.toBundleInProcess() ? state.toBundleInProcess()
: state.toBundle(controllerInfo.getInterfaceVersion())); : state.toBundleForRemoteProcess(controllerInfo.getInterfaceVersion()));
connected = true; connected = true;
} catch (RemoteException e) { } catch (RemoteException e) {
// Controller may be died prematurely. // Controller may be died prematurely.
@ -1985,7 +1985,7 @@ import java.util.concurrent.ExecutionException;
Bundle playerInfoBundle = Bundle playerInfoBundle =
iController instanceof MediaControllerStub iController instanceof MediaControllerStub
? filteredPlayerInfo.toBundleInProcess() ? filteredPlayerInfo.toBundleInProcess()
: filteredPlayerInfo.toBundle(controllerInterfaceVersion); : filteredPlayerInfo.toBundleForRemoteProcess(controllerInterfaceVersion);
iController.onPlayerInfoChangedWithExclusions( iController.onPlayerInfoChangedWithExclusions(
sequenceNumber, sequenceNumber,
playerInfoBundle, playerInfoBundle,
@ -1998,7 +1998,7 @@ import java.util.concurrent.ExecutionException;
//noinspection deprecation //noinspection deprecation
iController.onPlayerInfoChanged( iController.onPlayerInfoChanged(
sequenceNumber, sequenceNumber,
filteredPlayerInfo.toBundle(controllerInterfaceVersion), filteredPlayerInfo.toBundleForRemoteProcess(controllerInterfaceVersion),
bundlingExclusionsTimeline); bundlingExclusionsTimeline);
} }
} }

View File

@ -899,10 +899,10 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
@Override @Override
public Bundle toBundle() { public Bundle toBundle() {
return toBundle(Integer.MAX_VALUE); return toBundleForRemoteProcess(Integer.MAX_VALUE);
} }
public Bundle toBundle(int controllerInterfaceVersion) { public Bundle toBundleForRemoteProcess(int controllerInterfaceVersion) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (playerError != null) { if (playerError != null) {
bundle.putBundle(FIELD_PLAYBACK_ERROR, playerError.toBundle()); bundle.putBundle(FIELD_PLAYBACK_ERROR, playerError.toBundle());

View File

@ -651,18 +651,21 @@ public class PlayerInfoTest {
} }
@Test @Test
public void toBundle_withDefaultValues_omitsAllData() { public void toBundleForRemoteProcess_withDefaultValues_omitsAllData() {
Bundle bundle = Bundle bundle =
PlayerInfo.DEFAULT.toBundle(/* controllerInterfaceVersion= */ Integer.MAX_VALUE); PlayerInfo.DEFAULT.toBundleForRemoteProcess(
/* controllerInterfaceVersion= */ Integer.MAX_VALUE);
assertThat(bundle.isEmpty()).isTrue(); assertThat(bundle.isEmpty()).isTrue();
} }
@Test @Test
public void toBundle_withDefaultValuesForControllerInterfaceBefore3_includesPositionInfos() { public void
toBundleForRemoteProcess_withDefaultValuesForControllerInterfaceBefore3_includesPositionInfos() {
// Controller before version 3 uses invalid default values for indices in (Session)PositionInfo. // Controller before version 3 uses invalid default values for indices in (Session)PositionInfo.
// The Bundle should always include these fields to avoid using the invalid defaults. // The Bundle should always include these fields to avoid using the invalid defaults.
Bundle bundle = PlayerInfo.DEFAULT.toBundle(/* controllerInterfaceVersion= */ 2); Bundle bundle =
PlayerInfo.DEFAULT.toBundleForRemoteProcess(/* controllerInterfaceVersion= */ 2);
assertThat(bundle.keySet()) assertThat(bundle.keySet())
.containsAtLeast( .containsAtLeast(