blob: 51b1ae197821ea10d4ab12922dd1484ad11d0be6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
riddle_hsu6793fc32015-03-31 11:54:14 +080019import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
Yunfan Chen75157d72018-07-27 14:47:21 +090020
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070021import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
22import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080023import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
24import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070025import static com.android.server.am.ActivityManagerService.MY_PID;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.app.ActivityManager;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070028import android.app.ApplicationErrorReport;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.app.Dialog;
30import android.app.IApplicationThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ComponentName;
Dianne Hackbornc68c9132011-07-29 01:25:18 -070032import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.pm.ApplicationInfo;
Amith Yamasania0a30a12019-01-22 11:38:06 -080034import android.content.pm.ServiceInfo;
Zimuzo972e1cd2019-01-28 16:30:01 +000035import android.content.pm.VersionedPackage;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040036import android.content.res.CompatibilityInfo;
Joe Onorato57190282016-04-20 15:37:49 -070037import android.os.Binder;
Yunfan Chen75157d72018-07-27 14:47:21 +090038import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.IBinder;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070040import android.os.Message;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080041import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070042import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070043import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070044import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070045import android.os.UserHandle;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070046import android.provider.Settings;
Yang Lu732d6382018-11-05 07:53:12 -080047import android.server.ServerProtoEnums;
Dianne Hackborn390517b2013-05-30 15:03:32 -070048import android.util.ArrayMap;
Yunfan Chen75157d72018-07-27 14:47:21 +090049import android.util.ArraySet;
50import android.util.DebugUtils;
51import android.util.EventLog;
52import android.util.Slog;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070053import android.util.SparseArray;
Chenjie Yubd1a28f2018-07-17 14:55:19 -070054import android.util.StatsLog;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070055import android.util.TimeUtils;
Yi Jin129fc6c2017-09-28 15:48:38 -070056import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Yunfan Chen585f2932019-01-29 16:04:45 +090058import com.android.internal.annotations.VisibleForTesting;
Yunfan Chen75157d72018-07-27 14:47:21 +090059import com.android.internal.app.procstats.ProcessState;
60import com.android.internal.app.procstats.ProcessStats;
61import com.android.internal.os.BatteryStatsImpl;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070062import com.android.internal.os.ProcessCpuTracker;
Sudheer Shanka87915d62018-11-06 10:57:35 -080063import com.android.internal.os.Zygote;
Wale Ogunwale59507092018-10-29 09:00:30 -070064import com.android.server.wm.WindowProcessController;
65import com.android.server.wm.WindowProcessListener;
Yunfan Chen75157d72018-07-27 14:47:21 +090066
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070067import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import java.io.PrintWriter;
69import java.util.ArrayList;
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -040070import java.util.Arrays;
Zimuzo972e1cd2019-01-28 16:30:01 +000071import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
73/**
74 * Full information about a particular process that
75 * is currently running.
76 */
Yunfan Chen585f2932019-01-29 16:04:45 +090077class ProcessRecord implements WindowProcessListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080078 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
79
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -070080 private final ActivityManagerService mService; // where we came from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080082 final boolean isolated; // true if this is a special isolated process
Martijn Coenen01e719b2018-12-05 16:01:38 +010083 final boolean appZygote; // true if this is forked from the app zygote
Dianne Hackborna0c283e2012-02-09 10:47:01 -080084 final int uid; // uid of process; may be different from 'info' if isolated
85 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 final String processName; // name of the process
87 // List of packages running in the process
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070088 final PackageList pkgList = new PackageList();
89 final class PackageList {
90 final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>();
91
92 ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) {
93 mWindowProcessController.addPackage(key);
94 return mPkgList.put(key, value);
95 }
96
97 void clear() {
98 mPkgList.clear();
99 mWindowProcessController.clearPackageList();
100 }
101
102 int size() {
103 return mPkgList.size();
104 }
105
106 String keyAt(int index) {
107 return mPkgList.keyAt(index);
108 }
109
110 public ProcessStats.ProcessStateHolder valueAt(int index) {
111 return mPkgList.valueAt(index);
112 }
113
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700114 ProcessStats.ProcessStateHolder get(String pkgName) {
115 return mPkgList.get(pkgName);
116 }
117
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700118 boolean containsKey(Object key) {
119 return mPkgList.containsKey(key);
120 }
121 }
122
Dianne Hackborne17b4452018-01-10 13:15:40 -0800123 final ProcessList.ProcStateMemTracker procStateMemTracker
124 = new ProcessList.ProcStateMemTracker();
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700125 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700126 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 IApplicationThread thread; // the actual proc... may be null only if
128 // 'persistent' is true (in which case we
129 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700130 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -0800131 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700133 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800134 int[] gids; // The gids this process was launched with
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700135 private String mRequiredAbi;// The ABI this process was launched with
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800136 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800138 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700139 long lastPssTime; // Last time we retrieved PSS data
140 long nextPssTime; // Next time we want to request PSS data
141 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700142 long initialIdlePss; // Initial memory pss of process for idle maintenance.
143 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800144 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700145 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800146 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 int maxAdj; // Maximum OOM adjustment for this process
Wale Ogunwale31913b52018-10-13 08:29:31 -0700148 private int mCurRawAdj; // Current OOM unlimited adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 int setRawAdj; // Last set OOM unlimited adjustment for this process
150 int curAdj; // Current OOM adjustment for this process
151 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700152 int verifiedAdj; // The last adjustment that was verified as actually being set
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800153 long lastCompactTime; // The last time that this process was compacted
154 int reqCompactAction; // The most recent compaction action requested for this app.
155 int lastCompactAction; // The most recent compaction action performed for this app.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700156 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700157 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700158 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700159 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700160 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
Amith Yamasani08888c02018-12-07 09:38:25 -0800161 private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation
riddle_hsu6793fc32015-03-31 11:54:14 +0800162 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
163 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800164 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700165 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
166 int renderThreadTid; // TID for RenderThread
Dianne Hackborna631d562018-11-20 15:58:15 -0800167 ServiceRecord connectionService; // Service that applied current connectionGroup/Importance
168 int connectionGroup; // Last group set by a connection
169 int connectionImportance; // Last importance set by a connection
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700170 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700171 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700172 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700173 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700174 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700175 private boolean mHasForegroundServices; // Running any services that are foreground?
Amith Yamasania0a30a12019-01-22 11:38:06 -0800176 private int mFgServiceTypes; // Type of foreground service, if there is a foreground service.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700177 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700178 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700179 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700180 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700181 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800182 // is interacting with? E.g. The status bar when it is expanded, but
183 // not when it is minimized. When true the
184 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
185 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700186 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800187 // overlays on-top of activity UIs on screen. E.g. display a window
188 // of type
189 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
190 // When true the process will oom adj score will be set to
191 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
192 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100193 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
194 // the process will be set to use the
195 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
196 // performance, as well as oom adj score will be set to
197 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
198 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700199 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700200 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700201 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700203 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700204 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700205 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700206 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600207 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700208 private long mInteractionEventTime; // The time we sent the last interaction event
209 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700210 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700211 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700212 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700213 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
214 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700215 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700216 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700217 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700218 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
219 // process.
220 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800221 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700222 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700223 long lastCpuTime; // How long proc has run CPU at last check
224 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700226 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800227 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700228 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700229 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800230 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700231 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700232 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700233 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700234 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700235 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700236 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100237 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
238
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700239 // Cache of last retrieve memory info and uptime, to throttle how frequently
240 // apps can requyest it.
241 Debug.MemoryInfo lastMemInfo;
242 long lastMemInfoTime;
243
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700244 // Controller for driving the process state on the window manager side.
245 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700247 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700249 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700251 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700253 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700255 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700257 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Michal Karpinskiac116df2018-12-10 17:51:42 +0000258 // A set of tokens that currently contribute to this process being temporarily whitelisted
259 // to start activities even if it's not in the foreground
260 final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700261
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400262 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
263 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
264
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700265 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700266 private boolean mPersistent;// always keep this application running?
267 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700269 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700270 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 Dialog anrDialog; // dialog being displayed due to app not resp.
Riddle Hsuaaef7312019-01-24 19:00:58 +0800272 volatile boolean removed; // Whether this process should be killed and removed from process
273 // list. It is set when the package is force-stopped or the process
274 // has crashed too many times.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700275 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 boolean waitedForDebugger; // has process show wait for debugger dialog?
277 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700278
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800279 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700280 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700281 boolean pendingStart; // Process start is pending.
282 long startSeq; // Seq no. indicating the latest process start associated with
283 // this process record.
Sudheer Shanka87915d62018-11-06 10:57:35 -0800284 int mountMode; // Indicates how the external storage was mounted for this process.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 // These reports are generated & stored when an app gets into an error condition.
287 // They will be "null" when all is OK.
288 ActivityManager.ProcessErrorStateInfo crashingReport;
289 ActivityManager.ProcessErrorStateInfo notRespondingReport;
290
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200291 // Who will be notified of the error. This is usually an activity in the
292 // app that installed the package.
293 ComponentName errorReportReceiver;
294
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700295 // Process is currently hosting a backup agent for backup or restore
296 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700297 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
298 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700299
Sudheer Shankaf6690102017-10-16 10:20:32 -0700300 // Params used in starting this process.
301 String hostingType;
302 String hostingNameStr;
303 String seInfo;
304 long startTime;
305 // This will be same as {@link #uid} usually except for some apps used during factory testing.
306 int startUid;
307
308 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
309 long startTime) {
310 this.startUid = startUid;
311 this.hostingType = hostingType;
312 this.hostingNameStr = hostingNameStr;
313 this.seInfo = seInfo;
314 this.startTime = startTime;
315 }
316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700318 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700319
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800320 pw.print(prefix); pw.print("user #"); pw.print(userId);
321 pw.print(" uid="); pw.print(info.uid);
322 if (uid != info.uid) {
323 pw.print(" ISOLATED uid="); pw.print(uid);
324 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800325 pw.print(" gids={");
326 if (gids != null) {
327 for (int gi=0; gi<gids.length; gi++) {
328 if (gi != 0) pw.print(", ");
329 pw.print(gids[gi]);
330
331 }
332 }
333 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700334 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800335 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700336 if (info.className != null) {
337 pw.print(prefix); pw.print("class="); pw.println(info.className);
338 }
339 if (info.manageSpaceActivityName != null) {
340 pw.print(prefix); pw.print("manageSpaceActivityName=");
341 pw.println(info.manageSpaceActivityName);
342 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900343
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700344 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
345 pw.print(" publicDir="); pw.print(info.publicSourceDir);
346 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700347 pw.print(prefix); pw.print("packageList={");
348 for (int i=0; i<pkgList.size(); i++) {
349 if (i > 0) pw.print(", ");
350 pw.print(pkgList.keyAt(i));
351 }
352 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700353 if (pkgDeps != null) {
354 pw.print(prefix); pw.print("packageDependencies={");
355 for (int i=0; i<pkgDeps.size(); i++) {
356 if (i > 0) pw.print(", ");
357 pw.print(pkgDeps.valueAt(i));
358 }
359 pw.println("}");
360 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700361 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700362 if (mInstr != null) {
363 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700364 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700365 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700366 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700367 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700368 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700369 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700370 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700371 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800372 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700373 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700374 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700375 pw.println();
376 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
377 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800378 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800379 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800380 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800381 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800382 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800383 pw.print(prefix); pw.print("procStateMemTracker: ");
384 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700385 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800386 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700387 if (serviceb) {
388 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
389 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
390 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700391 if (notCachedSinceIdle) {
392 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700393 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700394 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700395 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700396 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700397 pw.print(" setRaw="); pw.print(setRawAdj);
398 pw.print(" cur="); pw.print(curAdj);
399 pw.print(" set="); pw.println(setAdj);
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800400 pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime);
401 pw.print(" lastCompactAction="); pw.print(lastCompactAction);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700402 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700403 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700404 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700405 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700406 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700407 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700408 pw.print(" pssProcState="); pw.print(pssProcState);
409 pw.print(" setProcState="); pw.print(setProcState);
410 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700411 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700412 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700413 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700414 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700415 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700416 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
417 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700418 }
Dianne Hackborna631d562018-11-20 15:58:15 -0800419 if (connectionService != null || connectionGroup != 0) {
420 pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup);
421 pw.print(" Importance="); pw.print(connectionImportance);
422 pw.print(" Service="); pw.println(connectionService);
423 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700424 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
425 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
426 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100427 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700428 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700429 if (mHasForegroundServices || forcingToImportant != null) {
430 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700431 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700432 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700433 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700434 pw.print(prefix); pw.print("reportedInteraction=");
435 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700436 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800437 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700438 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800439 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700440 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700441 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700442 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700443 }
444 pw.println();
445 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700446 if (mPersistent || removed) {
447 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700448 pw.print(" removed="); pw.println(removed);
449 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700450 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
451 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
452 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700453 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700454 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800455 if (lastProviderTime > 0) {
456 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700457 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800458 pw.println();
459 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700460 if (lastTopTime > 0) {
461 pw.print(prefix); pw.print("lastTopTime=");
462 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
463 pw.println();
464 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700465 if (hasStartedServices) {
466 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
467 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700468 if (pendingStart) {
469 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
470 }
471 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800472 pw.print(prefix); pw.print("mountMode="); pw.println(
473 DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode));
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700474 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700475 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700476 if (lastCpuTime > 0) {
477 pw.print(" timeUsed=");
478 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
479 }
480 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700481 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700482 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700483 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700484 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700485 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700486 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700487 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700488 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700489 if (killed || killedByAm || waitingToKill != null) {
490 pw.print(prefix); pw.print("killed="); pw.print(killed);
491 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700492 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700493 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700494 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700495 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700496 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700497 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700498 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700499 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700500 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200501 pw.print(" bad="); pw.print(bad);
502
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700503 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200504 if (errorReportReceiver != null) {
505 pw.print(" errorReportReceiver=");
506 pw.print(errorReportReceiver.flattenToShortString());
507 }
508 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700509 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700510 if (whitelistManager) {
511 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
512 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400513 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
514 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
515 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
516 pw.println(Arrays.toString(isolatedEntryPointArgs));
517 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700518 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700519 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700520 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700521 for (int i=0; i<services.size(); i++) {
522 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700523 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700524 }
525 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700526 pw.print(prefix); pw.print("Executing Services (fg=");
527 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700528 for (int i=0; i<executingServices.size(); i++) {
529 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700530 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700531 }
532 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700533 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700534 for (int i=0; i<connections.size(); i++) {
535 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700536 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700537 }
538 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700539 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700540 for (int i=0; i<pubProviders.size(); i++) {
541 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
542 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700543 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700544 }
545 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700546 pw.print(prefix); pw.println("Connected Providers:");
547 for (int i=0; i<conProviders.size(); i++) {
548 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
549 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700550 }
yangzhenyud509bc92016-08-31 18:26:46 +0800551 if (!curReceivers.isEmpty()) {
552 pw.print(prefix); pw.println("Current Receivers:");
553 for (int i=0; i < curReceivers.size(); i++) {
554 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
555 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700556 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700557 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700558 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700559 for (int i=0; i<receivers.size(); i++) {
560 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700561 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700564
Bookatz152623f2018-07-23 15:57:44 -0700565 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700566 int _uid) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700567 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800569 isolated = _info.uid != _uid;
Martijn Coenen01e719b2018-12-05 16:01:38 +0100570 appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
571 && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800572 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700573 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700575 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700576 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700577 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700578 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700580 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700581 mWindowProcessController = new WindowProcessController(
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700582 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700583 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 }
585
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700586 public void setPid(int _pid) {
587 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700588 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700589 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800590 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700591 stringName = null;
592 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700593
594 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
595 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700596 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700597 if (origBase != null) {
598 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700599 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700600 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
601 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
602 uid, processName, pkgList.keyAt(ipkg),
603 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
604 pkgList.valueAt(ipkg).appVersion);
605 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700606 origBase.makeInactive();
607 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800608 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700609 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700610 baseProcessTracker.makeActive();
611 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700612 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
613 if (holder.state != null && holder.state != origBase) {
614 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700615 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800616 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700617 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700618 if (holder.state != baseProcessTracker) {
619 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700620 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700621 }
622 }
623 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700624 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700625 }
626
627 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700628 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700629 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700630 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700631 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700632 if (origBase != null) {
633 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700634 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700635 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
636 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
637 uid, processName, pkgList.keyAt(ipkg),
638 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
639 pkgList.valueAt(ipkg).appVersion);
640 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700641 origBase.makeInactive();
642 }
643 baseProcessTracker = null;
644 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700645 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
646 if (holder.state != null && holder.state != origBase) {
647 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700648 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700649 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700650 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700651 }
652 }
653 }
654
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700655 boolean hasActivities() {
656 return mWindowProcessController.hasActivities();
657 }
658
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700659 boolean hasActivitiesOrRecentTasks() {
660 return mWindowProcessController.hasActivitiesOrRecentTasks();
661 }
662
663 boolean hasRecentTasks() {
664 return mWindowProcessController.hasRecentTasks();
665 }
666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 /**
668 * This method returns true if any of the activities within the process record are interesting
669 * to the user. See HistoryRecord.isInterestingToUserLocked()
670 */
671 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700672 if (mWindowProcessController.isInterestingToUser()) {
673 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100675
676 final int servicesSize = services.size();
677 for (int i = 0; i < servicesSize; i++) {
678 ServiceRecord r = services.valueAt(i);
679 if (r.isForeground) {
680 return true;
681 }
682 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 return false;
684 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800685
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700686 public void unlinkDeathRecipient() {
687 if (deathRecipient != null && thread != null) {
688 thread.asBinder().unlinkToDeath(deathRecipient, 0);
689 }
690 deathRecipient = null;
691 }
692
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700693 void updateHasAboveClientLocked() {
694 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700695 for (int i=connections.size()-1; i>=0; i--) {
696 ConnectionRecord cr = connections.valueAt(i);
697 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
698 hasAboveClient = true;
699 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700700 }
701 }
702 }
703
Dianne Hackbornc8230512013-07-13 21:32:12 -0700704 int modifyRawOomAdj(int adj) {
705 if (hasAboveClient) {
706 // If this process has bound to any services with BIND_ABOVE_CLIENT,
707 // then we need to drop its adjustment to be lower than the service's
708 // in order to honor the request. We want to drop it by one adjustment
709 // level... but there is special meaning applied to various levels so
710 // we will skip some of them.
711 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
712 // System process will not get dropped, ever
713 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
714 adj = ProcessList.VISIBLE_APP_ADJ;
715 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
716 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
Amith Yamasani0567ec62019-01-23 11:11:02 -0800717 } else if (adj < ProcessList.PERCEPTIBLE_LOW_APP_ADJ) {
718 adj = ProcessList.PERCEPTIBLE_LOW_APP_ADJ;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700719 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
720 adj = ProcessList.CACHED_APP_MIN_ADJ;
721 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
722 adj++;
723 }
724 }
725 return adj;
726 }
727
Joe Onorato57190282016-04-20 15:37:49 -0700728 void scheduleCrash(String message) {
729 // Checking killedbyAm should keep it from showing the crash dialog if the process
730 // was already dead for a good / normal reason.
731 if (!killedByAm) {
732 if (thread != null) {
733 if (pid == Process.myPid()) {
734 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
735 return;
736 }
737 long ident = Binder.clearCallingIdentity();
738 try {
739 thread.scheduleCrash(message);
740 } catch (RemoteException e) {
741 // If it's already dead our work is done. If it's wedged just kill it.
742 // We won't get the crash dialog or the error reporting.
743 kill("scheduleCrash for '" + message + "' failed", true);
744 } finally {
745 Binder.restoreCallingIdentity(ident);
746 }
747 }
748 }
749 }
750
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700751 void kill(String reason, boolean noisy) {
752 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700753 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700754 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
755 mService.reportUidInfoMessageLocked(TAG,
756 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
757 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700758 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700759 if (pid > 0) {
760 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
761 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400762 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700763 } else {
764 pendingStart = false;
765 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700766 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700767 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700768 killedByAm = true;
769 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700770 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700771 }
772 }
773
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700774 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700775 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800776 writeToProto(proto, fieldId, -1);
777 }
778
779 public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700780 long token = proto.start(fieldId);
781 proto.write(ProcessRecordProto.PID, pid);
782 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800783 proto.write(ProcessRecordProto.UID, info.uid);
784 if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700785 proto.write(ProcessRecordProto.USER_ID, userId);
786 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800787 }
788 if (uid != info.uid) {
789 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
Yi Jin129fc6c2017-09-28 15:48:38 -0700790 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700791 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800792 if (lruIndex >= 0) {
793 proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
794 }
Yi Jin129fc6c2017-09-28 15:48:38 -0700795 proto.end(token);
796 }
797
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800798 public String toShortString() {
799 if (shortStringName != null) {
800 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700801 }
802 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800803 toShortString(sb);
804 return shortStringName = sb.toString();
805 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700806
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800807 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700808 sb.append(pid);
809 sb.append(':');
810 sb.append(processName);
811 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800812 if (info.uid < Process.FIRST_APPLICATION_UID) {
813 sb.append(uid);
814 } else {
815 sb.append('u');
816 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700817 int appId = UserHandle.getAppId(info.uid);
818 if (appId >= Process.FIRST_APPLICATION_UID) {
819 sb.append('a');
820 sb.append(appId - Process.FIRST_APPLICATION_UID);
821 } else {
822 sb.append('s');
823 sb.append(appId);
824 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800825 if (uid != info.uid) {
826 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700827 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800828 }
829 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800830 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700831
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800832 public String toString() {
833 if (stringName != null) {
834 return stringName;
835 }
836 StringBuilder sb = new StringBuilder(128);
837 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700838 sb.append(Integer.toHexString(System.identityHashCode(this)));
839 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800840 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700841 sb.append('}');
842 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700844
845 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700846 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700847 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700848 sb.append(' ');
849 if (adjTarget instanceof ComponentName) {
850 sb.append(((ComponentName)adjTarget).flattenToShortString());
851 } else if (adjTarget != null) {
852 sb.append(adjTarget.toString());
853 } else {
854 sb.append("{null}");
855 }
856 sb.append("<=");
857 if (adjSource instanceof ProcessRecord) {
858 sb.append("Proc{");
859 sb.append(((ProcessRecord)adjSource).toShortString());
860 sb.append("}");
861 } else if (adjSource != null) {
862 sb.append(adjSource.toString());
863 } else {
864 sb.append("{null}");
865 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700866 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700867 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700868 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700869 }
870
Wale Ogunwale9c103022018-10-18 07:44:54 -0700871 @Override
872 public void addPackage(String pkg, long versionCode) {
873 synchronized (mService) {
874 addPackage(pkg, versionCode, mService.mProcessStats);
875 }
876 }
877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 /*
879 * Return true if package has been added false if not
880 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700881 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700882 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700883 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
884 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700885 if (baseProcessTracker != null) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800886 tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
887 processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700888 pkgList.put(pkg, holder);
889 if (holder.state != baseProcessTracker) {
890 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700891 }
892 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700893 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 return true;
896 }
897 return false;
898 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700899
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700900 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700901 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
902 if (hasStartedServices) {
903 return ProcessList.SERVICE_B_ADJ;
904 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700905 }
906 return setAdj;
907 }
908
Dianne Hackborna413dc02013-07-12 12:02:55 -0700909 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700910 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700911 mRepProcState = newState;
912 setCurProcState(newState);
Amith Yamasani08888c02018-12-07 09:38:25 -0800913 setCurRawProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700914 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
915 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
916 uid, processName, pkgList.keyAt(ipkg),
917 ActivityManager.processStateAmToProto(mRepProcState),
918 pkgList.valueAt(ipkg).appVersion);
919 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700920 }
921 }
922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 /*
924 * Delete all packages from list except the package indicated in info
925 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700926 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700927 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700928 if (baseProcessTracker != null) {
929 long now = SystemClock.uptimeMillis();
930 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700931 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700932 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
933 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
934 uid, processName, pkgList.keyAt(ipkg),
935 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
936 pkgList.valueAt(ipkg).appVersion);
937 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700938 if (N != 1) {
939 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700940 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
941 if (holder.state != null && holder.state != baseProcessTracker) {
942 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700943 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700944
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700945 }
946 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700947 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700948 info.longVersionCode);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800949 tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700950 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700951 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700952 if (holder.state != baseProcessTracker) {
953 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700954 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700955 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700956 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700957 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700958 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700959 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 public String[] getPackageList() {
963 int size = pkgList.size();
964 if (size == 0) {
965 return null;
966 }
967 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700968 for (int i=0; i<pkgList.size(); i++) {
969 list[i] = pkgList.keyAt(i);
970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 return list;
972 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700973
Zimuzo972e1cd2019-01-28 16:30:01 +0000974 public List<VersionedPackage> getPackageListWithVersionCode() {
975 int size = pkgList.size();
976 if (size == 0) {
977 return null;
978 }
979 List<VersionedPackage> list = new ArrayList<>();
980 for (int i = 0; i < pkgList.size(); i++) {
981 list.add(new VersionedPackage(pkgList.keyAt(i), pkgList.valueAt(i).appVersion));
982 }
983 return list;
984 }
985
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700986 WindowProcessController getWindowProcessController() {
987 return mWindowProcessController;
988 }
989
990 void setCurrentSchedulingGroup(int curSchedGroup) {
991 mCurSchedGroup = curSchedGroup;
992 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
993 }
994
995 int getCurrentSchedulingGroup() {
996 return mCurSchedGroup;
997 }
998
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700999 void setCurProcState(int curProcState) {
1000 mCurProcState = curProcState;
1001 mWindowProcessController.setCurrentProcState(mCurProcState);
1002 }
1003
1004 int getCurProcState() {
1005 return mCurProcState;
1006 }
1007
Amith Yamasani08888c02018-12-07 09:38:25 -08001008 void setCurRawProcState(int curRawProcState) {
1009 mCurRawProcState = curRawProcState;
1010 }
1011
1012 int getCurRawProcState() {
1013 return mCurRawProcState;
1014 }
1015
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001016 void setReportedProcState(int repProcState) {
1017 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -07001018 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
1019 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
1020 uid, processName, pkgList.keyAt(ipkg),
1021 ActivityManager.processStateAmToProto(mRepProcState),
1022 pkgList.valueAt(ipkg).appVersion);
1023 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001024 mWindowProcessController.setReportedProcState(repProcState);
1025 }
1026
1027 int getReportedProcState() {
1028 return mRepProcState;
1029 }
1030
1031 void setCrashing(boolean crashing) {
1032 mCrashing = crashing;
1033 mWindowProcessController.setCrashing(crashing);
1034 }
1035
1036 boolean isCrashing() {
1037 return mCrashing;
1038 }
1039
1040 void setNotResponding(boolean notResponding) {
1041 mNotResponding = notResponding;
1042 mWindowProcessController.setNotResponding(notResponding);
1043 }
1044
1045 boolean isNotResponding() {
1046 return mNotResponding;
1047 }
1048
1049 void setPersistent(boolean persistent) {
1050 mPersistent = persistent;
1051 mWindowProcessController.setPersistent(persistent);
1052 }
1053
1054 boolean isPersistent() {
1055 return mPersistent;
1056 }
1057
1058 public void setRequiredAbi(String requiredAbi) {
1059 mRequiredAbi = requiredAbi;
1060 mWindowProcessController.setRequiredAbi(requiredAbi);
1061 }
1062
1063 String getRequiredAbi() {
1064 return mRequiredAbi;
1065 }
1066
Amith Yamasania0a30a12019-01-22 11:38:06 -08001067 void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001068 mHasForegroundServices = hasForegroundServices;
Amith Yamasania0a30a12019-01-22 11:38:06 -08001069 mFgServiceTypes = fgServiceTypes;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001070 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1071 }
1072
1073 boolean hasForegroundServices() {
1074 return mHasForegroundServices;
1075 }
1076
Amith Yamasania0a30a12019-01-22 11:38:06 -08001077 boolean hasLocationForegroundServices() {
1078 return mHasForegroundServices
1079 && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0;
1080 }
1081
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001082 void setHasForegroundActivities(boolean hasForegroundActivities) {
1083 mHasForegroundActivities = hasForegroundActivities;
1084 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1085 }
1086
1087 boolean hasForegroundActivities() {
1088 return mHasForegroundActivities;
1089 }
1090
1091 void setHasClientActivities(boolean hasClientActivities) {
1092 mHasClientActivities = hasClientActivities;
1093 mWindowProcessController.setHasClientActivities(hasClientActivities);
1094 }
1095
1096 boolean hasClientActivities() {
1097 return mHasClientActivities;
1098 }
1099
1100 void setHasTopUi(boolean hasTopUi) {
1101 mHasTopUi = hasTopUi;
1102 mWindowProcessController.setHasTopUi(hasTopUi);
1103 }
1104
1105 boolean hasTopUi() {
1106 return mHasTopUi;
1107 }
1108
1109 void setHasOverlayUi(boolean hasOverlayUi) {
1110 mHasOverlayUi = hasOverlayUi;
1111 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1112 }
1113
1114 boolean hasOverlayUi() {
1115 return mHasOverlayUi;
1116 }
1117
1118 void setInteractionEventTime(long interactionEventTime) {
1119 mInteractionEventTime = interactionEventTime;
1120 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1121 }
1122
1123 long getInteractionEventTime() {
1124 return mInteractionEventTime;
1125 }
1126
1127 void setFgInteractionTime(long fgInteractionTime) {
1128 mFgInteractionTime = fgInteractionTime;
1129 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1130 }
1131
1132 long getFgInteractionTime() {
1133 return mFgInteractionTime;
1134 }
1135
1136 void setWhenUnimportant(long whenUnimportant) {
1137 mWhenUnimportant = whenUnimportant;
1138 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1139 }
1140
1141 long getWhenUnimportant() {
1142 return mWhenUnimportant;
1143 }
1144
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001145 void setDebugging(boolean debugging) {
1146 mDebugging = debugging;
1147 mWindowProcessController.setDebugging(debugging);
1148 }
1149
1150 boolean isDebugging() {
1151 return mDebugging;
1152 }
1153
1154 void setUsingWrapper(boolean usingWrapper) {
1155 mUsingWrapper = usingWrapper;
1156 mWindowProcessController.setUsingWrapper(usingWrapper);
1157 }
1158
1159 boolean isUsingWrapper() {
1160 return mUsingWrapper;
1161 }
1162
Michal Karpinskiac116df2018-12-10 17:51:42 +00001163 void addAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001164 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001165 mAllowBackgroundActivityStartsTokens.add(entity);
1166 mWindowProcessController.setAllowBackgroundActivityStarts(true);
1167 }
1168
1169 void removeAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001170 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001171 mAllowBackgroundActivityStartsTokens.remove(entity);
1172 mWindowProcessController.setAllowBackgroundActivityStarts(
1173 !mAllowBackgroundActivityStartsTokens.isEmpty());
1174 }
1175
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001176 void setActiveInstrumentation(ActiveInstrumentation instr) {
1177 mInstr = instr;
Michal Karpinski4bc56492019-01-31 12:07:33 +00001178 boolean isInstrumenting = instr != null;
1179 mWindowProcessController.setInstrumenting(isInstrumenting,
1180 isInstrumenting && instr.mHasBackgroundActivityStartsPermission);
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001181 }
1182
1183 ActiveInstrumentation getActiveInstrumentation() {
1184 return mInstr;
1185 }
1186
Wale Ogunwale31913b52018-10-13 08:29:31 -07001187 void setCurRawAdj(int curRawAdj) {
1188 mCurRawAdj = curRawAdj;
1189 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1190 }
1191
1192 int getCurRawAdj() {
1193 return mCurRawAdj;
1194 }
1195
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001196 @Override
1197 public void clearProfilerIfNeeded() {
1198 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001199 if (mService.mProfileData.getProfileProc() == null
1200 || mService.mProfileData.getProfilerInfo() == null
1201 || mService.mProfileData.getProfileProc() != this) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001202 return;
1203 }
1204 mService.clearProfilerLocked();
1205 }
1206 }
1207
1208 @Override
1209 public void updateServiceConnectionActivities() {
1210 synchronized (mService) {
1211 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1212 }
1213 }
1214
1215 @Override
1216 public void setPendingUiClean(boolean pendingUiClean) {
1217 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001218 mPendingUiClean = pendingUiClean;
1219 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001220 }
1221 }
1222
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001223 boolean hasPendingUiClean() {
1224 return mPendingUiClean;
1225 }
1226
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001227 @Override
1228 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1229 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001230 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001231 forceProcessStateUpTo(newState);
1232 }
1233 }
1234
1235 @Override
1236 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru,
1237 boolean activityChange, boolean updateOomAdj) {
1238 synchronized (mService) {
1239 if (updateServiceConnectionActivities) {
1240 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1241 }
1242 if (updateLru) {
Amith Yamasani98a00922018-08-21 12:50:30 -04001243 mService.mProcessList.updateLruProcessLocked(this, activityChange, null);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001244 }
1245 if (updateOomAdj) {
1246 mService.updateOomAdjLocked();
1247 }
1248 }
1249 }
1250
1251 @Override
Riddle Hsuaaef7312019-01-24 19:00:58 +08001252 public boolean isRemoved() {
1253 return removed;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001254 }
1255
Wale Ogunwale86b74462018-07-02 08:42:43 -07001256 /**
1257 * Returns the total time (in milliseconds) spent executing in both user and system code.
1258 * Safe to call without lock held.
1259 */
Wale Ogunwale9c103022018-10-18 07:44:54 -07001260 @Override
Wale Ogunwale86b74462018-07-02 08:42:43 -07001261 public long getCpuTime() {
1262 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1263 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001264
Wale Ogunwale9c103022018-10-18 07:44:54 -07001265 @Override
1266 public void clearWaitingToKill() {
1267 synchronized (mService) {
1268 waitingToKill = null;
1269 }
1270 }
1271
1272 @Override
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001273 public void onStartActivity(int topProcessState, boolean setProfileProc) {
Wale Ogunwale9c103022018-10-18 07:44:54 -07001274 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001275 if (setProfileProc) {
1276 mService.mProfileData.setProfileProc(this);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001277 }
1278
1279 hasShownUi = true;
1280 setPendingUiClean(true);
1281 forceProcessStateUpTo(topProcessState);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001282 }
1283 }
1284
1285 @Override
1286 public void appDied() {
1287 synchronized (mService) {
1288 mService.appDiedLocked(this);
1289 }
1290 }
1291
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001292 public long getInputDispatchingTimeout() {
1293 return mWindowProcessController.getInputDispatchingTimeout();
1294 }
1295
Yang Lu732d6382018-11-05 07:53:12 -08001296 public int getProcessClassEnum() {
1297 if (pid == MY_PID) {
1298 return ServerProtoEnums.SYSTEM_SERVER;
1299 }
1300 if (info == null) {
1301 return ServerProtoEnums.ERROR_SOURCE_UNKNOWN;
1302 }
1303 return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP :
1304 ServerProtoEnums.DATA_APP;
1305 }
1306
Yunfan Chen585f2932019-01-29 16:04:45 +09001307 /**
1308 * Unless configured otherwise, swallow ANRs in background processes & kill the process.
1309 * Non-private access is for tests only.
1310 */
1311 @VisibleForTesting
1312 boolean isSilentAnr() {
1313 return !getShowBackground() && !isInterestingForBackgroundTraces();
1314 }
1315
1316 /** Non-private access is for tests only. */
1317 @VisibleForTesting
1318 List<ProcessRecord> getLruProcessList() {
1319 return mService.mProcessList.mLruProcesses;
1320 }
1321
1322 /** Non-private access is for tests only. */
1323 @VisibleForTesting
1324 boolean isMonitorCpuUsage() {
1325 return mService.MONITOR_CPU_USAGE;
1326 }
1327
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001328 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1329 String parentShortComponentName, WindowProcessController parentProcess,
1330 boolean aboveSystem, String annotation) {
1331 ArrayList<Integer> firstPids = new ArrayList<>(5);
1332 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1333
Wale Ogunwalee2172292018-10-25 10:11:10 -07001334 mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true));
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001335
1336 long anrTime = SystemClock.uptimeMillis();
Yunfan Chen585f2932019-01-29 16:04:45 +09001337 if (isMonitorCpuUsage()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001338 mService.updateCpuStatsNow();
1339 }
1340
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001341 synchronized (mService) {
1342 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
Wale Ogunwale387b34c2018-10-25 19:59:40 -07001343 if (mService.mAtmInternal.isShuttingDown()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001344 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1345 return;
1346 } else if (isNotResponding()) {
1347 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1348 return;
1349 } else if (isCrashing()) {
1350 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1351 return;
1352 } else if (killedByAm) {
1353 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1354 return;
1355 } else if (killed) {
1356 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1357 return;
1358 }
1359
1360 // In case we come through here for the same app before completing
1361 // this one, mark as anring now so we will bail out.
1362 setNotResponding(true);
1363
1364 // Log the ANR to the event log.
1365 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1366 annotation);
1367
1368 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1369 firstPids.add(pid);
1370
1371 // Don't dump other PIDs if it's a background ANR
Yunfan Chen585f2932019-01-29 16:04:45 +09001372 if (!isSilentAnr()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001373 int parentPid = pid;
1374 if (parentProcess != null && parentProcess.getPid() > 0) {
1375 parentPid = parentProcess.getPid();
1376 }
1377 if (parentPid != pid) firstPids.add(parentPid);
1378
1379 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1380
Yunfan Chen585f2932019-01-29 16:04:45 +09001381 for (int i = getLruProcessList().size() - 1; i >= 0; i--) {
1382 ProcessRecord r = getLruProcessList().get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001383 if (r != null && r.thread != null) {
1384 int myPid = r.pid;
1385 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1386 if (r.isPersistent()) {
1387 firstPids.add(myPid);
1388 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1389 } else if (r.treatLikeActivity) {
1390 firstPids.add(myPid);
1391 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1392 } else {
1393 lastPids.put(myPid, Boolean.TRUE);
1394 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1395 }
1396 }
1397 }
1398 }
1399 }
1400 }
1401
1402 // Log the ANR to the main log.
1403 StringBuilder info = new StringBuilder();
1404 info.setLength(0);
1405 info.append("ANR in ").append(processName);
1406 if (activityShortComponentName != null) {
1407 info.append(" (").append(activityShortComponentName).append(")");
1408 }
1409 info.append("\n");
1410 info.append("PID: ").append(pid).append("\n");
1411 if (annotation != null) {
1412 info.append("Reason: ").append(annotation).append("\n");
1413 }
1414 if (parentShortComponentName != null
1415 && parentShortComponentName.equals(activityShortComponentName)) {
1416 info.append("Parent: ").append(parentShortComponentName).append("\n");
1417 }
1418
1419 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1420
1421 // don't dump native PIDs for background ANRs unless it is the process of interest
1422 String[] nativeProcs = null;
Yunfan Chen585f2932019-01-29 16:04:45 +09001423 if (isSilentAnr()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001424 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1425 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1426 nativeProcs = new String[] { processName };
1427 break;
1428 }
1429 }
1430 } else {
1431 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1432 }
1433
1434 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1435 ArrayList<Integer> nativePids = null;
1436
1437 if (pids != null) {
1438 nativePids = new ArrayList<>(pids.length);
1439 for (int i : pids) {
1440 nativePids.add(i);
1441 }
1442 }
1443
1444 // For background ANRs, don't pass the ProcessCpuTracker to
1445 // avoid spending 1/2 second collecting stats to rank lastPids.
1446 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
Yunfan Chen585f2932019-01-29 16:04:45 +09001447 (isSilentAnr()) ? null : processCpuTracker, (isSilentAnr()) ? null : lastPids,
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001448 nativePids);
1449
1450 String cpuInfo = null;
Yunfan Chen585f2932019-01-29 16:04:45 +09001451 if (isMonitorCpuUsage()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001452 mService.updateCpuStatsNow();
1453 synchronized (mService.mProcessCpuTracker) {
1454 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1455 }
1456 info.append(processCpuTracker.printCurrentLoad());
1457 info.append(cpuInfo);
1458 }
1459
1460 info.append(processCpuTracker.printCurrentState(anrTime));
1461
1462 Slog.e(TAG, info.toString());
1463 if (tracesFile == null) {
1464 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1465 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1466 }
1467
1468 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1469 activityShortComponentName == null ? "unknown": activityShortComponentName,
1470 annotation,
1471 (this.info != null) ? (this.info.isInstantApp()
1472 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1473 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1474 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1475 isInterestingToUserLocked()
1476 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
Yang Lu732d6382018-11-05 07:53:12 -08001477 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
1478 getProcessClassEnum(),
1479 (this.info != null) ? this.info.packageName : "");
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001480 final ProcessRecord parentPr = parentProcess != null
1481 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001482 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001483 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001484
Wale Ogunwalee2172292018-10-25 10:11:10 -07001485 if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true),
1486 () -> {
1487 synchronized (mService) {
1488 mService.mServices.scheduleServiceTimeoutLocked(this);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001489 }
Wale Ogunwalee2172292018-10-25 10:11:10 -07001490 })) {
1491 return;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001492 }
1493
1494 synchronized (mService) {
Yunfan Chen585f2932019-01-29 16:04:45 +09001495 // mBatteryStatsService can be null if the AMS is constructed with injector only. This
1496 // will only happen in tests.
1497 if (mService.mBatteryStatsService != null) {
1498 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1499 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001500
Yunfan Chen585f2932019-01-29 16:04:45 +09001501 if (isSilentAnr()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001502 kill("bg anr", true);
1503 return;
1504 }
1505
1506 // Set the app's notResponding state, and look up the errorReportReceiver
1507 makeAppNotRespondingLocked(activityShortComponentName,
1508 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1509
Yunfan Chen585f2932019-01-29 16:04:45 +09001510 // mUiHandler can be null if the AMS is constructed with injector only. This will only
1511 // happen in tests.
1512 if (mService.mUiHandler != null) {
1513 // Bring up the infamous App Not Responding dialog
1514 Message msg = Message.obtain();
1515 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1516 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001517
Yunfan Chen585f2932019-01-29 16:04:45 +09001518 mService.mUiHandler.sendMessage(msg);
1519 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001520 }
1521 }
1522
1523 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1524 setNotResponding(true);
Yunfan Chen585f2932019-01-29 16:04:45 +09001525 // mAppErrors can be null if the AMS is constructed with injector only. This will only
1526 // happen in tests.
1527 if (mService.mAppErrors != null) {
1528 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1529 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1530 activity, shortMsg, longMsg, null);
1531 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001532 startAppProblemLocked();
1533 getWindowProcessController().stopFreezingActivities();
1534 }
1535
1536 void startAppProblemLocked() {
1537 // If this app is not running under the current user, then we can't give it a report button
1538 // because that would require launching the report UI under a different user.
1539 errorReportReceiver = null;
1540
1541 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1542 if (this.userId == userId) {
1543 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1544 mService.mContext, info.packageName, info.flags);
1545 }
1546 }
1547 mService.skipCurrentReceiverLocked(this);
1548 }
1549
1550 private boolean isInterestingForBackgroundTraces() {
1551 // The system_server is always considered interesting.
1552 if (pid == MY_PID) {
1553 return true;
1554 }
1555
1556 // A package is considered interesting if any of the following is true :
1557 //
1558 // - It's displaying an activity.
1559 // - It's the SystemUI.
1560 // - It has an overlay or a top UI visible.
1561 //
1562 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1563 // process is a bit of a kludge, but the same pattern seems repeated at
1564 // several places in the system server.
1565 return isInterestingToUserLocked() ||
1566 (info != null && "com.android.systemui".equals(info.packageName))
1567 || (hasTopUi() || hasOverlayUi());
1568 }
Yunfan Chen585f2932019-01-29 16:04:45 +09001569
1570 private boolean getShowBackground() {
1571 return Settings.Secure.getInt(mService.mContext.getContentResolver(),
1572 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574}