blob: 5dccaf14e1f1b9ff99aa35620674267b50d40eff [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 Chen75157d72018-07-27 14:47:21 +090058import com.android.internal.app.procstats.ProcessState;
59import com.android.internal.app.procstats.ProcessStats;
60import com.android.internal.os.BatteryStatsImpl;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070061import com.android.internal.os.ProcessCpuTracker;
Sudheer Shanka87915d62018-11-06 10:57:35 -080062import com.android.internal.os.Zygote;
Wale Ogunwale59507092018-10-29 09:00:30 -070063import com.android.server.wm.WindowProcessController;
64import com.android.server.wm.WindowProcessListener;
Yunfan Chen75157d72018-07-27 14:47:21 +090065
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070066import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import java.io.PrintWriter;
68import java.util.ArrayList;
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -040069import java.util.Arrays;
Zimuzo972e1cd2019-01-28 16:30:01 +000070import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
72/**
73 * Full information about a particular process that
74 * is currently running.
75 */
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070076final class ProcessRecord implements WindowProcessListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080077 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
78
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -070079 private final ActivityManagerService mService; // where we came from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080081 final boolean isolated; // true if this is a special isolated process
Martijn Coenen01e719b2018-12-05 16:01:38 +010082 final boolean appZygote; // true if this is forked from the app zygote
Dianne Hackborna0c283e2012-02-09 10:47:01 -080083 final int uid; // uid of process; may be different from 'info' if isolated
84 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 final String processName; // name of the process
86 // List of packages running in the process
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070087 final PackageList pkgList = new PackageList();
88 final class PackageList {
89 final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>();
90
91 ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) {
92 mWindowProcessController.addPackage(key);
93 return mPkgList.put(key, value);
94 }
95
96 void clear() {
97 mPkgList.clear();
98 mWindowProcessController.clearPackageList();
99 }
100
101 int size() {
102 return mPkgList.size();
103 }
104
105 String keyAt(int index) {
106 return mPkgList.keyAt(index);
107 }
108
109 public ProcessStats.ProcessStateHolder valueAt(int index) {
110 return mPkgList.valueAt(index);
111 }
112
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700113 ProcessStats.ProcessStateHolder get(String pkgName) {
114 return mPkgList.get(pkgName);
115 }
116
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700117 boolean containsKey(Object key) {
118 return mPkgList.containsKey(key);
119 }
120 }
121
Dianne Hackborne17b4452018-01-10 13:15:40 -0800122 final ProcessList.ProcStateMemTracker procStateMemTracker
123 = new ProcessList.ProcStateMemTracker();
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700124 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700125 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 IApplicationThread thread; // the actual proc... may be null only if
127 // 'persistent' is true (in which case we
128 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700129 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -0800130 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700132 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800133 int[] gids; // The gids this process was launched with
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700134 private String mRequiredAbi;// The ABI this process was launched with
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800135 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800137 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700138 long lastPssTime; // Last time we retrieved PSS data
139 long nextPssTime; // Next time we want to request PSS data
140 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700141 long initialIdlePss; // Initial memory pss of process for idle maintenance.
142 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800143 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700144 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800145 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 int maxAdj; // Maximum OOM adjustment for this process
Wale Ogunwale31913b52018-10-13 08:29:31 -0700147 private int mCurRawAdj; // Current OOM unlimited adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 int setRawAdj; // Last set OOM unlimited adjustment for this process
149 int curAdj; // Current OOM adjustment for this process
150 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700151 int verifiedAdj; // The last adjustment that was verified as actually being set
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800152 long lastCompactTime; // The last time that this process was compacted
153 int reqCompactAction; // The most recent compaction action requested for this app.
154 int lastCompactAction; // The most recent compaction action performed for this app.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700155 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700156 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700157 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700158 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700159 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
Amith Yamasani08888c02018-12-07 09:38:25 -0800160 private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation
riddle_hsu6793fc32015-03-31 11:54:14 +0800161 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
162 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800163 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700164 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
165 int renderThreadTid; // TID for RenderThread
Dianne Hackborna631d562018-11-20 15:58:15 -0800166 ServiceRecord connectionService; // Service that applied current connectionGroup/Importance
167 int connectionGroup; // Last group set by a connection
168 int connectionImportance; // Last importance set by a connection
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700169 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700170 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700171 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700172 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700173 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700174 private boolean mHasForegroundServices; // Running any services that are foreground?
Amith Yamasania0a30a12019-01-22 11:38:06 -0800175 private int mFgServiceTypes; // Type of foreground service, if there is a foreground service.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700176 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700177 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700178 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700179 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700180 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800181 // is interacting with? E.g. The status bar when it is expanded, but
182 // not when it is minimized. When true the
183 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
184 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700185 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800186 // overlays on-top of activity UIs on screen. E.g. display a window
187 // of type
188 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
189 // When true the process will oom adj score will be set to
190 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
191 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100192 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
193 // the process will be set to use the
194 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
195 // performance, as well as oom adj score will be set to
196 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
197 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700198 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700199 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700200 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700202 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700203 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700204 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700205 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600206 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700207 private long mInteractionEventTime; // The time we sent the last interaction event
208 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700209 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700210 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700211 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700212 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
213 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700214 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700215 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700216 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700217 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
218 // process.
219 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800220 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700221 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700222 long lastCpuTime; // How long proc has run CPU at last check
223 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700225 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800226 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700227 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700228 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800229 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700230 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700231 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700232 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700233 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700234 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700235 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100236 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
237
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700238 // Cache of last retrieve memory info and uptime, to throttle how frequently
239 // apps can requyest it.
240 Debug.MemoryInfo lastMemInfo;
241 long lastMemInfoTime;
242
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700243 // Controller for driving the process state on the window manager side.
244 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700246 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700248 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700250 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700252 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700254 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700256 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Michal Karpinskiac116df2018-12-10 17:51:42 +0000257 // A set of tokens that currently contribute to this process being temporarily whitelisted
258 // to start activities even if it's not in the foreground
259 final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700260
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400261 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
262 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
263
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700264 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700265 private boolean mPersistent;// always keep this application running?
266 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700268 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700269 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 Dialog anrDialog; // dialog being displayed due to app not resp.
Riddle Hsuaaef7312019-01-24 19:00:58 +0800271 volatile boolean removed; // Whether this process should be killed and removed from process
272 // list. It is set when the package is force-stopped or the process
273 // has crashed too many times.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700274 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 boolean waitedForDebugger; // has process show wait for debugger dialog?
276 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700277
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800278 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700279 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700280 boolean pendingStart; // Process start is pending.
281 long startSeq; // Seq no. indicating the latest process start associated with
282 // this process record.
Sudheer Shanka87915d62018-11-06 10:57:35 -0800283 int mountMode; // Indicates how the external storage was mounted for this process.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 // These reports are generated & stored when an app gets into an error condition.
286 // They will be "null" when all is OK.
287 ActivityManager.ProcessErrorStateInfo crashingReport;
288 ActivityManager.ProcessErrorStateInfo notRespondingReport;
289
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200290 // Who will be notified of the error. This is usually an activity in the
291 // app that installed the package.
292 ComponentName errorReportReceiver;
293
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700294 // Process is currently hosting a backup agent for backup or restore
295 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700296 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
297 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700298
Sudheer Shankaf6690102017-10-16 10:20:32 -0700299 // Params used in starting this process.
300 String hostingType;
301 String hostingNameStr;
302 String seInfo;
303 long startTime;
304 // This will be same as {@link #uid} usually except for some apps used during factory testing.
305 int startUid;
306
307 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
308 long startTime) {
309 this.startUid = startUid;
310 this.hostingType = hostingType;
311 this.hostingNameStr = hostingNameStr;
312 this.seInfo = seInfo;
313 this.startTime = startTime;
314 }
315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700317 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700318
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800319 pw.print(prefix); pw.print("user #"); pw.print(userId);
320 pw.print(" uid="); pw.print(info.uid);
321 if (uid != info.uid) {
322 pw.print(" ISOLATED uid="); pw.print(uid);
323 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800324 pw.print(" gids={");
325 if (gids != null) {
326 for (int gi=0; gi<gids.length; gi++) {
327 if (gi != 0) pw.print(", ");
328 pw.print(gids[gi]);
329
330 }
331 }
332 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700333 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800334 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700335 if (info.className != null) {
336 pw.print(prefix); pw.print("class="); pw.println(info.className);
337 }
338 if (info.manageSpaceActivityName != null) {
339 pw.print(prefix); pw.print("manageSpaceActivityName=");
340 pw.println(info.manageSpaceActivityName);
341 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900342
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700343 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
344 pw.print(" publicDir="); pw.print(info.publicSourceDir);
345 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700346 pw.print(prefix); pw.print("packageList={");
347 for (int i=0; i<pkgList.size(); i++) {
348 if (i > 0) pw.print(", ");
349 pw.print(pkgList.keyAt(i));
350 }
351 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700352 if (pkgDeps != null) {
353 pw.print(prefix); pw.print("packageDependencies={");
354 for (int i=0; i<pkgDeps.size(); i++) {
355 if (i > 0) pw.print(", ");
356 pw.print(pkgDeps.valueAt(i));
357 }
358 pw.println("}");
359 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700360 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700361 if (mInstr != null) {
362 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700363 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700364 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700365 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700366 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700367 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700368 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700369 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700370 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800371 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700372 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700373 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700374 pw.println();
375 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
376 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800377 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800378 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800379 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800380 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800381 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800382 pw.print(prefix); pw.print("procStateMemTracker: ");
383 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700384 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800385 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700386 if (serviceb) {
387 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
388 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
389 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700390 if (notCachedSinceIdle) {
391 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700392 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700393 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700394 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700395 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700396 pw.print(" setRaw="); pw.print(setRawAdj);
397 pw.print(" cur="); pw.print(curAdj);
398 pw.print(" set="); pw.println(setAdj);
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800399 pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime);
400 pw.print(" lastCompactAction="); pw.print(lastCompactAction);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700401 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700402 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700403 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700404 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700405 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700406 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700407 pw.print(" pssProcState="); pw.print(pssProcState);
408 pw.print(" setProcState="); pw.print(setProcState);
409 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700410 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700411 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700412 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700413 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700414 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700415 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
416 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700417 }
Dianne Hackborna631d562018-11-20 15:58:15 -0800418 if (connectionService != null || connectionGroup != 0) {
419 pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup);
420 pw.print(" Importance="); pw.print(connectionImportance);
421 pw.print(" Service="); pw.println(connectionService);
422 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700423 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
424 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
425 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100426 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700427 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700428 if (mHasForegroundServices || forcingToImportant != null) {
429 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700430 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700431 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700432 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700433 pw.print(prefix); pw.print("reportedInteraction=");
434 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700435 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800436 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700437 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800438 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700439 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700440 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700441 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700442 }
443 pw.println();
444 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700445 if (mPersistent || removed) {
446 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700447 pw.print(" removed="); pw.println(removed);
448 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700449 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
450 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
451 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700452 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700453 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800454 if (lastProviderTime > 0) {
455 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700456 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800457 pw.println();
458 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700459 if (lastTopTime > 0) {
460 pw.print(prefix); pw.print("lastTopTime=");
461 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
462 pw.println();
463 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700464 if (hasStartedServices) {
465 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
466 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700467 if (pendingStart) {
468 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
469 }
470 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800471 pw.print(prefix); pw.print("mountMode="); pw.println(
472 DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode));
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700473 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700474 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700475 if (lastCpuTime > 0) {
476 pw.print(" timeUsed=");
477 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
478 }
479 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700480 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700481 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700482 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700483 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700484 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700485 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700486 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700487 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700488 if (killed || killedByAm || waitingToKill != null) {
489 pw.print(prefix); pw.print("killed="); pw.print(killed);
490 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700491 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700492 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700493 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700494 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700495 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700496 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700497 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700498 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700499 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200500 pw.print(" bad="); pw.print(bad);
501
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700502 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200503 if (errorReportReceiver != null) {
504 pw.print(" errorReportReceiver=");
505 pw.print(errorReportReceiver.flattenToShortString());
506 }
507 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700508 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700509 if (whitelistManager) {
510 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
511 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400512 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
513 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
514 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
515 pw.println(Arrays.toString(isolatedEntryPointArgs));
516 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700517 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700518 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700519 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700520 for (int i=0; i<services.size(); i++) {
521 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700522 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700523 }
524 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700525 pw.print(prefix); pw.print("Executing Services (fg=");
526 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700527 for (int i=0; i<executingServices.size(); i++) {
528 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700529 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700530 }
531 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700532 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700533 for (int i=0; i<connections.size(); i++) {
534 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700535 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700536 }
537 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700538 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700539 for (int i=0; i<pubProviders.size(); i++) {
540 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
541 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700542 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700543 }
544 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700545 pw.print(prefix); pw.println("Connected Providers:");
546 for (int i=0; i<conProviders.size(); i++) {
547 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
548 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700549 }
yangzhenyud509bc92016-08-31 18:26:46 +0800550 if (!curReceivers.isEmpty()) {
551 pw.print(prefix); pw.println("Current Receivers:");
552 for (int i=0; i < curReceivers.size(); i++) {
553 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
554 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700555 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700556 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700557 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700558 for (int i=0; i<receivers.size(); i++) {
559 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700560 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700563
Bookatz152623f2018-07-23 15:57:44 -0700564 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700565 int _uid) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700566 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800568 isolated = _info.uid != _uid;
Martijn Coenen01e719b2018-12-05 16:01:38 +0100569 appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
570 && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800571 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700572 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700574 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700575 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700576 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700577 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700579 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700580 mWindowProcessController = new WindowProcessController(
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700581 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700582 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 }
584
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700585 public void setPid(int _pid) {
586 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700587 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700588 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800589 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700590 stringName = null;
591 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700592
593 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
594 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700595 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700596 if (origBase != null) {
597 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700598 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700599 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
600 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
601 uid, processName, pkgList.keyAt(ipkg),
602 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
603 pkgList.valueAt(ipkg).appVersion);
604 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700605 origBase.makeInactive();
606 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800607 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700608 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700609 baseProcessTracker.makeActive();
610 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700611 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
612 if (holder.state != null && holder.state != origBase) {
613 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700614 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800615 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700616 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700617 if (holder.state != baseProcessTracker) {
618 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700619 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700620 }
621 }
622 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700623 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700624 }
625
626 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700627 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700628 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700629 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700630 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700631 if (origBase != null) {
632 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700633 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700634 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
635 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
636 uid, processName, pkgList.keyAt(ipkg),
637 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
638 pkgList.valueAt(ipkg).appVersion);
639 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700640 origBase.makeInactive();
641 }
642 baseProcessTracker = null;
643 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700644 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
645 if (holder.state != null && holder.state != origBase) {
646 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700647 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700648 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700649 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700650 }
651 }
652 }
653
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700654 boolean hasActivities() {
655 return mWindowProcessController.hasActivities();
656 }
657
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700658 boolean hasActivitiesOrRecentTasks() {
659 return mWindowProcessController.hasActivitiesOrRecentTasks();
660 }
661
662 boolean hasRecentTasks() {
663 return mWindowProcessController.hasRecentTasks();
664 }
665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 /**
667 * This method returns true if any of the activities within the process record are interesting
668 * to the user. See HistoryRecord.isInterestingToUserLocked()
669 */
670 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700671 if (mWindowProcessController.isInterestingToUser()) {
672 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100674
675 final int servicesSize = services.size();
676 for (int i = 0; i < servicesSize; i++) {
677 ServiceRecord r = services.valueAt(i);
678 if (r.isForeground) {
679 return true;
680 }
681 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 return false;
683 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800684
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700685 public void unlinkDeathRecipient() {
686 if (deathRecipient != null && thread != null) {
687 thread.asBinder().unlinkToDeath(deathRecipient, 0);
688 }
689 deathRecipient = null;
690 }
691
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700692 void updateHasAboveClientLocked() {
693 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700694 for (int i=connections.size()-1; i>=0; i--) {
695 ConnectionRecord cr = connections.valueAt(i);
696 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
697 hasAboveClient = true;
698 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700699 }
700 }
701 }
702
Dianne Hackbornc8230512013-07-13 21:32:12 -0700703 int modifyRawOomAdj(int adj) {
704 if (hasAboveClient) {
705 // If this process has bound to any services with BIND_ABOVE_CLIENT,
706 // then we need to drop its adjustment to be lower than the service's
707 // in order to honor the request. We want to drop it by one adjustment
708 // level... but there is special meaning applied to various levels so
709 // we will skip some of them.
710 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
711 // System process will not get dropped, ever
712 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
713 adj = ProcessList.VISIBLE_APP_ADJ;
714 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
715 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
716 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
717 adj = ProcessList.CACHED_APP_MIN_ADJ;
718 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
719 adj++;
720 }
721 }
722 return adj;
723 }
724
Joe Onorato57190282016-04-20 15:37:49 -0700725 void scheduleCrash(String message) {
726 // Checking killedbyAm should keep it from showing the crash dialog if the process
727 // was already dead for a good / normal reason.
728 if (!killedByAm) {
729 if (thread != null) {
730 if (pid == Process.myPid()) {
731 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
732 return;
733 }
734 long ident = Binder.clearCallingIdentity();
735 try {
736 thread.scheduleCrash(message);
737 } catch (RemoteException e) {
738 // If it's already dead our work is done. If it's wedged just kill it.
739 // We won't get the crash dialog or the error reporting.
740 kill("scheduleCrash for '" + message + "' failed", true);
741 } finally {
742 Binder.restoreCallingIdentity(ident);
743 }
744 }
745 }
746 }
747
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700748 void kill(String reason, boolean noisy) {
749 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700750 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700751 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
752 mService.reportUidInfoMessageLocked(TAG,
753 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
754 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700755 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700756 if (pid > 0) {
757 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
758 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400759 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700760 } else {
761 pendingStart = false;
762 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700763 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700764 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700765 killedByAm = true;
766 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700767 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700768 }
769 }
770
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700771 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700772 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800773 writeToProto(proto, fieldId, -1);
774 }
775
776 public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700777 long token = proto.start(fieldId);
778 proto.write(ProcessRecordProto.PID, pid);
779 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800780 proto.write(ProcessRecordProto.UID, info.uid);
781 if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700782 proto.write(ProcessRecordProto.USER_ID, userId);
783 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800784 }
785 if (uid != info.uid) {
786 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
Yi Jin129fc6c2017-09-28 15:48:38 -0700787 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700788 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800789 if (lruIndex >= 0) {
790 proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
791 }
Yi Jin129fc6c2017-09-28 15:48:38 -0700792 proto.end(token);
793 }
794
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800795 public String toShortString() {
796 if (shortStringName != null) {
797 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700798 }
799 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800800 toShortString(sb);
801 return shortStringName = sb.toString();
802 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700803
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800804 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700805 sb.append(pid);
806 sb.append(':');
807 sb.append(processName);
808 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800809 if (info.uid < Process.FIRST_APPLICATION_UID) {
810 sb.append(uid);
811 } else {
812 sb.append('u');
813 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700814 int appId = UserHandle.getAppId(info.uid);
815 if (appId >= Process.FIRST_APPLICATION_UID) {
816 sb.append('a');
817 sb.append(appId - Process.FIRST_APPLICATION_UID);
818 } else {
819 sb.append('s');
820 sb.append(appId);
821 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800822 if (uid != info.uid) {
823 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700824 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800825 }
826 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800827 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700828
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800829 public String toString() {
830 if (stringName != null) {
831 return stringName;
832 }
833 StringBuilder sb = new StringBuilder(128);
834 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700835 sb.append(Integer.toHexString(System.identityHashCode(this)));
836 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800837 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700838 sb.append('}');
839 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700841
842 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700843 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700844 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700845 sb.append(' ');
846 if (adjTarget instanceof ComponentName) {
847 sb.append(((ComponentName)adjTarget).flattenToShortString());
848 } else if (adjTarget != null) {
849 sb.append(adjTarget.toString());
850 } else {
851 sb.append("{null}");
852 }
853 sb.append("<=");
854 if (adjSource instanceof ProcessRecord) {
855 sb.append("Proc{");
856 sb.append(((ProcessRecord)adjSource).toShortString());
857 sb.append("}");
858 } else if (adjSource != null) {
859 sb.append(adjSource.toString());
860 } else {
861 sb.append("{null}");
862 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700863 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700864 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700865 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700866 }
867
Wale Ogunwale9c103022018-10-18 07:44:54 -0700868 @Override
869 public void addPackage(String pkg, long versionCode) {
870 synchronized (mService) {
871 addPackage(pkg, versionCode, mService.mProcessStats);
872 }
873 }
874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 /*
876 * Return true if package has been added false if not
877 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700878 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700879 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700880 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
881 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700882 if (baseProcessTracker != null) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800883 tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
884 processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700885 pkgList.put(pkg, holder);
886 if (holder.state != baseProcessTracker) {
887 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700888 }
889 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700890 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 return true;
893 }
894 return false;
895 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700896
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700897 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700898 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
899 if (hasStartedServices) {
900 return ProcessList.SERVICE_B_ADJ;
901 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700902 }
903 return setAdj;
904 }
905
Dianne Hackborna413dc02013-07-12 12:02:55 -0700906 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700907 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700908 mRepProcState = newState;
909 setCurProcState(newState);
Amith Yamasani08888c02018-12-07 09:38:25 -0800910 setCurRawProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700911 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
912 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
913 uid, processName, pkgList.keyAt(ipkg),
914 ActivityManager.processStateAmToProto(mRepProcState),
915 pkgList.valueAt(ipkg).appVersion);
916 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700917 }
918 }
919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 /*
921 * Delete all packages from list except the package indicated in info
922 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700923 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700924 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700925 if (baseProcessTracker != null) {
926 long now = SystemClock.uptimeMillis();
927 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700928 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700929 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
930 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
931 uid, processName, pkgList.keyAt(ipkg),
932 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
933 pkgList.valueAt(ipkg).appVersion);
934 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700935 if (N != 1) {
936 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700937 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
938 if (holder.state != null && holder.state != baseProcessTracker) {
939 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700940 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700941
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700942 }
943 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700944 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700945 info.longVersionCode);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800946 tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700947 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700948 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700949 if (holder.state != baseProcessTracker) {
950 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700951 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700952 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700953 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700954 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700955 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700956 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 public String[] getPackageList() {
960 int size = pkgList.size();
961 if (size == 0) {
962 return null;
963 }
964 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700965 for (int i=0; i<pkgList.size(); i++) {
966 list[i] = pkgList.keyAt(i);
967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 return list;
969 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700970
Zimuzo972e1cd2019-01-28 16:30:01 +0000971 public List<VersionedPackage> getPackageListWithVersionCode() {
972 int size = pkgList.size();
973 if (size == 0) {
974 return null;
975 }
976 List<VersionedPackage> list = new ArrayList<>();
977 for (int i = 0; i < pkgList.size(); i++) {
978 list.add(new VersionedPackage(pkgList.keyAt(i), pkgList.valueAt(i).appVersion));
979 }
980 return list;
981 }
982
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700983 WindowProcessController getWindowProcessController() {
984 return mWindowProcessController;
985 }
986
987 void setCurrentSchedulingGroup(int curSchedGroup) {
988 mCurSchedGroup = curSchedGroup;
989 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
990 }
991
992 int getCurrentSchedulingGroup() {
993 return mCurSchedGroup;
994 }
995
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700996 void setCurProcState(int curProcState) {
997 mCurProcState = curProcState;
998 mWindowProcessController.setCurrentProcState(mCurProcState);
999 }
1000
1001 int getCurProcState() {
1002 return mCurProcState;
1003 }
1004
Amith Yamasani08888c02018-12-07 09:38:25 -08001005 void setCurRawProcState(int curRawProcState) {
1006 mCurRawProcState = curRawProcState;
1007 }
1008
1009 int getCurRawProcState() {
1010 return mCurRawProcState;
1011 }
1012
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001013 void setReportedProcState(int repProcState) {
1014 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -07001015 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
1016 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
1017 uid, processName, pkgList.keyAt(ipkg),
1018 ActivityManager.processStateAmToProto(mRepProcState),
1019 pkgList.valueAt(ipkg).appVersion);
1020 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001021 mWindowProcessController.setReportedProcState(repProcState);
1022 }
1023
1024 int getReportedProcState() {
1025 return mRepProcState;
1026 }
1027
1028 void setCrashing(boolean crashing) {
1029 mCrashing = crashing;
1030 mWindowProcessController.setCrashing(crashing);
1031 }
1032
1033 boolean isCrashing() {
1034 return mCrashing;
1035 }
1036
1037 void setNotResponding(boolean notResponding) {
1038 mNotResponding = notResponding;
1039 mWindowProcessController.setNotResponding(notResponding);
1040 }
1041
1042 boolean isNotResponding() {
1043 return mNotResponding;
1044 }
1045
1046 void setPersistent(boolean persistent) {
1047 mPersistent = persistent;
1048 mWindowProcessController.setPersistent(persistent);
1049 }
1050
1051 boolean isPersistent() {
1052 return mPersistent;
1053 }
1054
1055 public void setRequiredAbi(String requiredAbi) {
1056 mRequiredAbi = requiredAbi;
1057 mWindowProcessController.setRequiredAbi(requiredAbi);
1058 }
1059
1060 String getRequiredAbi() {
1061 return mRequiredAbi;
1062 }
1063
Amith Yamasania0a30a12019-01-22 11:38:06 -08001064 void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001065 mHasForegroundServices = hasForegroundServices;
Amith Yamasania0a30a12019-01-22 11:38:06 -08001066 mFgServiceTypes = fgServiceTypes;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001067 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1068 }
1069
1070 boolean hasForegroundServices() {
1071 return mHasForegroundServices;
1072 }
1073
Amith Yamasania0a30a12019-01-22 11:38:06 -08001074 boolean hasLocationForegroundServices() {
1075 return mHasForegroundServices
1076 && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0;
1077 }
1078
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001079 void setHasForegroundActivities(boolean hasForegroundActivities) {
1080 mHasForegroundActivities = hasForegroundActivities;
1081 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1082 }
1083
1084 boolean hasForegroundActivities() {
1085 return mHasForegroundActivities;
1086 }
1087
1088 void setHasClientActivities(boolean hasClientActivities) {
1089 mHasClientActivities = hasClientActivities;
1090 mWindowProcessController.setHasClientActivities(hasClientActivities);
1091 }
1092
1093 boolean hasClientActivities() {
1094 return mHasClientActivities;
1095 }
1096
1097 void setHasTopUi(boolean hasTopUi) {
1098 mHasTopUi = hasTopUi;
1099 mWindowProcessController.setHasTopUi(hasTopUi);
1100 }
1101
1102 boolean hasTopUi() {
1103 return mHasTopUi;
1104 }
1105
1106 void setHasOverlayUi(boolean hasOverlayUi) {
1107 mHasOverlayUi = hasOverlayUi;
1108 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1109 }
1110
1111 boolean hasOverlayUi() {
1112 return mHasOverlayUi;
1113 }
1114
1115 void setInteractionEventTime(long interactionEventTime) {
1116 mInteractionEventTime = interactionEventTime;
1117 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1118 }
1119
1120 long getInteractionEventTime() {
1121 return mInteractionEventTime;
1122 }
1123
1124 void setFgInteractionTime(long fgInteractionTime) {
1125 mFgInteractionTime = fgInteractionTime;
1126 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1127 }
1128
1129 long getFgInteractionTime() {
1130 return mFgInteractionTime;
1131 }
1132
1133 void setWhenUnimportant(long whenUnimportant) {
1134 mWhenUnimportant = whenUnimportant;
1135 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1136 }
1137
1138 long getWhenUnimportant() {
1139 return mWhenUnimportant;
1140 }
1141
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001142 void setDebugging(boolean debugging) {
1143 mDebugging = debugging;
1144 mWindowProcessController.setDebugging(debugging);
1145 }
1146
1147 boolean isDebugging() {
1148 return mDebugging;
1149 }
1150
1151 void setUsingWrapper(boolean usingWrapper) {
1152 mUsingWrapper = usingWrapper;
1153 mWindowProcessController.setUsingWrapper(usingWrapper);
1154 }
1155
1156 boolean isUsingWrapper() {
1157 return mUsingWrapper;
1158 }
1159
Michal Karpinskiac116df2018-12-10 17:51:42 +00001160 void addAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001161 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001162 mAllowBackgroundActivityStartsTokens.add(entity);
1163 mWindowProcessController.setAllowBackgroundActivityStarts(true);
1164 }
1165
1166 void removeAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001167 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001168 mAllowBackgroundActivityStartsTokens.remove(entity);
1169 mWindowProcessController.setAllowBackgroundActivityStarts(
1170 !mAllowBackgroundActivityStartsTokens.isEmpty());
1171 }
1172
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001173 void setActiveInstrumentation(ActiveInstrumentation instr) {
1174 mInstr = instr;
Michal Karpinski4bc56492019-01-31 12:07:33 +00001175 boolean isInstrumenting = instr != null;
1176 mWindowProcessController.setInstrumenting(isInstrumenting,
1177 isInstrumenting && instr.mHasBackgroundActivityStartsPermission);
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001178 }
1179
1180 ActiveInstrumentation getActiveInstrumentation() {
1181 return mInstr;
1182 }
1183
Wale Ogunwale31913b52018-10-13 08:29:31 -07001184 void setCurRawAdj(int curRawAdj) {
1185 mCurRawAdj = curRawAdj;
1186 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1187 }
1188
1189 int getCurRawAdj() {
1190 return mCurRawAdj;
1191 }
1192
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001193 @Override
1194 public void clearProfilerIfNeeded() {
1195 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001196 if (mService.mProfileData.getProfileProc() == null
1197 || mService.mProfileData.getProfilerInfo() == null
1198 || mService.mProfileData.getProfileProc() != this) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001199 return;
1200 }
1201 mService.clearProfilerLocked();
1202 }
1203 }
1204
1205 @Override
1206 public void updateServiceConnectionActivities() {
1207 synchronized (mService) {
1208 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1209 }
1210 }
1211
1212 @Override
1213 public void setPendingUiClean(boolean pendingUiClean) {
1214 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001215 mPendingUiClean = pendingUiClean;
1216 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001217 }
1218 }
1219
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001220 boolean hasPendingUiClean() {
1221 return mPendingUiClean;
1222 }
1223
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001224 @Override
1225 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1226 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001227 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001228 forceProcessStateUpTo(newState);
1229 }
1230 }
1231
1232 @Override
1233 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru,
1234 boolean activityChange, boolean updateOomAdj) {
1235 synchronized (mService) {
1236 if (updateServiceConnectionActivities) {
1237 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1238 }
1239 if (updateLru) {
Amith Yamasani98a00922018-08-21 12:50:30 -04001240 mService.mProcessList.updateLruProcessLocked(this, activityChange, null);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001241 }
1242 if (updateOomAdj) {
1243 mService.updateOomAdjLocked();
1244 }
1245 }
1246 }
1247
1248 @Override
Riddle Hsuaaef7312019-01-24 19:00:58 +08001249 public boolean isRemoved() {
1250 return removed;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001251 }
1252
Wale Ogunwale86b74462018-07-02 08:42:43 -07001253 /**
1254 * Returns the total time (in milliseconds) spent executing in both user and system code.
1255 * Safe to call without lock held.
1256 */
Wale Ogunwale9c103022018-10-18 07:44:54 -07001257 @Override
Wale Ogunwale86b74462018-07-02 08:42:43 -07001258 public long getCpuTime() {
1259 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1260 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001261
Wale Ogunwale9c103022018-10-18 07:44:54 -07001262 @Override
1263 public void clearWaitingToKill() {
1264 synchronized (mService) {
1265 waitingToKill = null;
1266 }
1267 }
1268
1269 @Override
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001270 public void onStartActivity(int topProcessState, boolean setProfileProc) {
Wale Ogunwale9c103022018-10-18 07:44:54 -07001271 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001272 if (setProfileProc) {
1273 mService.mProfileData.setProfileProc(this);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001274 }
1275
1276 hasShownUi = true;
1277 setPendingUiClean(true);
1278 forceProcessStateUpTo(topProcessState);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001279 }
1280 }
1281
1282 @Override
1283 public void appDied() {
1284 synchronized (mService) {
1285 mService.appDiedLocked(this);
1286 }
1287 }
1288
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001289 public long getInputDispatchingTimeout() {
1290 return mWindowProcessController.getInputDispatchingTimeout();
1291 }
1292
Yang Lu732d6382018-11-05 07:53:12 -08001293 public int getProcessClassEnum() {
1294 if (pid == MY_PID) {
1295 return ServerProtoEnums.SYSTEM_SERVER;
1296 }
1297 if (info == null) {
1298 return ServerProtoEnums.ERROR_SOURCE_UNKNOWN;
1299 }
1300 return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP :
1301 ServerProtoEnums.DATA_APP;
1302 }
1303
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001304 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1305 String parentShortComponentName, WindowProcessController parentProcess,
1306 boolean aboveSystem, String annotation) {
1307 ArrayList<Integer> firstPids = new ArrayList<>(5);
1308 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1309
Wale Ogunwalee2172292018-10-25 10:11:10 -07001310 mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true));
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001311
1312 long anrTime = SystemClock.uptimeMillis();
1313 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1314 mService.updateCpuStatsNow();
1315 }
1316
1317 // Unless configured otherwise, swallow ANRs in background processes & kill the process.
1318 boolean showBackground = Settings.Secure.getInt(mService.mContext.getContentResolver(),
1319 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1320
1321 boolean isSilentANR;
1322
1323 synchronized (mService) {
1324 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
Wale Ogunwale387b34c2018-10-25 19:59:40 -07001325 if (mService.mAtmInternal.isShuttingDown()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001326 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1327 return;
1328 } else if (isNotResponding()) {
1329 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1330 return;
1331 } else if (isCrashing()) {
1332 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1333 return;
1334 } else if (killedByAm) {
1335 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1336 return;
1337 } else if (killed) {
1338 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1339 return;
1340 }
1341
1342 // In case we come through here for the same app before completing
1343 // this one, mark as anring now so we will bail out.
1344 setNotResponding(true);
1345
1346 // Log the ANR to the event log.
1347 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1348 annotation);
1349
1350 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1351 firstPids.add(pid);
1352
1353 // Don't dump other PIDs if it's a background ANR
1354 isSilentANR = !showBackground && !isInterestingForBackgroundTraces();
1355 if (!isSilentANR) {
1356 int parentPid = pid;
1357 if (parentProcess != null && parentProcess.getPid() > 0) {
1358 parentPid = parentProcess.getPid();
1359 }
1360 if (parentPid != pid) firstPids.add(parentPid);
1361
1362 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1363
Amith Yamasani98a00922018-08-21 12:50:30 -04001364 for (int i = mService.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
1365 ProcessRecord r = mService.mProcessList.mLruProcesses.get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001366 if (r != null && r.thread != null) {
1367 int myPid = r.pid;
1368 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1369 if (r.isPersistent()) {
1370 firstPids.add(myPid);
1371 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1372 } else if (r.treatLikeActivity) {
1373 firstPids.add(myPid);
1374 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1375 } else {
1376 lastPids.put(myPid, Boolean.TRUE);
1377 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1378 }
1379 }
1380 }
1381 }
1382 }
1383 }
1384
1385 // Log the ANR to the main log.
1386 StringBuilder info = new StringBuilder();
1387 info.setLength(0);
1388 info.append("ANR in ").append(processName);
1389 if (activityShortComponentName != null) {
1390 info.append(" (").append(activityShortComponentName).append(")");
1391 }
1392 info.append("\n");
1393 info.append("PID: ").append(pid).append("\n");
1394 if (annotation != null) {
1395 info.append("Reason: ").append(annotation).append("\n");
1396 }
1397 if (parentShortComponentName != null
1398 && parentShortComponentName.equals(activityShortComponentName)) {
1399 info.append("Parent: ").append(parentShortComponentName).append("\n");
1400 }
1401
1402 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1403
1404 // don't dump native PIDs for background ANRs unless it is the process of interest
1405 String[] nativeProcs = null;
1406 if (isSilentANR) {
1407 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1408 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1409 nativeProcs = new String[] { processName };
1410 break;
1411 }
1412 }
1413 } else {
1414 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1415 }
1416
1417 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1418 ArrayList<Integer> nativePids = null;
1419
1420 if (pids != null) {
1421 nativePids = new ArrayList<>(pids.length);
1422 for (int i : pids) {
1423 nativePids.add(i);
1424 }
1425 }
1426
1427 // For background ANRs, don't pass the ProcessCpuTracker to
1428 // avoid spending 1/2 second collecting stats to rank lastPids.
1429 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
1430 (isSilentANR) ? null : processCpuTracker, (isSilentANR) ? null : lastPids,
1431 nativePids);
1432
1433 String cpuInfo = null;
1434 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1435 mService.updateCpuStatsNow();
1436 synchronized (mService.mProcessCpuTracker) {
1437 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1438 }
1439 info.append(processCpuTracker.printCurrentLoad());
1440 info.append(cpuInfo);
1441 }
1442
1443 info.append(processCpuTracker.printCurrentState(anrTime));
1444
1445 Slog.e(TAG, info.toString());
1446 if (tracesFile == null) {
1447 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1448 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1449 }
1450
1451 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1452 activityShortComponentName == null ? "unknown": activityShortComponentName,
1453 annotation,
1454 (this.info != null) ? (this.info.isInstantApp()
1455 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1456 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1457 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1458 isInterestingToUserLocked()
1459 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
Yang Lu732d6382018-11-05 07:53:12 -08001460 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
1461 getProcessClassEnum(),
1462 (this.info != null) ? this.info.packageName : "");
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001463 final ProcessRecord parentPr = parentProcess != null
1464 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001465 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001466 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001467
Wale Ogunwalee2172292018-10-25 10:11:10 -07001468 if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true),
1469 () -> {
1470 synchronized (mService) {
1471 mService.mServices.scheduleServiceTimeoutLocked(this);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001472 }
Wale Ogunwalee2172292018-10-25 10:11:10 -07001473 })) {
1474 return;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001475 }
1476
1477 synchronized (mService) {
1478 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1479
1480 if (isSilentANR) {
1481 kill("bg anr", true);
1482 return;
1483 }
1484
1485 // Set the app's notResponding state, and look up the errorReportReceiver
1486 makeAppNotRespondingLocked(activityShortComponentName,
1487 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1488
1489 // Bring up the infamous App Not Responding dialog
1490 Message msg = Message.obtain();
1491 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1492 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
1493
1494 mService.mUiHandler.sendMessage(msg);
1495 }
1496 }
1497
1498 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1499 setNotResponding(true);
1500 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1501 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1502 activity, shortMsg, longMsg, null);
1503 startAppProblemLocked();
1504 getWindowProcessController().stopFreezingActivities();
1505 }
1506
1507 void startAppProblemLocked() {
1508 // If this app is not running under the current user, then we can't give it a report button
1509 // because that would require launching the report UI under a different user.
1510 errorReportReceiver = null;
1511
1512 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1513 if (this.userId == userId) {
1514 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1515 mService.mContext, info.packageName, info.flags);
1516 }
1517 }
1518 mService.skipCurrentReceiverLocked(this);
1519 }
1520
1521 private boolean isInterestingForBackgroundTraces() {
1522 // The system_server is always considered interesting.
1523 if (pid == MY_PID) {
1524 return true;
1525 }
1526
1527 // A package is considered interesting if any of the following is true :
1528 //
1529 // - It's displaying an activity.
1530 // - It's the SystemUI.
1531 // - It has an overlay or a top UI visible.
1532 //
1533 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1534 // process is a bit of a kludge, but the same pattern seems repeated at
1535 // several places in the system server.
1536 return isInterestingToUserLocked() ||
1537 (info != null && "com.android.systemui".equals(info.packageName))
1538 || (hasTopUi() || hasOverlayUi());
1539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540}