The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
riddle_hsu | 6793fc3 | 2015-03-31 11:54:14 +0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 20 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 21 | import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST; |
| 22 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 23 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 24 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 25 | import static com.android.server.am.ActivityManagerService.MY_PID; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 26 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.app.ActivityManager; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 28 | import android.app.ApplicationErrorReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.app.Dialog; |
| 30 | import android.app.IApplicationThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 32 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 34 | import android.content.res.CompatibilityInfo; |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 35 | import android.os.Binder; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 36 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.IBinder; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 38 | import android.os.Message; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 39 | import android.os.Process; |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 40 | import android.os.RemoteException; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 41 | import android.os.SystemClock; |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 42 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 43 | import android.os.UserHandle; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 44 | import android.provider.Settings; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 45 | import android.util.ArrayMap; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 46 | import android.util.ArraySet; |
| 47 | import android.util.DebugUtils; |
| 48 | import android.util.EventLog; |
| 49 | import android.util.Slog; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 50 | import android.util.SparseArray; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 51 | import android.util.StatsLog; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 52 | import android.util.TimeUtils; |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 53 | import android.util.proto.ProtoOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 55 | import com.android.internal.app.procstats.ProcessState; |
| 56 | import com.android.internal.app.procstats.ProcessStats; |
| 57 | import com.android.internal.os.BatteryStatsImpl; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 58 | import com.android.internal.os.ProcessCpuTracker; |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame^] | 59 | import com.android.internal.os.Zygote; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 60 | import com.android.server.wm.WindowProcessController; |
| 61 | import com.android.server.wm.WindowProcessListener; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 62 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 63 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import java.io.PrintWriter; |
| 65 | import java.util.ArrayList; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 66 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Full information about a particular process that |
| 70 | * is currently running. |
| 71 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 72 | final class ProcessRecord implements WindowProcessListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 73 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM; |
| 74 | |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 75 | private final ActivityManagerService mService; // where we came from |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | final ApplicationInfo info; // all about the first app in the process |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 77 | final boolean isolated; // true if this is a special isolated process |
| 78 | final int uid; // uid of process; may be different from 'info' if isolated |
| 79 | final int userId; // user of process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | final String processName; // name of the process |
| 81 | // List of packages running in the process |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 82 | final PackageList pkgList = new PackageList(); |
| 83 | final class PackageList { |
| 84 | final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>(); |
| 85 | |
| 86 | ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) { |
| 87 | mWindowProcessController.addPackage(key); |
| 88 | return mPkgList.put(key, value); |
| 89 | } |
| 90 | |
| 91 | void clear() { |
| 92 | mPkgList.clear(); |
| 93 | mWindowProcessController.clearPackageList(); |
| 94 | } |
| 95 | |
| 96 | int size() { |
| 97 | return mPkgList.size(); |
| 98 | } |
| 99 | |
| 100 | String keyAt(int index) { |
| 101 | return mPkgList.keyAt(index); |
| 102 | } |
| 103 | |
| 104 | public ProcessStats.ProcessStateHolder valueAt(int index) { |
| 105 | return mPkgList.valueAt(index); |
| 106 | } |
| 107 | |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 108 | ProcessStats.ProcessStateHolder get(String pkgName) { |
| 109 | return mPkgList.get(pkgName); |
| 110 | } |
| 111 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 112 | boolean containsKey(Object key) { |
| 113 | return mPkgList.containsKey(key); |
| 114 | } |
| 115 | } |
| 116 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 117 | final ProcessList.ProcStateMemTracker procStateMemTracker |
| 118 | = new ProcessList.ProcStateMemTracker(); |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 119 | UidRecord uidRecord; // overall state of process's uid. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 120 | ArraySet<String> pkgDeps; // additional packages we have a dependency on |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | IApplicationThread thread; // the actual proc... may be null only if |
| 122 | // 'persistent' is true (in which case we |
| 123 | // are in the process of launching the app) |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 124 | ProcessState baseProcessTracker; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 125 | BatteryStatsImpl.Uid.Proc curProcBatteryStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | int pid; // The process of this application; 0 if none |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 127 | String procStatFile; // path to /proc/<pid>/stat |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 128 | int[] gids; // The gids this process was launched with |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 129 | private String mRequiredAbi;// The ABI this process was launched with |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 130 | String instructionSet; // The instruction set this process was launched with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | boolean starting; // True if the process is being started |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 132 | long lastActivityTime; // For managing the LRU list |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 133 | long lastPssTime; // Last time we retrieved PSS data |
| 134 | long nextPssTime; // Next time we want to request PSS data |
| 135 | long lastStateTime; // Last time setProcState changed |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 136 | long initialIdlePss; // Initial memory pss of process for idle maintenance. |
| 137 | long lastPss; // Last computed memory pss. |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 138 | long lastSwapPss; // Last computed SwapPss. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 139 | long lastCachedPss; // Last computed pss when in cached state. |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 140 | long lastCachedSwapPss; // Last computed SwapPss when in cached state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | int maxAdj; // Maximum OOM adjustment for this process |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 142 | private int mCurRawAdj; // Current OOM unlimited adjustment for this process |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | int setRawAdj; // Last set OOM unlimited adjustment for this process |
| 144 | int curAdj; // Current OOM adjustment for this process |
| 145 | int setAdj; // Last set OOM adjustment for this process |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 146 | int verifiedAdj; // The last adjustment that was verified as actually being set |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 147 | private int mCurSchedGroup; // Currently desired scheduling class |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 148 | int setSchedGroup; // Last set to background scheduling class |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 149 | int trimMemoryLevel; // Last selected memory trimming level |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 150 | private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 151 | private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state |
riddle_hsu | 6793fc3 | 2015-03-31 11:54:14 +0800 | [diff] [blame] | 152 | int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker |
| 153 | int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 154 | int pssStatType; // The type of stat collection that we are currently requesting |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 155 | int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER |
| 156 | int renderThreadTid; // TID for RenderThread |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 157 | boolean serviceb; // Process currently is on the service B list |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 158 | boolean serviceHighRam; // We are forcing to service B list due to its RAM use |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 159 | boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle? |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 160 | private boolean mHasClientActivities; // Are there any client services with activities? |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 161 | boolean hasStartedServices; // Are there any started services running in this process? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 162 | private boolean mHasForegroundServices; // Running any services that are foreground? |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 163 | private boolean mHasForegroundActivities; // Running any activities that are foreground? |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 164 | boolean repForegroundActivities; // Last reported foreground activities. |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 165 | boolean systemNoUi; // This is a system process, but not currently showing UI. |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 166 | boolean hasShownUi; // Has UI been shown in this process since it was started? |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 167 | private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 168 | // is interacting with? E.g. The status bar when it is expanded, but |
| 169 | // not when it is minimized. When true the |
| 170 | // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP |
| 171 | // scheduling group to boost performance. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 172 | private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 173 | // overlays on-top of activity UIs on screen. E.g. display a window |
| 174 | // of type |
| 175 | // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY |
| 176 | // When true the process will oom adj score will be set to |
| 177 | // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance |
| 178 | // of the process getting killed. |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 179 | boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true |
| 180 | // the process will be set to use the |
| 181 | // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost |
| 182 | // performance, as well as oom adj score will be set to |
| 183 | // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance |
| 184 | // of the process getting killed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 185 | private boolean mPendingUiClean; // Want to clean up resources from showing UI? |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 186 | boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 187 | boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | boolean bad; // True if disabled in the bad process list |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 189 | boolean killedByAm; // True when proc has been killed by activity manager, not for RAM |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 190 | boolean killed; // True once we know the process has been killed |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 191 | boolean procStateChanged; // Keep track of whether we changed 'setAdj'. |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 192 | boolean reportedInteraction;// Whether we have told usage stats about it being an interaction |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 193 | boolean unlocked; // True when proc was started in user unlocked state |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 194 | private long mInteractionEventTime; // The time we sent the last interaction event |
| 195 | private long mFgInteractionTime; // When we became foreground for interaction purposes |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 196 | String waitingToKill; // Process is waiting to be killed when in the bg, and reason |
Dianne Hackborn | f965f40 | 2017-05-04 23:27:23 -0700 | [diff] [blame] | 197 | Object forcingToImportant; // Token that is forcing this process to be important |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 198 | int adjSeq; // Sequence id for identifying oom_adj assignment cycles |
Tim Murray | b52f000 | 2018-05-02 15:14:35 -0700 | [diff] [blame] | 199 | int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles |
| 200 | boolean containsCycle; // Whether this app has encountered a cycle in the most recent update |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 201 | int lruSeq; // Sequence id for identifying LRU update cycles |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 202 | CompatibilityInfo compat; // last used compatibility mode |
Dianne Hackborn | 1b64e0d | 2011-07-17 15:23:59 -0700 | [diff] [blame] | 203 | IBinder.DeathRecipient deathRecipient; // Who is watching for the death. |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 204 | private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in |
| 205 | // process. |
| 206 | private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached |
yangzhenyu | d509bc9 | 2016-08-31 18:26:46 +0800 | [diff] [blame] | 207 | final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 208 | private long mWhenUnimportant; // When (uptime) the process last became unimportant |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 209 | long lastCpuTime; // How long proc has run CPU at last check |
| 210 | long curCpuTime; // How long proc has run CPU most recently |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | long lastRequestedGc; // When we last asked the app to do a gc |
Dianne Hackborn | fd12af4 | 2009-08-27 00:44:33 -0700 | [diff] [blame] | 212 | long lastLowMemory; // When we last told the app that memory is low |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 213 | long lastProviderTime; // The last time someone else was using a provider in this process. |
Amith Yamasani | e5bfeee | 2018-09-05 18:52:35 -0700 | [diff] [blame] | 214 | long lastTopTime; // The last time the process was in the TOP state or greater. |
Dianne Hackborn | fd12af4 | 2009-08-27 00:44:33 -0700 | [diff] [blame] | 215 | boolean reportLowMemory; // Set to true when waiting to report low mem |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 216 | boolean empty; // Is this an empty background process? |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 217 | boolean cached; // Is this a cached process? |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 218 | String adjType; // Debugging: primary thing impacting oom_adj. |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 219 | int adjTypeCode; // Debugging: adj code to report to app. |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 220 | Object adjSource; // Debugging: option dependent object. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 221 | int adjSourceProcState; // Debugging: proc state of adjSource's process. |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 222 | Object adjTarget; // Debugging: target component impacting oom_adj. |
Primiano Tucci | 810c052 | 2014-07-25 18:03:16 +0100 | [diff] [blame] | 223 | Runnable crashHandler; // Optional local handler to be invoked in the process crash. |
| 224 | |
Dianne Hackborn | 8c76d91 | 2018-08-23 15:20:05 -0700 | [diff] [blame] | 225 | // Cache of last retrieve memory info and uptime, to throttle how frequently |
| 226 | // apps can requyest it. |
| 227 | Debug.MemoryInfo lastMemInfo; |
| 228 | long lastMemInfoTime; |
| 229 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 230 | // Controller for driving the process state on the window manager side. |
| 231 | final private WindowProcessController mWindowProcessController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | // all ServiceRecord running in this process |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 233 | final ArraySet<ServiceRecord> services = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | // services that are currently executing code (need to remain foreground). |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 235 | final ArraySet<ServiceRecord> executingServices = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | // All ConnectionRecord this process holds |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 237 | final ArraySet<ConnectionRecord> connections = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | // all IIntentReceivers that are registered from this process. |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 239 | final ArraySet<ReceiverList> receivers = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | // class (String) -> ContentProviderRecord |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 241 | final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | // All ContentProviderRecord process is using |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 243 | final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>(); |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 244 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 245 | String isolatedEntryPoint; // Class to run on start if this is a special isolated process. |
| 246 | String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main(). |
| 247 | |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 248 | boolean execServicesFg; // do we need to be executing services in the foreground? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 249 | private boolean mPersistent;// always keep this application running? |
| 250 | private boolean mCrashing; // are we in the process of crashing? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | Dialog crashDialog; // dialog being displayed due to crash. |
Christopher Tate | 58d380d | 2013-03-19 13:10:03 -0700 | [diff] [blame] | 252 | boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 253 | private boolean mNotResponding; // does the app have a not responding dialog? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | Dialog anrDialog; // dialog being displayed due to app not resp. |
| 255 | boolean removed; // has app package been removed from device? |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 256 | private boolean mDebugging; // was app launched for debugging? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | boolean waitedForDebugger; // has process show wait for debugger dialog? |
| 258 | Dialog waitDialog; // current wait for debugger dialog |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 259 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 260 | String shortStringName; // caching of toShortString() result. |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 261 | String stringName; // caching of toString() result. |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 262 | boolean pendingStart; // Process start is pending. |
| 263 | long startSeq; // Seq no. indicating the latest process start associated with |
| 264 | // this process record. |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame^] | 265 | int mountMode; // Indicates how the external storage was mounted for this process. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | // These reports are generated & stored when an app gets into an error condition. |
| 268 | // They will be "null" when all is OK. |
| 269 | ActivityManager.ProcessErrorStateInfo crashingReport; |
| 270 | ActivityManager.ProcessErrorStateInfo notRespondingReport; |
| 271 | |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 272 | // Who will be notified of the error. This is usually an activity in the |
| 273 | // app that installed the package. |
| 274 | ComponentName errorReportReceiver; |
| 275 | |
Amith Yamasani | b5f3b5c | 2016-05-16 14:23:04 -0700 | [diff] [blame] | 276 | // Process is currently hosting a backup agent for backup or restore |
| 277 | public boolean inFullBackup; |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 278 | // App is allowed to manage whitelists such as temporary Power Save mode whitelist. |
| 279 | boolean whitelistManager; |
Amith Yamasani | b5f3b5c | 2016-05-16 14:23:04 -0700 | [diff] [blame] | 280 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 281 | // Params used in starting this process. |
| 282 | String hostingType; |
| 283 | String hostingNameStr; |
| 284 | String seInfo; |
| 285 | long startTime; |
| 286 | // This will be same as {@link #uid} usually except for some apps used during factory testing. |
| 287 | int startUid; |
| 288 | |
| 289 | void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo, |
| 290 | long startTime) { |
| 291 | this.startUid = startUid; |
| 292 | this.hostingType = hostingType; |
| 293 | this.hostingNameStr = hostingNameStr; |
| 294 | this.seInfo = seInfo; |
| 295 | this.startTime = startTime; |
| 296 | } |
| 297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 299 | final long nowUptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 300 | |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 301 | pw.print(prefix); pw.print("user #"); pw.print(userId); |
| 302 | pw.print(" uid="); pw.print(info.uid); |
| 303 | if (uid != info.uid) { |
| 304 | pw.print(" ISOLATED uid="); pw.print(uid); |
| 305 | } |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 306 | pw.print(" gids={"); |
| 307 | if (gids != null) { |
| 308 | for (int gi=0; gi<gids.length; gi++) { |
| 309 | if (gi != 0) pw.print(", "); |
| 310 | pw.print(gids[gi]); |
| 311 | |
| 312 | } |
| 313 | } |
| 314 | pw.println("}"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 315 | pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi); |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 316 | pw.print(" instructionSet="); pw.println(instructionSet); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 317 | if (info.className != null) { |
| 318 | pw.print(prefix); pw.print("class="); pw.println(info.className); |
| 319 | } |
| 320 | if (info.manageSpaceActivityName != null) { |
| 321 | pw.print(prefix); pw.print("manageSpaceActivityName="); |
| 322 | pw.println(info.manageSpaceActivityName); |
| 323 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 324 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 325 | pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir); |
| 326 | pw.print(" publicDir="); pw.print(info.publicSourceDir); |
| 327 | pw.print(" data="); pw.println(info.dataDir); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 328 | pw.print(prefix); pw.print("packageList={"); |
| 329 | for (int i=0; i<pkgList.size(); i++) { |
| 330 | if (i > 0) pw.print(", "); |
| 331 | pw.print(pkgList.keyAt(i)); |
| 332 | } |
| 333 | pw.println("}"); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 334 | if (pkgDeps != null) { |
| 335 | pw.print(prefix); pw.print("packageDependencies={"); |
| 336 | for (int i=0; i<pkgDeps.size(); i++) { |
| 337 | if (i > 0) pw.print(", "); |
| 338 | pw.print(pkgDeps.valueAt(i)); |
| 339 | } |
| 340 | pw.println("}"); |
| 341 | } |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 342 | pw.print(prefix); pw.print("compat="); pw.println(compat); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 343 | if (mInstr != null) { |
| 344 | pw.print(prefix); pw.print("mInstr="); pw.println(mInstr); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 345 | } |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 346 | pw.print(prefix); pw.print("thread="); pw.println(thread); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 347 | pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting="); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 348 | pw.println(starting); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 349 | pw.print(prefix); pw.print("lastActivityTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 350 | TimeUtils.formatDuration(lastActivityTime, nowUptime, pw); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 351 | pw.print(" lastPssTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 352 | TimeUtils.formatDuration(lastPssTime, nowUptime, pw); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 353 | pw.print(" pssStatType="); pw.print(pssStatType); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 354 | pw.print(" nextPssTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 355 | TimeUtils.formatDuration(nextPssTime, nowUptime, pw); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 356 | pw.println(); |
| 357 | pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq); |
| 358 | pw.print(" lruSeq="); pw.print(lruSeq); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 359 | pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024); |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 360 | pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 361 | pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024); |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 362 | pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 363 | pw.println(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 364 | pw.print(prefix); pw.print("procStateMemTracker: "); |
| 365 | procStateMemTracker.dumpLine(pw); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 366 | pw.print(prefix); pw.print("cached="); pw.print(cached); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 367 | pw.print(" empty="); pw.println(empty); |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 368 | if (serviceb) { |
| 369 | pw.print(prefix); pw.print("serviceb="); pw.print(serviceb); |
| 370 | pw.print(" serviceHighRam="); pw.println(serviceHighRam); |
| 371 | } |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 372 | if (notCachedSinceIdle) { |
| 373 | pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 374 | pw.print(" initialIdlePss="); pw.println(initialIdlePss); |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 375 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 376 | pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 377 | pw.print(" curRaw="); pw.print(mCurRawAdj); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 378 | pw.print(" setRaw="); pw.print(setRawAdj); |
| 379 | pw.print(" cur="); pw.print(curAdj); |
| 380 | pw.print(" set="); pw.println(setAdj); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 381 | pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 382 | pw.print(" setSchedGroup="); pw.print(setSchedGroup); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 383 | pw.print(" systemNoUi="); pw.print(systemNoUi); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 384 | pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 385 | pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState()); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 386 | pw.print(" mRepProcState="); pw.print(mRepProcState); |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 387 | pw.print(" pssProcState="); pw.print(pssProcState); |
| 388 | pw.print(" setProcState="); pw.print(setProcState); |
| 389 | pw.print(" lastStateTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 390 | TimeUtils.formatDuration(lastStateTime, nowUptime, pw); |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 391 | pw.println(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 392 | if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) { |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 393 | pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 394 | pw.print(" pendingUiClean="); pw.print(mPendingUiClean); |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 395 | pw.print(" hasAboveClient="); pw.print(hasAboveClient); |
| 396 | pw.print(" treatLikeActivity="); pw.println(treatLikeActivity); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 397 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 398 | if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) { |
| 399 | pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi()); |
| 400 | pw.print(" hasOverlayUi="); pw.print(hasOverlayUi()); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 401 | pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation); |
Dianne Hackborn | a1baf73 | 2017-05-25 15:33:53 -0700 | [diff] [blame] | 402 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 403 | if (mHasForegroundServices || forcingToImportant != null) { |
| 404 | pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices); |
Dianne Hackborn | f965f40 | 2017-05-04 23:27:23 -0700 | [diff] [blame] | 405 | pw.print(" forcingToImportant="); pw.println(forcingToImportant); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 406 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 407 | if (reportedInteraction || mFgInteractionTime != 0) { |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 408 | pw.print(prefix); pw.print("reportedInteraction="); |
| 409 | pw.print(reportedInteraction); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 410 | if (mInteractionEventTime != 0) { |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 411 | pw.print(" time="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 412 | TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw); |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 413 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 414 | if (mFgInteractionTime != 0) { |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 415 | pw.print(" fgInteractionTime="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 416 | TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw); |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 417 | } |
| 418 | pw.println(); |
| 419 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 420 | if (mPersistent || removed) { |
| 421 | pw.print(prefix); pw.print("persistent="); pw.print(mPersistent); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 422 | pw.print(" removed="); pw.println(removed); |
| 423 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 424 | if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) { |
| 425 | pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities); |
| 426 | pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 427 | pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")"); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 428 | } |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 429 | if (lastProviderTime > 0) { |
| 430 | pw.print(prefix); pw.print("lastProviderTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 431 | TimeUtils.formatDuration(lastProviderTime, nowUptime, pw); |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 432 | pw.println(); |
| 433 | } |
Amith Yamasani | e5bfeee | 2018-09-05 18:52:35 -0700 | [diff] [blame] | 434 | if (lastTopTime > 0) { |
| 435 | pw.print(prefix); pw.print("lastTopTime="); |
| 436 | TimeUtils.formatDuration(lastTopTime, nowUptime, pw); |
| 437 | pw.println(); |
| 438 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 439 | if (hasStartedServices) { |
| 440 | pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices); |
| 441 | } |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 442 | if (pendingStart) { |
| 443 | pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart); |
| 444 | } |
| 445 | pw.print(prefix); pw.print("startSeq="); pw.println(startSeq); |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame^] | 446 | pw.print(prefix); pw.print("mountMode="); pw.println( |
| 447 | DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode)); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 448 | if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 449 | pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 450 | if (lastCpuTime > 0) { |
| 451 | pw.print(" timeUsed="); |
| 452 | TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw); |
| 453 | } |
| 454 | pw.print(" whenUnimportant="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 455 | TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 456 | pw.println(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 457 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 458 | pw.print(prefix); pw.print("lastRequestedGc="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 459 | TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 460 | pw.print(" lastLowMemory="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 461 | TimeUtils.formatDuration(lastLowMemory, nowUptime, pw); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 462 | pw.print(" reportLowMemory="); pw.println(reportLowMemory); |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 463 | if (killed || killedByAm || waitingToKill != null) { |
| 464 | pw.print(prefix); pw.print("killed="); pw.print(killed); |
| 465 | pw.print(" killedByAm="); pw.print(killedByAm); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 466 | pw.print(" waitingToKill="); pw.println(waitingToKill); |
Dianne Hackborn | 149427c | 2010-04-23 14:20:03 -0700 | [diff] [blame] | 467 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 468 | if (mDebugging || mCrashing || crashDialog != null || mNotResponding |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 469 | || anrDialog != null || bad) { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 470 | pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 471 | pw.print(" mCrashing="); pw.print(mCrashing); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 472 | pw.print(" "); pw.print(crashDialog); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 473 | pw.print(" mNotResponding="); pw.print(mNotResponding); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 474 | pw.print(" " ); pw.print(anrDialog); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 475 | pw.print(" bad="); pw.print(bad); |
| 476 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 477 | // mCrashing or mNotResponding is always set before errorReportReceiver |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 478 | if (errorReportReceiver != null) { |
| 479 | pw.print(" errorReportReceiver="); |
| 480 | pw.print(errorReportReceiver.flattenToShortString()); |
| 481 | } |
| 482 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 483 | } |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 484 | if (whitelistManager) { |
| 485 | pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager); |
| 486 | } |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 487 | if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) { |
| 488 | pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint); |
| 489 | pw.print(prefix); pw.print("isolatedEntryPointArgs="); |
| 490 | pw.println(Arrays.toString(isolatedEntryPointArgs)); |
| 491 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 492 | mWindowProcessController.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 493 | if (services.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 494 | pw.print(prefix); pw.println("Services:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 495 | for (int i=0; i<services.size(); i++) { |
| 496 | pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 497 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 498 | } |
| 499 | if (executingServices.size() > 0) { |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 500 | pw.print(prefix); pw.print("Executing Services (fg="); |
| 501 | pw.print(execServicesFg); pw.println(")"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 502 | for (int i=0; i<executingServices.size(); i++) { |
| 503 | pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 504 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 505 | } |
| 506 | if (connections.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 507 | pw.print(prefix); pw.println("Connections:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 508 | for (int i=0; i<connections.size(); i++) { |
| 509 | pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 510 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 511 | } |
| 512 | if (pubProviders.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 513 | pw.print(prefix); pw.println("Published Providers:"); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 514 | for (int i=0; i<pubProviders.size(); i++) { |
| 515 | pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i)); |
| 516 | pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 517 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 518 | } |
| 519 | if (conProviders.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 520 | pw.print(prefix); pw.println("Connected Providers:"); |
| 521 | for (int i=0; i<conProviders.size(); i++) { |
| 522 | pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString()); |
| 523 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 524 | } |
yangzhenyu | d509bc9 | 2016-08-31 18:26:46 +0800 | [diff] [blame] | 525 | if (!curReceivers.isEmpty()) { |
| 526 | pw.print(prefix); pw.println("Current Receivers:"); |
| 527 | for (int i=0; i < curReceivers.size(); i++) { |
| 528 | pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i)); |
| 529 | } |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 530 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 531 | if (receivers.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 532 | pw.print(prefix); pw.println("Receivers:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 533 | for (int i=0; i<receivers.size(); i++) { |
| 534 | pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 535 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 538 | |
Bookatz | 152623f | 2018-07-23 15:57:44 -0700 | [diff] [blame] | 539 | ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName, |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 540 | int _uid) { |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 541 | mService = _service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | info = _info; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 543 | isolated = _info.uid != _uid; |
| 544 | uid = _uid; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 545 | userId = UserHandle.getUserId(_uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | processName = _processName; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 547 | maxAdj = ProcessList.UNKNOWN_ADJ; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 548 | mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ; |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 549 | curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 550 | mPersistent = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | removed = false; |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 552 | lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 553 | mWindowProcessController = new WindowProcessController( |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 554 | mService.mActivityTaskManager, info, processName, uid, userId, this, this); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 555 | pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 558 | public void setPid(int _pid) { |
| 559 | pid = _pid; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 560 | mWindowProcessController.setPid(pid); |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 561 | procStatFile = null; |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 562 | shortStringName = null; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 563 | stringName = null; |
| 564 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 565 | |
| 566 | public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) { |
| 567 | if (thread == null) { |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 568 | final ProcessState origBase = baseProcessTracker; |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 569 | if (origBase != null) { |
| 570 | origBase.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 571 | tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 572 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 573 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 574 | uid, processName, pkgList.keyAt(ipkg), |
| 575 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 576 | pkgList.valueAt(ipkg).appVersion); |
| 577 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 578 | origBase.makeInactive(); |
| 579 | } |
Ronnie Leng | 4c5c6f4 | 2015-03-25 10:57:24 -0500 | [diff] [blame] | 580 | baseProcessTracker = tracker.getProcessStateLocked(info.packageName, uid, |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 581 | info.longVersionCode, processName); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 582 | baseProcessTracker.makeActive(); |
| 583 | for (int i=0; i<pkgList.size(); i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 584 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 585 | if (holder.state != null && holder.state != origBase) { |
| 586 | holder.state.makeInactive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 587 | } |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 588 | tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), uid, |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 589 | info.longVersionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 590 | if (holder.state != baseProcessTracker) { |
| 591 | holder.state.makeActive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 592 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | thread = _thread; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 596 | mWindowProcessController.setThread(thread); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | public void makeInactive(ProcessStatsService tracker) { |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 600 | thread = null; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 601 | mWindowProcessController.setThread(null); |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 602 | final ProcessState origBase = baseProcessTracker; |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 603 | if (origBase != null) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 604 | if (origBase != null) { |
| 605 | origBase.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 606 | tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 607 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 608 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 609 | uid, processName, pkgList.keyAt(ipkg), |
| 610 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 611 | pkgList.valueAt(ipkg).appVersion); |
| 612 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 613 | origBase.makeInactive(); |
| 614 | } |
| 615 | baseProcessTracker = null; |
| 616 | for (int i=0; i<pkgList.size(); i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 617 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 618 | if (holder.state != null && holder.state != origBase) { |
| 619 | holder.state.makeInactive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 620 | } |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 621 | holder.pkg = null; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 622 | holder.state = null; |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 627 | boolean hasActivities() { |
| 628 | return mWindowProcessController.hasActivities(); |
| 629 | } |
| 630 | |
| 631 | void clearActivities() { |
| 632 | mWindowProcessController.clearActivities(); |
| 633 | } |
| 634 | |
| 635 | boolean hasActivitiesOrRecentTasks() { |
| 636 | return mWindowProcessController.hasActivitiesOrRecentTasks(); |
| 637 | } |
| 638 | |
| 639 | boolean hasRecentTasks() { |
| 640 | return mWindowProcessController.hasRecentTasks(); |
| 641 | } |
| 642 | |
| 643 | void clearRecentTasks() { |
| 644 | mWindowProcessController.clearRecentTasks(); |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 645 | } |
| 646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | /** |
| 648 | * This method returns true if any of the activities within the process record are interesting |
| 649 | * to the user. See HistoryRecord.isInterestingToUserLocked() |
| 650 | */ |
| 651 | public boolean isInterestingToUserLocked() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 652 | if (mWindowProcessController.isInterestingToUser()) { |
| 653 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | } |
Narayan Kamath | a22d9fb | 2017-04-26 15:14:26 +0100 | [diff] [blame] | 655 | |
| 656 | final int servicesSize = services.size(); |
| 657 | for (int i = 0; i < servicesSize; i++) { |
| 658 | ServiceRecord r = services.valueAt(i); |
| 659 | if (r.isForeground) { |
| 660 | return true; |
| 661 | } |
| 662 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | return false; |
| 664 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 665 | |
Dianne Hackborn | 1b64e0d | 2011-07-17 15:23:59 -0700 | [diff] [blame] | 666 | public void unlinkDeathRecipient() { |
| 667 | if (deathRecipient != null && thread != null) { |
| 668 | thread.asBinder().unlinkToDeath(deathRecipient, 0); |
| 669 | } |
| 670 | deathRecipient = null; |
| 671 | } |
| 672 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 673 | void updateHasAboveClientLocked() { |
| 674 | hasAboveClient = false; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 675 | for (int i=connections.size()-1; i>=0; i--) { |
| 676 | ConnectionRecord cr = connections.valueAt(i); |
| 677 | if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) { |
| 678 | hasAboveClient = true; |
| 679 | break; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 684 | int modifyRawOomAdj(int adj) { |
| 685 | if (hasAboveClient) { |
| 686 | // If this process has bound to any services with BIND_ABOVE_CLIENT, |
| 687 | // then we need to drop its adjustment to be lower than the service's |
| 688 | // in order to honor the request. We want to drop it by one adjustment |
| 689 | // level... but there is special meaning applied to various levels so |
| 690 | // we will skip some of them. |
| 691 | if (adj < ProcessList.FOREGROUND_APP_ADJ) { |
| 692 | // System process will not get dropped, ever |
| 693 | } else if (adj < ProcessList.VISIBLE_APP_ADJ) { |
| 694 | adj = ProcessList.VISIBLE_APP_ADJ; |
| 695 | } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) { |
| 696 | adj = ProcessList.PERCEPTIBLE_APP_ADJ; |
| 697 | } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) { |
| 698 | adj = ProcessList.CACHED_APP_MIN_ADJ; |
| 699 | } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) { |
| 700 | adj++; |
| 701 | } |
| 702 | } |
| 703 | return adj; |
| 704 | } |
| 705 | |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 706 | void scheduleCrash(String message) { |
| 707 | // Checking killedbyAm should keep it from showing the crash dialog if the process |
| 708 | // was already dead for a good / normal reason. |
| 709 | if (!killedByAm) { |
| 710 | if (thread != null) { |
| 711 | if (pid == Process.myPid()) { |
| 712 | Slog.w(TAG, "scheduleCrash: trying to crash system process!"); |
| 713 | return; |
| 714 | } |
| 715 | long ident = Binder.clearCallingIdentity(); |
| 716 | try { |
| 717 | thread.scheduleCrash(message); |
| 718 | } catch (RemoteException e) { |
| 719 | // If it's already dead our work is done. If it's wedged just kill it. |
| 720 | // We won't get the crash dialog or the error reporting. |
| 721 | kill("scheduleCrash for '" + message + "' failed", true); |
| 722 | } finally { |
| 723 | Binder.restoreCallingIdentity(ident); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 729 | void kill(String reason, boolean noisy) { |
| 730 | if (!killedByAm) { |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 731 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill"); |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 732 | if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) { |
| 733 | mService.reportUidInfoMessageLocked(TAG, |
| 734 | "Killing " + toShortString() + " (adj " + setAdj + "): " + reason, |
| 735 | info.uid); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 736 | } |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 737 | if (pid > 0) { |
| 738 | EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason); |
| 739 | Process.killProcessQuiet(pid); |
Amith Yamasani | 98a0092 | 2018-08-21 12:50:30 -0400 | [diff] [blame] | 740 | ProcessList.killProcessGroup(uid, pid); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 741 | } else { |
| 742 | pendingStart = false; |
| 743 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 744 | if (!mPersistent) { |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 745 | killed = true; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 746 | killedByAm = true; |
| 747 | } |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 748 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 752 | @Override |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 753 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 754 | long token = proto.start(fieldId); |
| 755 | proto.write(ProcessRecordProto.PID, pid); |
| 756 | proto.write(ProcessRecordProto.PROCESS_NAME, processName); |
| 757 | if (info.uid < Process.FIRST_APPLICATION_UID) { |
| 758 | proto.write(ProcessRecordProto.UID, uid); |
| 759 | } else { |
| 760 | proto.write(ProcessRecordProto.USER_ID, userId); |
| 761 | proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid)); |
| 762 | if (uid != info.uid) { |
| 763 | proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid)); |
| 764 | } |
| 765 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 766 | proto.write(ProcessRecordProto.PERSISTENT, mPersistent); |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 767 | proto.end(token); |
| 768 | } |
| 769 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 770 | public String toShortString() { |
| 771 | if (shortStringName != null) { |
| 772 | return shortStringName; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 773 | } |
| 774 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 775 | toShortString(sb); |
| 776 | return shortStringName = sb.toString(); |
| 777 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 778 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 779 | void toShortString(StringBuilder sb) { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 780 | sb.append(pid); |
| 781 | sb.append(':'); |
| 782 | sb.append(processName); |
| 783 | sb.append('/'); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 784 | if (info.uid < Process.FIRST_APPLICATION_UID) { |
| 785 | sb.append(uid); |
| 786 | } else { |
| 787 | sb.append('u'); |
| 788 | sb.append(userId); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 789 | int appId = UserHandle.getAppId(info.uid); |
| 790 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 791 | sb.append('a'); |
| 792 | sb.append(appId - Process.FIRST_APPLICATION_UID); |
| 793 | } else { |
| 794 | sb.append('s'); |
| 795 | sb.append(appId); |
| 796 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 797 | if (uid != info.uid) { |
| 798 | sb.append('i'); |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 799 | sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 800 | } |
| 801 | } |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 802 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 803 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 804 | public String toString() { |
| 805 | if (stringName != null) { |
| 806 | return stringName; |
| 807 | } |
| 808 | StringBuilder sb = new StringBuilder(128); |
| 809 | sb.append("ProcessRecord{"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 810 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 811 | sb.append(' '); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 812 | toShortString(sb); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 813 | sb.append('}'); |
| 814 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | } |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 816 | |
| 817 | public String makeAdjReason() { |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 818 | if (adjSource != null || adjTarget != null) { |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 819 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 820 | sb.append(' '); |
| 821 | if (adjTarget instanceof ComponentName) { |
| 822 | sb.append(((ComponentName)adjTarget).flattenToShortString()); |
| 823 | } else if (adjTarget != null) { |
| 824 | sb.append(adjTarget.toString()); |
| 825 | } else { |
| 826 | sb.append("{null}"); |
| 827 | } |
| 828 | sb.append("<="); |
| 829 | if (adjSource instanceof ProcessRecord) { |
| 830 | sb.append("Proc{"); |
| 831 | sb.append(((ProcessRecord)adjSource).toShortString()); |
| 832 | sb.append("}"); |
| 833 | } else if (adjSource != null) { |
| 834 | sb.append(adjSource.toString()); |
| 835 | } else { |
| 836 | sb.append("{null}"); |
| 837 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 838 | return sb.toString(); |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 839 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 840 | return null; |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 843 | @Override |
| 844 | public void addPackage(String pkg, long versionCode) { |
| 845 | synchronized (mService) { |
| 846 | addPackage(pkg, versionCode, mService.mProcessStats); |
| 847 | } |
| 848 | } |
| 849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | /* |
| 851 | * Return true if package has been added false if not |
| 852 | */ |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 853 | public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) { |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 854 | if (!pkgList.containsKey(pkg)) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 855 | ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder( |
| 856 | versionCode); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 857 | if (baseProcessTracker != null) { |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 858 | tracker.updateProcessStateHolderLocked(holder, pkg, uid, versionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 859 | pkgList.put(pkg, holder); |
| 860 | if (holder.state != baseProcessTracker) { |
| 861 | holder.state.makeActive(); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 862 | } |
| 863 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 864 | pkgList.put(pkg, holder); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 865 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | return true; |
| 867 | } |
| 868 | return false; |
| 869 | } |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 870 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 871 | public int getSetAdjWithServices() { |
Dianne Hackborn | 20cdcee | 2013-07-10 18:47:04 -0700 | [diff] [blame] | 872 | if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) { |
| 873 | if (hasStartedServices) { |
| 874 | return ProcessList.SERVICE_B_ADJ; |
| 875 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 876 | } |
| 877 | return setAdj; |
| 878 | } |
| 879 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 880 | public void forceProcessStateUpTo(int newState) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 881 | if (mRepProcState > newState) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 882 | mRepProcState = newState; |
| 883 | setCurProcState(newState); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 884 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 885 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 886 | uid, processName, pkgList.keyAt(ipkg), |
| 887 | ActivityManager.processStateAmToProto(mRepProcState), |
| 888 | pkgList.valueAt(ipkg).appVersion); |
| 889 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | /* |
| 894 | * Delete all packages from list except the package indicated in info |
| 895 | */ |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 896 | public void resetPackageList(ProcessStatsService tracker) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 897 | final int N = pkgList.size(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 898 | if (baseProcessTracker != null) { |
| 899 | long now = SystemClock.uptimeMillis(); |
| 900 | baseProcessTracker.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 901 | tracker.getMemFactorLocked(), now, pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 902 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 903 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 904 | uid, processName, pkgList.keyAt(ipkg), |
| 905 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 906 | pkgList.valueAt(ipkg).appVersion); |
| 907 | } |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 908 | if (N != 1) { |
| 909 | for (int i=0; i<N; i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 910 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 911 | if (holder.state != null && holder.state != baseProcessTracker) { |
| 912 | holder.state.makeInactive(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 913 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 914 | |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 915 | } |
| 916 | pkgList.clear(); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 917 | ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder( |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 918 | info.longVersionCode); |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 919 | tracker.updateProcessStateHolderLocked(holder, info.packageName, uid, |
| 920 | info.longVersionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 921 | pkgList.put(info.packageName, holder); |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 922 | if (holder.state != baseProcessTracker) { |
| 923 | holder.state.makeActive(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 924 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 925 | } |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 926 | } else if (N != 1) { |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 927 | pkgList.clear(); |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 928 | pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode)); |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 929 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 930 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | public String[] getPackageList() { |
| 933 | int size = pkgList.size(); |
| 934 | if (size == 0) { |
| 935 | return null; |
| 936 | } |
| 937 | String list[] = new String[size]; |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 938 | for (int i=0; i<pkgList.size(); i++) { |
| 939 | list[i] = pkgList.keyAt(i); |
| 940 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | return list; |
| 942 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 943 | |
| 944 | WindowProcessController getWindowProcessController() { |
| 945 | return mWindowProcessController; |
| 946 | } |
| 947 | |
| 948 | void setCurrentSchedulingGroup(int curSchedGroup) { |
| 949 | mCurSchedGroup = curSchedGroup; |
| 950 | mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup); |
| 951 | } |
| 952 | |
| 953 | int getCurrentSchedulingGroup() { |
| 954 | return mCurSchedGroup; |
| 955 | } |
| 956 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 957 | void setCurProcState(int curProcState) { |
| 958 | mCurProcState = curProcState; |
| 959 | mWindowProcessController.setCurrentProcState(mCurProcState); |
| 960 | } |
| 961 | |
| 962 | int getCurProcState() { |
| 963 | return mCurProcState; |
| 964 | } |
| 965 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 966 | void setReportedProcState(int repProcState) { |
| 967 | mRepProcState = repProcState; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 968 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 969 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 970 | uid, processName, pkgList.keyAt(ipkg), |
| 971 | ActivityManager.processStateAmToProto(mRepProcState), |
| 972 | pkgList.valueAt(ipkg).appVersion); |
| 973 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 974 | mWindowProcessController.setReportedProcState(repProcState); |
| 975 | } |
| 976 | |
| 977 | int getReportedProcState() { |
| 978 | return mRepProcState; |
| 979 | } |
| 980 | |
| 981 | void setCrashing(boolean crashing) { |
| 982 | mCrashing = crashing; |
| 983 | mWindowProcessController.setCrashing(crashing); |
| 984 | } |
| 985 | |
| 986 | boolean isCrashing() { |
| 987 | return mCrashing; |
| 988 | } |
| 989 | |
| 990 | void setNotResponding(boolean notResponding) { |
| 991 | mNotResponding = notResponding; |
| 992 | mWindowProcessController.setNotResponding(notResponding); |
| 993 | } |
| 994 | |
| 995 | boolean isNotResponding() { |
| 996 | return mNotResponding; |
| 997 | } |
| 998 | |
| 999 | void setPersistent(boolean persistent) { |
| 1000 | mPersistent = persistent; |
| 1001 | mWindowProcessController.setPersistent(persistent); |
| 1002 | } |
| 1003 | |
| 1004 | boolean isPersistent() { |
| 1005 | return mPersistent; |
| 1006 | } |
| 1007 | |
| 1008 | public void setRequiredAbi(String requiredAbi) { |
| 1009 | mRequiredAbi = requiredAbi; |
| 1010 | mWindowProcessController.setRequiredAbi(requiredAbi); |
| 1011 | } |
| 1012 | |
| 1013 | String getRequiredAbi() { |
| 1014 | return mRequiredAbi; |
| 1015 | } |
| 1016 | |
| 1017 | void setHasForegroundServices(boolean hasForegroundServices) { |
| 1018 | mHasForegroundServices = hasForegroundServices; |
| 1019 | mWindowProcessController.setHasForegroundServices(hasForegroundServices); |
| 1020 | } |
| 1021 | |
| 1022 | boolean hasForegroundServices() { |
| 1023 | return mHasForegroundServices; |
| 1024 | } |
| 1025 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1026 | void setHasForegroundActivities(boolean hasForegroundActivities) { |
| 1027 | mHasForegroundActivities = hasForegroundActivities; |
| 1028 | mWindowProcessController.setHasForegroundActivities(hasForegroundActivities); |
| 1029 | } |
| 1030 | |
| 1031 | boolean hasForegroundActivities() { |
| 1032 | return mHasForegroundActivities; |
| 1033 | } |
| 1034 | |
| 1035 | void setHasClientActivities(boolean hasClientActivities) { |
| 1036 | mHasClientActivities = hasClientActivities; |
| 1037 | mWindowProcessController.setHasClientActivities(hasClientActivities); |
| 1038 | } |
| 1039 | |
| 1040 | boolean hasClientActivities() { |
| 1041 | return mHasClientActivities; |
| 1042 | } |
| 1043 | |
| 1044 | void setHasTopUi(boolean hasTopUi) { |
| 1045 | mHasTopUi = hasTopUi; |
| 1046 | mWindowProcessController.setHasTopUi(hasTopUi); |
| 1047 | } |
| 1048 | |
| 1049 | boolean hasTopUi() { |
| 1050 | return mHasTopUi; |
| 1051 | } |
| 1052 | |
| 1053 | void setHasOverlayUi(boolean hasOverlayUi) { |
| 1054 | mHasOverlayUi = hasOverlayUi; |
| 1055 | mWindowProcessController.setHasOverlayUi(hasOverlayUi); |
| 1056 | } |
| 1057 | |
| 1058 | boolean hasOverlayUi() { |
| 1059 | return mHasOverlayUi; |
| 1060 | } |
| 1061 | |
| 1062 | void setInteractionEventTime(long interactionEventTime) { |
| 1063 | mInteractionEventTime = interactionEventTime; |
| 1064 | mWindowProcessController.setInteractionEventTime(interactionEventTime); |
| 1065 | } |
| 1066 | |
| 1067 | long getInteractionEventTime() { |
| 1068 | return mInteractionEventTime; |
| 1069 | } |
| 1070 | |
| 1071 | void setFgInteractionTime(long fgInteractionTime) { |
| 1072 | mFgInteractionTime = fgInteractionTime; |
| 1073 | mWindowProcessController.setFgInteractionTime(fgInteractionTime); |
| 1074 | } |
| 1075 | |
| 1076 | long getFgInteractionTime() { |
| 1077 | return mFgInteractionTime; |
| 1078 | } |
| 1079 | |
| 1080 | void setWhenUnimportant(long whenUnimportant) { |
| 1081 | mWhenUnimportant = whenUnimportant; |
| 1082 | mWindowProcessController.setWhenUnimportant(whenUnimportant); |
| 1083 | } |
| 1084 | |
| 1085 | long getWhenUnimportant() { |
| 1086 | return mWhenUnimportant; |
| 1087 | } |
| 1088 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1089 | void setDebugging(boolean debugging) { |
| 1090 | mDebugging = debugging; |
| 1091 | mWindowProcessController.setDebugging(debugging); |
| 1092 | } |
| 1093 | |
| 1094 | boolean isDebugging() { |
| 1095 | return mDebugging; |
| 1096 | } |
| 1097 | |
| 1098 | void setUsingWrapper(boolean usingWrapper) { |
| 1099 | mUsingWrapper = usingWrapper; |
| 1100 | mWindowProcessController.setUsingWrapper(usingWrapper); |
| 1101 | } |
| 1102 | |
| 1103 | boolean isUsingWrapper() { |
| 1104 | return mUsingWrapper; |
| 1105 | } |
| 1106 | |
| 1107 | void setActiveInstrumentation(ActiveInstrumentation instr) { |
| 1108 | mInstr = instr; |
| 1109 | mWindowProcessController.setInstrumenting(instr != null); |
| 1110 | } |
| 1111 | |
| 1112 | ActiveInstrumentation getActiveInstrumentation() { |
| 1113 | return mInstr; |
| 1114 | } |
| 1115 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 1116 | void setCurRawAdj(int curRawAdj) { |
| 1117 | mCurRawAdj = curRawAdj; |
| 1118 | mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ); |
| 1119 | } |
| 1120 | |
| 1121 | int getCurRawAdj() { |
| 1122 | return mCurRawAdj; |
| 1123 | } |
| 1124 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1125 | @Override |
| 1126 | public void clearProfilerIfNeeded() { |
| 1127 | synchronized (mService) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1128 | if (mService.mProfileData.getProfileProc() == null |
| 1129 | || mService.mProfileData.getProfilerInfo() == null |
| 1130 | || mService.mProfileData.getProfileProc() != this) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1131 | return; |
| 1132 | } |
| 1133 | mService.clearProfilerLocked(); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | @Override |
| 1138 | public void updateServiceConnectionActivities() { |
| 1139 | synchronized (mService) { |
| 1140 | mService.mServices.updateServiceConnectionActivitiesLocked(this); |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | @Override |
| 1145 | public void setPendingUiClean(boolean pendingUiClean) { |
| 1146 | synchronized (mService) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1147 | mPendingUiClean = pendingUiClean; |
| 1148 | mWindowProcessController.setPendingUiClean(pendingUiClean); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1149 | } |
| 1150 | } |
| 1151 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1152 | boolean hasPendingUiClean() { |
| 1153 | return mPendingUiClean; |
| 1154 | } |
| 1155 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1156 | @Override |
| 1157 | public void setPendingUiCleanAndForceProcessStateUpTo(int newState) { |
| 1158 | synchronized (mService) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1159 | setPendingUiClean(true); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1160 | forceProcessStateUpTo(newState); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | @Override |
| 1165 | public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru, |
| 1166 | boolean activityChange, boolean updateOomAdj) { |
| 1167 | synchronized (mService) { |
| 1168 | if (updateServiceConnectionActivities) { |
| 1169 | mService.mServices.updateServiceConnectionActivitiesLocked(this); |
| 1170 | } |
| 1171 | if (updateLru) { |
Amith Yamasani | 98a0092 | 2018-08-21 12:50:30 -0400 | [diff] [blame] | 1172 | mService.mProcessList.updateLruProcessLocked(this, activityChange, null); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1173 | } |
| 1174 | if (updateOomAdj) { |
| 1175 | mService.updateOomAdjLocked(); |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | @Override |
| 1181 | public void setRemoved(boolean removed) { |
| 1182 | synchronized (mService) { |
| 1183 | this.removed = removed; |
| 1184 | } |
| 1185 | } |
| 1186 | |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1187 | /** |
| 1188 | * Returns the total time (in milliseconds) spent executing in both user and system code. |
| 1189 | * Safe to call without lock held. |
| 1190 | */ |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1191 | @Override |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1192 | public long getCpuTime() { |
| 1193 | return mService.mProcessCpuTracker.getCpuTimeForPid(pid); |
| 1194 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1195 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1196 | @Override |
| 1197 | public void clearWaitingToKill() { |
| 1198 | synchronized (mService) { |
| 1199 | waitingToKill = null; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | @Override |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1204 | public void onStartActivity(int topProcessState, boolean setProfileProc) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1205 | synchronized (mService) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1206 | if (setProfileProc) { |
| 1207 | mService.mProfileData.setProfileProc(this); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | hasShownUi = true; |
| 1211 | setPendingUiClean(true); |
| 1212 | forceProcessStateUpTo(topProcessState); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | @Override |
| 1217 | public void appDied() { |
| 1218 | synchronized (mService) { |
| 1219 | mService.appDiedLocked(this); |
| 1220 | } |
| 1221 | } |
| 1222 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1223 | public long getInputDispatchingTimeout() { |
| 1224 | return mWindowProcessController.getInputDispatchingTimeout(); |
| 1225 | } |
| 1226 | |
| 1227 | void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo, |
| 1228 | String parentShortComponentName, WindowProcessController parentProcess, |
| 1229 | boolean aboveSystem, String annotation) { |
| 1230 | ArrayList<Integer> firstPids = new ArrayList<>(5); |
| 1231 | SparseArray<Boolean> lastPids = new SparseArray<>(20); |
| 1232 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1233 | mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true)); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1234 | |
| 1235 | long anrTime = SystemClock.uptimeMillis(); |
| 1236 | if (ActivityManagerService.MONITOR_CPU_USAGE) { |
| 1237 | mService.updateCpuStatsNow(); |
| 1238 | } |
| 1239 | |
| 1240 | // Unless configured otherwise, swallow ANRs in background processes & kill the process. |
| 1241 | boolean showBackground = Settings.Secure.getInt(mService.mContext.getContentResolver(), |
| 1242 | Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0; |
| 1243 | |
| 1244 | boolean isSilentANR; |
| 1245 | |
| 1246 | synchronized (mService) { |
| 1247 | // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down. |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 1248 | if (mService.mAtmInternal.isShuttingDown()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1249 | Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation); |
| 1250 | return; |
| 1251 | } else if (isNotResponding()) { |
| 1252 | Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation); |
| 1253 | return; |
| 1254 | } else if (isCrashing()) { |
| 1255 | Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation); |
| 1256 | return; |
| 1257 | } else if (killedByAm) { |
| 1258 | Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation); |
| 1259 | return; |
| 1260 | } else if (killed) { |
| 1261 | Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation); |
| 1262 | return; |
| 1263 | } |
| 1264 | |
| 1265 | // In case we come through here for the same app before completing |
| 1266 | // this one, mark as anring now so we will bail out. |
| 1267 | setNotResponding(true); |
| 1268 | |
| 1269 | // Log the ANR to the event log. |
| 1270 | EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags, |
| 1271 | annotation); |
| 1272 | |
| 1273 | // Dump thread traces as quickly as we can, starting with "interesting" processes. |
| 1274 | firstPids.add(pid); |
| 1275 | |
| 1276 | // Don't dump other PIDs if it's a background ANR |
| 1277 | isSilentANR = !showBackground && !isInterestingForBackgroundTraces(); |
| 1278 | if (!isSilentANR) { |
| 1279 | int parentPid = pid; |
| 1280 | if (parentProcess != null && parentProcess.getPid() > 0) { |
| 1281 | parentPid = parentProcess.getPid(); |
| 1282 | } |
| 1283 | if (parentPid != pid) firstPids.add(parentPid); |
| 1284 | |
| 1285 | if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID); |
| 1286 | |
Amith Yamasani | 98a0092 | 2018-08-21 12:50:30 -0400 | [diff] [blame] | 1287 | for (int i = mService.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) { |
| 1288 | ProcessRecord r = mService.mProcessList.mLruProcesses.get(i); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1289 | if (r != null && r.thread != null) { |
| 1290 | int myPid = r.pid; |
| 1291 | if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) { |
| 1292 | if (r.isPersistent()) { |
| 1293 | firstPids.add(myPid); |
| 1294 | if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r); |
| 1295 | } else if (r.treatLikeActivity) { |
| 1296 | firstPids.add(myPid); |
| 1297 | if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r); |
| 1298 | } else { |
| 1299 | lastPids.put(myPid, Boolean.TRUE); |
| 1300 | if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r); |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | // Log the ANR to the main log. |
| 1309 | StringBuilder info = new StringBuilder(); |
| 1310 | info.setLength(0); |
| 1311 | info.append("ANR in ").append(processName); |
| 1312 | if (activityShortComponentName != null) { |
| 1313 | info.append(" (").append(activityShortComponentName).append(")"); |
| 1314 | } |
| 1315 | info.append("\n"); |
| 1316 | info.append("PID: ").append(pid).append("\n"); |
| 1317 | if (annotation != null) { |
| 1318 | info.append("Reason: ").append(annotation).append("\n"); |
| 1319 | } |
| 1320 | if (parentShortComponentName != null |
| 1321 | && parentShortComponentName.equals(activityShortComponentName)) { |
| 1322 | info.append("Parent: ").append(parentShortComponentName).append("\n"); |
| 1323 | } |
| 1324 | |
| 1325 | ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true); |
| 1326 | |
| 1327 | // don't dump native PIDs for background ANRs unless it is the process of interest |
| 1328 | String[] nativeProcs = null; |
| 1329 | if (isSilentANR) { |
| 1330 | for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) { |
| 1331 | if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) { |
| 1332 | nativeProcs = new String[] { processName }; |
| 1333 | break; |
| 1334 | } |
| 1335 | } |
| 1336 | } else { |
| 1337 | nativeProcs = NATIVE_STACKS_OF_INTEREST; |
| 1338 | } |
| 1339 | |
| 1340 | int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs); |
| 1341 | ArrayList<Integer> nativePids = null; |
| 1342 | |
| 1343 | if (pids != null) { |
| 1344 | nativePids = new ArrayList<>(pids.length); |
| 1345 | for (int i : pids) { |
| 1346 | nativePids.add(i); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | // For background ANRs, don't pass the ProcessCpuTracker to |
| 1351 | // avoid spending 1/2 second collecting stats to rank lastPids. |
| 1352 | File tracesFile = ActivityManagerService.dumpStackTraces(firstPids, |
| 1353 | (isSilentANR) ? null : processCpuTracker, (isSilentANR) ? null : lastPids, |
| 1354 | nativePids); |
| 1355 | |
| 1356 | String cpuInfo = null; |
| 1357 | if (ActivityManagerService.MONITOR_CPU_USAGE) { |
| 1358 | mService.updateCpuStatsNow(); |
| 1359 | synchronized (mService.mProcessCpuTracker) { |
| 1360 | cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime); |
| 1361 | } |
| 1362 | info.append(processCpuTracker.printCurrentLoad()); |
| 1363 | info.append(cpuInfo); |
| 1364 | } |
| 1365 | |
| 1366 | info.append(processCpuTracker.printCurrentState(anrTime)); |
| 1367 | |
| 1368 | Slog.e(TAG, info.toString()); |
| 1369 | if (tracesFile == null) { |
| 1370 | // There is no trace file, so dump (only) the alleged culprit's threads to the log |
| 1371 | Process.sendSignal(pid, Process.SIGNAL_QUIT); |
| 1372 | } |
| 1373 | |
| 1374 | StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName, |
| 1375 | activityShortComponentName == null ? "unknown": activityShortComponentName, |
| 1376 | annotation, |
| 1377 | (this.info != null) ? (this.info.isInstantApp() |
| 1378 | ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE |
| 1379 | : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE) |
| 1380 | : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE, |
| 1381 | isInterestingToUserLocked() |
| 1382 | ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND |
| 1383 | : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND); |
Wale Ogunwale | 97b2b74 | 2018-10-18 08:08:54 -0700 | [diff] [blame] | 1384 | final ProcessRecord parentPr = parentProcess != null |
| 1385 | ? (ProcessRecord) parentProcess.mOwner : null; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1386 | mService.addErrorToDropBox("anr", this, processName, activityShortComponentName, |
Wale Ogunwale | 97b2b74 | 2018-10-18 08:08:54 -0700 | [diff] [blame] | 1387 | parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1388 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1389 | if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true), |
| 1390 | () -> { |
| 1391 | synchronized (mService) { |
| 1392 | mService.mServices.scheduleServiceTimeoutLocked(this); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1393 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1394 | })) { |
| 1395 | return; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | synchronized (mService) { |
| 1399 | mService.mBatteryStatsService.noteProcessAnr(processName, uid); |
| 1400 | |
| 1401 | if (isSilentANR) { |
| 1402 | kill("bg anr", true); |
| 1403 | return; |
| 1404 | } |
| 1405 | |
| 1406 | // Set the app's notResponding state, and look up the errorReportReceiver |
| 1407 | makeAppNotRespondingLocked(activityShortComponentName, |
| 1408 | annotation != null ? "ANR " + annotation : "ANR", info.toString()); |
| 1409 | |
| 1410 | // Bring up the infamous App Not Responding dialog |
| 1411 | Message msg = Message.obtain(); |
| 1412 | msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG; |
| 1413 | msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem); |
| 1414 | |
| 1415 | mService.mUiHandler.sendMessage(msg); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) { |
| 1420 | setNotResponding(true); |
| 1421 | notRespondingReport = mService.mAppErrors.generateProcessError(this, |
| 1422 | ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING, |
| 1423 | activity, shortMsg, longMsg, null); |
| 1424 | startAppProblemLocked(); |
| 1425 | getWindowProcessController().stopFreezingActivities(); |
| 1426 | } |
| 1427 | |
| 1428 | void startAppProblemLocked() { |
| 1429 | // If this app is not running under the current user, then we can't give it a report button |
| 1430 | // because that would require launching the report UI under a different user. |
| 1431 | errorReportReceiver = null; |
| 1432 | |
| 1433 | for (int userId : mService.mUserController.getCurrentProfileIds()) { |
| 1434 | if (this.userId == userId) { |
| 1435 | errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver( |
| 1436 | mService.mContext, info.packageName, info.flags); |
| 1437 | } |
| 1438 | } |
| 1439 | mService.skipCurrentReceiverLocked(this); |
| 1440 | } |
| 1441 | |
| 1442 | private boolean isInterestingForBackgroundTraces() { |
| 1443 | // The system_server is always considered interesting. |
| 1444 | if (pid == MY_PID) { |
| 1445 | return true; |
| 1446 | } |
| 1447 | |
| 1448 | // A package is considered interesting if any of the following is true : |
| 1449 | // |
| 1450 | // - It's displaying an activity. |
| 1451 | // - It's the SystemUI. |
| 1452 | // - It has an overlay or a top UI visible. |
| 1453 | // |
| 1454 | // NOTE: The check whether a given ProcessRecord belongs to the systemui |
| 1455 | // process is a bit of a kludge, but the same pattern seems repeated at |
| 1456 | // several places in the system server. |
| 1457 | return isInterestingToUserLocked() || |
| 1458 | (info != null && "com.android.systemui".equals(info.packageName)) |
| 1459 | || (hasTopUi() || hasOverlayUi()); |
| 1460 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | } |