From 64c820d3d4510b4953a8e888eb792a367b52eaa0 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 21 Mar 2017 12:36:55 +0000 Subject: [PATCH] Change the thread for handling shutdown of PowerManagerService. Symptom: Watchdog due to blocked handler PowerManagerService during shutdown sequence. Root cause: While creating the dialogue for shutdown, HashMap object is accessed by createView() at LayoutInflater. This object is not excluded at multi threads. When this issue is occurred, multiple threads accesses this object. As the result, invalid state is generated inside HashMap object. And circulating reference is occurred at getEntry method. So system cannot get out of "for" loop. It blockes the processing of PowerManagerService thread and causes watchdog. That thing is happening. Solution: Change the thread for handling shutdown from "PowerManagerService" to "android.ui" thread. As the result, exclusive control is not needed. Bug: 35791029 Test: Manual Change-Id: Icbc12fb2706fb3c7e859f53bbb4c65f488850ce6 --- .../java/com/android/server/power/PowerManagerService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index a8d19e94dea56..61c1e38034e5e 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -87,6 +87,7 @@ import com.android.server.LockGuard; import com.android.server.RescueParty; import com.android.server.ServiceThread; import com.android.server.SystemService; +import com.android.server.UiThread; import com.android.server.Watchdog; import com.android.server.am.BatteryStatsService; import com.android.server.lights.Light; @@ -2728,9 +2729,9 @@ public final class PowerManagerService extends SystemService }; // ShutdownThread must run on a looper capable of displaying the UI. - Message msg = Message.obtain(mHandler, runnable); + Message msg = Message.obtain(UiThread.getHandler(), runnable); msg.setAsynchronous(true); - mHandler.sendMessage(msg); + UiThread.getHandler().sendMessage(msg); // PowerManager.reboot() is documented not to return so just wait for the inevitable. if (wait) {