Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b5acfe2 authored by Tim Murray's avatar Tim Murray
Browse files

media: don't reuse ParceledListSlices

ParceledListSlice cannot be used for more than one transfer.

Test: boots, no exceptions
Bug: 213236807
Change-Id: I434f7cfef496d19e5fd58b7c8d699ba5700383d2
parent dd4769c8
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -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);
                }
+10 −9
Original line number Diff line number Diff line
@@ -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) {