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