Make PlaybackState immutable with a builder

bug:15862252
Change-Id: I8944b7753cd6a36a74b0091f71a386f77040c4ab
This commit is contained in:
RoboErik
2014-07-09 13:34:32 -07:00
committed by Erik Pasternak
parent b3d91779cb
commit 5a4e011143
7 changed files with 279 additions and 157 deletions

View File

@@ -682,9 +682,13 @@ public class RemoteControlClient
// USE_SESSIONS
if (mSession != null) {
int pbState = PlaybackState.getStateFromRccState(state);
mSessionPlaybackState.setState(pbState, hasPosition ?
mPlaybackPositionMs : PlaybackState.PLAYBACK_POSITION_UNKNOWN,
playbackSpeed);
long position = hasPosition ? mPlaybackPositionMs
: PlaybackState.PLAYBACK_POSITION_UNKNOWN;
PlaybackState.Builder bob = new PlaybackState.Builder(mSessionPlaybackState);
bob.setState(pbState, position, playbackSpeed, SystemClock.elapsedRealtime());
bob.setErrorMessage(null);
mSessionPlaybackState = bob.build();
mSession.setPlaybackState(mSessionPlaybackState);
}
}
@@ -745,8 +749,9 @@ public class RemoteControlClient
// USE_SESSIONS
if (mSession != null) {
mSessionPlaybackState.setActions(PlaybackState
.getActionsFromRccControlFlags(transportControlFlags));
PlaybackState.Builder bob = new PlaybackState.Builder(mSessionPlaybackState);
bob.setActions(PlaybackState.getActionsFromRccControlFlags(transportControlFlags));
mSessionPlaybackState = bob.build();
mSession.setPlaybackState(mSessionPlaybackState);
}
}
@@ -946,7 +951,7 @@ public class RemoteControlClient
/**
* Cache for the current playback state using Session APIs.
*/
private final PlaybackState mSessionPlaybackState = new PlaybackState();
private PlaybackState mSessionPlaybackState = null;
/**
* Cache for metadata using Session APIs. This is re-initialized in apply().