blob: f153ab9cfa9edb92ac33cdc14e74383794e71734 [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;
Zimuzo972e1cd2019-01-28 16:30:01 +000037import android.content.pm.VersionedPackage;
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080038import android.net.Uri;
Adrian Roos20d7df32016-01-12 18:59:43 +010039import android.os.Binder;
Adrian Roos20d7df32016-01-12 18:59:43 +010040import android.os.Message;
41import android.os.Process;
Adrian Roos20d7df32016-01-12 18:59:43 +010042import android.os.SystemClock;
43import android.os.SystemProperties;
44import android.os.UserHandle;
45import android.provider.Settings;
46import android.util.ArrayMap;
47import android.util.ArraySet;
48import android.util.EventLog;
Adrian Roos20d7df32016-01-12 18:59:43 +010049import android.util.Slog;
50import android.util.SparseArray;
51import android.util.TimeUtils;
Yi Jin148d7f42017-11-28 14:23:56 -080052import android.util.proto.ProtoOutputStream;
Adrian Roos20d7df32016-01-12 18:59:43 +010053
Makoto Onukie276b442018-08-30 09:38:44 -070054import com.android.internal.app.ProcessMap;
55import com.android.internal.logging.MetricsLogger;
56import com.android.internal.logging.nano.MetricsProto;
Zimuzo6efba542018-11-29 12:47:58 +000057import com.android.server.PackageWatchdog;
Makoto Onukie276b442018-08-30 09:38:44 -070058import com.android.server.RescueParty;
Wale Ogunwale59507092018-10-29 09:00:30 -070059import com.android.server.wm.WindowProcessController;
Makoto Onukie276b442018-08-30 09:38:44 -070060
Adrian Roos20d7df32016-01-12 18:59:43 +010061import java.io.FileDescriptor;
62import java.io.PrintWriter;
Adrian Roos20d7df32016-01-12 18:59:43 +010063import java.util.Collections;
Zimuzo972e1cd2019-01-28 16:30:01 +000064import java.util.List;
Adrian Roos20d7df32016-01-12 18:59:43 +010065
Adrian Roos20d7df32016-01-12 18:59:43 +010066/**
67 * Controls error conditions in applications.
68 */
69class AppErrors {
70
71 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppErrors" : TAG_AM;
72
73 private final ActivityManagerService mService;
74 private final Context mContext;
Zimuzo6efba542018-11-29 12:47:58 +000075 private final PackageWatchdog mPackageWatchdog;
Adrian Roos20d7df32016-01-12 18:59:43 +010076
77 private ArraySet<String> mAppsNotReportingCrashes;
78
79 /**
80 * The last time that various processes have crashed since they were last explicitly started.
81 */
82 private final ProcessMap<Long> mProcessCrashTimes = new ProcessMap<>();
83
84 /**
85 * The last time that various processes have crashed (not reset even when explicitly started).
86 */
87 private final ProcessMap<Long> mProcessCrashTimesPersistent = new ProcessMap<>();
88
89 /**
90 * Set of applications that we consider to be bad, and will reject
91 * incoming broadcasts from (which the user has no control over).
92 * Processes are added to this set when they have crashed twice within
93 * a minimum amount of time; they are removed from it when they are
94 * later restarted (hopefully due to some user action). The value is the
95 * time it was added to the list.
96 */
97 private final ProcessMap<BadProcessInfo> mBadProcesses = new ProcessMap<>();
98
99
Zimuzo6efba542018-11-29 12:47:58 +0000100 AppErrors(Context context, ActivityManagerService service, PackageWatchdog watchdog) {
Adam Lesinskia82b6262017-03-21 16:56:17 -0700101 context.assertRuntimeOverlayThemable();
Adrian Roos20d7df32016-01-12 18:59:43 +0100102 mService = service;
103 mContext = context;
Zimuzo6efba542018-11-29 12:47:58 +0000104 mPackageWatchdog = watchdog;
Adrian Roos20d7df32016-01-12 18:59:43 +0100105 }
106
Yi Jin148d7f42017-11-28 14:23:56 -0800107 void writeToProto(ProtoOutputStream proto, long fieldId, String dumpPackage) {
108 if (mProcessCrashTimes.getMap().isEmpty() && mBadProcesses.getMap().isEmpty()) {
109 return;
110 }
111
112 final long token = proto.start(fieldId);
113 final long now = SystemClock.uptimeMillis();
114 proto.write(AppErrorsProto.NOW_UPTIME_MS, now);
115
116 if (!mProcessCrashTimes.getMap().isEmpty()) {
117 final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
118 final int procCount = pmap.size();
119 for (int ip = 0; ip < procCount; ip++) {
120 final long ctoken = proto.start(AppErrorsProto.PROCESS_CRASH_TIMES);
121 final String pname = pmap.keyAt(ip);
122 final SparseArray<Long> uids = pmap.valueAt(ip);
123 final int uidCount = uids.size();
124
125 proto.write(AppErrorsProto.ProcessCrashTime.PROCESS_NAME, pname);
126 for (int i = 0; i < uidCount; i++) {
127 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400128 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Yi Jin148d7f42017-11-28 14:23:56 -0800129 if (dumpPackage != null && (r == null || !r.pkgList.containsKey(dumpPackage))) {
130 continue;
131 }
132 final long etoken = proto.start(AppErrorsProto.ProcessCrashTime.ENTRIES);
133 proto.write(AppErrorsProto.ProcessCrashTime.Entry.UID, puid);
134 proto.write(AppErrorsProto.ProcessCrashTime.Entry.LAST_CRASHED_AT_MS,
135 uids.valueAt(i));
136 proto.end(etoken);
137 }
138 proto.end(ctoken);
139 }
140
141 }
142
143 if (!mBadProcesses.getMap().isEmpty()) {
144 final ArrayMap<String, SparseArray<BadProcessInfo>> pmap = mBadProcesses.getMap();
145 final int processCount = pmap.size();
146 for (int ip = 0; ip < processCount; ip++) {
147 final long btoken = proto.start(AppErrorsProto.BAD_PROCESSES);
148 final String pname = pmap.keyAt(ip);
149 final SparseArray<BadProcessInfo> uids = pmap.valueAt(ip);
150 final int uidCount = uids.size();
151
152 proto.write(AppErrorsProto.BadProcess.PROCESS_NAME, pname);
153 for (int i = 0; i < uidCount; i++) {
154 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400155 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Yi Jin148d7f42017-11-28 14:23:56 -0800156 if (dumpPackage != null && (r == null
157 || !r.pkgList.containsKey(dumpPackage))) {
158 continue;
159 }
160 final BadProcessInfo info = uids.valueAt(i);
161 final long etoken = proto.start(AppErrorsProto.BadProcess.ENTRIES);
162 proto.write(AppErrorsProto.BadProcess.Entry.UID, puid);
163 proto.write(AppErrorsProto.BadProcess.Entry.CRASHED_AT_MS, info.time);
164 proto.write(AppErrorsProto.BadProcess.Entry.SHORT_MSG, info.shortMsg);
165 proto.write(AppErrorsProto.BadProcess.Entry.LONG_MSG, info.longMsg);
166 proto.write(AppErrorsProto.BadProcess.Entry.STACK, info.stack);
167 proto.end(etoken);
168 }
169 proto.end(btoken);
170 }
171 }
172
173 proto.end(token);
174 }
175
176 boolean dumpLocked(FileDescriptor fd, PrintWriter pw, boolean needSep, String dumpPackage) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100177 if (!mProcessCrashTimes.getMap().isEmpty()) {
178 boolean printed = false;
179 final long now = SystemClock.uptimeMillis();
180 final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
181 final int processCount = pmap.size();
182 for (int ip = 0; ip < processCount; ip++) {
183 final String pname = pmap.keyAt(ip);
184 final SparseArray<Long> uids = pmap.valueAt(ip);
185 final int uidCount = uids.size();
186 for (int i = 0; i < uidCount; i++) {
187 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400188 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Adrian Roos20d7df32016-01-12 18:59:43 +0100189 if (dumpPackage != null && (r == null
190 || !r.pkgList.containsKey(dumpPackage))) {
191 continue;
192 }
193 if (!printed) {
194 if (needSep) pw.println();
195 needSep = true;
196 pw.println(" Time since processes crashed:");
197 printed = true;
198 }
199 pw.print(" Process "); pw.print(pname);
200 pw.print(" uid "); pw.print(puid);
201 pw.print(": last crashed ");
202 TimeUtils.formatDuration(now-uids.valueAt(i), pw);
203 pw.println(" ago");
204 }
205 }
206 }
207
208 if (!mBadProcesses.getMap().isEmpty()) {
209 boolean printed = false;
210 final ArrayMap<String, SparseArray<BadProcessInfo>> pmap = mBadProcesses.getMap();
211 final int processCount = pmap.size();
212 for (int ip = 0; ip < processCount; ip++) {
213 final String pname = pmap.keyAt(ip);
214 final SparseArray<BadProcessInfo> uids = pmap.valueAt(ip);
215 final int uidCount = uids.size();
216 for (int i = 0; i < uidCount; i++) {
217 final int puid = uids.keyAt(i);
Amith Yamasani98a00922018-08-21 12:50:30 -0400218 final ProcessRecord r = mService.getProcessNames().get(pname, puid);
Adrian Roos20d7df32016-01-12 18:59:43 +0100219 if (dumpPackage != null && (r == null
220 || !r.pkgList.containsKey(dumpPackage))) {
221 continue;
222 }
223 if (!printed) {
224 if (needSep) pw.println();
225 needSep = true;
226 pw.println(" Bad processes:");
227 printed = true;
228 }
229 final BadProcessInfo info = uids.valueAt(i);
230 pw.print(" Bad process "); pw.print(pname);
231 pw.print(" uid "); pw.print(puid);
232 pw.print(": crashed at time "); pw.println(info.time);
233 if (info.shortMsg != null) {
234 pw.print(" Short msg: "); pw.println(info.shortMsg);
235 }
236 if (info.longMsg != null) {
237 pw.print(" Long msg: "); pw.println(info.longMsg);
238 }
239 if (info.stack != null) {
240 pw.println(" Stack:");
241 int lastPos = 0;
242 for (int pos = 0; pos < info.stack.length(); pos++) {
243 if (info.stack.charAt(pos) == '\n') {
244 pw.print(" ");
245 pw.write(info.stack, lastPos, pos-lastPos);
246 pw.println();
247 lastPos = pos+1;
248 }
249 }
250 if (lastPos < info.stack.length()) {
251 pw.print(" ");
252 pw.write(info.stack, lastPos, info.stack.length()-lastPos);
253 pw.println();
254 }
255 }
256 }
257 }
258 }
259 return needSep;
260 }
261
262 boolean isBadProcessLocked(ApplicationInfo info) {
263 return mBadProcesses.get(info.processName, info.uid) != null;
264 }
265
266 void clearBadProcessLocked(ApplicationInfo info) {
267 mBadProcesses.remove(info.processName, info.uid);
268 }
269
270 void resetProcessCrashTimeLocked(ApplicationInfo info) {
271 mProcessCrashTimes.remove(info.processName, info.uid);
272 }
273
274 void resetProcessCrashTimeLocked(boolean resetEntireUser, int appId, int userId) {
275 final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
276 for (int ip = pmap.size() - 1; ip >= 0; ip--) {
277 SparseArray<Long> ba = pmap.valueAt(ip);
278 for (int i = ba.size() - 1; i >= 0; i--) {
279 boolean remove = false;
280 final int entUid = ba.keyAt(i);
281 if (!resetEntireUser) {
282 if (userId == UserHandle.USER_ALL) {
283 if (UserHandle.getAppId(entUid) == appId) {
284 remove = true;
285 }
286 } else {
287 if (entUid == UserHandle.getUid(userId, appId)) {
288 remove = true;
289 }
290 }
291 } else if (UserHandle.getUserId(entUid) == userId) {
292 remove = true;
293 }
294 if (remove) {
295 ba.removeAt(i);
296 }
297 }
298 if (ba.size() == 0) {
299 pmap.removeAt(ip);
300 }
301 }
302 }
303
304 void loadAppsNotReportingCrashesFromConfigLocked(String appsNotReportingCrashesConfig) {
305 if (appsNotReportingCrashesConfig != null) {
306 final String[] split = appsNotReportingCrashesConfig.split(",");
307 if (split.length > 0) {
308 mAppsNotReportingCrashes = new ArraySet<>();
309 Collections.addAll(mAppsNotReportingCrashes, split);
310 }
311 }
312 }
313
314 void killAppAtUserRequestLocked(ProcessRecord app, Dialog fromDialog) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700315 app.setCrashing(false);
Adrian Roos20d7df32016-01-12 18:59:43 +0100316 app.crashingReport = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700317 app.setNotResponding(false);
Adrian Roos20d7df32016-01-12 18:59:43 +0100318 app.notRespondingReport = null;
319 if (app.anrDialog == fromDialog) {
320 app.anrDialog = null;
321 }
322 if (app.waitDialog == fromDialog) {
323 app.waitDialog = null;
324 }
325 if (app.pid > 0 && app.pid != MY_PID) {
326 handleAppCrashLocked(app, "user-terminated" /*reason*/,
327 null /*shortMsg*/, null /*longMsg*/, null /*stackTrace*/, null /*data*/);
328 app.kill("user request after error", true);
329 }
330 }
331
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800332 /**
333 * Induce a crash in the given app.
334 *
335 * @param uid if nonnegative, the required matching uid of the target to crash
336 * @param initialPid fast-path match for the target to crash
337 * @param packageName fallback match if the stated pid is not found or doesn't match uid
338 * @param userId If nonnegative, required to identify a match by package name
339 * @param message
340 */
341 void scheduleAppCrashLocked(int uid, int initialPid, String packageName, int userId,
Adrian Roos20d7df32016-01-12 18:59:43 +0100342 String message) {
343 ProcessRecord proc = null;
344
345 // Figure out which process to kill. We don't trust that initialPid
346 // still has any relation to current pids, so must scan through the
347 // list.
348
349 synchronized (mService.mPidsSelfLocked) {
350 for (int i=0; i<mService.mPidsSelfLocked.size(); i++) {
351 ProcessRecord p = mService.mPidsSelfLocked.valueAt(i);
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800352 if (uid >= 0 && p.uid != uid) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100353 continue;
354 }
355 if (p.pid == initialPid) {
356 proc = p;
357 break;
358 }
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800359 if (p.pkgList.containsKey(packageName)
360 && (userId < 0 || p.userId == userId)) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100361 proc = p;
362 }
363 }
364 }
365
366 if (proc == null) {
367 Slog.w(TAG, "crashApplication: nothing for uid=" + uid
368 + " initialPid=" + initialPid
Christopher Tate8aa8fe12017-01-20 17:50:32 -0800369 + " packageName=" + packageName
370 + " userId=" + userId);
Adrian Roos20d7df32016-01-12 18:59:43 +0100371 return;
372 }
373
Joe Onorato57190282016-04-20 15:37:49 -0700374 proc.scheduleCrash(message);
Adrian Roos20d7df32016-01-12 18:59:43 +0100375 }
376
377 /**
378 * Bring up the "unexpected error" dialog box for a crashing app.
379 * Deal with edge cases (intercepts from instrumented applications,
380 * ActivityController, error intent receivers, that sort of thing).
381 * @param r the application crashing
382 * @param crashInfo describing the failure
383 */
384 void crashApplication(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo) {
Mark Lub5e24992016-11-21 15:38:13 +0800385 final int callingPid = Binder.getCallingPid();
386 final int callingUid = Binder.getCallingUid();
387
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700388 final long origId = Binder.clearCallingIdentity();
389 try {
Mark Lub5e24992016-11-21 15:38:13 +0800390 crashApplicationInner(r, crashInfo, callingPid, callingUid);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700391 } finally {
392 Binder.restoreCallingIdentity(origId);
393 }
394 }
395
Mark Lub5e24992016-11-21 15:38:13 +0800396 void crashApplicationInner(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo,
397 int callingPid, int callingUid) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100398 long timeMillis = System.currentTimeMillis();
399 String shortMsg = crashInfo.exceptionClassName;
400 String longMsg = crashInfo.exceptionMessage;
401 String stackTrace = crashInfo.stackTrace;
402 if (shortMsg != null && longMsg != null) {
403 longMsg = shortMsg + ": " + longMsg;
404 } else if (shortMsg != null) {
405 longMsg = shortMsg;
406 }
407
Zimuzo6efba542018-11-29 12:47:58 +0000408 if (r != null) {
409 if (r.isPersistent()) {
410 // If a persistent app is stuck in a crash loop, the device isn't very
411 // usable, so we want to consider sending out a rescue party.
412 RescueParty.notePersistentAppCrash(mContext, r.uid);
413 } else {
414 // If a non-persistent app is stuck in crash loop, we want to inform
415 // the package watchdog, maybe an update or experiment can be rolled back.
Zimuzo972e1cd2019-01-28 16:30:01 +0000416 mPackageWatchdog.onPackageFailure(r.getPackageListWithVersionCode());
Zimuzo6efba542018-11-29 12:47:58 +0000417 }
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -0700418 }
419
Garfield Tan2746ab52018-07-25 12:33:01 -0700420 final int relaunchReason = r != null
Wale Ogunwale64258362018-10-16 15:13:37 -0700421 ? r.getWindowProcessController().computeRelaunchReason() : RELAUNCH_REASON_NONE;
Garfield Tan2746ab52018-07-25 12:33:01 -0700422
Adrian Roos20d7df32016-01-12 18:59:43 +0100423 AppErrorResult result = new AppErrorResult();
Wale Ogunwale64258362018-10-16 15:13:37 -0700424 int taskId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100425 synchronized (mService) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700426 /**
427 * If crash is handled by instance of {@link android.app.IActivityController},
428 * finish now and don't show the app error dialog.
429 */
430 if (handleAppCrashInActivityController(r, crashInfo, shortMsg, longMsg, stackTrace,
Mark Lub5e24992016-11-21 15:38:13 +0800431 timeMillis, callingPid, callingUid)) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700432 return;
Adrian Roos20d7df32016-01-12 18:59:43 +0100433 }
434
Garfield Tan2746ab52018-07-25 12:33:01 -0700435 // Suppress crash dialog if the process is being relaunched due to a crash during a free
436 // resize.
Wale Ogunwale64258362018-10-16 15:13:37 -0700437 if (relaunchReason == RELAUNCH_REASON_FREE_RESIZE) {
Garfield Tan2746ab52018-07-25 12:33:01 -0700438 return;
439 }
440
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700441 /**
442 * If this process was running instrumentation, finish now - it will be handled in
443 * {@link ActivityManagerService#handleAppDiedLocked}.
444 */
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700445 if (r != null && r.getActiveInstrumentation() != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100446 return;
447 }
448
449 // Log crash in battery stats.
450 if (r != null) {
451 mService.mBatteryStatsService.noteProcessCrash(r.processName, r.uid);
452 }
453
454 AppErrorDialog.Data data = new AppErrorDialog.Data();
455 data.result = result;
456 data.proc = r;
457
458 // If we can't identify the process or it's already exceeded its crash quota,
459 // quit right away without showing a crash dialog.
460 if (r == null || !makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace, data)) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100461 return;
462 }
463
Wale Ogunwale9645b0f2016-09-12 10:49:35 -0700464 final Message msg = Message.obtain();
Adrian Roos20d7df32016-01-12 18:59:43 +0100465 msg.what = ActivityManagerService.SHOW_ERROR_UI_MSG;
466
Wale Ogunwale64258362018-10-16 15:13:37 -0700467 taskId = data.taskId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100468 msg.obj = data;
469 mService.mUiHandler.sendMessage(msg);
Adrian Roos20d7df32016-01-12 18:59:43 +0100470 }
471
472 int res = result.get();
473
474 Intent appErrorIntent = null;
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700475 MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_CRASH, res);
Adrian Roosad028c12016-05-17 14:30:42 -0700476 if (res == AppErrorDialog.TIMEOUT || res == AppErrorDialog.CANCEL) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700477 res = AppErrorDialog.FORCE_QUIT;
478 }
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700479 synchronized (mService) {
480 if (res == AppErrorDialog.MUTE) {
481 stopReportingCrashesLocked(r);
482 }
483 if (res == AppErrorDialog.RESTART) {
Amith Yamasani98a00922018-08-21 12:50:30 -0400484 mService.mProcessList.removeProcessLocked(r, false, true, "crash");
Wale Ogunwale64258362018-10-16 15:13:37 -0700485 if (taskId != INVALID_TASK_ID) {
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700486 try {
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700487 mService.startActivityFromRecents(taskId,
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700488 ActivityOptions.makeBasic().toBundle());
489 } catch (IllegalArgumentException e) {
Wale Ogunwale64258362018-10-16 15:13:37 -0700490 // Hmm...that didn't work. Task should either be in recents or associated
491 // with a stack.
492 Slog.e(TAG, "Could not restart taskId=" + taskId, e);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700493 }
494 }
495 }
496 if (res == AppErrorDialog.FORCE_QUIT) {
497 long orig = Binder.clearCallingIdentity();
498 try {
499 // Kill it with fire!
Wale Ogunwale31913b52018-10-13 08:29:31 -0700500 mService.mAtmInternal.onHandleAppCrash(r.getWindowProcessController());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700501 if (!r.isPersistent()) {
Amith Yamasani98a00922018-08-21 12:50:30 -0400502 mService.mProcessList.removeProcessLocked(r, false, false, "crash");
Wale Ogunwale31913b52018-10-13 08:29:31 -0700503 mService.mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700504 }
505 } finally {
506 Binder.restoreCallingIdentity(orig);
507 }
508 }
Andrew Sapperstein5b679c42018-01-16 11:13:40 -0800509 if (res == AppErrorDialog.APP_INFO) {
510 appErrorIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
511 appErrorIntent.setData(Uri.parse("package:" + r.info.packageName));
512 appErrorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
513 }
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700514 if (res == AppErrorDialog.FORCE_QUIT_AND_REPORT) {
515 appErrorIntent = createAppErrorIntentLocked(r, timeMillis, crashInfo);
516 }
517 if (r != null && !r.isolated && res != AppErrorDialog.RESTART) {
518 // XXX Can't keep track of crash time for isolated processes,
519 // since they don't have a persistent identity.
520 mProcessCrashTimes.put(r.info.processName, r.uid,
521 SystemClock.uptimeMillis());
522 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100523 }
524
525 if (appErrorIntent != null) {
526 try {
527 mContext.startActivityAsUser(appErrorIntent, new UserHandle(r.userId));
528 } catch (ActivityNotFoundException e) {
529 Slog.w(TAG, "bug report receiver dissappeared", e);
530 }
531 }
532 }
533
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700534 private boolean handleAppCrashInActivityController(ProcessRecord r,
535 ApplicationErrorReport.CrashInfo crashInfo,
536 String shortMsg, String longMsg,
Mark Lub5e24992016-11-21 15:38:13 +0800537 String stackTrace, long timeMillis,
538 int callingPid, int callingUid) {
Wale Ogunwalee2172292018-10-25 10:11:10 -0700539 String name = r != null ? r.processName : null;
540 int pid = r != null ? r.pid : callingPid;
541 int uid = r != null ? r.info.uid : callingUid;
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700542
Wale Ogunwalee2172292018-10-25 10:11:10 -0700543 return mService.mAtmInternal.handleAppCrashInActivityController(
544 name, pid, shortMsg, longMsg, timeMillis, crashInfo.stackTrace, () -> {
545 if ("1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"))
546 && "Native crash".equals(crashInfo.exceptionClassName)) {
547 Slog.w(TAG, "Skip killing native crashed app " + name
548 + "(" + pid + ") during testing");
549 } else {
550 Slog.w(TAG, "Force-killing crashed app " + name + " at watcher's request");
551 if (r != null) {
552 if (!makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace, null)) {
553 r.kill("crash", true);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700554 }
Wale Ogunwalee2172292018-10-25 10:11:10 -0700555 } else {
556 // Huh.
557 Process.killProcess(pid);
558 ProcessList.killProcessGroup(uid, pid);
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700559 }
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700560 }
Wale Ogunwalee2172292018-10-25 10:11:10 -0700561 });
Andrii Kulianfa3991a2016-04-28 14:18:37 -0700562 }
563
Adrian Roos20d7df32016-01-12 18:59:43 +0100564 private boolean makeAppCrashingLocked(ProcessRecord app,
565 String shortMsg, String longMsg, String stackTrace, AppErrorDialog.Data data) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700566 app.setCrashing(true);
Adrian Roos20d7df32016-01-12 18:59:43 +0100567 app.crashingReport = generateProcessError(app,
568 ActivityManager.ProcessErrorStateInfo.CRASHED, null, shortMsg, longMsg, stackTrace);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700569 app.startAppProblemLocked();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700570 app.getWindowProcessController().stopFreezingActivities();
Adrian Roos20d7df32016-01-12 18:59:43 +0100571 return handleAppCrashLocked(app, "force-crash" /*reason*/, shortMsg, longMsg, stackTrace,
572 data);
573 }
574
Adrian Roos20d7df32016-01-12 18:59:43 +0100575 /**
576 * Generate a process error record, suitable for attachment to a ProcessRecord.
577 *
578 * @param app The ProcessRecord in which the error occurred.
579 * @param condition Crashing, Application Not Responding, etc. Values are defined in
Sudheer Shankaf6690102017-10-16 10:20:32 -0700580 * ActivityManager.ProcessErrorStateInfo
Adrian Roos20d7df32016-01-12 18:59:43 +0100581 * @param activity The activity associated with the crash, if known.
582 * @param shortMsg Short message describing the crash.
583 * @param longMsg Long message describing the crash.
584 * @param stackTrace Full crash stack trace, may be null.
585 *
Sudheer Shankaf6690102017-10-16 10:20:32 -0700586 * @return Returns a fully-formed ProcessErrorStateInfo record.
Adrian Roos20d7df32016-01-12 18:59:43 +0100587 */
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700588 ActivityManager.ProcessErrorStateInfo generateProcessError(ProcessRecord app,
Adrian Roos20d7df32016-01-12 18:59:43 +0100589 int condition, String activity, String shortMsg, String longMsg, String stackTrace) {
590 ActivityManager.ProcessErrorStateInfo report = new ActivityManager.ProcessErrorStateInfo();
591
592 report.condition = condition;
593 report.processName = app.processName;
594 report.pid = app.pid;
595 report.uid = app.info.uid;
596 report.tag = activity;
597 report.shortMsg = shortMsg;
598 report.longMsg = longMsg;
599 report.stackTrace = stackTrace;
600
601 return report;
602 }
603
604 Intent createAppErrorIntentLocked(ProcessRecord r,
605 long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
606 ApplicationErrorReport report = createAppErrorReportLocked(r, timeMillis, crashInfo);
607 if (report == null) {
608 return null;
609 }
610 Intent result = new Intent(Intent.ACTION_APP_ERROR);
611 result.setComponent(r.errorReportReceiver);
612 result.putExtra(Intent.EXTRA_BUG_REPORT, report);
613 result.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
614 return result;
615 }
616
617 private ApplicationErrorReport createAppErrorReportLocked(ProcessRecord r,
618 long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
619 if (r.errorReportReceiver == null) {
620 return null;
621 }
622
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700623 if (!r.isCrashing() && !r.isNotResponding() && !r.forceCrashReport) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100624 return null;
625 }
626
627 ApplicationErrorReport report = new ApplicationErrorReport();
628 report.packageName = r.info.packageName;
629 report.installerPackageName = r.errorReportReceiver.getPackageName();
630 report.processName = r.processName;
631 report.time = timeMillis;
Wale Ogunwale59507092018-10-29 09:00:30 -0700632 report.systemApp = (r.info.flags & FLAG_SYSTEM) != 0;
Adrian Roos20d7df32016-01-12 18:59:43 +0100633
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700634 if (r.isCrashing() || r.forceCrashReport) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100635 report.type = ApplicationErrorReport.TYPE_CRASH;
636 report.crashInfo = crashInfo;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700637 } else if (r.isNotResponding()) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100638 report.type = ApplicationErrorReport.TYPE_ANR;
639 report.anrInfo = new ApplicationErrorReport.AnrInfo();
640
641 report.anrInfo.activity = r.notRespondingReport.tag;
642 report.anrInfo.cause = r.notRespondingReport.shortMsg;
643 report.anrInfo.info = r.notRespondingReport.longMsg;
644 }
645
646 return report;
647 }
648
649 boolean handleAppCrashLocked(ProcessRecord app, String reason,
650 String shortMsg, String longMsg, String stackTrace, AppErrorDialog.Data data) {
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700651 final long now = SystemClock.uptimeMillis();
652 final boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
Adrian Roos6a7e0892016-08-23 14:26:39 +0200653 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
Adrian Roos20d7df32016-01-12 18:59:43 +0100654
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700655 final boolean procIsBoundForeground =
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700656 (app.getCurProcState() == ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700657
Adrian Roos20d7df32016-01-12 18:59:43 +0100658 Long crashTime;
659 Long crashTimePersistent;
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700660 boolean tryAgain = false;
661
Adrian Roos20d7df32016-01-12 18:59:43 +0100662 if (!app.isolated) {
663 crashTime = mProcessCrashTimes.get(app.info.processName, app.uid);
664 crashTimePersistent = mProcessCrashTimesPersistent.get(app.info.processName, app.uid);
665 } else {
666 crashTime = crashTimePersistent = null;
667 }
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700668
669 // Bump up the crash count of any services currently running in the proc.
670 for (int i = app.services.size() - 1; i >= 0; i--) {
671 // Any services running in the application need to be placed
672 // back in the pending list.
673 ServiceRecord sr = app.services.valueAt(i);
674 // If the service was restarted a while ago, then reset crash count, else increment it.
675 if (now > sr.restartTime + ProcessList.MIN_CRASH_INTERVAL) {
676 sr.crashCount = 1;
677 } else {
678 sr.crashCount++;
679 }
680 // Allow restarting for started or bound foreground services that are crashing.
681 // This includes wallpapers.
682 if (sr.crashCount < mService.mConstants.BOUND_SERVICE_MAX_CRASH_RETRY
683 && (sr.isForeground || procIsBoundForeground)) {
684 tryAgain = true;
685 }
686 }
687
688 if (crashTime != null && now < crashTime + ProcessList.MIN_CRASH_INTERVAL) {
689 // The process crashed again very quickly. If it was a bound foreground service, let's
690 // try to restart again in a while, otherwise the process loses!
Adrian Roos20d7df32016-01-12 18:59:43 +0100691 Slog.w(TAG, "Process " + app.info.processName
692 + " has crashed too many times: killing!");
693 EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
694 app.userId, app.info.processName, app.uid);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700695 mService.mAtmInternal.onHandleAppCrash(app.getWindowProcessController());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700696 if (!app.isPersistent()) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100697 // We don't want to start this process again until the user
698 // explicitly does so... but for persistent process, we really
699 // need to keep it running. If a persistent process is actually
700 // repeatedly crashing, then badness for everyone.
701 EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid,
702 app.info.processName);
703 if (!app.isolated) {
704 // XXX We don't have a way to mark isolated processes
705 // as bad, since they don't have a peristent identity.
706 mBadProcesses.put(app.info.processName, app.uid,
707 new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
708 mProcessCrashTimes.remove(app.info.processName, app.uid);
709 }
710 app.bad = true;
711 app.removed = true;
712 // Don't let services in this process be restarted and potentially
713 // annoy the user repeatedly. Unless it is persistent, since those
714 // processes run critical code.
Amith Yamasani98a00922018-08-21 12:50:30 -0400715 mService.mProcessList.removeProcessLocked(app, false, tryAgain, "crash");
Wale Ogunwale31913b52018-10-13 08:29:31 -0700716 mService.mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
Adrian Roos6a7e0892016-08-23 14:26:39 +0200717 if (!showBackground) {
718 return false;
719 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100720 }
Wale Ogunwale31913b52018-10-13 08:29:31 -0700721 mService.mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
Adrian Roos20d7df32016-01-12 18:59:43 +0100722 } else {
Wale Ogunwale64258362018-10-16 15:13:37 -0700723 final int affectedTaskId = mService.mAtmInternal.finishTopCrashedActivities(
Wale Ogunwale31913b52018-10-13 08:29:31 -0700724 app.getWindowProcessController(), reason);
Adrian Roos20d7df32016-01-12 18:59:43 +0100725 if (data != null) {
Wale Ogunwale64258362018-10-16 15:13:37 -0700726 data.taskId = affectedTaskId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100727 }
728 if (data != null && crashTimePersistent != null
729 && now < crashTimePersistent + ProcessList.MIN_CRASH_INTERVAL) {
730 data.repeating = true;
731 }
732 }
733
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700734 if (data != null && tryAgain) {
735 data.isRestartableForService = true;
Adrian Roos20d7df32016-01-12 18:59:43 +0100736 }
737
738 // If the crashing process is what we consider to be the "home process" and it has been
739 // replaced by a third-party app, clear the package preferred activities from packages
740 // with a home activity running in the process to prevent a repeatedly crashing app
741 // from blocking the user to manually clear the list.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700742 final WindowProcessController proc = app.getWindowProcessController();
Wale Ogunwaled4d67d02018-10-25 18:09:39 -0700743 final WindowProcessController homeProc = mService.mAtmInternal.getHomeProcess();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700744 if (proc == homeProc && proc.hasActivities()
Wale Ogunwale59507092018-10-29 09:00:30 -0700745 && (((ProcessRecord) homeProc.mOwner).info.flags & FLAG_SYSTEM) == 0) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700746 proc.clearPackagePreferredForHomeActivities();
Adrian Roos20d7df32016-01-12 18:59:43 +0100747 }
748
749 if (!app.isolated) {
750 // XXX Can't keep track of crash times for isolated processes,
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700751 // because they don't have a persistent identity.
Adrian Roos20d7df32016-01-12 18:59:43 +0100752 mProcessCrashTimes.put(app.info.processName, app.uid, now);
753 mProcessCrashTimesPersistent.put(app.info.processName, app.uid, now);
754 }
755
756 if (app.crashHandler != null) mService.mHandler.post(app.crashHandler);
757 return true;
758 }
759
760 void handleShowAppErrorUi(Message msg) {
761 AppErrorDialog.Data data = (AppErrorDialog.Data) msg.obj;
762 boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
763 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
Adrian Roosc3a06e52018-02-16 18:33:17 +0100764
765 AppErrorDialog dialogToShow = null;
766 final String packageName;
767 final int userId;
Adrian Roos20d7df32016-01-12 18:59:43 +0100768 synchronized (mService) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100769 final ProcessRecord proc = data.proc;
770 final AppErrorResult res = data.result;
771 if (proc == null) {
772 Slog.e(TAG, "handleShowAppErrorUi: proc is null");
773 return;
774 }
775 packageName = proc.info.packageName;
776 userId = proc.userId;
777 if (proc.crashDialog != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100778 Slog.e(TAG, "App already has crash dialog: " + proc);
779 if (res != null) {
Adrian Roos90462222016-02-17 15:45:09 -0800780 res.set(AppErrorDialog.ALREADY_SHOWING);
Adrian Roos20d7df32016-01-12 18:59:43 +0100781 }
782 return;
783 }
784 boolean isBackground = (UserHandle.getAppId(proc.uid)
785 >= Process.FIRST_APPLICATION_UID
786 && proc.pid != MY_PID);
Adrian Roosc3a06e52018-02-16 18:33:17 +0100787 for (int profileId : mService.mUserController.getCurrentProfileIds()) {
788 isBackground &= (userId != profileId);
Adrian Roos20d7df32016-01-12 18:59:43 +0100789 }
790 if (isBackground && !showBackground) {
791 Slog.w(TAG, "Skipping crash dialog of " + proc + ": background");
792 if (res != null) {
Adrian Roos90462222016-02-17 15:45:09 -0800793 res.set(AppErrorDialog.BACKGROUND_USER);
Adrian Roos20d7df32016-01-12 18:59:43 +0100794 }
795 return;
796 }
Andrew Sapperstein43643ae2017-12-20 15:17:33 -0800797 final boolean showFirstCrash = Settings.Global.getInt(
798 mContext.getContentResolver(),
799 Settings.Global.SHOW_FIRST_CRASH_DIALOG, 0) != 0;
800 final boolean showFirstCrashDevOption = Settings.Secure.getIntForUser(
801 mContext.getContentResolver(),
802 Settings.Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION,
803 0,
Andrew Sappersteinfd5238c2018-01-21 09:45:05 -0800804 mService.mUserController.getCurrentUserId()) != 0;
Adrian Roos20d7df32016-01-12 18:59:43 +0100805 final boolean crashSilenced = mAppsNotReportingCrashes != null &&
806 mAppsNotReportingCrashes.contains(proc.info.packageName);
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700807 if ((mService.mAtmInternal.canShowErrorDialogs() || showBackground)
Wale Ogunwalef6733932018-06-27 05:14:34 -0700808 && !crashSilenced
Andrew Sapperstein43643ae2017-12-20 15:17:33 -0800809 && (showFirstCrash || showFirstCrashDevOption || data.repeating)) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100810 proc.crashDialog = dialogToShow = new AppErrorDialog(mContext, mService, data);
Adrian Roos20d7df32016-01-12 18:59:43 +0100811 } else {
812 // The device is asleep, so just pretend that the user
813 // saw a crash dialog and hit "force quit".
814 if (res != null) {
Adrian Roos90462222016-02-17 15:45:09 -0800815 res.set(AppErrorDialog.CANT_SHOW);
Adrian Roos20d7df32016-01-12 18:59:43 +0100816 }
817 }
818 }
Phil Weaver445fd2a2016-03-17 17:26:24 -0700819 // If we've created a crash dialog, show it without the lock held
Adrian Roosc3a06e52018-02-16 18:33:17 +0100820 if (dialogToShow != null) {
821 Slog.i(TAG, "Showing crash dialog for package " + packageName + " u" + userId);
822 dialogToShow.show();
Phil Weaver445fd2a2016-03-17 17:26:24 -0700823 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100824 }
825
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700826 private void stopReportingCrashesLocked(ProcessRecord proc) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100827 if (mAppsNotReportingCrashes == null) {
828 mAppsNotReportingCrashes = new ArraySet<>();
829 }
830 mAppsNotReportingCrashes.add(proc.info.packageName);
831 }
832
Adrian Roos20d7df32016-01-12 18:59:43 +0100833 void handleShowAnrUi(Message msg) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100834 Dialog dialogToShow = null;
Zimuzo972e1cd2019-01-28 16:30:01 +0000835 List<VersionedPackage> packageList = null;
Adrian Roos20d7df32016-01-12 18:59:43 +0100836 synchronized (mService) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100837 AppNotRespondingDialog.Data data = (AppNotRespondingDialog.Data) msg.obj;
838 final ProcessRecord proc = data.proc;
839 if (proc == null) {
840 Slog.e(TAG, "handleShowAnrUi: proc is null");
841 return;
842 }
Zimuzo6efba542018-11-29 12:47:58 +0000843 if (!proc.isPersistent()) {
Zimuzo972e1cd2019-01-28 16:30:01 +0000844 packageList = proc.getPackageListWithVersionCode();
Zimuzo6efba542018-11-29 12:47:58 +0000845 }
Adrian Roosc3a06e52018-02-16 18:33:17 +0100846 if (proc.anrDialog != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100847 Slog.e(TAG, "App already has anr dialog: " + proc);
Adrian Roos90462222016-02-17 15:45:09 -0800848 MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_ANR,
849 AppNotRespondingDialog.ALREADY_SHOWING);
Adrian Roos20d7df32016-01-12 18:59:43 +0100850 return;
851 }
852
Adrian Roos6a7e0892016-08-23 14:26:39 +0200853 boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
854 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700855 if (mService.mAtmInternal.canShowErrorDialogs() || showBackground) {
Adrian Roosc3a06e52018-02-16 18:33:17 +0100856 dialogToShow = new AppNotRespondingDialog(mService, mContext, data);
857 proc.anrDialog = dialogToShow;
Adrian Roos20d7df32016-01-12 18:59:43 +0100858 } else {
Adrian Roos90462222016-02-17 15:45:09 -0800859 MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_ANR,
860 AppNotRespondingDialog.CANT_SHOW);
Adrian Roos20d7df32016-01-12 18:59:43 +0100861 // Just kill the app if there is no dialog to be shown.
862 mService.killAppAtUsersRequest(proc, null);
863 }
864 }
Phil Weaver445fd2a2016-03-17 17:26:24 -0700865 // If we've created a crash dialog, show it without the lock held
Adrian Roosc3a06e52018-02-16 18:33:17 +0100866 if (dialogToShow != null) {
867 dialogToShow.show();
Phil Weaver445fd2a2016-03-17 17:26:24 -0700868 }
Zimuzo6efba542018-11-29 12:47:58 +0000869 // Notify PackageWatchdog without the lock held
870 if (packageList != null) {
871 mPackageWatchdog.onPackageFailure(packageList);
872 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100873 }
874
875 /**
876 * Information about a process that is currently marked as bad.
877 */
878 static final class BadProcessInfo {
879 BadProcessInfo(long time, String shortMsg, String longMsg, String stack) {
880 this.time = time;
881 this.shortMsg = shortMsg;
882 this.longMsg = longMsg;
883 this.stack = stack;
884 }
885
886 final long time;
887 final String shortMsg;
888 final String longMsg;
889 final String stack;
890 }
891
892}