Tighten lock in writeState

This commit is contained in:
Adrian Ulrich 2017-09-24 20:27:15 +02:00
parent 3369774158
commit 5a15f52a29

View File

@ -407,8 +407,14 @@ public final class SongTimeline {
{ {
// Must update PlaybackService.STATE_VERSION when changing behavior // Must update PlaybackService.STATE_VERSION when changing behavior
// here. // here.
ArrayList<Song> songs;
synchronized (this) { synchronized (this) {
ArrayList<Song> songs = mSongs; // Just grab a copy and release the lock soon:
// Performing the actual IO is pretty expensive and
// could stall UI elements accessing the timeline.
songs = new ArrayList(mSongs);
}
int size = songs.size(); int size = songs.size();
out.writeInt(size); out.writeInt(size);
@ -427,7 +433,6 @@ public final class SongTimeline {
out.writeInt(mFinishAction); out.writeInt(mFinishAction);
out.writeInt(mShuffleMode); out.writeInt(mShuffleMode);
} }
}
/** /**
* Sets the current callback to <code>callback</code>. * Sets the current callback to <code>callback</code>.