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

Commit f2a4568a authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Fix race conditions in WakeLocks."

parents 28baf6f0 d7350e3a
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);