blob: dfffd2ec37a52a395559e34becfd4e728656819e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Dianne Hackborn5b88a2f2013-05-03 16:25:11 -070019import android.app.IActivityController;
20import android.os.Binder;
21import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import com.android.server.am.ActivityManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070023import com.android.server.power.PowerManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25import android.app.AlarmManager;
26import android.app.PendingIntent;
27import android.content.BroadcastReceiver;
28import android.content.ContentResolver;
29import android.content.Context;
30import android.content.Intent;
31import android.content.IntentFilter;
Jeff Browna4d82042012-10-02 19:11:19 -070032import android.os.BatteryManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.Debug;
34import android.os.Handler;
John Michelau11641522013-03-18 18:28:23 -050035import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.Process;
Suchi Amalapurapu6ffce2e2010-03-08 14:48:40 -080037import android.os.ServiceManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.SystemClock;
39import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.util.EventLog;
Dan Egnor9bdc94b2010-03-04 14:20:31 -080041import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080042import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Dan Egnor9bdc94b2010-03-04 14:20:31 -080044import java.io.File;
Colin Cross5df1d872012-11-29 11:42:11 -080045import java.io.FileWriter;
46import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.util.ArrayList;
48import java.util.Calendar;
49
50/** This class calls its monitor every minute. Killing this process if they don't return **/
51public class Watchdog extends Thread {
52 static final String TAG = "Watchdog";
Joe Onorato43a17652011-04-06 19:22:23 -070053 static final boolean localLOGV = false || false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
55 // Set this to true to use debug default values.
56 static final boolean DB = false;
57
Christopher Tateecaa7b42010-06-04 14:55:02 -070058 // Set this to true to have the watchdog record kernel thread stacks when it fires
59 static final boolean RECORD_KERNEL_THREADS = true;
60
Dianne Hackbornf6438b12013-05-09 18:53:48 -070061 static final int TIME_TO_WAIT = DB ? 5*1000 : 30*1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Igor Murashkin44d04aa2013-10-23 10:56:02 -070063 // Which native processes to dump into dropbox's stack traces
64 public static final String[] NATIVE_STACKS_OF_INTEREST = new String[] {
Dianne Hackbornf72467a2012-06-08 17:23:59 -070065 "/system/bin/mediaserver",
66 "/system/bin/sdcard",
67 "/system/bin/surfaceflinger"
68 };
69
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 static Watchdog sWatchdog;
71
72 /* This handler will be used to post message back onto the main thread */
Dianne Hackborn8d044e82013-04-30 17:24:15 -070073 final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<HandlerChecker>();
74 final HandlerChecker mMonitorChecker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 ContentResolver mResolver;
76 BatteryService mBattery;
77 PowerManagerService mPower;
78 AlarmManagerService mAlarm;
79 ActivityManagerService mActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 int mPhonePid;
Dianne Hackborn5b88a2f2013-05-03 16:25:11 -070082 IActivityController mController;
Dianne Hackborn8bd64df2013-05-06 16:07:26 -070083 boolean mAllowRestart = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 /**
Dianne Hackborn8d044e82013-04-30 17:24:15 -070086 * Used for checking status of handle threads and scheduling monitor callbacks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 */
Dianne Hackborn8d044e82013-04-30 17:24:15 -070088 public final class HandlerChecker implements Runnable {
89 private final Handler mHandler;
90 private final String mName;
91 private final ArrayList<Monitor> mMonitors = new ArrayList<Monitor>();
Dianne Hackborn8d044e82013-04-30 17:24:15 -070092 private boolean mCompleted;
93 private Monitor mCurrentMonitor;
94
Dianne Hackbornf6438b12013-05-09 18:53:48 -070095 HandlerChecker(Handler handler, String name) {
Dianne Hackborn8d044e82013-04-30 17:24:15 -070096 mHandler = handler;
97 mName = name;
Dianne Hackborn8d044e82013-04-30 17:24:15 -070098 }
99
100 public void addMonitor(Monitor monitor) {
101 mMonitors.add(monitor);
102 }
103
104 public void scheduleCheckLocked() {
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700105 if (mMonitors.size() == 0 && mHandler.getLooper().isIdling()) {
Dianne Hackbornefa92b22013-05-03 14:11:43 -0700106 // If the target looper is or just recently was idling, then
107 // there is no reason to enqueue our checker on it since that
108 // is as good as it not being deadlocked. This avoid having
109 // to do a context switch to check the thread. Note that we
110 // only do this if mCheckReboot is false and we have no
111 // monitors, since those would need to be executed at this point.
112 mCompleted = true;
113 return;
114 }
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700115 mCompleted = false;
116 mCurrentMonitor = null;
117 mHandler.postAtFrontOfQueue(this);
118 }
119
120 public boolean isCompletedLocked() {
121 return mCompleted;
122 }
123
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700124 public Thread getThread() {
125 return mHandler.getLooper().getThread();
126 }
127
128 public String getName() {
129 return mName;
130 }
131
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700132 public String describeBlockedStateLocked() {
Jeff Brown7dd2d192013-09-06 15:05:23 -0700133 if (mCurrentMonitor == null) {
134 return "Blocked in handler on " + mName + " (" + getThread().getName() + ")";
135 } else {
136 return "Blocked in monitor " + mCurrentMonitor.getClass().getName()
137 + " on " + mName + " (" + getThread().getName() + ")";
138 }
John Michelau11641522013-03-18 18:28:23 -0500139 }
140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 @Override
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700142 public void run() {
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700143 final int size = mMonitors.size();
144 for (int i = 0 ; i < size ; i++) {
145 synchronized (Watchdog.this) {
146 mCurrentMonitor = mMonitors.get(i);
147 }
148 mCurrentMonitor.monitor();
149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700151 synchronized (Watchdog.this) {
152 mCompleted = true;
153 mCurrentMonitor = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 }
155 }
156 }
157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 final class RebootRequestReceiver extends BroadcastReceiver {
159 @Override
160 public void onReceive(Context c, Intent intent) {
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700161 if (intent.getIntExtra("nowait", 0) != 0) {
162 rebootSystem("Received ACTION_REBOOT broadcast");
163 return;
164 }
165 Slog.w(TAG, "Unsupported ACTION_REBOOT broadcast: " + intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 }
167 }
168
169 public interface Monitor {
170 void monitor();
171 }
172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 public static Watchdog getInstance() {
174 if (sWatchdog == null) {
175 sWatchdog = new Watchdog();
176 }
177
178 return sWatchdog;
179 }
180
181 private Watchdog() {
182 super("watchdog");
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700183 // Initialize handler checkers for each common thread we want to check. Note
184 // that we are not currently checking the background thread, since it can
185 // potentially hold longer running operations with no guarantees about the timeliness
186 // of operations there.
187
188 // The shared foreground thread is the main checker. It is where we
189 // will also dispatch monitor checks and do other work.
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700190 mMonitorChecker = new HandlerChecker(FgThread.getHandler(), "foreground thread");
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700191 mHandlerCheckers.add(mMonitorChecker);
192 // Add checker for main thread. We only do a quick check since there
193 // can be UI running on the thread.
194 mHandlerCheckers.add(new HandlerChecker(new Handler(Looper.getMainLooper()),
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700195 "main thread"));
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700196 // Add checker for shared UI thread.
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700197 mHandlerCheckers.add(new HandlerChecker(UiThread.getHandler(), "ui thread"));
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700198 // And also check IO thread.
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700199 mHandlerCheckers.add(new HandlerChecker(IoThread.getHandler(), "i/o thread"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
201
202 public void init(Context context, BatteryService battery,
203 PowerManagerService power, AlarmManagerService alarm,
204 ActivityManagerService activity) {
205 mResolver = context.getContentResolver();
206 mBattery = battery;
207 mPower = power;
208 mAlarm = alarm;
209 mActivity = activity;
210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 context.registerReceiver(new RebootRequestReceiver(),
212 new IntentFilter(Intent.ACTION_REBOOT),
213 android.Manifest.permission.REBOOT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
215
Christopher Tatec27181c2010-06-30 14:41:09 -0700216 public void processStarted(String name, int pid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 synchronized (this) {
218 if ("com.android.phone".equals(name)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 mPhonePid = pid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 }
221 }
222 }
223
Dianne Hackborn5b88a2f2013-05-03 16:25:11 -0700224 public void setActivityController(IActivityController controller) {
225 synchronized (this) {
226 mController = controller;
227 }
228 }
229
Dianne Hackborn8bd64df2013-05-06 16:07:26 -0700230 public void setAllowRestart(boolean allowRestart) {
231 synchronized (this) {
232 mAllowRestart = allowRestart;
233 }
234 }
235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 public void addMonitor(Monitor monitor) {
237 synchronized (this) {
238 if (isAlive()) {
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700239 throw new RuntimeException("Monitors can't be added once the Watchdog is running");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 }
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700241 mMonitorChecker.addMonitor(monitor);
242 }
243 }
244
245 public void addThread(Handler thread, String name) {
246 synchronized (this) {
247 if (isAlive()) {
248 throw new RuntimeException("Threads can't be added once the Watchdog is running");
249 }
Dianne Hackbornf6438b12013-05-09 18:53:48 -0700250 mHandlerCheckers.add(new HandlerChecker(thread, name));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 }
252 }
253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 /**
255 * Perform a full reboot of the system.
256 */
257 void rebootSystem(String reason) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800258 Slog.i(TAG, "Rebooting system because: " + reason);
Suchi Amalapurapu6ffce2e2010-03-08 14:48:40 -0800259 PowerManagerService pms = (PowerManagerService) ServiceManager.getService("power");
Dianne Hackbornc428aae2012-10-03 16:38:22 -0700260 pms.reboot(false, reason, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 }
262
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700263 private boolean haveAllCheckersCompletedLocked() {
264 for (int i=0; i<mHandlerCheckers.size(); i++) {
265 HandlerChecker hc = mHandlerCheckers.get(i);
266 if (!hc.isCompletedLocked()) {
267 return false;
268 }
269 }
270 return true;
271 }
272
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700273 private ArrayList<HandlerChecker> getBlockedCheckersLocked() {
274 ArrayList<HandlerChecker> checkers = new ArrayList<HandlerChecker>();
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700275 for (int i=0; i<mHandlerCheckers.size(); i++) {
276 HandlerChecker hc = mHandlerCheckers.get(i);
277 if (!hc.isCompletedLocked()) {
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700278 checkers.add(hc);
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700279 }
280 }
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700281 return checkers;
282 }
283
284 private String describeCheckersLocked(ArrayList<HandlerChecker> checkers) {
285 StringBuilder builder = new StringBuilder(128);
286 for (int i=0; i<checkers.size(); i++) {
287 if (builder.length() > 0) {
288 builder.append(", ");
289 }
290 builder.append(checkers.get(i).describeBlockedStateLocked());
291 }
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700292 return builder.toString();
293 }
294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 @Override
296 public void run() {
Christopher Tate6ee412d2010-05-28 12:01:56 -0700297 boolean waitedHalf = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 while (true) {
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700299 final ArrayList<HandlerChecker> blockedCheckers;
Jeff Brown7dd2d192013-09-06 15:05:23 -0700300 final String subject;
Dianne Hackborn8bd64df2013-05-06 16:07:26 -0700301 final boolean allowRestart;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 synchronized (this) {
303 long timeout = TIME_TO_WAIT;
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700304 if (!waitedHalf) {
305 // If we are not at the half-point of waiting, perform a
306 // new set of checks. Otherwise we are still waiting for a previous set.
307 for (int i=0; i<mHandlerCheckers.size(); i++) {
308 HandlerChecker hc = mHandlerCheckers.get(i);
309 hc.scheduleCheckLocked();
310 }
311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312
313 // NOTE: We use uptimeMillis() here because we do not want to increment the time we
314 // wait while asleep. If the device is asleep then the thing that we are waiting
Christopher Tate6ee412d2010-05-28 12:01:56 -0700315 // to timeout on is asleep as well and won't have a chance to run, causing a false
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 // positive on when to kill things.
317 long start = SystemClock.uptimeMillis();
Michael Wright8fa56f62013-04-01 16:36:05 -0700318 while (timeout > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 try {
Michael Wright8fa56f62013-04-01 16:36:05 -0700320 wait(timeout);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 } catch (InterruptedException e) {
Dan Egnor9bdc94b2010-03-04 14:20:31 -0800322 Log.wtf(TAG, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 }
324 timeout = TIME_TO_WAIT - (SystemClock.uptimeMillis() - start);
Dan Egnor9bdc94b2010-03-04 14:20:31 -0800325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700327 if (haveAllCheckersCompletedLocked()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 // The monitors have returned.
Christopher Tate6ee412d2010-05-28 12:01:56 -0700329 waitedHalf = false;
330 continue;
331 }
332
333 if (!waitedHalf) {
334 // We've waited half the deadlock-detection interval. Pull a stack
335 // trace and wait another half.
Dianne Hackborn6b1afeb2010-08-31 15:40:21 -0700336 ArrayList<Integer> pids = new ArrayList<Integer>();
Christopher Tate6ee412d2010-05-28 12:01:56 -0700337 pids.add(Process.myPid());
Dianne Hackbornf72467a2012-06-08 17:23:59 -0700338 ActivityManagerService.dumpStackTraces(true, pids, null, null,
339 NATIVE_STACKS_OF_INTEREST);
Christopher Tate6ee412d2010-05-28 12:01:56 -0700340 waitedHalf = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 continue;
342 }
Michael Wright8fa56f62013-04-01 16:36:05 -0700343
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700344 blockedCheckers = getBlockedCheckersLocked();
Jeff Brown7dd2d192013-09-06 15:05:23 -0700345 subject = describeCheckersLocked(blockedCheckers);
Dianne Hackborn8bd64df2013-05-06 16:07:26 -0700346 allowRestart = mAllowRestart;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 }
348
349 // If we got here, that means that the system is most likely hung.
Jean-Baptiste Queru784827b2012-09-04 13:35:12 -0700350 // First collect stack traces from all threads of the system process.
351 // Then kill this process so that the system will restart.
Jeff Brown7dd2d192013-09-06 15:05:23 -0700352 EventLog.writeEvent(EventLogTags.WATCHDOG, subject);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353
Dianne Hackborn6b1afeb2010-08-31 15:40:21 -0700354 ArrayList<Integer> pids = new ArrayList<Integer>();
Dan Egnor9bdc94b2010-03-04 14:20:31 -0800355 pids.add(Process.myPid());
Dan Egnor4bded072010-03-11 22:00:47 -0800356 if (mPhonePid > 0) pids.add(mPhonePid);
Christopher Tate6ee412d2010-05-28 12:01:56 -0700357 // Pass !waitedHalf so that just in case we somehow wind up here without having
358 // dumped the halfway stacks, we properly re-initialize the trace file.
Brad Fitzpatrick9765c722011-01-14 11:28:22 -0800359 final File stack = ActivityManagerService.dumpStackTraces(
Dianne Hackbornf72467a2012-06-08 17:23:59 -0700360 !waitedHalf, pids, null, null, NATIVE_STACKS_OF_INTEREST);
Dan Egnor4bded072010-03-11 22:00:47 -0800361
362 // Give some extra time to make sure the stack traces get written.
363 // The system's been hanging for a minute, another second or two won't hurt much.
364 SystemClock.sleep(2000);
365
Christopher Tateecaa7b42010-06-04 14:55:02 -0700366 // Pull our own kernel thread stacks as well if we're configured for that
367 if (RECORD_KERNEL_THREADS) {
368 dumpKernelStackTraces();
369 }
370
Colin Cross5df1d872012-11-29 11:42:11 -0800371 // Trigger the kernel to dump all blocked threads to the kernel log
372 try {
373 FileWriter sysrq_trigger = new FileWriter("/proc/sysrq-trigger");
374 sysrq_trigger.write("w");
375 sysrq_trigger.close();
376 } catch (IOException e) {
377 Slog.e(TAG, "Failed to write to /proc/sysrq-trigger");
378 Slog.e(TAG, e.getMessage());
379 }
380
Brad Fitzpatrick9765c722011-01-14 11:28:22 -0800381 // Try to add the error to the dropbox, but assuming that the ActivityManager
382 // itself may be deadlocked. (which has happened, causing this statement to
383 // deadlock and the watchdog as a whole to be ineffective)
384 Thread dropboxThread = new Thread("watchdogWriteToDropbox") {
385 public void run() {
386 mActivity.addErrorToDropBox(
Jeff Sharkeya353d262011-10-28 11:12:06 -0700387 "watchdog", null, "system_server", null, null,
Jeff Brown7dd2d192013-09-06 15:05:23 -0700388 subject, null, stack, null);
Brad Fitzpatrick9765c722011-01-14 11:28:22 -0800389 }
390 };
391 dropboxThread.start();
392 try {
393 dropboxThread.join(2000); // wait up to 2 seconds for it to return.
394 } catch (InterruptedException ignored) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395
Dianne Hackborn5b88a2f2013-05-03 16:25:11 -0700396 IActivityController controller;
397 synchronized (this) {
398 controller = mController;
399 }
400 if (controller != null) {
401 Slog.i(TAG, "Reporting stuck state to activity controller");
402 try {
403 Binder.setDumpDisabled("Service dumps disabled due to hung system process.");
404 // 1 = keep waiting, -1 = kill system
Jeff Brown7dd2d192013-09-06 15:05:23 -0700405 int res = controller.systemNotResponding(subject);
Dianne Hackborn5b88a2f2013-05-03 16:25:11 -0700406 if (res >= 0) {
407 Slog.i(TAG, "Activity controller requested to coninue to wait");
408 waitedHalf = false;
409 continue;
410 }
411 } catch (RemoteException e) {
412 }
413 }
414
Jean-Baptiste Queru784827b2012-09-04 13:35:12 -0700415 // Only kill the process if the debugger is not attached.
Dianne Hackborn8bd64df2013-05-06 16:07:26 -0700416 if (Debug.isDebuggerConnected()) {
417 Slog.w(TAG, "Debugger connected: Watchdog is *not* killing the system process");
418 } else if (!allowRestart) {
419 Slog.w(TAG, "Restart not allowed: Watchdog is *not* killing the system process");
420 } else {
Jeff Brown7dd2d192013-09-06 15:05:23 -0700421 Slog.w(TAG, "*** WATCHDOG KILLING SYSTEM PROCESS: " + subject);
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700422 for (int i=0; i<blockedCheckers.size(); i++) {
423 Slog.w(TAG, blockedCheckers.get(i).getName() + " stack trace:");
424 StackTraceElement[] stackTrace
425 = blockedCheckers.get(i).getThread().getStackTrace();
426 for (StackTraceElement element: stackTrace) {
427 Slog.w(TAG, " at " + element);
428 }
Michael Wright56a6c662013-04-30 20:13:07 -0700429 }
Dianne Hackbornfa012b32013-05-10 15:23:28 -0700430 Slog.w(TAG, "*** GOODBYE!");
Jean-Baptiste Queru784827b2012-09-04 13:35:12 -0700431 Process.killProcess(Process.myPid());
432 System.exit(10);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 }
Christopher Tate6ee412d2010-05-28 12:01:56 -0700434
435 waitedHalf = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437 }
Christopher Tateecaa7b42010-06-04 14:55:02 -0700438
439 private File dumpKernelStackTraces() {
440 String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
441 if (tracesPath == null || tracesPath.length() == 0) {
442 return null;
443 }
444
445 native_dumpKernelStacks(tracesPath);
446 return new File(tracesPath);
447 }
448
449 private native void native_dumpKernelStacks(String tracesPath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450}