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
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.putInt(FIELD_LIBRARY_VERSION, libraryVersion);
BundleCompat.putBinder(bundle, FIELD_SESSION_BINDER, sessionBinder.asBinder());
@ -121,7 +121,7 @@ import java.util.List;
playerInfo
.filterByAvailableCommands(
intersectedCommands, /* excludeTimeline= */ false, /* excludeTracks= */ false)
.toBundle(controllerInterfaceVersion));
.toBundleForRemoteProcess(controllerInterfaceVersion));
bundle.putInt(FIELD_SESSION_INTERFACE_VERSION, sessionInterfaceVersion);
return bundle;
}

View File

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

View File

@ -899,10 +899,10 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
@Override
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();
if (playerError != null) {
bundle.putBundle(FIELD_PLAYBACK_ERROR, playerError.toBundle());

View File

@ -651,18 +651,21 @@ public class PlayerInfoTest {
}
@Test
public void toBundle_withDefaultValues_omitsAllData() {
public void toBundleForRemoteProcess_withDefaultValues_omitsAllData() {
Bundle bundle =
PlayerInfo.DEFAULT.toBundle(/* controllerInterfaceVersion= */ Integer.MAX_VALUE);
PlayerInfo.DEFAULT.toBundleForRemoteProcess(
/* controllerInterfaceVersion= */ Integer.MAX_VALUE);
assertThat(bundle.isEmpty()).isTrue();
}
@Test
public void toBundle_withDefaultValuesForControllerInterfaceBefore3_includesPositionInfos() {
public void
toBundleForRemoteProcess_withDefaultValuesForControllerInterfaceBefore3_includesPositionInfos() {
// 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.
Bundle bundle = PlayerInfo.DEFAULT.toBundle(/* controllerInterfaceVersion= */ 2);
Bundle bundle =
PlayerInfo.DEFAULT.toBundleForRemoteProcess(/* controllerInterfaceVersion= */ 2);
assertThat(bundle.keySet())
.containsAtLeast(