blob: a634b577f506bd749438a95adcde2cdae8e0d731 [file] [log] [blame]
Adrian Roos20d7df32016-01-12 18:59:43 +01001/*
2 * Copyright (C) 2016 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.am;
18
Wale Ogunwale64258362018-10-16 15:13:37 -070019import static android.app.ActivityTaskManager.INVALID_TASK_ID;
Wale Ogunwale59507092018-10-29 09:00:30 -070020import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
Adrian Roos86cb6392018-12-13 16:42:43 +010021
Makoto Onukie276b442018-08-30 09:38:44 -070022import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
23import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
24import static com.android.server.am.ActivityManagerService.MY_PID;
25import static com.android.server.am.ActivityManagerService.SYSTEM_DEBUGGABLE;
Wale Ogunwale59507092018-10-29 09:00:30 -070026import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE;
27import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
Adrian Roos20d7df32016-01-12 18:59:43 +010028
Adrian Roos20d7df32016-01-12 18:59:43 +010029import android.app.ActivityManager;
30import android.app.ActivityOptions;
Adrian Roos20d7df32016-01-12 18:59:43 +010031import android.app.ApplicationErrorReport;
32import android.app.Dialog;
33import android.content.ActivityNotFoundException;
34import android.content.Context;
35import android.content.Intent;
36import android.content.pm.ApplicationInfo;
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080037import android.net.Uri;
Adrian Roos20d7df32016-01-12 18:59:43 +010038import android.os.Binder;
Adrian Roos20d7df32016-01-12 18:59:43 +010039import android.os.Message;
40import android.os.Process;
Adrian Roos20d7df32016-01-12 18:59:43 +010041import android.os.SystemClock;
42import android.os.SystemProperties;
43import android.os.UserHandle;
44import android.provider.Settings;
45import android.util.ArrayMap;
46import android.util.ArraySet;
47import android.util.EventLog;
Adrian Roos20d7df32016-01-12 18:59:43 +010048import android.util.Slog;
49import android.util.SparseArray;
50import android.util.TimeUtils;
Yi Jin148d7f42017-11-28 14:23:56 -080051import android.util.proto.ProtoOutputStream;
Adrian Roos20d7df32016-01-12 18:59:43 +010052
Makoto Onukie276b442018-08-30 09:38:44 -070053import com.android.internal.app.ProcessMap;
54import com.android.internal.logging.MetricsLogger;
55import com.android.internal.logging.nano.MetricsProto;
Zimuzo6efba542018-11-29 12:47:58 +000056import com.android.server.PackageWatchdog;
Makoto Onukie276b442018-08-30 09:38:44 -070057import com.android.server.RescueParty;
Wale Ogunwale59507092018-10-29 09:00:30 -070058import com.android.server.wm.WindowProcessController;
Makoto Onukie276b442018-08-30 09:38:44 -070059
Adrian Roos20d7df32016-01-12 18:59:43 +010060import java.io.FileDescriptor;
61import java.io.PrintWriter;
Adrian Roos20d7df32016-01-12 18:59:43 +010062import java.util.Collections;
Adrian Roos20d7df32016-01-12 18:59:43 +010063
Adrian Roos20d7df32016-01-12 18:59:43 +010064/**
65 * Controls error conditions in applications.
66 */
67class AppErrors {
68
69 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppErrors" : TAG_AM;
70
71 private final ActivityManagerService mService;
72 private final Context mContext;
Zimuzo6efba542018-11-29 12:47:58 +000073 private final PackageWatchdog mPackageWatchdog;
Adrian Roos20d7df32016-01-12 18:59:43 +010074
75 private ArraySet<String> mAppsNotReportingCrashes;
76
77 /**
78 * The last time that various processes have crashed since they were last explicitly started.
79 */
80 private final ProcessMap<Long> mProcessCrashTimes = new ProcessMap<>();
81
82 /**
83 * The last time that various processes have crashed (not reset even when explicitly started).
84 */
85 private final ProcessMap<Long> mProcessCrashTimesPersistent = new ProcessMap<>();
86
87 /**
88 * Set of applications that we consider to be bad, and will reject
89 * incoming broadcasts from (which the user has no control over).
90 * Processes are added to this set when they have crashed twice within
91 * a minimum amount of time; they are removed from it when they are
92 * later restarted (hopefully due to some user action). The value is the
93 * time it was added to the list.
94 */
95 private final ProcessMap<BadProcessInfo> mBadProcesses = new ProcessMap<>();
96
97
Zimuzo6efba542018-11-29 12:47:58 +000098 AppErrors(Context context, ActivityManagerService service, PackageWatchdog watchdog) {
Adam Lesinskia82b6262017-03-21 16:56:17 -070099 context.assertRuntimeOverlayThemable();
Adrian Roos20d7df32016-01-12 18:59:43 +0100100 mService = service;
101 mContext = context;
Zimuzo6efba542018-11-29 12:47:58 +0000102 mPackageWatchdog = watchdog;
Adrian Roos20d7df32016-01-12 18:59:43 +0100103 }
104
Yi Jin148d7f42017-11-28 14:23:56 -0800105 void writeToProto(ProtoOutputStream proto, long fieldId, String dumpPackage) {
106 if (mProcessCrashTimes.getMap().isEmpty() && mBadProcesses.getMap().isEmpty()) {
107 return;
108 }
109
110 final long token = proto.start(fieldId);
111 final long now = SystemClock.uptimeMillis();
112 proto.write(AppErrorsProto.NOW_UPTIME_MS, now);
113
114 if (!mProcessCrashTimes.getMap().isEmpty()) {
115 final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
116 final int procCount = pmap.size();
117 for (int ip = 0; ip < procCount; ip++) {
118 final long ctoken = proto.start(AppErrorsProto.PROCESS_CRASH_TIMES);
119 final String pname = pmap.keyAt(ip);
120 final SparseArray<Long> uids = pmap.valueAt(ip);
121 final int uidCount = uids.size();
122
123 proto.write(AppErrorsProto.ProcessCrashTime.PROCESS_NAME, pname);
124 for (int i = 0; i < uidCount; i++) {
125 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400126 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Yi Jin148d7f42017-11-28 14:23:56 -0800127 if (dumpPackage != null && (r == null || !r.pkgList.containsKey(dumpPackage))) {
128 continue;
129 }
130 final long etoken = proto.start(AppErrorsProto.ProcessCrashTime.ENTRIES);
131 proto.write(AppErrorsProto.ProcessCrashTime.Entry.UID, puid);
132 proto.write(AppErrorsProto.ProcessCrashTime.Entry.LAST_CRASHED_AT_MS,
133 uids.valueAt(i));
134 proto.end(etoken);
135 }
136 proto.end(ctoken);
137 }
138
139 }
140
141 if (!mBadProcesses.getMap().isEmpty()) {
142 final ArrayMap<String, SparseArray<BadProcessInfo>> pmap = mBadProcesses.getMap();
143 final int processCount = pmap.size();
144 for (int ip = 0; ip < processCount; ip++) {
145 final long btoken = proto.start(AppErrorsProto.BAD_PROCESSES);
146 final String pname = pmap.keyAt(ip);
147 final SparseArray<BadProcessInfo> uids = pmap.valueAt(ip);
148 final int uidCount = uids.size();
149
150 proto.write(AppErrorsProto.BadProcess.PROCESS_NAME, pname);
151 for (int i = 0; i < uidCount; i++) {
152 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400153 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Yi Jin148d7f42017-11-28 14:23:56 -0800154 if (dumpPackage != null && (r == null
155 || !r.pkgList.containsKey(dumpPackage))) {
156 continue;
157 }
158 final BadProcessInfo info = uids.valueAt(i);
159 final long etoken = proto.start(AppErrorsProto.BadProcess.ENTRIES);
160 proto.write(AppErrorsProto.BadProcess.Entry.UID, puid);
161 proto.write(AppErrorsProto.BadProcess.Entry.CRASHED_AT_MS, info.time);
162 proto.write(AppErrorsProto.BadProcess.Entry.SHORT_MSG, info.shortMsg);
163 proto.write(AppErrorsProto.BadProcess.Entry.LONG_MSG, info.longMsg);
164 proto.write(AppErrorsProto.BadProcess.Entry.STACK, info.stack);
165 proto.end(etoken);
166 }
167 proto.end(btoken);
168 }
169 }
170
171 proto.end(token);
172 }
173
174 boolean dumpLocked(FileDescriptor fd, PrintWriter pw, boolean needSep, String dumpPackage) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100175 if (!mProcessCrashTimes.getMap().isEmpty()) {
176 boolean printed = false;
177 final long now = SystemClock.uptimeMillis();
178 final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
179 final int processCount = pmap.size();
180 for (int ip = 0; ip < processCount; ip++) {
181 final String pname = pmap.keyAt(ip);
182 final SparseArray<Long> uids = pmap.valueAt(ip);
183 final int uidCount = uids.size();
184 for (int i = 0; i < uidCount; i++) {
185 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400186 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Adrian Roos20d7df32016-01-12 18:59:43 +0100187 if (dumpPackage != null && (r == null
188 || !r.pkgList.containsKey(dumpPackage))) {
189 continue;
190 }
191 if (!printed) {
192 if (needSep) pw.println();
193 needSep = true;
194 pw.println(" Time since processes crashed:");
195 printed = true;
196 }
197 pw.print(" Process "); pw.print(pname);
198 pw.print(" uid "); pw.print(puid);
199 pw.print(": last crashed ");
200 TimeUtils.formatDuration(now-uids.valueAt(i), pw);
201 pw.println(" ago");
202 }
203 }
204 }
205
206 if (!mBadProcesses.getMap().isEmpty()) {
207 boolean printed = false;
208 final ArrayMap<String, SparseArray<BadProcessInfo>> pmap = mBadProcesses.getMap();
209 final int processCount = pmap.size();
210 for (int ip = 0; ip < processCount; ip++) {
211 final String pname = pmap.keyAt(ip);
212 final SparseArray<BadProcessInfo> uids = pmap.valueAt(ip);
213 final int uidCount = uids.size();
214 for (int i = 0; i < uidCount; i++) {
215 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400216 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Adrian Roos20d7df32016-01-12 18:59:43 +0100217 if (dumpPackage != null && (r == null
218 || !r.pkgList.containsKey(dumpPackage))) {
219 continue;
220 }
221 if (!printed) {
222 if (needSep) pw.println();
223 needSep = true;
224 pw.println(" Bad processes:");
225 printed = true;
226 }
227 final BadProcessInfo info = uids.valueAt(i);
228 pw.print(" Bad process "); pw.print(pname);
229 pw.print(" uid "); pw.print(puid);
230 pw.print(": crashed at time "); pw.println(info.time);
231 if (info.shortMsg != null) {
232 pw.print(" Short msg: "); pw.println(info.shortMsg);
233 }
234 if (info.longMsg != null) {
235 pw.print(" Long msg: "); pw.println(info.longMsg);
236 }
237 if (info.stack != null) {
238 pw.println(" Stack:");
239 int lastPos = 0;
240 for (int pos = 0; pos < info.stack.length(); pos++) {
241 if (info.stack.charAt(pos) == '\n') {
242 pw.print(" ");
243 pw.write(info.stack, lastPos, pos-lastPos);
244 pw.println();
245 lastPos = pos+1;
246 }
247 }
248 if (lastPos < info.stack.length()) {
249 pw.print(" ");
250 pw.write(info.stack, lastPos, info.stack.length()-lastPos);
251 pw.println();
252 }
253 }
254 }
255 }
256 }
257 return needSep;
258 }
259
260 boolean isBadProcessLocked(ApplicationInfo info) {
261 return mBadProcesses.get(info.processName, info.uid) != null;
262 }
263
264 void clearBadProcessLocked(ApplicationInfo info) {
265 mBadProcesses.remove(info.processName, info.uid);
266 }
267
268 void resetProcessCrashTimeLocked(ApplicationInfo info) {
269 mProcessCrashTimes.remove(info.processName, info.uid);
270 }
271
272 void resetProcessCrashTimeLocked(boolean resetEntireUser, int appId, int userId) {
273 final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
274 for (int ip = pmap.size() - 1; ip >= 0; ip--) {
275 SparseArray<Long> ba = pmap.valueAt(ip);
276 for (int i = ba.size() - 1; i >= 0; i--) {
277 boolean remove = false;
278 final int entUid = ba.keyAt(i);
279 if (!resetEntireUser) {
280 if (userId == UserHandle.USER_ALL) {
281 if (UserHandle.getAppId(entUid) == appId) {
282 remove = true;
283 }
284 } else {
285 if (entUid == UserHandle.getUid(userId, appId)) {
286 remove = true;
287 }
288 }
289 } else if (UserHandle.getUserId(entUid) == userId) {
290 remove = true;
291 }
292 if (remove) {
293 ba.removeAt(i);
294 }
295 }
296 if (ba.size() == 0) {
297 pmap.removeAt(ip);
298 }
299 }
300 }
301
302 void loadAppsNotReportingCrashesFromConfigLocked(String appsNotReportingCrashesConfig) {
303 if (appsNotReportingCrashesConfig != null) {
304 final String[] split = appsNotReportingCrashesConfig.split(",");
305 if (split.length > 0) {
306 mAppsNotReportingCrashes = new ArraySet<>();
307 Collections.addAll(mAppsNotReportingCrashes, split);
308 }
309 }
310 }
311
312 void killAppAtUserRequestLocked(ProcessRecord app, Dialog fromDialog) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700313 app.setCrashing(false);
Adrian Roos20d7df32016-01-12 18:59:43 +0100314 app.crashingReport = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700315 app.setNotResponding(false);
Adrian Roos20d7df32016-01-12 18:59:43 +0100316 app.notRespondingReport = null;
317 if (app.anrDialog == fromDialog) {
318 app.anrDialog = null;
319 }
320 if (app.waitDialog == fromDialog) {
321 app.waitDialog = null;
322 }
323 if (app.pid > 0 && app.pid != MY_PID) {
324 handleAppCrashLocked(app, "user-terminated" /*reason*/,
325 null /*shortMsg*/, null /*longMsg*/, null /*stackTrace*/, null /*data*/);
326 app.kill("user request after error", true);
327 }
328 }
329
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800330 /**
331 * Induce a crash in the given app.
332 *
333 * @param uid if nonnegative, the required matching uid of the target to crash
334 * @param initialPid fast-path match for the target to crash
335 * @param packageName fallback match if the stated pid is not found or doesn't match uid
336 * @param userId If nonnegative, required to identify a match by package name
337 * @param message
338 */
339 void scheduleAppCrashLocked(int uid, int initialPid, String packageName, int userId,
Adrian Roos20d7df32016-01-12 18:59:43 +0100340 String message) {
341 ProcessRecord proc = null;
342
343 // Figure out which process to kill. We don't trust that initialPid
344 // still has any relation to current pids, so must scan through the
345 // list.
346
347 synchronized (mService.mPidsSelfLocked) {
348 for (int i=0; i<mService.mPidsSelfLocked.size(); i++) {
349 ProcessRecord p = mService.mPidsSelfLocked.valueAt(i);
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800350 if (uid >= 0 && p.uid != uid) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100351 continue;
352 }
353 if (p.pid == initialPid) {
354 proc = p;
355 break;
356 }
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800357 if (p.pkgList.containsKey(packageName)
358 && (userId < 0 || p.userId == userId)) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100359 proc = p;
360 }
361 }
362 }
363
364 if (proc == null) {
365 Slog.w(TAG, "crashApplication: nothing for uid=" + uid
366 + " initialPid=" + initialPid
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800367 + " packageName=" + packageName
368 + " userId=" + userId);
Adrian Roos20d7df32016-01-12 18:59:43 +0100369 return;
370 }
371
Joe Onorato57190282016-04-20 15:37:49 -0700372 proc.scheduleCrash(message);
Adrian Roos20d7df32016-01-12 18:59:43 +0100373 }
374
375 /**
376 * Bring up the "unexpected error" dialog box for a crashing app.
377 * Deal with edge cases (intercepts from instrumented applications,
378 * ActivityController, error intent receivers, that sort of thing).
379 * @param r the application crashing
380 * @param crashInfo describing the failure
381 */
382 void crashApplication(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo) {
Mark Lub5e24992016-11-21 15:38:13 +0800383 final int callingPid = Binder.getCallingPid();
384 final int callingUid = Binder.getCallingUid();
385
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700386 final long origId = Binder.clearCallingIdentity();
387 try {
Mark Lub5e24992016-11-21 15:38:13 +0800388 crashApplicationInner(r, crashInfo, callingPid, callingUid);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700389 } finally {
390 Binder.restoreCallingIdentity(origId);
391 }
392 }
393
Mark Lub5e24992016-11-21 15:38:13 +0800394 void crashApplicationInner(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo,
395 int callingPid, int callingUid) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100396 long timeMillis = System.currentTimeMillis();
397 String shortMsg = crashInfo.exceptionClassName;
398 String longMsg = crashInfo.exceptionMessage;
399 String stackTrace = crashInfo.stackTrace;
400 if (shortMsg != null && longMsg != null) {
401 longMsg = shortMsg + ": " + longMsg;
402 } else if (shortMsg != null) {
403 longMsg = shortMsg;
404 }
405
Zimuzo6efba542018-11-29 12:47:58 +0000406 if (r != null) {
407 if (r.isPersistent()) {
408 // If a persistent app is stuck in a crash loop, the device isn't very
409 // usable, so we want to consider sending out a rescue party.
410 RescueParty.notePersistentAppCrash(mContext, r.uid);
411 } else {
412 // If a non-persistent app is stuck in crash loop, we want to inform
413 // the package watchdog, maybe an update or experiment can be rolled back.
414 mPackageWatchdog.onPackageFailure(r.getPackageList());
415 }
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -0700416 }
417
Garfield Tan2746ab52018-07-25 12:33:01 -0700418 final int relaunchReason = r != null
Wale Ogunwale64258362018-10-16 15:13:37 -0700419 ? r.getWindowProcessController().computeRelaunchReason() : RELAUNCH_REASON_NONE;
Garfield Tan2746ab52018-07-25 12:33:01 -0700420
Adrian Roos20d7df32016-01-12 18:59:43 +0100421 AppErrorResult result = new AppErrorResult();
Wale Ogunwale64258362018-10-16 15:13:37 -0700422 int taskId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100423 synchronized (mService) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700424 /**
425 * If crash is handled by instance of {@link android.app.IActivityController},
426 * finish now and don't show the app error dialog.
427 */
428 if (handleAppCrashInActivityController(r, crashInfo, shortMsg, longMsg, stackTrace,
Mark Lub5e24992016-11-21 15:38:13 +0800429 timeMillis, callingPid, callingUid)) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700430 return;
Adrian Roos20d7df32016-01-12 18:59:43 +0100431 }
432
Garfield Tan2746ab52018-07-25 12:33:01 -0700433 // Suppress crash dialog if the process is being relaunched due to a crash during a free
434 // resize.
Wale Ogunwale64258362018-10-16 15:13:37 -0700435 if (relaunchReason == RELAUNCH_REASON_FREE_RESIZE) {
Garfield Tan2746ab52018-07-25 12:33:01 -0700436 return;
437 }
438
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700439 /**
440 * If this process was running instrumentation, finish now - it will be handled in
441 * {@link ActivityManagerService#handleAppDiedLocked}.
442 */
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700443 if (r != null && r.getActiveInstrumentation() != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100444 return;
445 }
446
447 // Log crash in battery stats.
448 if (r != null) {
449 mService.mBatteryStatsService.noteProcessCrash(r.processName, r.uid);
450 }
451
452 AppErrorDialog.Data data = new AppErrorDialog.Data();
453 data.result = result;
454 data.proc = r;
455
456 // If we can't identify the process or it's already exceeded its crash quota,
457 // quit right away without showing a crash dialog.
458 if (r == null || !makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace, data)) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100459 return;
460 }
461
Wale Ogunwale9645b0f2016-09-12 10:49:35 -0700462 final Message msg = Message.obtain();
Adrian Roos20d7df32016-01-12 18:59:43 +0100463 msg.what = ActivityManagerService.SHOW_ERROR_UI_MSG;
464
Wale Ogunwale64258362018-10-16 15:13:37 -0700465 taskId = data.taskId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100466 msg.obj = data;
467 mService.mUiHandler.sendMessage(msg);
Adrian Roos20d7df32016-01-12 18:59:43 +0100468 }
469
470 int res = result.get();
471
472 Intent appErrorIntent = null;
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700473 MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_CRASH, res);
Adrian Roosad028c12016-05-17 14:30:42 -0700474 if (res == AppErrorDialog.TIMEOUT || res == AppErrorDialog.CANCEL) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700475 res = AppErrorDialog.FORCE_QUIT;
476 }
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700477 synchronized (mService) {
478 if (res == AppErrorDialog.MUTE) {
479 stopReportingCrashesLocked(r);
480 }
481 if (res == AppErrorDialog.RESTART) {
Amith Yamasani98a00922018-08-21 12:50:30 -0400482 mService.mProcessList.removeProcessLocked(r, false, true, "crash");
Wale Ogunwale64258362018-10-16 15:13:37 -0700483 if (taskId != INVALID_TASK_ID) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700484 try {
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700485 mService.startActivityFromRecents(taskId,
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700486 ActivityOptions.makeBasic().toBundle());
487 } catch (IllegalArgumentException e) {
Wale Ogunwale64258362018-10-16 15:13:37 -0700488 // Hmm...that didn't work. Task should either be in recents or associated
489 // with a stack.
490 Slog.e(TAG, "Could not restart taskId=" + taskId, e);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700491 }
492 }
493 }
494 if (res == AppErrorDialog.FORCE_QUIT) {
495 long orig = Binder.clearCallingIdentity();
496 try {
497 // Kill it with fire!
Wale Ogunwale31913b52018-10-13 08:29:31 -0700498 mService.mAtmInternal.onHandleAppCrash(r.getWindowProcessController());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700499 if (!r.isPersistent()) {
Amith Yamasani98a00922018-08-21 12:50:30 -0400500 mService.mProcessList.removeProcessLocked(r, false, false, "crash");
Wale Ogunwale31913b52018-10-13 08:29:31 -0700501 mService.mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700502 }
503 } finally {
504 Binder.restoreCallingIdentity(orig);
505 }
506 }
Andrew Sapperstein5b679c42018-01-16 11:13:40 -0800507 if (res == AppErrorDialog.APP_INFO) {
508 appErrorIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
509 appErrorIntent.setData(Uri.parse("package:" + r.info.packageName));
510 appErrorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
511 }
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700512 if (res == AppErrorDialog.FORCE_QUIT_AND_REPORT) {
513 appErrorIntent = createAppErrorIntentLocked(r, timeMillis, crashInfo);
514 }
515 if (r != null && !r.isolated && res != AppErrorDialog.RESTART) {
516 // XXX Can't keep track of crash time for isolated processes,
517 // since they don't have a persistent identity.
518 mProcessCrashTimes.put(r.info.processName, r.uid,
519 SystemClock.uptimeMillis());
520 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100521 }
522
523 if (appErrorIntent != null) {
524 try {
525 mContext.startActivityAsUser(appErrorIntent, new UserHandle(r.userId));
526 } catch (ActivityNotFoundException e) {
527 Slog.w(TAG, "bug report receiver dissappeared", e);
528 }
529 }
530 }
531
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700532 private boolean handleAppCrashInActivityController(ProcessRecord r,
533 ApplicationErrorReport.CrashInfo crashInfo,
534 String shortMsg, String longMsg,
Mark Lub5e24992016-11-21 15:38:13 +0800535 String stackTrace, long timeMillis,
536 int callingPid, int callingUid) {
Wale Ogunwalee2172292018-10-25 10:11:10 -0700537 String name = r != null ? r.processName : null;
538 int pid = r != null ? r.pid : callingPid;
539 int uid = r != null ? r.info.uid : callingUid;
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700540
Wale Ogunwalee2172292018-10-25 10:11:10 -0700541 return mService.mAtmInternal.handleAppCrashInActivityController(
542 name, pid, shortMsg, longMsg, timeMillis, crashInfo.stackTrace, () -> {
543 if ("1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"))
544 && "Native crash".equals(crashInfo.exceptionClassName)) {
545 Slog.w(TAG, "Skip killing native crashed app " + name
546 + "(" + pid + ") during testing");
547 } else {
548 Slog.w(TAG, "Force-killing crashed app " + name + " at watcher's request");
549 if (r != null) {
550 if (!makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace, null)) {
551 r.kill("crash", true);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700552 }
Wale Ogunwalee2172292018-10-25 10:11:10 -0700553 } else {
554 // Huh.
555 Process.killProcess(pid);
556 ProcessList.killProcessGroup(uid, pid);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700557 }
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700558 }
Wale Ogunwalee2172292018-10-25 10:11:10 -0700559 });
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700560 }
561
Adrian Roos20d7df32016-01-12 18:59:43 +0100562 private boolean makeAppCrashingLocked(ProcessRecord app,
563 String shortMsg, String longMsg, String stackTrace, AppErrorDialog.Data data) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700564 app.setCrashing(true);
Adrian Roos20d7df32016-01-12 18:59:43 +0100565 app.crashingReport = generateProcessError(app,
566 ActivityManager.ProcessErrorStateInfo.CRASHED, null, shortMsg, longMsg, stackTrace);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700567 app.startAppProblemLocked();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700568 app.getWindowProcessController().stopFreezingActivities();
Adrian Roos20d7df32016-01-12 18:59:43 +0100569 return handleAppCrashLocked(app, "force-crash" /*reason*/, shortMsg, longMsg, stackTrace,
570 data);
571 }
572
Adrian Roos20d7df32016-01-12 18:59:43 +0100573 /**
574 * Generate a process error record, suitable for attachment to a ProcessRecord.
575 *
576 * @param app The ProcessRecord in which the error occurred.
577 * @param condition Crashing, Application Not Responding, etc. Values are defined in
Sudheer Shankaf6690102017-10-16 10:20:32 -0700578 * ActivityManager.ProcessErrorStateInfo
Adrian Roos20d7df32016-01-12 18:59:43 +0100579 * @param activity The activity associated with the crash, if known.
580 * @param shortMsg Short message describing the crash.
581 * @param longMsg Long message describing the crash.
582 * @param stackTrace Full crash stack trace, may be null.
583 *
Sudheer Shankaf6690102017-10-16 10:20:32 -0700584 * @return Returns a fully-formed ProcessErrorStateInfo record.
Adrian Roos20d7df32016-01-12 18:59:43 +0100585 */
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700586 ActivityManager.ProcessErrorStateInfo generateProcessError(ProcessRecord app,
Adrian Roos20d7df32016-01-12 18:59:43 +0100587 int condition, String activity, String shortMsg, String longMsg, String stackTrace) {
588 ActivityManager.ProcessErrorStateInfo report = new ActivityManager.ProcessErrorStateInfo();
589
590 report.condition = condition;
591 report.processName = app.processName;
592 report.pid = app.pid;
593 report.uid = app.info.uid;
594 report.tag = activity;
595 report.shortMsg = shortMsg;
596 report.longMsg = longMsg;
597 report.stackTrace = stackTrace;
598
599 return report;
600 }
601
602 Intent createAppErrorIntentLocked(ProcessRecord r,
603 long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
604 ApplicationErrorReport report = createAppErrorReportLocked(r, timeMillis, crashInfo);
605 if (report == null) {
606 return null;
607 }
608 Intent result = new Intent(Intent.ACTION_APP_ERROR);
609 result.setComponent(r.errorReportReceiver);
610 result.putExtra(Intent.EXTRA_BUG_REPORT, report);
611 result.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
612 return result;
613 }
614
615 private ApplicationErrorReport createAppErrorReportLocked(ProcessRecord r,
616 long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
617 if (r.errorReportReceiver == null) {
618 return null;
619 }
620
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700621 if (!r.isCrashing() && !r.isNotResponding() && !r.forceCrashReport) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100622 return null;
623 }
624
625 ApplicationErrorReport report = new ApplicationErrorReport();
626 report.packageName = r.info.packageName;
627 report.installerPackageName = r.errorReportReceiver.getPackageName();
628 report.processName = r.processName;
629 report.time = timeMillis;
Wale Ogunwale59507092018-10-29 09:00:30 -0700630 report.systemApp = (r.info.flags & FLAG_SYSTEM) != 0;
Adrian Roos20d7df32016-01-12 18:59:43 +0100631
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700632 if (r.isCrashing() || r.forceCrashReport) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100633 report.type = ApplicationErrorReport.TYPE_CRASH;
634 report.crashInfo = crashInfo;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700635 } else if (r.isNotResponding()) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100636 report.type = ApplicationErrorReport.TYPE_ANR;
637 report.anrInfo = new ApplicationErrorReport.AnrInfo();
638
639 report.anrInfo.activity = r.notRespondingReport.tag;
640 report.anrInfo.cause = r.notRespondingReport.shortMsg;
641 report.anrInfo.info = r.notRespondingReport.longMsg;
642 }
643
644 return report;
645 }
646
647 boolean handleAppCrashLocked(ProcessRecord app, String reason,
648 String shortMsg, String longMsg, String stackTrace, AppErrorDialog.Data data) {
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700649 final long now = SystemClock.uptimeMillis();
650 final boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
Adrian Roos6a7e0892016-08-23 14:26:39 +0200651 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
Adrian Roos20d7df32016-01-12 18:59:43 +0100652
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700653 final boolean procIsBoundForeground =
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700654 (app.getCurProcState() == ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700655
Adrian Roos20d7df32016-01-12 18:59:43 +0100656 Long crashTime;
657 Long crashTimePersistent;
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700658 boolean tryAgain = false;
659
Adrian Roos20d7df32016-01-12 18:59:43 +0100660 if (!app.isolated) {
661 crashTime = mProcessCrashTimes.get(app.info.processName, app.uid);
662 crashTimePersistent = mProcessCrashTimesPersistent.get(app.info.processName, app.uid);
663 } else {
664 crashTime = crashTimePersistent = null;
665 }
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700666
667 // Bump up the crash count of any services currently running in the proc.
668 for (int i = app.services.size() - 1; i >= 0; i--) {
669 // Any services running in the application need to be placed
670 // back in the pending list.
671 ServiceRecord sr = app.services.valueAt(i);
672 // If the service was restarted a while ago, then reset crash count, else increment it.
673 if (now > sr.restartTime + ProcessList.MIN_CRASH_INTERVAL) {
674 sr.crashCount = 1;
675 } else {
676 sr.crashCount++;
677 }
678 // Allow restarting for started or bound foreground services that are crashing.
679 // This includes wallpapers.
680 if (sr.crashCount < mService.mConstants.BOUND_SERVICE_MAX_CRASH_RETRY
681 && (sr.isForeground || procIsBoundForeground)) {
682 tryAgain = true;
683 }
684 }
685
686 if (crashTime != null && now < crashTime + ProcessList.MIN_CRASH_INTERVAL) {
687 // The process crashed again very quickly. If it was a bound foreground service, let's
688 // try to restart again in a while, otherwise the process loses!
Adrian Roos20d7df32016-01-12 18:59:43 +0100689 Slog.w(TAG, "Process " + app.info.processName
690 + " has crashed too many times: killing!");
691 EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
692 app.userId, app.info.processName, app.uid);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700693 mService.mAtmInternal.onHandleAppCrash(app.getWindowProcessController());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700694 if (!app.isPersistent()) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100695 // We don't want to start this process again until the user
696 // explicitly does so... but for persistent process, we really
697 // need to keep it running. If a persistent process is actually
698 // repeatedly crashing, then badness for everyone.
699 EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid,
700 app.info.processName);
701 if (!app.isolated) {
702 // XXX We don't have a way to mark isolated processes
703 // as bad, since they don't have a peristent identity.
704 mBadProcesses.put(app.info.processName, app.uid,
705 new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
706 mProcessCrashTimes.remove(app.info.processName, app.uid);
707 }
708 app.bad = true;
709 app.removed = true;
710 // Don't let services in this process be restarted and potentially
711 // annoy the user repeatedly. Unless it is persistent, since those
712 // processes run critical code.
Amith Yamasani98a00922018-08-21 12:50:30 -0400713 mService.mProcessList.removeProcessLocked(app, false, tryAgain, "crash");
Wale Ogunwale31913b52018-10-13 08:29:31 -0700714 mService.mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
Adrian Roos6a7e0892016-08-23 14:26:39 +0200715 if (!showBackground) {
716 return false;
717 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100718 }
Wale Ogunwale31913b52018-10-13 08:29:31 -0700719 mService.mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
Adrian Roos20d7df32016-01-12 18:59:43 +0100720 } else {
Wale Ogunwale64258362018-10-16 15:13:37 -0700721 final int affectedTaskId = mService.mAtmInternal.finishTopCrashedActivities(
Wale Ogunwale31913b52018-10-13 08:29:31 -0700722 app.getWindowProcessController(), reason);
Adrian Roos20d7df32016-01-12 18:59:43 +0100723 if (data != null) {
Wale Ogunwale64258362018-10-16 15:13:37 -0700724 data.taskId = affectedTaskId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100725 }
726 if (data != null && crashTimePersistent != null
727 && now < crashTimePersistent + ProcessList.MIN_CRASH_INTERVAL) {
728 data.repeating = true;
729 }
730 }
731
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700732 if (data != null && tryAgain) {
733 data.isRestartableForService = true;
Adrian Roos20d7df32016-01-12 18:59:43 +0100734 }
735
736 // If the crashing process is what we consider to be the "home process" and it has been
737 // replaced by a third-party app, clear the package preferred activities from packages
738 // with a home activity running in the process to prevent a repeatedly crashing app
739 // from blocking the user to manually clear the list.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700740 final WindowProcessController proc = app.getWindowProcessController();
Wale Ogunwaled4d67d02018-10-25 18:09:39 -0700741 final WindowProcessController homeProc = mService.mAtmInternal.getHomeProcess();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700742 if (proc == homeProc && proc.hasActivities()
Wale Ogunwale59507092018-10-29 09:00:30 -0700743 && (((ProcessRecord) homeProc.mOwner).info.flags & FLAG_SYSTEM) == 0) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700744 proc.clearPackagePreferredForHomeActivities();
Adrian Roos20d7df32016-01-12 18:59:43 +0100745 }
746
747 if (!app.isolated) {
748 // XXX Can't keep track of crash times for isolated processes,
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700749 // because they don't have a persistent identity.
Adrian Roos20d7df32016-01-12 18:59:43 +0100750 mProcessCrashTimes.put(app.info.processName, app.uid, now);
751 mProcessCrashTimesPersistent.put(app.info.processName, app.uid, now);
752 }
753
754 if (app.crashHandler != null) mService.mHandler.post(app.crashHandler);
755 return true;
756 }
757
758 void handleShowAppErrorUi(Message msg) {
759 AppErrorDialog.Data data = (AppErrorDialog.Data) msg.obj;
760 boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
761 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
Adrian Roosc3a06e52018-02-16 18:33:17 +0100762
763 AppErrorDialog dialogToShow = null;
764 final String packageName;
765 final int userId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100766 synchronized (mService) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100767 final ProcessRecord proc = data.proc;
768 final AppErrorResult res = data.result;
769 if (proc == null) {
770 Slog.e(TAG, "handleShowAppErrorUi: proc is null");
771 return;
772 }
773 packageName = proc.info.packageName;
774 userId = proc.userId;
775 if (proc.crashDialog != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100776 Slog.e(TAG, "App already has crash dialog: " + proc);
777 if (res != null) {
Adrian Roos90462222016-02-17 15:45:09 -0800778 res.set(AppErrorDialog.ALREADY_SHOWING);
Adrian Roos20d7df32016-01-12 18:59:43 +0100779 }
780 return;
781 }
782 boolean isBackground = (UserHandle.getAppId(proc.uid)
783 >= Process.FIRST_APPLICATION_UID
784 && proc.pid != MY_PID);
Adrian Roosc3a06e52018-02-16 18:33:17 +0100785 for (int profileId : mService.mUserController.getCurrentProfileIds()) {
786 isBackground &= (userId != profileId);
Adrian Roos20d7df32016-01-12 18:59:43 +0100787 }
788 if (isBackground && !showBackground) {
789 Slog.w(TAG, "Skipping crash dialog of " + proc + ": background");
790 if (res != null) {
Adrian Roos90462222016-02-17 15:45:09 -0800791 res.set(AppErrorDialog.BACKGROUND_USER);
Adrian Roos20d7df32016-01-12 18:59:43 +0100792 }
793 return;
794 }
Andrew Sapperstein43643ae2017-12-20 15:17:33 -0800795 final boolean showFirstCrash = Settings.Global.getInt(
796 mContext.getContentResolver(),
797 Settings.Global.SHOW_FIRST_CRASH_DIALOG, 0) != 0;
798 final boolean showFirstCrashDevOption = Settings.Secure.getIntForUser(
799 mContext.getContentResolver(),
800 Settings.Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION,
801 0,
Andrew Sappersteinfd5238c2018-01-21 09:45:05 -0800802 mService.mUserController.getCurrentUserId()) != 0;
Adrian Roos20d7df32016-01-12 18:59:43 +0100803 final boolean crashSilenced = mAppsNotReportingCrashes != null &&
804 mAppsNotReportingCrashes.contains(proc.info.packageName);
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700805 if ((mService.mAtmInternal.canShowErrorDialogs() || showBackground)
Wale Ogunwalef6733932018-06-27 05:14:34 -0700806 && !crashSilenced
Andrew Sapperstein43643ae2017-12-20 15:17:33 -0800807 && (showFirstCrash || showFirstCrashDevOption || data.repeating)) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100808 proc.crashDialog = dialogToShow = new AppErrorDialog(mContext, mService, data);
Adrian Roos20d7df32016-01-12 18:59:43 +0100809 } else {
810 // The device is asleep, so just pretend that the user
811 // saw a crash dialog and hit "force quit".
812 if (res != null) {
Adrian Roos90462222016-02-17 15:45:09 -0800813 res.set(AppErrorDialog.CANT_SHOW);
Adrian Roos20d7df32016-01-12 18:59:43 +0100814 }
815 }
816 }
Phil Weaver445fd2a2016-03-17 17:26:24 -0700817 // If we've created a crash dialog, show it without the lock held
Adrian Roosc3a06e52018-02-16 18:33:17 +0100818 if (dialogToShow != null) {
819 Slog.i(TAG, "Showing crash dialog for package " + packageName + " u" + userId);
820 dialogToShow.show();
Phil Weaver445fd2a2016-03-17 17:26:24 -0700821 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100822 }
823
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700824 private void stopReportingCrashesLocked(ProcessRecord proc) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100825 if (mAppsNotReportingCrashes == null) {
826 mAppsNotReportingCrashes = new ArraySet<>();
827 }
828 mAppsNotReportingCrashes.add(proc.info.packageName);
829 }
830
Adrian Roos20d7df32016-01-12 18:59:43 +0100831 void handleShowAnrUi(Message msg) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100832 Dialog dialogToShow = null;
Zimuzo6efba542018-11-29 12:47:58 +0000833 String[] packageList = null;
Adrian Roos20d7df32016-01-12 18:59:43 +0100834 synchronized (mService) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100835 AppNotRespondingDialog.Data data = (AppNotRespondingDialog.Data) msg.obj;
836 final ProcessRecord proc = data.proc;
837 if (proc == null) {
838 Slog.e(TAG, "handleShowAnrUi: proc is null");
839 return;
840 }
Zimuzo6efba542018-11-29 12:47:58 +0000841 if (!proc.isPersistent()) {
842 packageList = proc.getPackageList();
843 }
Adrian Roosc3a06e52018-02-16 18:33:17 +0100844 if (proc.anrDialog != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100845 Slog.e(TAG, "App already has anr dialog: " + proc);
Adrian Roos90462222016-02-17 15:45:09 -0800846 MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_ANR,
847 AppNotRespondingDialog.ALREADY_SHOWING);
Adrian Roos20d7df32016-01-12 18:59:43 +0100848 return;
849 }
850
Adrian Roos6a7e0892016-08-23 14:26:39 +0200851 boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
852 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700853 if (mService.mAtmInternal.canShowErrorDialogs() || showBackground) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100854 dialogToShow = new AppNotRespondingDialog(mService, mContext, data);
855 proc.anrDialog = dialogToShow;
Adrian Roos20d7df32016-01-12 18:59:43 +0100856 } else {
Adrian Roos90462222016-02-17 15:45:09 -0800857 MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_ANR,
858 AppNotRespondingDialog.CANT_SHOW);
Adrian Roos20d7df32016-01-12 18:59:43 +0100859 // Just kill the app if there is no dialog to be shown.
860 mService.killAppAtUsersRequest(proc, null);
861 }
862 }
Phil Weaver445fd2a2016-03-17 17:26:24 -0700863 // If we've created a crash dialog, show it without the lock held
Adrian Roosc3a06e52018-02-16 18:33:17 +0100864 if (dialogToShow != null) {
865 dialogToShow.show();
Phil Weaver445fd2a2016-03-17 17:26:24 -0700866 }
Zimuzo6efba542018-11-29 12:47:58 +0000867 // Notify PackageWatchdog without the lock held
868 if (packageList != null) {
869 mPackageWatchdog.onPackageFailure(packageList);
870 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100871 }
872
873 /**
874 * Information about a process that is currently marked as bad.
875 */
876 static final class BadProcessInfo {
877 BadProcessInfo(long time, String shortMsg, String longMsg, String stack) {
878 this.time = time;
879 this.shortMsg = shortMsg;
880 this.longMsg = longMsg;
881 this.stack = stack;
882 }
883
884 final long time;
885 final String shortMsg;
886 final String longMsg;
887 final String stack;
888 }
889
890}