diff options
author | John Michelau <w14107@motorola.com> | 2013-03-18 18:28:23 -0500 |
---|---|---|
committer | John Michelau <w14107@motorola.com> | 2013-03-19 14:39:33 -0500 |
commit | 116415271b952ab9e842f3850faa1a44cb70bf6a (patch) | |
tree | 1ce5439168e51fe0a28dd9cdd37942a9c77dc7a5 /services | |
parent | ebebb80b4a629756128b5a4fcf483133f01dbfd7 (diff) | |
download | frameworks_base-116415271b952ab9e842f3850faa1a44cb70bf6a.zip frameworks_base-116415271b952ab9e842f3850faa1a44cb70bf6a.tar.gz frameworks_base-116415271b952ab9e842f3850faa1a44cb70bf6a.tar.bz2 |
Fix Watchdog HeartbeatHandler to run on correct thread
The HeartbeatHandler for the System Server Watchdog has been running
on the wrong thread due to a race condition in initialization. It's
designed to run on ServerThread, so that it can catch lockups in the
main looper of the System Server. It has been running on
ActivityManagerThread instead, so it does not detect lockups on the
ServerThread as it should.
ActivityManagerService is calling Watchdog.getInstance() before
ServerThread calls Watchdog.getInstance().init(), so the handler is
being bound to the ActivityManagerThread instead of the ServerThread.
Explicitly bind HeartbeatHandler to ServerThread, so that the Watchdog
catches lockups on this critical thread.
Change-Id: Iccb184ac3adb817feb86ed4ee0e50e443bf74636
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/Watchdog.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/services/java/com/android/server/Watchdog.java b/services/java/com/android/server/Watchdog.java index b2a8ad8..1663106 100644 --- a/services/java/com/android/server/Watchdog.java +++ b/services/java/com/android/server/Watchdog.java @@ -29,6 +29,7 @@ import android.content.IntentFilter; import android.os.BatteryManager; import android.os.Debug; import android.os.Handler; +import android.os.Looper; import android.os.Message; import android.os.Process; import android.os.ServiceManager; @@ -114,6 +115,10 @@ public class Watchdog extends Thread { * Used for scheduling monitor callbacks and checking memory usage. */ final class HeartbeatHandler extends Handler { + HeartbeatHandler(Looper looper) { + super(looper); + } + @Override public void handleMessage(Message msg) { switch (msg.what) { @@ -183,7 +188,9 @@ public class Watchdog extends Thread { private Watchdog() { super("watchdog"); - mHandler = new HeartbeatHandler(); + // Explicitly bind the HeartbeatHandler to run on the ServerThread, so + // that it can't get accidentally bound to another thread. + mHandler = new HeartbeatHandler(Looper.getMainLooper()); } public void init(Context context, BatteryService battery, |