From b62f959430afa80e616675fe15cec5392e8178de Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Fri, 12 Mar 2010 07:55:23 -0500 Subject: [PATCH] Fix problems with new PowerManager.reboot() implementation. ShutdownThread.reboot() does return so we need to block after calling it to prevent PowerManager.reboot() from returning. Since PowerManager.reboot() can now take significantly longer than before, we now ignore ANRs during shutdown. Change-Id: Ibceeb265ae382567215f6a399108d8be3a7bbc95 Signed-off-by: Mike Lockwood --- .../android/server/PowerManagerService.java | 20 ++++++++----------- .../server/am/ActivityManagerService.java | 3 ++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index fc6bfcd72a90c..d72416d8206be 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -2205,32 +2205,28 @@ class PowerManagerService extends IPowerManager.Stub if (mHandler == null || !ActivityManagerNative.isSystemReady()) { throw new IllegalStateException("Too early to call reboot()"); } - + final String finalReason = reason; Runnable runnable = new Runnable() { public void run() { synchronized (this) { ShutdownThread.reboot(mContext, finalReason, false); - // if we get here we failed - notify(); } } }; - + // ShutdownThread must run on a looper capable of displaying the UI. mHandler.post(runnable); - // block until we reboot or fail. - // throw an exception if we failed to reboot + // PowerManager.reboot() is documented not to return so just wait for the inevitable. synchronized (runnable) { - try { - runnable.wait(); - } catch (InterruptedException e) { + while (true) { + try { + runnable.wait(); + } catch (InterruptedException e) { + } } } - - // if we get here we failed - throw new IllegalStateException("unable to reboot!"); } /** diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index f6289ae3abb61..8866bbd26d8d9 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -4708,7 +4708,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen final void appNotRespondingLocked(ProcessRecord app, HistoryRecord activity, HistoryRecord parent, final String annotation) { - if (app.notResponding || app.crashing) { + // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down. + if (mShuttingDown || app.notResponding || app.crashing) { return; }