am 34c5813e: am 174b7269: Merge change Id886fb28 into eclair

Merge commit '34c5813e488fd4f044e545f177a20f553580ce6a' into eclair-mr2-plus-aosp

* commit '34c5813e488fd4f044e545f177a20f553580ce6a':
  Fix deadlock in WindowManagerService.reenableKeyguard()
This commit is contained in:
Mike Lockwood
2009-11-23 10:45:24 -08:00
committed by Android Git Automerger

View File

@@ -224,20 +224,22 @@ public class WindowManagerService extends IWindowManager.Stub
/** /**
* Condition waited on by {@link #reenableKeyguard} to know the call to * Condition waited on by {@link #reenableKeyguard} to know the call to
* the window policy has finished. * the window policy has finished.
* This is set to true only if mKeyguardTokenWatcher.acquired() has
* actually disabled the keyguard.
*/ */
private boolean mWaitingUntilKeyguardReenabled = false; private boolean mKeyguardDisabled = false;
final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
final TokenWatcher mKeyguardDisabled = new TokenWatcher( new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
new Handler(), "WindowManagerService.mKeyguardDisabled") {
public void acquired() { public void acquired() {
mPolicy.enableKeyguard(false); mPolicy.enableKeyguard(false);
mKeyguardDisabled = true;
} }
public void released() { public void released() {
mPolicy.enableKeyguard(true); mPolicy.enableKeyguard(true);
synchronized (mKeyguardDisabled) { synchronized (mKeyguardTokenWatcher) {
mWaitingUntilKeyguardReenabled = false; mKeyguardDisabled = false;
mKeyguardDisabled.notifyAll(); mKeyguardTokenWatcher.notifyAll();
} }
} }
}; };
@@ -4040,8 +4042,8 @@ public class WindowManagerService extends IWindowManager.Stub
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires DISABLE_KEYGUARD permission"); throw new SecurityException("Requires DISABLE_KEYGUARD permission");
} }
synchronized (mKeyguardDisabled) { synchronized (mKeyguardTokenWatcher) {
mKeyguardDisabled.acquire(token, tag); mKeyguardTokenWatcher.acquire(token, tag);
} }
} }
@@ -4050,16 +4052,20 @@ public class WindowManagerService extends IWindowManager.Stub
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires DISABLE_KEYGUARD permission"); throw new SecurityException("Requires DISABLE_KEYGUARD permission");
} }
synchronized (mKeyguardDisabled) { synchronized (mKeyguardTokenWatcher) {
mKeyguardDisabled.release(token); mKeyguardTokenWatcher.release(token);
if (!mKeyguardDisabled.isAcquired()) { if (!mKeyguardTokenWatcher.isAcquired()) {
// if we are the last one to reenable the keyguard wait until // If we are the last one to reenable the keyguard wait until
// we have actaully finished reenabling until returning // we have actaully finished reenabling until returning.
mWaitingUntilKeyguardReenabled = true; // It is possible that reenableKeyguard() can be called before
while (mWaitingUntilKeyguardReenabled) { // the previous disableKeyguard() is handled, in which case
// neither mKeyguardTokenWatcher.acquired() or released() would
// be called. In that case mKeyguardDisabled will be false here
// and we have nothing to wait for.
while (mKeyguardDisabled) {
try { try {
mKeyguardDisabled.wait(); mKeyguardTokenWatcher.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
@@ -10854,7 +10860,7 @@ public class WindowManagerService extends IWindowManager.Stub
public void monitor() { public void monitor() {
synchronized (mWindowMap) { } synchronized (mWindowMap) { }
synchronized (mKeyguardDisabled) { } synchronized (mKeyguardTokenWatcher) { }
synchronized (mKeyWaiter) { } synchronized (mKeyWaiter) { }
} }