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

Commit 3e79e0fb authored by Jing Ji's avatar Jing Ji
Browse files

Move the mStrictModeCallbacks to be self-locked

We can't use AMS lock here since it's potentially called from
many places with other locks held.

Bug: 339293659
Test: treehugger
Flag: EXEMPT bugfix
Change-Id: I552e3e1c680fde2f707c6dda7fd26940bd9974ce
parent 39f039cc
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -730,7 +730,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    /** Whether some specified important processes are allowed to use FIFO priority. */
    boolean mAllowSpecifiedFifoScheduling = true;
    @GuardedBy("this")
    @GuardedBy("mStrictModeCallbacks")
    private final SparseArray<IUnsafeIntentStrictModeCallback>
            mStrictModeCallbacks = new SparseArray<>();
@@ -9538,13 +9538,14 @@ public class ActivityManagerService extends IActivityManager.Stub
     * @param callback The binder used to communicate the violations.
     */
    @Override
    public synchronized void registerStrictModeCallback(IBinder callback) {
        int callingPid = Binder.getCallingPid();
    public void registerStrictModeCallback(IBinder callback) {
        final int callingPid = Binder.getCallingPid();
        synchronized (mStrictModeCallbacks) {
            mStrictModeCallbacks.put(callingPid,
                    IUnsafeIntentStrictModeCallback.Stub.asInterface(callback));
            try {
                callback.linkToDeath(() -> {
                synchronized (ActivityManagerService.this) {
                    synchronized (mStrictModeCallbacks) {
                        mStrictModeCallbacks.remove(callingPid);
                    }
                }, 0);
@@ -9552,6 +9553,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                mStrictModeCallbacks.remove(callingPid);
            }
        }
    }
    // Depending on the policy in effect, there could be a bunch of
    // these in quick succession so we try to batch these together to
@@ -19930,7 +19932,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        public void triggerUnsafeIntentStrictMode(int callingPid, int type, Intent intent) {
            final IUnsafeIntentStrictModeCallback callback;
            final Intent i = intent.cloneFilter();
            synchronized (ActivityManagerService.this) {
            synchronized (mStrictModeCallbacks) {
                callback = mStrictModeCallbacks.get(callingPid);
            }
            if (callback != null) {
@@ -19938,7 +19940,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    try {
                        callback.onUnsafeIntent(type, i);
                    } catch (RemoteException e) {
                        synchronized (ActivityManagerService.this) {
                        synchronized (mStrictModeCallbacks) {
                            mStrictModeCallbacks.remove(callingPid);
                        }
                    }