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

Commit d7350e3a authored by Joe Onorato's avatar Joe Onorato
Browse files

Fix race conditions in WakeLocks.

Bug: 3439332
Change-Id: I70c583e6a73960df8faad69675947b87642c6228
parent 7ba631f8
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -261,13 +261,7 @@ public class PowerManager
        public void acquire()
        {
            synchronized (mToken) {
                if (!mRefCounted || mCount++ == 0) {
                    try {
                        mService.acquireWakeLock(mFlags, mToken, mTag, mWorkSource);
                    } catch (RemoteException e) {
                    }
                    mHeld = true;
                }
                acquireLocked();
            }
        }

@@ -278,10 +272,22 @@ public class PowerManager
         * @param timeout Release the lock after the give timeout in milliseconds.
         */
        public void acquire(long timeout) {
            acquire();
            synchronized (mToken) {
                acquireLocked();
                mHandler.postDelayed(mReleaser, timeout);
            }
        }
        
        private void acquireLocked() {
            if (!mRefCounted || mCount++ == 0) {
                mHandler.removeCallbacks(mReleaser);
                try {
                    mService.acquireWakeLock(mFlags, mToken, mTag, mWorkSource);
                } catch (RemoteException e) {
                }
                mHeld = true;
            }
        }

        /**
         * Release your claim to the CPU or screen being on.
@@ -290,8 +296,7 @@ public class PowerManager
         * It may turn off shortly after you release it, or it may not if there
         * are other wake locks held.
         */
        public void release()
        {
        public void release() {
            release(0);
        }

@@ -306,9 +311,9 @@ public class PowerManager
         *
         * {@hide}
         */
        public void release(int flags)
        {
        public void release(int flags) {
            synchronized (mToken) {
                mHandler.removeCallbacks(mReleaser);
                if (!mRefCounted || --mCount == 0) {
                    try {
                        mService.releaseWakeLock(mToken, flags);