blob: 7e524631fcfe75edd6420abc4232b441798aef52 [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;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040035import android.content.res.CompatibilityInfo;
Joe Onorato57190282016-04-20 15:37:49 -070036import android.os.Binder;
Yunfan Chen75157d72018-07-27 14:47:21 +090037import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.IBinder;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070039import android.os.Message;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080040import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070041import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070042import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070043import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070044import android.os.UserHandle;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070045import android.provider.Settings;
Yang Lu732d6382018-11-05 07:53:12 -080046import android.server.ServerProtoEnums;
Dianne Hackborn390517b2013-05-30 15:03:32 -070047import android.util.ArrayMap;
Yunfan Chen75157d72018-07-27 14:47:21 +090048import android.util.ArraySet;
49import android.util.DebugUtils;
50import android.util.EventLog;
51import android.util.Slog;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070052import android.util.SparseArray;
Chenjie Yubd1a28f2018-07-17 14:55:19 -070053import android.util.StatsLog;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070054import android.util.TimeUtils;
Yi Jin129fc6c2017-09-28 15:48:38 -070055import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Yunfan Chen75157d72018-07-27 14:47:21 +090057import com.android.internal.app.procstats.ProcessState;
58import com.android.internal.app.procstats.ProcessStats;
59import com.android.internal.os.BatteryStatsImpl;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070060import com.android.internal.os.ProcessCpuTracker;
Sudheer Shanka87915d62018-11-06 10:57:35 -080061import com.android.internal.os.Zygote;
Wale Ogunwale59507092018-10-29 09:00:30 -070062import com.android.server.wm.WindowProcessController;
63import com.android.server.wm.WindowProcessListener;
Yunfan Chen75157d72018-07-27 14:47:21 +090064
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070065import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import java.io.PrintWriter;
67import java.util.ArrayList;
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -040068import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
70/**
71 * Full information about a particular process that
72 * is currently running.
73 */
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070074final class ProcessRecord implements WindowProcessListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080075 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
76
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -070077 private final ActivityManagerService mService; // where we came from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080079 final boolean isolated; // true if this is a special isolated process
Martijn Coenen01e719b2018-12-05 16:01:38 +010080 final boolean appZygote; // true if this is forked from the app zygote
Dianne Hackborna0c283e2012-02-09 10:47:01 -080081 final int uid; // uid of process; may be different from 'info' if isolated
82 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 final String processName; // name of the process
84 // List of packages running in the process
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070085 final PackageList pkgList = new PackageList();
86 final class PackageList {
87 final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>();
88
89 ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) {
90 mWindowProcessController.addPackage(key);
91 return mPkgList.put(key, value);
92 }
93
94 void clear() {
95 mPkgList.clear();
96 mWindowProcessController.clearPackageList();
97 }
98
99 int size() {
100 return mPkgList.size();
101 }
102
103 String keyAt(int index) {
104 return mPkgList.keyAt(index);
105 }
106
107 public ProcessStats.ProcessStateHolder valueAt(int index) {
108 return mPkgList.valueAt(index);
109 }
110
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700111 ProcessStats.ProcessStateHolder get(String pkgName) {
112 return mPkgList.get(pkgName);
113 }
114
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700115 boolean containsKey(Object key) {
116 return mPkgList.containsKey(key);
117 }
118 }
119
Dianne Hackborne17b4452018-01-10 13:15:40 -0800120 final ProcessList.ProcStateMemTracker procStateMemTracker
121 = new ProcessList.ProcStateMemTracker();
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700122 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700123 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 IApplicationThread thread; // the actual proc... may be null only if
125 // 'persistent' is true (in which case we
126 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700127 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -0800128 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700130 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800131 int[] gids; // The gids this process was launched with
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700132 private String mRequiredAbi;// The ABI this process was launched with
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800133 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800135 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700136 long lastPssTime; // Last time we retrieved PSS data
137 long nextPssTime; // Next time we want to request PSS data
138 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700139 long initialIdlePss; // Initial memory pss of process for idle maintenance.
140 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800141 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700142 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800143 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 int maxAdj; // Maximum OOM adjustment for this process
Wale Ogunwale31913b52018-10-13 08:29:31 -0700145 private int mCurRawAdj; // Current OOM unlimited adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 int setRawAdj; // Last set OOM unlimited adjustment for this process
147 int curAdj; // Current OOM adjustment for this process
148 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700149 int verifiedAdj; // The last adjustment that was verified as actually being set
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800150 long lastCompactTime; // The last time that this process was compacted
151 int reqCompactAction; // The most recent compaction action requested for this app.
152 int lastCompactAction; // The most recent compaction action performed for this app.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700153 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700154 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700155 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700156 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700157 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
Amith Yamasani08888c02018-12-07 09:38:25 -0800158 private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation
riddle_hsu6793fc32015-03-31 11:54:14 +0800159 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
160 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800161 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700162 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
163 int renderThreadTid; // TID for RenderThread
Dianne Hackborna631d562018-11-20 15:58:15 -0800164 ServiceRecord connectionService; // Service that applied current connectionGroup/Importance
165 int connectionGroup; // Last group set by a connection
166 int connectionImportance; // Last importance set by a connection
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700167 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700168 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700169 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700170 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700171 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700172 private boolean mHasForegroundServices; // Running any services that are foreground?
Amith Yamasania0a30a12019-01-22 11:38:06 -0800173 private int mFgServiceTypes; // Type of foreground service, if there is a foreground service.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700174 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700175 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700176 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700177 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700178 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800179 // is interacting with? E.g. The status bar when it is expanded, but
180 // not when it is minimized. When true the
181 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
182 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700183 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800184 // overlays on-top of activity UIs on screen. E.g. display a window
185 // of type
186 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
187 // When true the process will oom adj score will be set to
188 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
189 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100190 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
191 // the process will be set to use the
192 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
193 // performance, as well as oom adj score will be set to
194 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
195 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700196 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700197 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700198 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700200 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700201 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700202 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700203 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600204 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700205 private long mInteractionEventTime; // The time we sent the last interaction event
206 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700207 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700208 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700209 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700210 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
211 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700212 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700213 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700214 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700215 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
216 // process.
217 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800218 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700219 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700220 long lastCpuTime; // How long proc has run CPU at last check
221 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700223 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800224 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700225 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700226 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800227 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700228 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700229 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700230 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700231 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700232 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700233 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100234 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
235
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700236 // Cache of last retrieve memory info and uptime, to throttle how frequently
237 // apps can requyest it.
238 Debug.MemoryInfo lastMemInfo;
239 long lastMemInfoTime;
240
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700241 // Controller for driving the process state on the window manager side.
242 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700244 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700246 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700248 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700250 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700252 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700254 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Michal Karpinskiac116df2018-12-10 17:51:42 +0000255 // A set of tokens that currently contribute to this process being temporarily whitelisted
256 // to start activities even if it's not in the foreground
257 final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700258
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400259 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
260 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
261
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700262 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700263 private boolean mPersistent;// always keep this application running?
264 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700266 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700267 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 Dialog anrDialog; // dialog being displayed due to app not resp.
269 boolean removed; // has app package been removed from device?
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700270 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 boolean waitedForDebugger; // has process show wait for debugger dialog?
272 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700273
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800274 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700275 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700276 boolean pendingStart; // Process start is pending.
277 long startSeq; // Seq no. indicating the latest process start associated with
278 // this process record.
Sudheer Shanka87915d62018-11-06 10:57:35 -0800279 int mountMode; // Indicates how the external storage was mounted for this process.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 // These reports are generated & stored when an app gets into an error condition.
282 // They will be "null" when all is OK.
283 ActivityManager.ProcessErrorStateInfo crashingReport;
284 ActivityManager.ProcessErrorStateInfo notRespondingReport;
285
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200286 // Who will be notified of the error. This is usually an activity in the
287 // app that installed the package.
288 ComponentName errorReportReceiver;
289
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700290 // Process is currently hosting a backup agent for backup or restore
291 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700292 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
293 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700294
Sudheer Shankaf6690102017-10-16 10:20:32 -0700295 // Params used in starting this process.
296 String hostingType;
297 String hostingNameStr;
298 String seInfo;
299 long startTime;
300 // This will be same as {@link #uid} usually except for some apps used during factory testing.
301 int startUid;
302
303 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
304 long startTime) {
305 this.startUid = startUid;
306 this.hostingType = hostingType;
307 this.hostingNameStr = hostingNameStr;
308 this.seInfo = seInfo;
309 this.startTime = startTime;
310 }
311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700313 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700314
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800315 pw.print(prefix); pw.print("user #"); pw.print(userId);
316 pw.print(" uid="); pw.print(info.uid);
317 if (uid != info.uid) {
318 pw.print(" ISOLATED uid="); pw.print(uid);
319 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800320 pw.print(" gids={");
321 if (gids != null) {
322 for (int gi=0; gi<gids.length; gi++) {
323 if (gi != 0) pw.print(", ");
324 pw.print(gids[gi]);
325
326 }
327 }
328 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700329 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800330 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700331 if (info.className != null) {
332 pw.print(prefix); pw.print("class="); pw.println(info.className);
333 }
334 if (info.manageSpaceActivityName != null) {
335 pw.print(prefix); pw.print("manageSpaceActivityName=");
336 pw.println(info.manageSpaceActivityName);
337 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900338
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700339 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
340 pw.print(" publicDir="); pw.print(info.publicSourceDir);
341 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700342 pw.print(prefix); pw.print("packageList={");
343 for (int i=0; i<pkgList.size(); i++) {
344 if (i > 0) pw.print(", ");
345 pw.print(pkgList.keyAt(i));
346 }
347 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700348 if (pkgDeps != null) {
349 pw.print(prefix); pw.print("packageDependencies={");
350 for (int i=0; i<pkgDeps.size(); i++) {
351 if (i > 0) pw.print(", ");
352 pw.print(pkgDeps.valueAt(i));
353 }
354 pw.println("}");
355 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700356 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700357 if (mInstr != null) {
358 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700359 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700360 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700361 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700362 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700363 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700364 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700365 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700366 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800367 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700368 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700369 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700370 pw.println();
371 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
372 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800373 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800374 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800375 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800376 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800377 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800378 pw.print(prefix); pw.print("procStateMemTracker: ");
379 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700380 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800381 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700382 if (serviceb) {
383 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
384 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
385 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700386 if (notCachedSinceIdle) {
387 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700388 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700389 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700390 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700391 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700392 pw.print(" setRaw="); pw.print(setRawAdj);
393 pw.print(" cur="); pw.print(curAdj);
394 pw.print(" set="); pw.println(setAdj);
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800395 pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime);
396 pw.print(" lastCompactAction="); pw.print(lastCompactAction);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700397 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700398 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700399 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700400 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700401 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700402 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700403 pw.print(" pssProcState="); pw.print(pssProcState);
404 pw.print(" setProcState="); pw.print(setProcState);
405 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700406 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700407 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700408 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700409 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700410 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700411 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
412 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700413 }
Dianne Hackborna631d562018-11-20 15:58:15 -0800414 if (connectionService != null || connectionGroup != 0) {
415 pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup);
416 pw.print(" Importance="); pw.print(connectionImportance);
417 pw.print(" Service="); pw.println(connectionService);
418 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700419 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
420 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
421 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100422 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700423 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700424 if (mHasForegroundServices || forcingToImportant != null) {
425 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700426 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700427 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700428 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700429 pw.print(prefix); pw.print("reportedInteraction=");
430 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700431 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800432 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700433 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800434 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700435 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700436 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700437 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700438 }
439 pw.println();
440 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700441 if (mPersistent || removed) {
442 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700443 pw.print(" removed="); pw.println(removed);
444 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700445 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
446 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
447 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700448 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700449 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800450 if (lastProviderTime > 0) {
451 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700452 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800453 pw.println();
454 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700455 if (lastTopTime > 0) {
456 pw.print(prefix); pw.print("lastTopTime=");
457 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
458 pw.println();
459 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700460 if (hasStartedServices) {
461 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
462 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700463 if (pendingStart) {
464 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
465 }
466 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800467 pw.print(prefix); pw.print("mountMode="); pw.println(
468 DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode));
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700469 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700470 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700471 if (lastCpuTime > 0) {
472 pw.print(" timeUsed=");
473 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
474 }
475 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700476 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700477 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700478 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700479 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700480 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700481 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700482 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700483 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700484 if (killed || killedByAm || waitingToKill != null) {
485 pw.print(prefix); pw.print("killed="); pw.print(killed);
486 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700487 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700488 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700489 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700490 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700491 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700492 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700493 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700494 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700495 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200496 pw.print(" bad="); pw.print(bad);
497
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700498 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200499 if (errorReportReceiver != null) {
500 pw.print(" errorReportReceiver=");
501 pw.print(errorReportReceiver.flattenToShortString());
502 }
503 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700504 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700505 if (whitelistManager) {
506 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
507 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400508 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
509 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
510 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
511 pw.println(Arrays.toString(isolatedEntryPointArgs));
512 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700513 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700514 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700515 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700516 for (int i=0; i<services.size(); i++) {
517 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700518 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700519 }
520 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700521 pw.print(prefix); pw.print("Executing Services (fg=");
522 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700523 for (int i=0; i<executingServices.size(); i++) {
524 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700525 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700526 }
527 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700528 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700529 for (int i=0; i<connections.size(); i++) {
530 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700531 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700532 }
533 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700534 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700535 for (int i=0; i<pubProviders.size(); i++) {
536 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
537 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700538 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700539 }
540 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700541 pw.print(prefix); pw.println("Connected Providers:");
542 for (int i=0; i<conProviders.size(); i++) {
543 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
544 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700545 }
yangzhenyud509bc92016-08-31 18:26:46 +0800546 if (!curReceivers.isEmpty()) {
547 pw.print(prefix); pw.println("Current Receivers:");
548 for (int i=0; i < curReceivers.size(); i++) {
549 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
550 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700551 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700552 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700553 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700554 for (int i=0; i<receivers.size(); i++) {
555 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700556 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700559
Bookatz152623f2018-07-23 15:57:44 -0700560 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700561 int _uid) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700562 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800564 isolated = _info.uid != _uid;
Martijn Coenen01e719b2018-12-05 16:01:38 +0100565 appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
566 && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800567 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700568 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700570 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700571 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700572 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700573 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700575 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700576 mWindowProcessController = new WindowProcessController(
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700577 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700578 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
580
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700581 public void setPid(int _pid) {
582 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700583 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700584 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800585 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700586 stringName = null;
587 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700588
589 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
590 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700591 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700592 if (origBase != null) {
593 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700594 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700595 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
596 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
597 uid, processName, pkgList.keyAt(ipkg),
598 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
599 pkgList.valueAt(ipkg).appVersion);
600 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700601 origBase.makeInactive();
602 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800603 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700604 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700605 baseProcessTracker.makeActive();
606 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700607 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
608 if (holder.state != null && holder.state != origBase) {
609 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700610 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800611 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700612 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700613 if (holder.state != baseProcessTracker) {
614 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700615 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700616 }
617 }
618 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700619 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700620 }
621
622 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700623 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700624 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700625 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700626 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700627 if (origBase != null) {
628 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700629 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700630 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
631 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
632 uid, processName, pkgList.keyAt(ipkg),
633 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
634 pkgList.valueAt(ipkg).appVersion);
635 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700636 origBase.makeInactive();
637 }
638 baseProcessTracker = null;
639 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700640 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
641 if (holder.state != null && holder.state != origBase) {
642 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700643 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700644 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700645 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700646 }
647 }
648 }
649
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700650 boolean hasActivities() {
651 return mWindowProcessController.hasActivities();
652 }
653
654 void clearActivities() {
655 mWindowProcessController.clearActivities();
656 }
657
658 boolean hasActivitiesOrRecentTasks() {
659 return mWindowProcessController.hasActivitiesOrRecentTasks();
660 }
661
662 boolean hasRecentTasks() {
663 return mWindowProcessController.hasRecentTasks();
664 }
665
666 void clearRecentTasks() {
667 mWindowProcessController.clearRecentTasks();
Dianne Hackborn68a06332017-11-15 17:54:18 -0800668 }
669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 /**
671 * This method returns true if any of the activities within the process record are interesting
672 * to the user. See HistoryRecord.isInterestingToUserLocked()
673 */
674 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700675 if (mWindowProcessController.isInterestingToUser()) {
676 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100678
679 final int servicesSize = services.size();
680 for (int i = 0; i < servicesSize; i++) {
681 ServiceRecord r = services.valueAt(i);
682 if (r.isForeground) {
683 return true;
684 }
685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 return false;
687 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800688
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700689 public void unlinkDeathRecipient() {
690 if (deathRecipient != null && thread != null) {
691 thread.asBinder().unlinkToDeath(deathRecipient, 0);
692 }
693 deathRecipient = null;
694 }
695
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700696 void updateHasAboveClientLocked() {
697 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700698 for (int i=connections.size()-1; i>=0; i--) {
699 ConnectionRecord cr = connections.valueAt(i);
700 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
701 hasAboveClient = true;
702 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700703 }
704 }
705 }
706
Dianne Hackbornc8230512013-07-13 21:32:12 -0700707 int modifyRawOomAdj(int adj) {
708 if (hasAboveClient) {
709 // If this process has bound to any services with BIND_ABOVE_CLIENT,
710 // then we need to drop its adjustment to be lower than the service's
711 // in order to honor the request. We want to drop it by one adjustment
712 // level... but there is special meaning applied to various levels so
713 // we will skip some of them.
714 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
715 // System process will not get dropped, ever
716 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
717 adj = ProcessList.VISIBLE_APP_ADJ;
718 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
719 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
720 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
721 adj = ProcessList.CACHED_APP_MIN_ADJ;
722 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
723 adj++;
724 }
725 }
726 return adj;
727 }
728
Joe Onorato57190282016-04-20 15:37:49 -0700729 void scheduleCrash(String message) {
730 // Checking killedbyAm should keep it from showing the crash dialog if the process
731 // was already dead for a good / normal reason.
732 if (!killedByAm) {
733 if (thread != null) {
734 if (pid == Process.myPid()) {
735 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
736 return;
737 }
738 long ident = Binder.clearCallingIdentity();
739 try {
740 thread.scheduleCrash(message);
741 } catch (RemoteException e) {
742 // If it's already dead our work is done. If it's wedged just kill it.
743 // We won't get the crash dialog or the error reporting.
744 kill("scheduleCrash for '" + message + "' failed", true);
745 } finally {
746 Binder.restoreCallingIdentity(ident);
747 }
748 }
749 }
750 }
751
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700752 void kill(String reason, boolean noisy) {
753 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700754 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700755 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
756 mService.reportUidInfoMessageLocked(TAG,
757 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
758 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700759 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700760 if (pid > 0) {
761 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
762 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400763 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700764 } else {
765 pendingStart = false;
766 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700767 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700768 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700769 killedByAm = true;
770 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700771 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700772 }
773 }
774
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700775 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700776 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800777 writeToProto(proto, fieldId, -1);
778 }
779
780 public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700781 long token = proto.start(fieldId);
782 proto.write(ProcessRecordProto.PID, pid);
783 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800784 proto.write(ProcessRecordProto.UID, info.uid);
785 if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700786 proto.write(ProcessRecordProto.USER_ID, userId);
787 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800788 }
789 if (uid != info.uid) {
790 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
Yi Jin129fc6c2017-09-28 15:48:38 -0700791 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700792 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800793 if (lruIndex >= 0) {
794 proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
795 }
Yi Jin129fc6c2017-09-28 15:48:38 -0700796 proto.end(token);
797 }
798
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800799 public String toShortString() {
800 if (shortStringName != null) {
801 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700802 }
803 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800804 toShortString(sb);
805 return shortStringName = sb.toString();
806 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700807
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800808 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700809 sb.append(pid);
810 sb.append(':');
811 sb.append(processName);
812 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800813 if (info.uid < Process.FIRST_APPLICATION_UID) {
814 sb.append(uid);
815 } else {
816 sb.append('u');
817 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700818 int appId = UserHandle.getAppId(info.uid);
819 if (appId >= Process.FIRST_APPLICATION_UID) {
820 sb.append('a');
821 sb.append(appId - Process.FIRST_APPLICATION_UID);
822 } else {
823 sb.append('s');
824 sb.append(appId);
825 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800826 if (uid != info.uid) {
827 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700828 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800829 }
830 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800831 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700832
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800833 public String toString() {
834 if (stringName != null) {
835 return stringName;
836 }
837 StringBuilder sb = new StringBuilder(128);
838 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700839 sb.append(Integer.toHexString(System.identityHashCode(this)));
840 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800841 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700842 sb.append('}');
843 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700845
846 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700847 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700848 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700849 sb.append(' ');
850 if (adjTarget instanceof ComponentName) {
851 sb.append(((ComponentName)adjTarget).flattenToShortString());
852 } else if (adjTarget != null) {
853 sb.append(adjTarget.toString());
854 } else {
855 sb.append("{null}");
856 }
857 sb.append("<=");
858 if (adjSource instanceof ProcessRecord) {
859 sb.append("Proc{");
860 sb.append(((ProcessRecord)adjSource).toShortString());
861 sb.append("}");
862 } else if (adjSource != null) {
863 sb.append(adjSource.toString());
864 } else {
865 sb.append("{null}");
866 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700867 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700868 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700869 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700870 }
871
Wale Ogunwale9c103022018-10-18 07:44:54 -0700872 @Override
873 public void addPackage(String pkg, long versionCode) {
874 synchronized (mService) {
875 addPackage(pkg, versionCode, mService.mProcessStats);
876 }
877 }
878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 /*
880 * Return true if package has been added false if not
881 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700882 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700883 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700884 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
885 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700886 if (baseProcessTracker != null) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800887 tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
888 processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700889 pkgList.put(pkg, holder);
890 if (holder.state != baseProcessTracker) {
891 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700892 }
893 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700894 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 return true;
897 }
898 return false;
899 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700900
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700901 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700902 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
903 if (hasStartedServices) {
904 return ProcessList.SERVICE_B_ADJ;
905 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700906 }
907 return setAdj;
908 }
909
Dianne Hackborna413dc02013-07-12 12:02:55 -0700910 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700911 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700912 mRepProcState = newState;
913 setCurProcState(newState);
Amith Yamasani08888c02018-12-07 09:38:25 -0800914 setCurRawProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700915 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
916 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
917 uid, processName, pkgList.keyAt(ipkg),
918 ActivityManager.processStateAmToProto(mRepProcState),
919 pkgList.valueAt(ipkg).appVersion);
920 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700921 }
922 }
923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 /*
925 * Delete all packages from list except the package indicated in info
926 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700927 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700928 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700929 if (baseProcessTracker != null) {
930 long now = SystemClock.uptimeMillis();
931 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700932 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700933 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
934 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
935 uid, processName, pkgList.keyAt(ipkg),
936 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
937 pkgList.valueAt(ipkg).appVersion);
938 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700939 if (N != 1) {
940 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700941 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
942 if (holder.state != null && holder.state != baseProcessTracker) {
943 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700944 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700945
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700946 }
947 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700948 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700949 info.longVersionCode);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800950 tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700951 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700952 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700953 if (holder.state != baseProcessTracker) {
954 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700955 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700956 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700957 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700958 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700959 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700960 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 public String[] getPackageList() {
964 int size = pkgList.size();
965 if (size == 0) {
966 return null;
967 }
968 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700969 for (int i=0; i<pkgList.size(); i++) {
970 list[i] = pkgList.keyAt(i);
971 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 return list;
973 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700974
975 WindowProcessController getWindowProcessController() {
976 return mWindowProcessController;
977 }
978
979 void setCurrentSchedulingGroup(int curSchedGroup) {
980 mCurSchedGroup = curSchedGroup;
981 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
982 }
983
984 int getCurrentSchedulingGroup() {
985 return mCurSchedGroup;
986 }
987
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700988 void setCurProcState(int curProcState) {
989 mCurProcState = curProcState;
990 mWindowProcessController.setCurrentProcState(mCurProcState);
991 }
992
993 int getCurProcState() {
994 return mCurProcState;
995 }
996
Amith Yamasani08888c02018-12-07 09:38:25 -0800997 void setCurRawProcState(int curRawProcState) {
998 mCurRawProcState = curRawProcState;
999 }
1000
1001 int getCurRawProcState() {
1002 return mCurRawProcState;
1003 }
1004
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001005 void setReportedProcState(int repProcState) {
1006 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -07001007 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
1008 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
1009 uid, processName, pkgList.keyAt(ipkg),
1010 ActivityManager.processStateAmToProto(mRepProcState),
1011 pkgList.valueAt(ipkg).appVersion);
1012 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001013 mWindowProcessController.setReportedProcState(repProcState);
1014 }
1015
1016 int getReportedProcState() {
1017 return mRepProcState;
1018 }
1019
1020 void setCrashing(boolean crashing) {
1021 mCrashing = crashing;
1022 mWindowProcessController.setCrashing(crashing);
1023 }
1024
1025 boolean isCrashing() {
1026 return mCrashing;
1027 }
1028
1029 void setNotResponding(boolean notResponding) {
1030 mNotResponding = notResponding;
1031 mWindowProcessController.setNotResponding(notResponding);
1032 }
1033
1034 boolean isNotResponding() {
1035 return mNotResponding;
1036 }
1037
1038 void setPersistent(boolean persistent) {
1039 mPersistent = persistent;
1040 mWindowProcessController.setPersistent(persistent);
1041 }
1042
1043 boolean isPersistent() {
1044 return mPersistent;
1045 }
1046
1047 public void setRequiredAbi(String requiredAbi) {
1048 mRequiredAbi = requiredAbi;
1049 mWindowProcessController.setRequiredAbi(requiredAbi);
1050 }
1051
1052 String getRequiredAbi() {
1053 return mRequiredAbi;
1054 }
1055
Amith Yamasania0a30a12019-01-22 11:38:06 -08001056 void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001057 mHasForegroundServices = hasForegroundServices;
Amith Yamasania0a30a12019-01-22 11:38:06 -08001058 mFgServiceTypes = fgServiceTypes;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001059 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1060 }
1061
1062 boolean hasForegroundServices() {
1063 return mHasForegroundServices;
1064 }
1065
Amith Yamasania0a30a12019-01-22 11:38:06 -08001066 boolean hasLocationForegroundServices() {
1067 return mHasForegroundServices
1068 && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0;
1069 }
1070
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001071 void setHasForegroundActivities(boolean hasForegroundActivities) {
1072 mHasForegroundActivities = hasForegroundActivities;
1073 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1074 }
1075
1076 boolean hasForegroundActivities() {
1077 return mHasForegroundActivities;
1078 }
1079
1080 void setHasClientActivities(boolean hasClientActivities) {
1081 mHasClientActivities = hasClientActivities;
1082 mWindowProcessController.setHasClientActivities(hasClientActivities);
1083 }
1084
1085 boolean hasClientActivities() {
1086 return mHasClientActivities;
1087 }
1088
1089 void setHasTopUi(boolean hasTopUi) {
1090 mHasTopUi = hasTopUi;
1091 mWindowProcessController.setHasTopUi(hasTopUi);
1092 }
1093
1094 boolean hasTopUi() {
1095 return mHasTopUi;
1096 }
1097
1098 void setHasOverlayUi(boolean hasOverlayUi) {
1099 mHasOverlayUi = hasOverlayUi;
1100 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1101 }
1102
1103 boolean hasOverlayUi() {
1104 return mHasOverlayUi;
1105 }
1106
1107 void setInteractionEventTime(long interactionEventTime) {
1108 mInteractionEventTime = interactionEventTime;
1109 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1110 }
1111
1112 long getInteractionEventTime() {
1113 return mInteractionEventTime;
1114 }
1115
1116 void setFgInteractionTime(long fgInteractionTime) {
1117 mFgInteractionTime = fgInteractionTime;
1118 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1119 }
1120
1121 long getFgInteractionTime() {
1122 return mFgInteractionTime;
1123 }
1124
1125 void setWhenUnimportant(long whenUnimportant) {
1126 mWhenUnimportant = whenUnimportant;
1127 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1128 }
1129
1130 long getWhenUnimportant() {
1131 return mWhenUnimportant;
1132 }
1133
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001134 void setDebugging(boolean debugging) {
1135 mDebugging = debugging;
1136 mWindowProcessController.setDebugging(debugging);
1137 }
1138
1139 boolean isDebugging() {
1140 return mDebugging;
1141 }
1142
1143 void setUsingWrapper(boolean usingWrapper) {
1144 mUsingWrapper = usingWrapper;
1145 mWindowProcessController.setUsingWrapper(usingWrapper);
1146 }
1147
1148 boolean isUsingWrapper() {
1149 return mUsingWrapper;
1150 }
1151
Michal Karpinskiac116df2018-12-10 17:51:42 +00001152 void addAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001153 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001154 mAllowBackgroundActivityStartsTokens.add(entity);
1155 mWindowProcessController.setAllowBackgroundActivityStarts(true);
1156 }
1157
1158 void removeAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001159 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001160 mAllowBackgroundActivityStartsTokens.remove(entity);
1161 mWindowProcessController.setAllowBackgroundActivityStarts(
1162 !mAllowBackgroundActivityStartsTokens.isEmpty());
1163 }
1164
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001165 void setActiveInstrumentation(ActiveInstrumentation instr) {
1166 mInstr = instr;
1167 mWindowProcessController.setInstrumenting(instr != null);
1168 }
1169
1170 ActiveInstrumentation getActiveInstrumentation() {
1171 return mInstr;
1172 }
1173
Wale Ogunwale31913b52018-10-13 08:29:31 -07001174 void setCurRawAdj(int curRawAdj) {
1175 mCurRawAdj = curRawAdj;
1176 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1177 }
1178
1179 int getCurRawAdj() {
1180 return mCurRawAdj;
1181 }
1182
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001183 @Override
1184 public void clearProfilerIfNeeded() {
1185 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001186 if (mService.mProfileData.getProfileProc() == null
1187 || mService.mProfileData.getProfilerInfo() == null
1188 || mService.mProfileData.getProfileProc() != this) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001189 return;
1190 }
1191 mService.clearProfilerLocked();
1192 }
1193 }
1194
1195 @Override
1196 public void updateServiceConnectionActivities() {
1197 synchronized (mService) {
1198 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1199 }
1200 }
1201
1202 @Override
1203 public void setPendingUiClean(boolean pendingUiClean) {
1204 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001205 mPendingUiClean = pendingUiClean;
1206 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001207 }
1208 }
1209
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001210 boolean hasPendingUiClean() {
1211 return mPendingUiClean;
1212 }
1213
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001214 @Override
1215 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1216 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001217 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001218 forceProcessStateUpTo(newState);
1219 }
1220 }
1221
1222 @Override
1223 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru,
1224 boolean activityChange, boolean updateOomAdj) {
1225 synchronized (mService) {
1226 if (updateServiceConnectionActivities) {
1227 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1228 }
1229 if (updateLru) {
Amith Yamasani98a00922018-08-21 12:50:30 -04001230 mService.mProcessList.updateLruProcessLocked(this, activityChange, null);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001231 }
1232 if (updateOomAdj) {
1233 mService.updateOomAdjLocked();
1234 }
1235 }
1236 }
1237
1238 @Override
1239 public void setRemoved(boolean removed) {
1240 synchronized (mService) {
1241 this.removed = removed;
1242 }
1243 }
1244
Wale Ogunwale86b74462018-07-02 08:42:43 -07001245 /**
1246 * Returns the total time (in milliseconds) spent executing in both user and system code.
1247 * Safe to call without lock held.
1248 */
Wale Ogunwale9c103022018-10-18 07:44:54 -07001249 @Override
Wale Ogunwale86b74462018-07-02 08:42:43 -07001250 public long getCpuTime() {
1251 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1252 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001253
Wale Ogunwale9c103022018-10-18 07:44:54 -07001254 @Override
1255 public void clearWaitingToKill() {
1256 synchronized (mService) {
1257 waitingToKill = null;
1258 }
1259 }
1260
1261 @Override
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001262 public void onStartActivity(int topProcessState, boolean setProfileProc) {
Wale Ogunwale9c103022018-10-18 07:44:54 -07001263 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001264 if (setProfileProc) {
1265 mService.mProfileData.setProfileProc(this);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001266 }
1267
1268 hasShownUi = true;
1269 setPendingUiClean(true);
1270 forceProcessStateUpTo(topProcessState);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001271 }
1272 }
1273
1274 @Override
1275 public void appDied() {
1276 synchronized (mService) {
1277 mService.appDiedLocked(this);
1278 }
1279 }
1280
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001281 public long getInputDispatchingTimeout() {
1282 return mWindowProcessController.getInputDispatchingTimeout();
1283 }
1284
Yang Lu732d6382018-11-05 07:53:12 -08001285 public int getProcessClassEnum() {
1286 if (pid == MY_PID) {
1287 return ServerProtoEnums.SYSTEM_SERVER;
1288 }
1289 if (info == null) {
1290 return ServerProtoEnums.ERROR_SOURCE_UNKNOWN;
1291 }
1292 return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP :
1293 ServerProtoEnums.DATA_APP;
1294 }
1295
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001296 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1297 String parentShortComponentName, WindowProcessController parentProcess,
1298 boolean aboveSystem, String annotation) {
1299 ArrayList<Integer> firstPids = new ArrayList<>(5);
1300 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1301
Wale Ogunwalee2172292018-10-25 10:11:10 -07001302 mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true));
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001303
1304 long anrTime = SystemClock.uptimeMillis();
1305 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1306 mService.updateCpuStatsNow();
1307 }
1308
1309 // Unless configured otherwise, swallow ANRs in background processes & kill the process.
1310 boolean showBackground = Settings.Secure.getInt(mService.mContext.getContentResolver(),
1311 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1312
1313 boolean isSilentANR;
1314
1315 synchronized (mService) {
1316 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
Wale Ogunwale387b34c2018-10-25 19:59:40 -07001317 if (mService.mAtmInternal.isShuttingDown()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001318 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1319 return;
1320 } else if (isNotResponding()) {
1321 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1322 return;
1323 } else if (isCrashing()) {
1324 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1325 return;
1326 } else if (killedByAm) {
1327 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1328 return;
1329 } else if (killed) {
1330 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1331 return;
1332 }
1333
1334 // In case we come through here for the same app before completing
1335 // this one, mark as anring now so we will bail out.
1336 setNotResponding(true);
1337
1338 // Log the ANR to the event log.
1339 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1340 annotation);
1341
1342 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1343 firstPids.add(pid);
1344
1345 // Don't dump other PIDs if it's a background ANR
1346 isSilentANR = !showBackground && !isInterestingForBackgroundTraces();
1347 if (!isSilentANR) {
1348 int parentPid = pid;
1349 if (parentProcess != null && parentProcess.getPid() > 0) {
1350 parentPid = parentProcess.getPid();
1351 }
1352 if (parentPid != pid) firstPids.add(parentPid);
1353
1354 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1355
Amith Yamasani98a00922018-08-21 12:50:30 -04001356 for (int i = mService.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
1357 ProcessRecord r = mService.mProcessList.mLruProcesses.get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001358 if (r != null && r.thread != null) {
1359 int myPid = r.pid;
1360 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1361 if (r.isPersistent()) {
1362 firstPids.add(myPid);
1363 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1364 } else if (r.treatLikeActivity) {
1365 firstPids.add(myPid);
1366 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1367 } else {
1368 lastPids.put(myPid, Boolean.TRUE);
1369 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1370 }
1371 }
1372 }
1373 }
1374 }
1375 }
1376
1377 // Log the ANR to the main log.
1378 StringBuilder info = new StringBuilder();
1379 info.setLength(0);
1380 info.append("ANR in ").append(processName);
1381 if (activityShortComponentName != null) {
1382 info.append(" (").append(activityShortComponentName).append(")");
1383 }
1384 info.append("\n");
1385 info.append("PID: ").append(pid).append("\n");
1386 if (annotation != null) {
1387 info.append("Reason: ").append(annotation).append("\n");
1388 }
1389 if (parentShortComponentName != null
1390 && parentShortComponentName.equals(activityShortComponentName)) {
1391 info.append("Parent: ").append(parentShortComponentName).append("\n");
1392 }
1393
1394 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1395
1396 // don't dump native PIDs for background ANRs unless it is the process of interest
1397 String[] nativeProcs = null;
1398 if (isSilentANR) {
1399 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1400 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1401 nativeProcs = new String[] { processName };
1402 break;
1403 }
1404 }
1405 } else {
1406 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1407 }
1408
1409 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1410 ArrayList<Integer> nativePids = null;
1411
1412 if (pids != null) {
1413 nativePids = new ArrayList<>(pids.length);
1414 for (int i : pids) {
1415 nativePids.add(i);
1416 }
1417 }
1418
1419 // For background ANRs, don't pass the ProcessCpuTracker to
1420 // avoid spending 1/2 second collecting stats to rank lastPids.
1421 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
1422 (isSilentANR) ? null : processCpuTracker, (isSilentANR) ? null : lastPids,
1423 nativePids);
1424
1425 String cpuInfo = null;
1426 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1427 mService.updateCpuStatsNow();
1428 synchronized (mService.mProcessCpuTracker) {
1429 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1430 }
1431 info.append(processCpuTracker.printCurrentLoad());
1432 info.append(cpuInfo);
1433 }
1434
1435 info.append(processCpuTracker.printCurrentState(anrTime));
1436
1437 Slog.e(TAG, info.toString());
1438 if (tracesFile == null) {
1439 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1440 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1441 }
1442
1443 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1444 activityShortComponentName == null ? "unknown": activityShortComponentName,
1445 annotation,
1446 (this.info != null) ? (this.info.isInstantApp()
1447 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1448 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1449 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1450 isInterestingToUserLocked()
1451 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
Yang Lu732d6382018-11-05 07:53:12 -08001452 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
1453 getProcessClassEnum(),
1454 (this.info != null) ? this.info.packageName : "");
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001455 final ProcessRecord parentPr = parentProcess != null
1456 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001457 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001458 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001459
Wale Ogunwalee2172292018-10-25 10:11:10 -07001460 if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true),
1461 () -> {
1462 synchronized (mService) {
1463 mService.mServices.scheduleServiceTimeoutLocked(this);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001464 }
Wale Ogunwalee2172292018-10-25 10:11:10 -07001465 })) {
1466 return;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001467 }
1468
1469 synchronized (mService) {
1470 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1471
1472 if (isSilentANR) {
1473 kill("bg anr", true);
1474 return;
1475 }
1476
1477 // Set the app's notResponding state, and look up the errorReportReceiver
1478 makeAppNotRespondingLocked(activityShortComponentName,
1479 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1480
1481 // Bring up the infamous App Not Responding dialog
1482 Message msg = Message.obtain();
1483 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1484 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
1485
1486 mService.mUiHandler.sendMessage(msg);
1487 }
1488 }
1489
1490 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1491 setNotResponding(true);
1492 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1493 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1494 activity, shortMsg, longMsg, null);
1495 startAppProblemLocked();
1496 getWindowProcessController().stopFreezingActivities();
1497 }
1498
1499 void startAppProblemLocked() {
1500 // If this app is not running under the current user, then we can't give it a report button
1501 // because that would require launching the report UI under a different user.
1502 errorReportReceiver = null;
1503
1504 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1505 if (this.userId == userId) {
1506 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1507 mService.mContext, info.packageName, info.flags);
1508 }
1509 }
1510 mService.skipCurrentReceiverLocked(this);
1511 }
1512
1513 private boolean isInterestingForBackgroundTraces() {
1514 // The system_server is always considered interesting.
1515 if (pid == MY_PID) {
1516 return true;
1517 }
1518
1519 // A package is considered interesting if any of the following is true :
1520 //
1521 // - It's displaying an activity.
1522 // - It's the SystemUI.
1523 // - It has an overlay or a top UI visible.
1524 //
1525 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1526 // process is a bit of a kludge, but the same pattern seems repeated at
1527 // several places in the system server.
1528 return isInterestingToUserLocked() ||
1529 (info != null && "com.android.systemui".equals(info.packageName))
1530 || (hasTopUi() || hasOverlayUi());
1531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532}