1 /* 2 * Copyright (C) 2020 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 17 package com.android.server.am; 18 19 import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST; 20 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR; 21 import static com.android.server.am.ActivityManagerService.MY_PID; 22 import static com.android.server.am.ProcessRecord.TAG; 23 24 import android.app.ActivityManager; 25 import android.app.AnrController; 26 import android.app.ApplicationErrorReport; 27 import android.app.ApplicationExitInfo; 28 import android.content.ComponentName; 29 import android.content.Context; 30 import android.content.pm.ApplicationInfo; 31 import android.content.pm.IncrementalStatesInfo; 32 import android.content.pm.PackageManagerInternal; 33 import android.os.IBinder; 34 import android.os.Message; 35 import android.os.Process; 36 import android.os.ServiceManager; 37 import android.os.SystemClock; 38 import android.os.incremental.IIncrementalService; 39 import android.os.incremental.IncrementalManager; 40 import android.os.incremental.IncrementalMetrics; 41 import android.provider.Settings; 42 import android.util.EventLog; 43 import android.util.Slog; 44 import android.util.SparseArray; 45 46 import com.android.internal.annotations.CompositeRWLock; 47 import com.android.internal.annotations.GuardedBy; 48 import com.android.internal.annotations.VisibleForTesting; 49 import com.android.internal.os.ProcessCpuTracker; 50 import com.android.internal.util.FrameworkStatsLog; 51 import com.android.server.MemoryPressureUtil; 52 import com.android.server.wm.WindowProcessController; 53 54 import java.io.File; 55 import java.io.PrintWriter; 56 import java.io.StringWriter; 57 import java.util.ArrayList; 58 import java.util.UUID; 59 /** 60 * The error state of the process, such as if it's crashing/ANR etc. 61 */ 62 class ProcessErrorStateRecord { 63 final ProcessRecord mApp; 64 private final ActivityManagerService mService; 65 66 private final ActivityManagerGlobalLock mProcLock; 67 68 /** 69 * True if disabled in the bad process list. 70 */ 71 @CompositeRWLock({"mService", "mProcLock"}) 72 private boolean mBad; 73 74 /** 75 * Are we in the process of crashing? 76 */ 77 @CompositeRWLock({"mService", "mProcLock"}) 78 private boolean mCrashing; 79 80 /** 81 * Suppress normal auto-dismiss of crash dialog & report UI? 82 */ 83 @CompositeRWLock({"mService", "mProcLock"}) 84 private boolean mForceCrashReport; 85 86 /** 87 * Does the app have a not responding dialog? 88 */ 89 @CompositeRWLock({"mService", "mProcLock"}) 90 private boolean mNotResponding; 91 92 /** 93 * The report about crash of the app, generated & stored when an app gets into a crash. 94 * Will be "null" when all is OK. 95 */ 96 @CompositeRWLock({"mService", "mProcLock"}) 97 private ActivityManager.ProcessErrorStateInfo mCrashingReport; 98 99 /** 100 * The report about ANR of the app, generated & stored when an app gets into an ANR. 101 * Will be "null" when all is OK. 102 */ 103 @CompositeRWLock({"mService", "mProcLock"}) 104 private ActivityManager.ProcessErrorStateInfo mNotRespondingReport; 105 106 /** 107 * Controller for error dialogs. 108 */ 109 @CompositeRWLock({"mService", "mProcLock"}) 110 private final ErrorDialogController mDialogController; 111 112 /** 113 * Who will be notified of the error. This is usually an activity in the 114 * app that installed the package. 115 */ 116 @CompositeRWLock({"mService", "mProcLock"}) 117 private ComponentName mErrorReportReceiver; 118 119 /** 120 * Optional local handler to be invoked in the process crash. 121 */ 122 @CompositeRWLock({"mService", "mProcLock"}) 123 private Runnable mCrashHandler; 124 125 @GuardedBy(anyOf = {"mService", "mProcLock"}) isBad()126 boolean isBad() { 127 return mBad; 128 } 129 130 @GuardedBy({"mService", "mProcLock"}) setBad(boolean bad)131 void setBad(boolean bad) { 132 mBad = bad; 133 } 134 135 @GuardedBy(anyOf = {"mService", "mProcLock"}) isCrashing()136 boolean isCrashing() { 137 return mCrashing; 138 } 139 140 @GuardedBy({"mService", "mProcLock"}) setCrashing(boolean crashing)141 void setCrashing(boolean crashing) { 142 mCrashing = crashing; 143 mApp.getWindowProcessController().setCrashing(crashing); 144 } 145 146 @GuardedBy(anyOf = {"mService", "mProcLock"}) isForceCrashReport()147 boolean isForceCrashReport() { 148 return mForceCrashReport; 149 } 150 151 @GuardedBy({"mService", "mProcLock"}) setForceCrashReport(boolean forceCrashReport)152 void setForceCrashReport(boolean forceCrashReport) { 153 mForceCrashReport = forceCrashReport; 154 } 155 156 @GuardedBy(anyOf = {"mService", "mProcLock"}) isNotResponding()157 boolean isNotResponding() { 158 return mNotResponding; 159 } 160 161 @GuardedBy({"mService", "mProcLock"}) setNotResponding(boolean notResponding)162 void setNotResponding(boolean notResponding) { 163 mNotResponding = notResponding; 164 mApp.getWindowProcessController().setNotResponding(notResponding); 165 } 166 167 @GuardedBy(anyOf = {"mService", "mProcLock"}) getCrashHandler()168 Runnable getCrashHandler() { 169 return mCrashHandler; 170 } 171 172 @GuardedBy({"mService", "mProcLock"}) setCrashHandler(Runnable crashHandler)173 void setCrashHandler(Runnable crashHandler) { 174 mCrashHandler = crashHandler; 175 } 176 177 @GuardedBy(anyOf = {"mService", "mProcLock"}) getCrashingReport()178 ActivityManager.ProcessErrorStateInfo getCrashingReport() { 179 return mCrashingReport; 180 } 181 182 @GuardedBy({"mService", "mProcLock"}) setCrashingReport(ActivityManager.ProcessErrorStateInfo crashingReport)183 void setCrashingReport(ActivityManager.ProcessErrorStateInfo crashingReport) { 184 mCrashingReport = crashingReport; 185 } 186 187 @GuardedBy(anyOf = {"mService", "mProcLock"}) getNotRespondingReport()188 ActivityManager.ProcessErrorStateInfo getNotRespondingReport() { 189 return mNotRespondingReport; 190 } 191 192 @GuardedBy({"mService", "mProcLock"}) setNotRespondingReport(ActivityManager.ProcessErrorStateInfo notRespondingReport)193 void setNotRespondingReport(ActivityManager.ProcessErrorStateInfo notRespondingReport) { 194 mNotRespondingReport = notRespondingReport; 195 } 196 197 @GuardedBy(anyOf = {"mService", "mProcLock"}) getErrorReportReceiver()198 ComponentName getErrorReportReceiver() { 199 return mErrorReportReceiver; 200 } 201 202 @GuardedBy({"mService", "mProcLock"}) setErrorReportReceiver(ComponentName errorReportReceiver)203 void setErrorReportReceiver(ComponentName errorReportReceiver) { 204 mErrorReportReceiver = errorReportReceiver; 205 } 206 207 @GuardedBy(anyOf = {"mService", "mProcLock"}) getDialogController()208 ErrorDialogController getDialogController() { 209 return mDialogController; 210 } 211 ProcessErrorStateRecord(ProcessRecord app)212 ProcessErrorStateRecord(ProcessRecord app) { 213 mApp = app; 214 mService = app.mService; 215 mProcLock = mService.mProcLock; 216 mDialogController = new ErrorDialogController(app); 217 } 218 appNotResponding(String activityShortComponentName, ApplicationInfo aInfo, String parentShortComponentName, WindowProcessController parentProcess, boolean aboveSystem, String annotation, boolean onlyDumpSelf)219 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo, 220 String parentShortComponentName, WindowProcessController parentProcess, 221 boolean aboveSystem, String annotation, boolean onlyDumpSelf) { 222 ArrayList<Integer> firstPids = new ArrayList<>(5); 223 SparseArray<Boolean> lastPids = new SparseArray<>(20); 224 225 mApp.getWindowProcessController().appEarlyNotResponding(annotation, () -> { 226 synchronized (mService) { 227 mApp.killLocked("anr", ApplicationExitInfo.REASON_ANR, true); 228 } 229 }); 230 231 long anrTime = SystemClock.uptimeMillis(); 232 if (isMonitorCpuUsage()) { 233 mService.updateCpuStatsNow(); 234 } 235 236 final boolean isSilentAnr; 237 final int pid = mApp.getPid(); 238 final UUID errorId; 239 synchronized (mService) { 240 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down. 241 if (mService.mAtmInternal.isShuttingDown()) { 242 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation); 243 return; 244 } else if (isNotResponding()) { 245 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation); 246 return; 247 } else if (isCrashing()) { 248 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation); 249 return; 250 } else if (mApp.isKilledByAm()) { 251 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation); 252 return; 253 } else if (mApp.isKilled()) { 254 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation); 255 return; 256 } 257 258 // In case we come through here for the same app before completing 259 // this one, mark as anring now so we will bail out. 260 synchronized (mProcLock) { 261 setNotResponding(true); 262 } 263 264 // Log the ANR to the event log. 265 EventLog.writeEvent(EventLogTags.AM_ANR, mApp.userId, pid, mApp.processName, 266 mApp.info.flags, annotation); 267 268 if (mService.mTraceErrorLogger.isAddErrorIdEnabled()) { 269 errorId = mService.mTraceErrorLogger.generateErrorId(); 270 mService.mTraceErrorLogger.addErrorIdToTrace(mApp.processName, errorId); 271 } else { 272 errorId = null; 273 } 274 275 // This atom is only logged with the purpose of triggering Perfetto and the logging 276 // needs to happen as close as possible to the time when the ANR is detected. 277 // Also, it needs to be logged after adding the error id to the trace, to make sure 278 // the error id is present in the trace when the Perfetto trace is captured. 279 FrameworkStatsLog.write(FrameworkStatsLog.ANR_OCCURRED_PROCESSING_STARTED, 280 mApp.processName); 281 282 // Dump thread traces as quickly as we can, starting with "interesting" processes. 283 firstPids.add(pid); 284 285 // Don't dump other PIDs if it's a background ANR or is requested to only dump self. 286 isSilentAnr = isSilentAnr(); 287 if (!isSilentAnr && !onlyDumpSelf) { 288 int parentPid = pid; 289 if (parentProcess != null && parentProcess.getPid() > 0) { 290 parentPid = parentProcess.getPid(); 291 } 292 if (parentPid != pid) firstPids.add(parentPid); 293 294 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID); 295 296 final int ppid = parentPid; 297 mService.mProcessList.forEachLruProcessesLOSP(false, r -> { 298 if (r != null && r.getThread() != null) { 299 int myPid = r.getPid(); 300 if (myPid > 0 && myPid != pid && myPid != ppid && myPid != MY_PID) { 301 if (r.isPersistent()) { 302 firstPids.add(myPid); 303 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r); 304 } else if (r.mServices.isTreatedLikeActivity()) { 305 firstPids.add(myPid); 306 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r); 307 } else { 308 lastPids.put(myPid, Boolean.TRUE); 309 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r); 310 } 311 } 312 } 313 }); 314 } 315 } 316 317 // Log the ANR to the main log. 318 StringBuilder info = new StringBuilder(); 319 info.setLength(0); 320 info.append("ANR in ").append(mApp.processName); 321 if (activityShortComponentName != null) { 322 info.append(" (").append(activityShortComponentName).append(")"); 323 } 324 info.append("\n"); 325 info.append("PID: ").append(pid).append("\n"); 326 if (annotation != null) { 327 info.append("Reason: ").append(annotation).append("\n"); 328 } 329 if (parentShortComponentName != null 330 && parentShortComponentName.equals(activityShortComponentName)) { 331 info.append("Parent: ").append(parentShortComponentName).append("\n"); 332 } 333 if (errorId != null) { 334 info.append("ErrorId: ").append(errorId.toString()).append("\n"); 335 } 336 info.append("Frozen: ").append(mApp.mOptRecord.isFrozen()).append("\n"); 337 338 // Retrieve controller with max ANR delay from AnrControllers 339 // Note that we retrieve the controller before dumping stacks because dumping stacks can 340 // take a few seconds, after which the cause of the ANR delay might have completed and 341 // there might no longer be a valid ANR controller to cancel the dialog in that case 342 AnrController anrController = mService.mActivityTaskManager.getAnrController(aInfo); 343 long anrDialogDelayMs = 0; 344 if (anrController != null) { 345 String packageName = aInfo.packageName; 346 int uid = aInfo.uid; 347 anrDialogDelayMs = anrController.getAnrDelayMillis(packageName, uid); 348 // Might execute an async binder call to a system app to show an interim 349 // ANR progress UI 350 anrController.onAnrDelayStarted(packageName, uid); 351 Slog.i(TAG, "ANR delay of " + anrDialogDelayMs + "ms started for " + packageName); 352 } 353 354 StringBuilder report = new StringBuilder(); 355 report.append(MemoryPressureUtil.currentPsiState()); 356 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true); 357 358 // don't dump native PIDs for background ANRs unless it is the process of interest 359 String[] nativeProcs = null; 360 if (isSilentAnr || onlyDumpSelf) { 361 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) { 362 if (NATIVE_STACKS_OF_INTEREST[i].equals(mApp.processName)) { 363 nativeProcs = new String[] { mApp.processName }; 364 break; 365 } 366 } 367 } else { 368 nativeProcs = NATIVE_STACKS_OF_INTEREST; 369 } 370 371 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs); 372 ArrayList<Integer> nativePids = null; 373 374 if (pids != null) { 375 nativePids = new ArrayList<>(pids.length); 376 for (int i : pids) { 377 nativePids.add(i); 378 } 379 } 380 381 // For background ANRs, don't pass the ProcessCpuTracker to 382 // avoid spending 1/2 second collecting stats to rank lastPids. 383 StringWriter tracesFileException = new StringWriter(); 384 // To hold the start and end offset to the ANR trace file respectively. 385 final long[] offsets = new long[2]; 386 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids, 387 isSilentAnr ? null : processCpuTracker, isSilentAnr ? null : lastPids, 388 nativePids, tracesFileException, offsets, annotation); 389 390 if (isMonitorCpuUsage()) { 391 mService.updateCpuStatsNow(); 392 mService.mAppProfiler.printCurrentCpuState(report, anrTime); 393 info.append(processCpuTracker.printCurrentLoad()); 394 info.append(report); 395 } 396 report.append(tracesFileException.getBuffer()); 397 398 info.append(processCpuTracker.printCurrentState(anrTime)); 399 400 Slog.e(TAG, info.toString()); 401 if (tracesFile == null) { 402 // There is no trace file, so dump (only) the alleged culprit's threads to the log 403 Process.sendSignal(pid, Process.SIGNAL_QUIT); 404 } else if (offsets[1] > 0) { 405 // We've dumped into the trace file successfully 406 mService.mProcessList.mAppExitInfoTracker.scheduleLogAnrTrace( 407 pid, mApp.uid, mApp.getPackageList(), tracesFile, offsets[0], offsets[1]); 408 } 409 410 // Check if package is still being loaded 411 float loadingProgress = 1; 412 IncrementalMetrics incrementalMetrics = null; 413 final PackageManagerInternal packageManagerInternal = mService.getPackageManagerInternal(); 414 if (mApp.info != null && mApp.info.packageName != null) { 415 IncrementalStatesInfo incrementalStatesInfo = 416 packageManagerInternal.getIncrementalStatesInfo( 417 mApp.info.packageName, mApp.uid, mApp.userId); 418 if (incrementalStatesInfo != null) { 419 loadingProgress = incrementalStatesInfo.getProgress(); 420 } 421 final String codePath = mApp.info.getCodePath(); 422 if (codePath != null && !codePath.isEmpty() 423 && IncrementalManager.isIncrementalPath(codePath)) { 424 // Report in the main log that the incremental package is still loading 425 Slog.e(TAG, "App ANR on incremental package " + mApp.info.packageName 426 + " which is " + ((int) (loadingProgress * 100)) + "% loaded."); 427 final IBinder incrementalService = ServiceManager.getService( 428 Context.INCREMENTAL_SERVICE); 429 if (incrementalService != null) { 430 final IncrementalManager incrementalManager = new IncrementalManager( 431 IIncrementalService.Stub.asInterface(incrementalService)); 432 incrementalMetrics = incrementalManager.getMetrics(codePath); 433 } 434 } 435 } 436 if (incrementalMetrics != null) { 437 // Report in the main log about the incremental package 438 info.append("Package is ").append((int) (loadingProgress * 100)).append("% loaded.\n"); 439 } 440 441 FrameworkStatsLog.write(FrameworkStatsLog.ANR_OCCURRED, mApp.uid, mApp.processName, 442 activityShortComponentName == null ? "unknown" : activityShortComponentName, 443 annotation, 444 (mApp.info != null) ? (mApp.info.isInstantApp() 445 ? FrameworkStatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE 446 : FrameworkStatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE) 447 : FrameworkStatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE, 448 mApp.isInterestingToUserLocked() 449 ? FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND 450 : FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND, 451 mApp.getProcessClassEnum(), 452 (mApp.info != null) ? mApp.info.packageName : "", 453 incrementalMetrics != null /* isIncremental */, loadingProgress, 454 incrementalMetrics != null ? incrementalMetrics.getMillisSinceOldestPendingRead() 455 : -1, 456 incrementalMetrics != null ? incrementalMetrics.getStorageHealthStatusCode() 457 : -1, 458 incrementalMetrics != null ? incrementalMetrics.getDataLoaderStatusCode() 459 : -1, 460 incrementalMetrics != null && incrementalMetrics.getReadLogsEnabled(), 461 incrementalMetrics != null ? incrementalMetrics.getMillisSinceLastDataLoaderBind() 462 : -1, 463 incrementalMetrics != null ? incrementalMetrics.getDataLoaderBindDelayMillis() 464 : -1, 465 incrementalMetrics != null ? incrementalMetrics.getTotalDelayedReads() 466 : -1, 467 incrementalMetrics != null ? incrementalMetrics.getTotalFailedReads() 468 : -1, 469 incrementalMetrics != null ? incrementalMetrics.getLastReadErrorUid() 470 : -1, 471 incrementalMetrics != null ? incrementalMetrics.getMillisSinceLastReadError() 472 : -1, 473 incrementalMetrics != null ? incrementalMetrics.getLastReadErrorNumber() 474 : 0, 475 incrementalMetrics != null ? incrementalMetrics.getTotalDelayedReadsDurationMillis() 476 : -1); 477 final ProcessRecord parentPr = parentProcess != null 478 ? (ProcessRecord) parentProcess.mOwner : null; 479 mService.addErrorToDropBox("anr", mApp, mApp.processName, activityShortComponentName, 480 parentShortComponentName, parentPr, null, report.toString(), tracesFile, 481 null, new Float(loadingProgress), incrementalMetrics, errorId); 482 483 if (mApp.getWindowProcessController().appNotResponding(info.toString(), 484 () -> { 485 synchronized (mService) { 486 mApp.killLocked("anr", ApplicationExitInfo.REASON_ANR, true); 487 } 488 }, 489 () -> { 490 synchronized (mService) { 491 mService.mServices.scheduleServiceTimeoutLocked(mApp); 492 } 493 })) { 494 return; 495 } 496 497 synchronized (mService) { 498 // mBatteryStatsService can be null if the AMS is constructed with injector only. This 499 // will only happen in tests. 500 if (mService.mBatteryStatsService != null) { 501 mService.mBatteryStatsService.noteProcessAnr(mApp.processName, mApp.uid); 502 } 503 504 if (isSilentAnr() && !mApp.isDebugging()) { 505 mApp.killLocked("bg anr", ApplicationExitInfo.REASON_ANR, true); 506 return; 507 } 508 509 synchronized (mProcLock) { 510 // Set the app's notResponding state, and look up the errorReportReceiver 511 makeAppNotRespondingLSP(activityShortComponentName, 512 annotation != null ? "ANR " + annotation : "ANR", info.toString()); 513 mDialogController.setAnrController(anrController); 514 } 515 516 // mUiHandler can be null if the AMS is constructed with injector only. This will only 517 // happen in tests. 518 if (mService.mUiHandler != null) { 519 // Bring up the infamous App Not Responding dialog 520 Message msg = Message.obtain(); 521 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG; 522 msg.obj = new AppNotRespondingDialog.Data(mApp, aInfo, aboveSystem); 523 524 mService.mUiHandler.sendMessageDelayed(msg, anrDialogDelayMs); 525 } 526 } 527 } 528 529 @GuardedBy({"mService", "mProcLock"}) makeAppNotRespondingLSP(String activity, String shortMsg, String longMsg)530 private void makeAppNotRespondingLSP(String activity, String shortMsg, String longMsg) { 531 setNotResponding(true); 532 // mAppErrors can be null if the AMS is constructed with injector only. This will only 533 // happen in tests. 534 if (mService.mAppErrors != null) { 535 mNotRespondingReport = mService.mAppErrors.generateProcessError(mApp, 536 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING, 537 activity, shortMsg, longMsg, null); 538 } 539 startAppProblemLSP(); 540 mApp.getWindowProcessController().stopFreezingActivities(); 541 } 542 543 @GuardedBy({"mService", "mProcLock"}) startAppProblemLSP()544 void startAppProblemLSP() { 545 // If this app is not running under the current user, then we can't give it a report button 546 // because that would require launching the report UI under a different user. 547 mErrorReportReceiver = null; 548 549 for (int userId : mService.mUserController.getCurrentProfileIds()) { 550 if (mApp.userId == userId) { 551 mErrorReportReceiver = ApplicationErrorReport.getErrorReportReceiver( 552 mService.mContext, mApp.info.packageName, mApp.info.flags); 553 } 554 } 555 mService.skipCurrentReceiverLocked(mApp); 556 } 557 558 @GuardedBy("mService") isInterestingForBackgroundTraces()559 private boolean isInterestingForBackgroundTraces() { 560 // The system_server is always considered interesting. 561 if (mApp.getPid() == MY_PID) { 562 return true; 563 } 564 565 // A package is considered interesting if any of the following is true : 566 // 567 // - It's displaying an activity. 568 // - It's the SystemUI. 569 // - It has an overlay or a top UI visible. 570 // 571 // NOTE: The check whether a given ProcessRecord belongs to the systemui 572 // process is a bit of a kludge, but the same pattern seems repeated at 573 // several places in the system server. 574 return mApp.isInterestingToUserLocked() 575 || (mApp.info != null && "com.android.systemui".equals(mApp.info.packageName)) 576 || (mApp.mState.hasTopUi() || mApp.mState.hasOverlayUi()); 577 } 578 getShowBackground()579 private boolean getShowBackground() { 580 return Settings.Secure.getInt(mService.mContext.getContentResolver(), 581 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0; 582 } 583 584 /** 585 * Unless configured otherwise, swallow ANRs in background processes & kill the process. 586 * Non-private access is for tests only. 587 */ 588 @VisibleForTesting 589 @GuardedBy("mService") isSilentAnr()590 boolean isSilentAnr() { 591 return !getShowBackground() && !isInterestingForBackgroundTraces(); 592 } 593 594 /** Non-private access is for tests only. */ 595 @VisibleForTesting isMonitorCpuUsage()596 boolean isMonitorCpuUsage() { 597 return mService.mAppProfiler.MONITOR_CPU_USAGE; 598 } 599 600 @GuardedBy({"mService", "mProcLock"}) onCleanupApplicationRecordLSP()601 void onCleanupApplicationRecordLSP() { 602 // Dismiss any open dialogs. 603 getDialogController().clearAllErrorDialogs(); 604 605 setCrashing(false); 606 setNotResponding(false); 607 } 608 dump(PrintWriter pw, String prefix, long nowUptime)609 void dump(PrintWriter pw, String prefix, long nowUptime) { 610 synchronized (mProcLock) { 611 if (mCrashing || mDialogController.hasCrashDialogs() || mNotResponding 612 || mDialogController.hasAnrDialogs() || mBad) { 613 pw.print(prefix); 614 pw.print(" mCrashing=" + mCrashing); 615 pw.print(" " + mDialogController.getCrashDialogs()); 616 pw.print(" mNotResponding=" + mNotResponding); 617 pw.print(" " + mDialogController.getAnrDialogs()); 618 pw.print(" bad=" + mBad); 619 620 // mCrashing or mNotResponding is always set before errorReportReceiver 621 if (mErrorReportReceiver != null) { 622 pw.print(" errorReportReceiver="); 623 pw.print(mErrorReportReceiver.flattenToShortString()); 624 } 625 pw.println(); 626 } 627 } 628 } 629 } 630