Merge "media: don't reuse ParceledListSlices"

This commit is contained in:
TreeHugger Robot
2022-01-12 04:55:39 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 24 deletions

View File

@@ -79,7 +79,7 @@ public class MediaCommunicationService extends SystemService {
final Executor mRecordExecutor = Executors.newSingleThreadExecutor();
@GuardedBy("mLock")
final List<CallbackRecord> mCallbackRecords = new ArrayList<>();
final ArrayList<CallbackRecord> mCallbackRecords = new ArrayList<>();
final NotificationManager mNotificationManager;
MediaSessionManager mSessionManager;
@@ -150,8 +150,8 @@ public class MediaCommunicationService extends SystemService {
return null;
}
List<Session2Token> getSession2TokensLocked(int userId) {
List<Session2Token> list = new ArrayList<>();
ArrayList<Session2Token> getSession2TokensLocked(int userId) {
ArrayList<Session2Token> list = new ArrayList<>();
if (userId == ALL.getIdentifier()) {
int size = mUserRecords.size();
for (int i = 0; i < size; i++) {
@@ -237,28 +237,29 @@ public class MediaCommunicationService extends SystemService {
}
void dispatchSession2Changed(int userId) {
MediaParceledListSlice<Session2Token> allSession2Tokens;
MediaParceledListSlice<Session2Token> userSession2Tokens;
ArrayList<Session2Token> allSession2Tokens;
ArrayList<Session2Token> userSession2Tokens;
synchronized (mLock) {
allSession2Tokens =
new MediaParceledListSlice<>(getSession2TokensLocked(ALL.getIdentifier()));
userSession2Tokens = new MediaParceledListSlice<>(getSession2TokensLocked(userId));
}
allSession2Tokens.setInlineCountLimit(1);
userSession2Tokens.setInlineCountLimit(1);
allSession2Tokens = getSession2TokensLocked(ALL.getIdentifier());
userSession2Tokens = getSession2TokensLocked(userId);
synchronized (mLock) {
for (CallbackRecord record : mCallbackRecords) {
if (record.mUserId == ALL.getIdentifier()) {
try {
record.mCallback.onSession2Changed(allSession2Tokens);
MediaParceledListSlice<Session2Token> toSend =
new MediaParceledListSlice<>(allSession2Tokens);
toSend.setInlineCountLimit(0);
record.mCallback.onSession2Changed(toSend);
} catch (RemoteException e) {
Log.w(TAG, "Failed to notify session2 tokens changed " + record);
}
} else if (record.mUserId == userId) {
try {
record.mCallback.onSession2Changed(userSession2Tokens);
MediaParceledListSlice<Session2Token> toSend =
new MediaParceledListSlice<>(userSession2Tokens);
toSend.setInlineCountLimit(0);
record.mCallback.onSession2Changed(toSend);
} catch (RemoteException e) {
Log.w(TAG, "Failed to notify session2 tokens changed " + record);
}
@@ -382,7 +383,7 @@ public class MediaCommunicationService extends SystemService {
try {
// Check that they can make calls on behalf of the user and get the final user id
int resolvedUserId = handleIncomingUser(pid, uid, userId, null);
List<Session2Token> result;
ArrayList<Session2Token> result;
synchronized (mLock) {
result = getSession2TokensLocked(resolvedUserId);
}

View File

@@ -52,7 +52,6 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
@@ -643,22 +642,24 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
}
private void pushQueueUpdate() {
ParceledListSlice<QueueItem> parcelableQueue;
ArrayList<QueueItem> toSend;
synchronized (mLock) {
if (mDestroyed) {
return;
}
if (mQueue == null) {
parcelableQueue = null;
} else {
parcelableQueue = new ParceledListSlice<>(mQueue);
// Limit the size of initial Parcel to prevent binder buffer overflow
// as onQueueChanged is an async binder call.
parcelableQueue.setInlineCountLimit(1);
toSend = new ArrayList<>();
if (mQueue != null) {
toSend.ensureCapacity(mQueue.size());
toSend.addAll(mQueue);
}
}
Collection<ISessionControllerCallbackHolder> deadCallbackHolders = null;
for (ISessionControllerCallbackHolder holder : mControllerCallbackHolders) {
ParceledListSlice<QueueItem> parcelableQueue = new ParceledListSlice<>(toSend);
// Limit the size of initial Parcel to prevent binder buffer overflow
// as onQueueChanged is an async binder call.
parcelableQueue.setInlineCountLimit(1);
try {
holder.mCallback.onQueueChanged(parcelableQueue);
} catch (DeadObjectException e) {