From b5962e73e841455b8e2a4e2d5c0ef0a19d62a803 Mon Sep 17 00:00:00 2001 From: Jake Hamby Date: Wed, 15 Jun 2011 19:17:08 -0700 Subject: [PATCH] Fix race condition in WakeLocks. A previous fix to PowerManager.WakeLock introduced a new bug. When a reference counted wakelock (such as SMSDispatcher) is acquired multiple times in quick succession with a timeout, the first timeout would remove the second callback from the handler, decrement the reference count, but then the wakelock never gets released because the second callback has been removed. Bug: 4535237 Change-Id: I4f1240189bf3ed3396c86200c687282597b107d6 --- core/java/android/os/PowerManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index a17983a0fd37a..21373ec89715d 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -313,8 +313,8 @@ public class PowerManager */ public void release(int flags) { synchronized (mToken) { - mHandler.removeCallbacks(mReleaser); if (!mRefCounted || --mCount == 0) { + mHandler.removeCallbacks(mReleaser); try { mService.releaseWakeLock(mToken, flags); } catch (RemoteException e) {