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

Commit 99e5e6e7 authored by Christopher Lais's avatar Christopher Lais Committed by Steve Kondik
Browse files

Avoid deadlocks updating WakeLock status in AM



The ActivityManagerService can acquire or release wake locks with the
ActivityManagerService locked.  Now that the PowerManagerService
notifies it of wakelocks, this can cause a deadlock.

This patch removes the immediate oomAdj update, to avoid needing to
lock ActivityManagerService while being notified of WakeLock status.

This may cause delays in updating the oomAdj value, but should be
limited to leaving an app marked foreground longer than it should be.

Signed-off-by: default avatarChristopher Lais <chris+android@zenthought.org>
parent 9e0e0f11
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -4260,29 +4260,26 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
    public void noteStartWakeLock(int uid, String tag, int type) {
        Integer iuid = Integer.valueOf(uid);
        synchronized (this) {
        synchronized (mUidWakeLocks) {
            Integer count = mUidWakeLocks.get(iuid);
            if (count == null) {
                count = new Integer(1);
                mUidWakeLocks.put(iuid, count);
                updateOomAdjLocked();
            } else {
                ++count;
                mUidWakeLocks.put(iuid, count);
            }
            mUidWakeLocks.put(iuid, count);
        }
    }
    public void noteStopWakeLock(int uid, String tag, int type) {
        Integer iuid = Integer.valueOf(uid);
        synchronized (this) {
        synchronized (mUidWakeLocks) {
            Integer count = mUidWakeLocks.get(iuid);
            if (count != null) {
                if (--count > 0) {
                    mUidWakeLocks.put(iuid, count);
                } else {
                    mUidWakeLocks.remove(iuid);
                    updateOomAdjLocked();
                }
            } else {
                Log.e(TAG, "Stopping stopped wake lock for uid "