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

Commit 1853357f authored by wumin3's avatar wumin3
Browse files

MediaSessionRecord: add synchronize control for modification of mControllerCallbackHolders



// ArrayIndexOutOfBoundsException thrown when unregisterCallback()
03-13 18:57:16.455  2112  6787 E JavaBinder: *** Uncaught remote exception! Exceptions are not yet supported across processes. Client PID 3726 UID 1000.
03-13 18:57:16.455  2112  6787 E JavaBinder: java.lang.ArrayIndexOutOfBoundsException: length=0; index=1
03-13 18:57:16.455  2112  6787 E JavaBinder:  at java.util.concurrent.CopyOnWriteArrayList.elementAt(CopyOnWriteArrayList.java:389)
03-13 18:57:16.455  2112  6787 E JavaBinder:  at java.util.concurrent.CopyOnWriteArrayList.remove(CopyOnWriteArrayList.java:482)
03-13 18:57:16.455  2112  6787 E JavaBinder:  at com.android.server.media.MediaSessionRecord$ControllerStub.unregisterCallback(MediaSessionRecord.java:1714)
03-13 18:57:16.455  2112  6787 E JavaBinder:  at android.media.session.ISessionController$Stub.onTransact(ISessionController.java:394)
03-13 18:57:16.455  2112  6787 E JavaBinder:  at android.os.Binder.execTransactInternal(Binder.java:1351)
03-13 18:57:16.455  2112  6787 E JavaBinder:  at android.os.Binder.execTransact(Binder.java:1282)

Change-Id: I02c3011ac8d27171016dd15ce7dbbadff4a2bb65
Signed-off-by: default avatarwumin3 <wumin3@xiaomi.com>
parent cab0c542
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -786,7 +786,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -813,7 +813,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -848,7 +848,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -875,7 +875,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -902,7 +902,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -929,7 +929,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -954,7 +954,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        if (deadCallbackHolders != null) {
            mControllerCallbackHolders.removeAll(deadCallbackHolders);
            removeControllerHoldersSafely(deadCallbackHolders);
        }
    }

@@ -979,7 +979,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
            }
        }
        // After notifying clear all listeners
        mControllerCallbackHolders.clear();
        removeControllerHoldersSafely(null);
    }

    private PlaybackState getStateWithUpdatedPosition() {
@@ -1027,6 +1027,17 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
        return -1;
    }

    private void removeControllerHoldersSafely(
            Collection<ISessionControllerCallbackHolder> holders) {
        synchronized (mLock) {
            if (holders == null) {
                mControllerCallbackHolders.clear();
            } else {
                mControllerCallbackHolders.removeAll(holders);
            }
        }
    }

    private PlaybackInfo getVolumeAttributes() {
        int volumeType;
        AudioAttributes attributes;