blob: 99c236d630a2b2188557e7ab11af02a63b2b8717 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.am;
18
riddle_hsu6793fc32015-03-31 11:54:14 +080019import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
Yunfan Chen75157d72018-07-27 14:47:21 +090020
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070021import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
22import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080023import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
24import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070025import static com.android.server.am.ActivityManagerService.MY_PID;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.app.ActivityManager;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070028import android.app.ApplicationErrorReport;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.app.Dialog;
30import android.app.IApplicationThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ComponentName;
Dianne Hackbornc68c9132011-07-29 01:25:18 -070032import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.pm.ApplicationInfo;
Amith Yamasania0a30a12019-01-22 11:38:06 -080034import android.content.pm.ServiceInfo;
Zimuzo972e1cd2019-01-28 16:30:01 +000035import android.content.pm.VersionedPackage;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040036import android.content.res.CompatibilityInfo;
Joe Onorato57190282016-04-20 15:37:49 -070037import android.os.Binder;
Yunfan Chen75157d72018-07-27 14:47:21 +090038import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.IBinder;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070040import android.os.Message;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080041import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070042import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070043import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070044import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070045import android.os.UserHandle;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070046import android.provider.Settings;
Yang Lu732d6382018-11-05 07:53:12 -080047import android.server.ServerProtoEnums;
Dianne Hackborn390517b2013-05-30 15:03:32 -070048import android.util.ArrayMap;
Yunfan Chen75157d72018-07-27 14:47:21 +090049import android.util.ArraySet;
50import android.util.DebugUtils;
51import android.util.EventLog;
52import android.util.Slog;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070053import android.util.SparseArray;
Chenjie Yubd1a28f2018-07-17 14:55:19 -070054import android.util.StatsLog;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070055import android.util.TimeUtils;
Yi Jin129fc6c2017-09-28 15:48:38 -070056import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Yunfan Chen585f2932019-01-29 16:04:45 +090058import com.android.internal.annotations.VisibleForTesting;
Yunfan Chen75157d72018-07-27 14:47:21 +090059import com.android.internal.app.procstats.ProcessState;
60import com.android.internal.app.procstats.ProcessStats;
61import com.android.internal.os.BatteryStatsImpl;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070062import com.android.internal.os.ProcessCpuTracker;
Sudheer Shanka87915d62018-11-06 10:57:35 -080063import com.android.internal.os.Zygote;
Wale Ogunwale59507092018-10-29 09:00:30 -070064import com.android.server.wm.WindowProcessController;
65import com.android.server.wm.WindowProcessListener;
Yunfan Chen75157d72018-07-27 14:47:21 +090066
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070067import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import java.io.PrintWriter;
69import java.util.ArrayList;
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -040070import java.util.Arrays;
Zimuzo972e1cd2019-01-28 16:30:01 +000071import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
73/**
74 * Full information about a particular process that
75 * is currently running.
76 */
Yunfan Chen585f2932019-01-29 16:04:45 +090077class ProcessRecord implements WindowProcessListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080078 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
79
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -070080 private final ActivityManagerService mService; // where we came from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080082 final boolean isolated; // true if this is a special isolated process
Martijn Coenen01e719b2018-12-05 16:01:38 +010083 final boolean appZygote; // true if this is forked from the app zygote
Dianne Hackborna0c283e2012-02-09 10:47:01 -080084 final int uid; // uid of process; may be different from 'info' if isolated
85 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 final String processName; // name of the process
87 // List of packages running in the process
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070088 final PackageList pkgList = new PackageList();
89 final class PackageList {
90 final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>();
91
92 ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) {
93 mWindowProcessController.addPackage(key);
94 return mPkgList.put(key, value);
95 }
96
97 void clear() {
98 mPkgList.clear();
99 mWindowProcessController.clearPackageList();
100 }
101
102 int size() {
103 return mPkgList.size();
104 }
105
106 String keyAt(int index) {
107 return mPkgList.keyAt(index);
108 }
109
110 public ProcessStats.ProcessStateHolder valueAt(int index) {
111 return mPkgList.valueAt(index);
112 }
113
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700114 ProcessStats.ProcessStateHolder get(String pkgName) {
115 return mPkgList.get(pkgName);
116 }
117
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700118 boolean containsKey(Object key) {
119 return mPkgList.containsKey(key);
120 }
121 }
122
Dianne Hackborne17b4452018-01-10 13:15:40 -0800123 final ProcessList.ProcStateMemTracker procStateMemTracker
124 = new ProcessList.ProcStateMemTracker();
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700125 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700126 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 IApplicationThread thread; // the actual proc... may be null only if
128 // 'persistent' is true (in which case we
129 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700130 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -0800131 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700133 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800134 int[] gids; // The gids this process was launched with
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700135 private String mRequiredAbi;// The ABI this process was launched with
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800136 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800138 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700139 long lastPssTime; // Last time we retrieved PSS data
140 long nextPssTime; // Next time we want to request PSS data
141 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700142 long initialIdlePss; // Initial memory pss of process for idle maintenance.
143 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800144 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700145 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800146 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 int maxAdj; // Maximum OOM adjustment for this process
Wale Ogunwale31913b52018-10-13 08:29:31 -0700148 private int mCurRawAdj; // Current OOM unlimited adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 int setRawAdj; // Last set OOM unlimited adjustment for this process
150 int curAdj; // Current OOM adjustment for this process
151 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700152 int verifiedAdj; // The last adjustment that was verified as actually being set
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800153 long lastCompactTime; // The last time that this process was compacted
154 int reqCompactAction; // The most recent compaction action requested for this app.
155 int lastCompactAction; // The most recent compaction action performed for this app.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700156 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700157 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700158 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700159 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700160 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
Amith Yamasani08888c02018-12-07 09:38:25 -0800161 private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation
riddle_hsu6793fc32015-03-31 11:54:14 +0800162 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
163 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800164 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700165 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
166 int renderThreadTid; // TID for RenderThread
Dianne Hackborna631d562018-11-20 15:58:15 -0800167 ServiceRecord connectionService; // Service that applied current connectionGroup/Importance
168 int connectionGroup; // Last group set by a connection
169 int connectionImportance; // Last importance set by a connection
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700170 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700171 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700172 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700173 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700174 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700175 private boolean mHasForegroundServices; // Running any services that are foreground?
Amith Yamasania0a30a12019-01-22 11:38:06 -0800176 private int mFgServiceTypes; // Type of foreground service, if there is a foreground service.
Narayan Kamath396ce722019-03-01 16:53:26 +0000177 private int mRepFgServiceTypes; // Last reported foreground service types.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700178 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700179 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700180 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700181 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700182 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800183 // is interacting with? E.g. The status bar when it is expanded, but
184 // not when it is minimized. When true the
185 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
186 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700187 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800188 // overlays on-top of activity UIs on screen. E.g. display a window
189 // of type
190 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
191 // When true the process will oom adj score will be set to
192 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
193 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100194 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
195 // the process will be set to use the
196 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
197 // performance, as well as oom adj score will be set to
198 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
199 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700200 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700201 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700202 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700204 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700205 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700206 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700207 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600208 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700209 private long mInteractionEventTime; // The time we sent the last interaction event
210 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700211 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700212 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700213 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700214 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
215 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700216 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700217 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700218 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700219 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
220 // process.
221 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800222 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700223 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700224 long lastCpuTime; // How long proc has run CPU at last check
225 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700227 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800228 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700229 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700230 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800231 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700232 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700233 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700234 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700235 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700236 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700237 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100238 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
239
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700240 // Cache of last retrieve memory info and uptime, to throttle how frequently
241 // apps can requyest it.
242 Debug.MemoryInfo lastMemInfo;
243 long lastMemInfoTime;
244
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700245 // Controller for driving the process state on the window manager side.
246 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700248 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700250 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700252 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700254 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700256 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700258 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Michal Karpinskiac116df2018-12-10 17:51:42 +0000259 // A set of tokens that currently contribute to this process being temporarily whitelisted
260 // to start activities even if it's not in the foreground
261 final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>();
Michal Karpinskib7daac22019-03-25 10:12:41 +0000262 // a set of UIDs of all bound clients
263 private ArraySet<Integer> mBoundClientUids = new ArraySet<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700264
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400265 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
266 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
267
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700268 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700269 private boolean mPersistent;// always keep this application running?
270 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700272 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700273 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 Dialog anrDialog; // dialog being displayed due to app not resp.
Riddle Hsuaaef7312019-01-24 19:00:58 +0800275 volatile boolean removed; // Whether this process should be killed and removed from process
276 // list. It is set when the package is force-stopped or the process
277 // has crashed too many times.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700278 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 boolean waitedForDebugger; // has process show wait for debugger dialog?
280 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700281
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800282 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700283 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700284 boolean pendingStart; // Process start is pending.
285 long startSeq; // Seq no. indicating the latest process start associated with
286 // this process record.
Sudheer Shanka87915d62018-11-06 10:57:35 -0800287 int mountMode; // Indicates how the external storage was mounted for this process.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 // These reports are generated & stored when an app gets into an error condition.
290 // They will be "null" when all is OK.
291 ActivityManager.ProcessErrorStateInfo crashingReport;
292 ActivityManager.ProcessErrorStateInfo notRespondingReport;
293
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200294 // Who will be notified of the error. This is usually an activity in the
295 // app that installed the package.
296 ComponentName errorReportReceiver;
297
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700298 // Process is currently hosting a backup agent for backup or restore
299 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700300 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
301 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700302
Sudheer Shankaf6690102017-10-16 10:20:32 -0700303 // Params used in starting this process.
304 String hostingType;
305 String hostingNameStr;
306 String seInfo;
307 long startTime;
308 // This will be same as {@link #uid} usually except for some apps used during factory testing.
309 int startUid;
310
311 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
312 long startTime) {
313 this.startUid = startUid;
314 this.hostingType = hostingType;
315 this.hostingNameStr = hostingNameStr;
316 this.seInfo = seInfo;
317 this.startTime = startTime;
318 }
319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700321 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700322
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800323 pw.print(prefix); pw.print("user #"); pw.print(userId);
324 pw.print(" uid="); pw.print(info.uid);
325 if (uid != info.uid) {
326 pw.print(" ISOLATED uid="); pw.print(uid);
327 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800328 pw.print(" gids={");
329 if (gids != null) {
330 for (int gi=0; gi<gids.length; gi++) {
331 if (gi != 0) pw.print(", ");
332 pw.print(gids[gi]);
333
334 }
335 }
336 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700337 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800338 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700339 if (info.className != null) {
340 pw.print(prefix); pw.print("class="); pw.println(info.className);
341 }
342 if (info.manageSpaceActivityName != null) {
343 pw.print(prefix); pw.print("manageSpaceActivityName=");
344 pw.println(info.manageSpaceActivityName);
345 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900346
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700347 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
348 pw.print(" publicDir="); pw.print(info.publicSourceDir);
349 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700350 pw.print(prefix); pw.print("packageList={");
351 for (int i=0; i<pkgList.size(); i++) {
352 if (i > 0) pw.print(", ");
353 pw.print(pkgList.keyAt(i));
354 }
355 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700356 if (pkgDeps != null) {
357 pw.print(prefix); pw.print("packageDependencies={");
358 for (int i=0; i<pkgDeps.size(); i++) {
359 if (i > 0) pw.print(", ");
360 pw.print(pkgDeps.valueAt(i));
361 }
362 pw.println("}");
363 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700364 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700365 if (mInstr != null) {
366 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700367 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700368 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700369 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700370 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700371 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700372 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700373 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700374 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800375 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700376 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700377 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700378 pw.println();
379 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
380 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800381 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800382 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800383 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800384 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800385 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800386 pw.print(prefix); pw.print("procStateMemTracker: ");
387 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700388 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800389 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700390 if (serviceb) {
391 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
392 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
393 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700394 if (notCachedSinceIdle) {
395 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700396 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700397 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700398 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700399 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700400 pw.print(" setRaw="); pw.print(setRawAdj);
401 pw.print(" cur="); pw.print(curAdj);
402 pw.print(" set="); pw.println(setAdj);
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800403 pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime);
404 pw.print(" lastCompactAction="); pw.print(lastCompactAction);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700405 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700406 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700407 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700408 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700409 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700410 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700411 pw.print(" pssProcState="); pw.print(pssProcState);
412 pw.print(" setProcState="); pw.print(setProcState);
413 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700414 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700415 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700416 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700417 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700418 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700419 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
420 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700421 }
Dianne Hackborna631d562018-11-20 15:58:15 -0800422 if (connectionService != null || connectionGroup != 0) {
423 pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup);
424 pw.print(" Importance="); pw.print(connectionImportance);
425 pw.print(" Service="); pw.println(connectionService);
426 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700427 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
428 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
429 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100430 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700431 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700432 if (mHasForegroundServices || forcingToImportant != null) {
433 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700434 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700435 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700436 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700437 pw.print(prefix); pw.print("reportedInteraction=");
438 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700439 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800440 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700441 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800442 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700443 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700444 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700445 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700446 }
447 pw.println();
448 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700449 if (mPersistent || removed) {
450 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700451 pw.print(" removed="); pw.println(removed);
452 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700453 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
454 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
455 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700456 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700457 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800458 if (lastProviderTime > 0) {
459 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700460 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800461 pw.println();
462 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700463 if (lastTopTime > 0) {
464 pw.print(prefix); pw.print("lastTopTime=");
465 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
466 pw.println();
467 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700468 if (hasStartedServices) {
469 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
470 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700471 if (pendingStart) {
472 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
473 }
474 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800475 pw.print(prefix); pw.print("mountMode="); pw.println(
476 DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode));
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700477 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700478 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700479 if (lastCpuTime > 0) {
480 pw.print(" timeUsed=");
481 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
482 }
483 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700484 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700485 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700486 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700487 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700488 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700489 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700490 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700491 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700492 if (killed || killedByAm || waitingToKill != null) {
493 pw.print(prefix); pw.print("killed="); pw.print(killed);
494 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700495 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700496 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700497 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700498 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700499 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700500 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700501 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700502 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700503 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200504 pw.print(" bad="); pw.print(bad);
505
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700506 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200507 if (errorReportReceiver != null) {
508 pw.print(" errorReportReceiver=");
509 pw.print(errorReportReceiver.flattenToShortString());
510 }
511 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700512 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700513 if (whitelistManager) {
514 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
515 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400516 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
517 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
518 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
519 pw.println(Arrays.toString(isolatedEntryPointArgs));
520 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700521 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700522 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700523 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700524 for (int i=0; i<services.size(); i++) {
525 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700526 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700527 }
528 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700529 pw.print(prefix); pw.print("Executing Services (fg=");
530 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700531 for (int i=0; i<executingServices.size(); i++) {
532 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700533 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700534 }
535 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700536 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700537 for (int i=0; i<connections.size(); i++) {
538 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700539 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700540 }
541 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700542 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700543 for (int i=0; i<pubProviders.size(); i++) {
544 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
545 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700546 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700547 }
548 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700549 pw.print(prefix); pw.println("Connected Providers:");
550 for (int i=0; i<conProviders.size(); i++) {
551 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
552 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700553 }
yangzhenyud509bc92016-08-31 18:26:46 +0800554 if (!curReceivers.isEmpty()) {
555 pw.print(prefix); pw.println("Current Receivers:");
556 for (int i=0; i < curReceivers.size(); i++) {
557 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
558 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700559 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700560 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700561 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700562 for (int i=0; i<receivers.size(); i++) {
563 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700564 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700565 }
Edward Cunninghamde661762019-03-27 15:51:56 +0000566 if (mAllowBackgroundActivityStartsTokens.size() > 0) {
567 pw.print(prefix); pw.println("Background activity start whitelist tokens:");
568 for (int i = 0; i < mAllowBackgroundActivityStartsTokens.size(); i++) {
569 pw.print(prefix); pw.print(" - ");
570 pw.println(mAllowBackgroundActivityStartsTokens.valueAt(i));
571 }
572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700574
Bookatz152623f2018-07-23 15:57:44 -0700575 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700576 int _uid) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700577 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800579 isolated = _info.uid != _uid;
Martijn Coenen01e719b2018-12-05 16:01:38 +0100580 appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
581 && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800582 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700583 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700585 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700586 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700587 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700588 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700590 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700591 mWindowProcessController = new WindowProcessController(
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700592 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700593 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700596 public void setPid(int _pid) {
597 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700598 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700599 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800600 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700601 stringName = null;
602 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700603
604 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
605 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700606 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700607 if (origBase != null) {
608 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700609 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700610 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
611 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
612 uid, processName, pkgList.keyAt(ipkg),
613 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
614 pkgList.valueAt(ipkg).appVersion);
615 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700616 origBase.makeInactive();
617 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800618 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700619 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700620 baseProcessTracker.makeActive();
621 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700622 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
623 if (holder.state != null && holder.state != origBase) {
624 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700625 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800626 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700627 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700628 if (holder.state != baseProcessTracker) {
629 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700630 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700631 }
632 }
633 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700634 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700635 }
636
637 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700638 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700639 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700640 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700641 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700642 if (origBase != null) {
643 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700644 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700645 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
646 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
647 uid, processName, pkgList.keyAt(ipkg),
648 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
649 pkgList.valueAt(ipkg).appVersion);
650 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700651 origBase.makeInactive();
652 }
653 baseProcessTracker = null;
654 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700655 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
656 if (holder.state != null && holder.state != origBase) {
657 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700658 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700659 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700660 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700661 }
662 }
663 }
664
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700665 boolean hasActivities() {
666 return mWindowProcessController.hasActivities();
667 }
668
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700669 boolean hasActivitiesOrRecentTasks() {
670 return mWindowProcessController.hasActivitiesOrRecentTasks();
671 }
672
673 boolean hasRecentTasks() {
674 return mWindowProcessController.hasRecentTasks();
675 }
676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 /**
678 * This method returns true if any of the activities within the process record are interesting
679 * to the user. See HistoryRecord.isInterestingToUserLocked()
680 */
681 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700682 if (mWindowProcessController.isInterestingToUser()) {
683 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100685
686 final int servicesSize = services.size();
687 for (int i = 0; i < servicesSize; i++) {
688 ServiceRecord r = services.valueAt(i);
689 if (r.isForeground) {
690 return true;
691 }
692 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 return false;
694 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800695
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700696 public void unlinkDeathRecipient() {
697 if (deathRecipient != null && thread != null) {
698 thread.asBinder().unlinkToDeath(deathRecipient, 0);
699 }
700 deathRecipient = null;
701 }
702
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700703 void updateHasAboveClientLocked() {
704 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700705 for (int i=connections.size()-1; i>=0; i--) {
706 ConnectionRecord cr = connections.valueAt(i);
707 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
708 hasAboveClient = true;
709 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700710 }
711 }
712 }
713
Dianne Hackbornc8230512013-07-13 21:32:12 -0700714 int modifyRawOomAdj(int adj) {
715 if (hasAboveClient) {
716 // If this process has bound to any services with BIND_ABOVE_CLIENT,
717 // then we need to drop its adjustment to be lower than the service's
718 // in order to honor the request. We want to drop it by one adjustment
719 // level... but there is special meaning applied to various levels so
720 // we will skip some of them.
721 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
722 // System process will not get dropped, ever
723 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
724 adj = ProcessList.VISIBLE_APP_ADJ;
725 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
726 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
Amith Yamasani0567ec62019-01-23 11:11:02 -0800727 } else if (adj < ProcessList.PERCEPTIBLE_LOW_APP_ADJ) {
728 adj = ProcessList.PERCEPTIBLE_LOW_APP_ADJ;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700729 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
730 adj = ProcessList.CACHED_APP_MIN_ADJ;
731 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
732 adj++;
733 }
734 }
735 return adj;
736 }
737
Joe Onorato57190282016-04-20 15:37:49 -0700738 void scheduleCrash(String message) {
739 // Checking killedbyAm should keep it from showing the crash dialog if the process
740 // was already dead for a good / normal reason.
741 if (!killedByAm) {
742 if (thread != null) {
743 if (pid == Process.myPid()) {
744 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
745 return;
746 }
747 long ident = Binder.clearCallingIdentity();
748 try {
749 thread.scheduleCrash(message);
750 } catch (RemoteException e) {
751 // If it's already dead our work is done. If it's wedged just kill it.
752 // We won't get the crash dialog or the error reporting.
753 kill("scheduleCrash for '" + message + "' failed", true);
754 } finally {
755 Binder.restoreCallingIdentity(ident);
756 }
757 }
758 }
759 }
760
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700761 void kill(String reason, boolean noisy) {
762 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700763 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700764 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
765 mService.reportUidInfoMessageLocked(TAG,
766 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
767 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700768 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700769 if (pid > 0) {
770 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
771 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400772 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700773 } else {
774 pendingStart = false;
775 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700776 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700777 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700778 killedByAm = true;
779 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700780 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700781 }
782 }
783
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700784 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700785 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800786 writeToProto(proto, fieldId, -1);
787 }
788
789 public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700790 long token = proto.start(fieldId);
791 proto.write(ProcessRecordProto.PID, pid);
792 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800793 proto.write(ProcessRecordProto.UID, info.uid);
794 if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700795 proto.write(ProcessRecordProto.USER_ID, userId);
796 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800797 }
798 if (uid != info.uid) {
799 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
Yi Jin129fc6c2017-09-28 15:48:38 -0700800 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700801 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800802 if (lruIndex >= 0) {
803 proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
804 }
Yi Jin129fc6c2017-09-28 15:48:38 -0700805 proto.end(token);
806 }
807
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800808 public String toShortString() {
809 if (shortStringName != null) {
810 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700811 }
812 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800813 toShortString(sb);
814 return shortStringName = sb.toString();
815 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700816
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800817 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700818 sb.append(pid);
819 sb.append(':');
820 sb.append(processName);
821 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800822 if (info.uid < Process.FIRST_APPLICATION_UID) {
823 sb.append(uid);
824 } else {
825 sb.append('u');
826 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700827 int appId = UserHandle.getAppId(info.uid);
828 if (appId >= Process.FIRST_APPLICATION_UID) {
829 sb.append('a');
830 sb.append(appId - Process.FIRST_APPLICATION_UID);
831 } else {
832 sb.append('s');
833 sb.append(appId);
834 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800835 if (uid != info.uid) {
836 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700837 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800838 }
839 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800840 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700841
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800842 public String toString() {
843 if (stringName != null) {
844 return stringName;
845 }
846 StringBuilder sb = new StringBuilder(128);
847 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700848 sb.append(Integer.toHexString(System.identityHashCode(this)));
849 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800850 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700851 sb.append('}');
852 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700854
855 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700856 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700857 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700858 sb.append(' ');
859 if (adjTarget instanceof ComponentName) {
860 sb.append(((ComponentName)adjTarget).flattenToShortString());
861 } else if (adjTarget != null) {
862 sb.append(adjTarget.toString());
863 } else {
864 sb.append("{null}");
865 }
866 sb.append("<=");
867 if (adjSource instanceof ProcessRecord) {
868 sb.append("Proc{");
869 sb.append(((ProcessRecord)adjSource).toShortString());
870 sb.append("}");
871 } else if (adjSource != null) {
872 sb.append(adjSource.toString());
873 } else {
874 sb.append("{null}");
875 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700876 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700877 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700878 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700879 }
880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 /*
882 * Return true if package has been added false if not
883 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700884 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700885 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700886 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
887 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700888 if (baseProcessTracker != null) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800889 tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
890 processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700891 pkgList.put(pkg, holder);
892 if (holder.state != baseProcessTracker) {
893 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700894 }
895 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700896 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 return true;
899 }
900 return false;
901 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700902
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700903 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700904 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
905 if (hasStartedServices) {
906 return ProcessList.SERVICE_B_ADJ;
907 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700908 }
909 return setAdj;
910 }
911
Dianne Hackborna413dc02013-07-12 12:02:55 -0700912 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700913 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700914 mRepProcState = newState;
915 setCurProcState(newState);
Amith Yamasani08888c02018-12-07 09:38:25 -0800916 setCurRawProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700917 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
918 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
919 uid, processName, pkgList.keyAt(ipkg),
920 ActivityManager.processStateAmToProto(mRepProcState),
921 pkgList.valueAt(ipkg).appVersion);
922 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700923 }
924 }
925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 /*
927 * Delete all packages from list except the package indicated in info
928 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700929 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700930 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700931 if (baseProcessTracker != null) {
932 long now = SystemClock.uptimeMillis();
933 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700934 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700935 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
936 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
937 uid, processName, pkgList.keyAt(ipkg),
938 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
939 pkgList.valueAt(ipkg).appVersion);
940 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700941 if (N != 1) {
942 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700943 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
944 if (holder.state != null && holder.state != baseProcessTracker) {
945 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700946 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700947
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700948 }
949 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700950 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700951 info.longVersionCode);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800952 tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700953 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700954 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700955 if (holder.state != baseProcessTracker) {
956 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700957 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700958 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700959 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700960 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700961 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 public String[] getPackageList() {
966 int size = pkgList.size();
967 if (size == 0) {
968 return null;
969 }
970 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700971 for (int i=0; i<pkgList.size(); i++) {
972 list[i] = pkgList.keyAt(i);
973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 return list;
975 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700976
Zimuzo972e1cd2019-01-28 16:30:01 +0000977 public List<VersionedPackage> getPackageListWithVersionCode() {
978 int size = pkgList.size();
979 if (size == 0) {
980 return null;
981 }
982 List<VersionedPackage> list = new ArrayList<>();
983 for (int i = 0; i < pkgList.size(); i++) {
984 list.add(new VersionedPackage(pkgList.keyAt(i), pkgList.valueAt(i).appVersion));
985 }
986 return list;
987 }
988
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700989 WindowProcessController getWindowProcessController() {
990 return mWindowProcessController;
991 }
992
993 void setCurrentSchedulingGroup(int curSchedGroup) {
994 mCurSchedGroup = curSchedGroup;
995 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
996 }
997
998 int getCurrentSchedulingGroup() {
999 return mCurSchedGroup;
1000 }
1001
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001002 void setCurProcState(int curProcState) {
1003 mCurProcState = curProcState;
1004 mWindowProcessController.setCurrentProcState(mCurProcState);
1005 }
1006
1007 int getCurProcState() {
1008 return mCurProcState;
1009 }
1010
Amith Yamasani08888c02018-12-07 09:38:25 -08001011 void setCurRawProcState(int curRawProcState) {
1012 mCurRawProcState = curRawProcState;
1013 }
1014
1015 int getCurRawProcState() {
1016 return mCurRawProcState;
1017 }
1018
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001019 void setReportedProcState(int repProcState) {
1020 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -07001021 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
1022 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
1023 uid, processName, pkgList.keyAt(ipkg),
1024 ActivityManager.processStateAmToProto(mRepProcState),
1025 pkgList.valueAt(ipkg).appVersion);
1026 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001027 mWindowProcessController.setReportedProcState(repProcState);
1028 }
1029
1030 int getReportedProcState() {
1031 return mRepProcState;
1032 }
1033
1034 void setCrashing(boolean crashing) {
1035 mCrashing = crashing;
1036 mWindowProcessController.setCrashing(crashing);
1037 }
1038
1039 boolean isCrashing() {
1040 return mCrashing;
1041 }
1042
1043 void setNotResponding(boolean notResponding) {
1044 mNotResponding = notResponding;
1045 mWindowProcessController.setNotResponding(notResponding);
1046 }
1047
1048 boolean isNotResponding() {
1049 return mNotResponding;
1050 }
1051
1052 void setPersistent(boolean persistent) {
1053 mPersistent = persistent;
1054 mWindowProcessController.setPersistent(persistent);
1055 }
1056
1057 boolean isPersistent() {
1058 return mPersistent;
1059 }
1060
1061 public void setRequiredAbi(String requiredAbi) {
1062 mRequiredAbi = requiredAbi;
1063 mWindowProcessController.setRequiredAbi(requiredAbi);
1064 }
1065
1066 String getRequiredAbi() {
1067 return mRequiredAbi;
1068 }
1069
Amith Yamasania0a30a12019-01-22 11:38:06 -08001070 void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001071 mHasForegroundServices = hasForegroundServices;
Amith Yamasania0a30a12019-01-22 11:38:06 -08001072 mFgServiceTypes = fgServiceTypes;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001073 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1074 }
1075
1076 boolean hasForegroundServices() {
1077 return mHasForegroundServices;
1078 }
1079
Amith Yamasania0a30a12019-01-22 11:38:06 -08001080 boolean hasLocationForegroundServices() {
1081 return mHasForegroundServices
1082 && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0;
1083 }
1084
Narayan Kamath396ce722019-03-01 16:53:26 +00001085 int getForegroundServiceTypes() {
1086 return mHasForegroundServices ? mFgServiceTypes : 0;
1087 }
1088
1089 int getReportedForegroundServiceTypes() {
1090 return mRepFgServiceTypes;
1091 }
1092
1093 void setReportedForegroundServiceTypes(int foregroundServiceTypes) {
1094 mRepFgServiceTypes = foregroundServiceTypes;
1095 }
1096
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001097 void setHasForegroundActivities(boolean hasForegroundActivities) {
1098 mHasForegroundActivities = hasForegroundActivities;
1099 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1100 }
1101
1102 boolean hasForegroundActivities() {
1103 return mHasForegroundActivities;
1104 }
1105
1106 void setHasClientActivities(boolean hasClientActivities) {
1107 mHasClientActivities = hasClientActivities;
1108 mWindowProcessController.setHasClientActivities(hasClientActivities);
1109 }
1110
1111 boolean hasClientActivities() {
1112 return mHasClientActivities;
1113 }
1114
1115 void setHasTopUi(boolean hasTopUi) {
1116 mHasTopUi = hasTopUi;
1117 mWindowProcessController.setHasTopUi(hasTopUi);
1118 }
1119
1120 boolean hasTopUi() {
1121 return mHasTopUi;
1122 }
1123
1124 void setHasOverlayUi(boolean hasOverlayUi) {
1125 mHasOverlayUi = hasOverlayUi;
1126 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1127 }
1128
1129 boolean hasOverlayUi() {
1130 return mHasOverlayUi;
1131 }
1132
1133 void setInteractionEventTime(long interactionEventTime) {
1134 mInteractionEventTime = interactionEventTime;
1135 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1136 }
1137
1138 long getInteractionEventTime() {
1139 return mInteractionEventTime;
1140 }
1141
1142 void setFgInteractionTime(long fgInteractionTime) {
1143 mFgInteractionTime = fgInteractionTime;
1144 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1145 }
1146
1147 long getFgInteractionTime() {
1148 return mFgInteractionTime;
1149 }
1150
1151 void setWhenUnimportant(long whenUnimportant) {
1152 mWhenUnimportant = whenUnimportant;
1153 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1154 }
1155
1156 long getWhenUnimportant() {
1157 return mWhenUnimportant;
1158 }
1159
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001160 void setDebugging(boolean debugging) {
1161 mDebugging = debugging;
1162 mWindowProcessController.setDebugging(debugging);
1163 }
1164
1165 boolean isDebugging() {
1166 return mDebugging;
1167 }
1168
1169 void setUsingWrapper(boolean usingWrapper) {
1170 mUsingWrapper = usingWrapper;
1171 mWindowProcessController.setUsingWrapper(usingWrapper);
1172 }
1173
1174 boolean isUsingWrapper() {
1175 return mUsingWrapper;
1176 }
1177
Michal Karpinskiac116df2018-12-10 17:51:42 +00001178 void addAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001179 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001180 mAllowBackgroundActivityStartsTokens.add(entity);
1181 mWindowProcessController.setAllowBackgroundActivityStarts(true);
1182 }
1183
1184 void removeAllowBackgroundActivityStartsToken(Binder entity) {
Michal Karpinskic8aa91b2019-01-10 16:45:59 +00001185 if (entity == null) return;
Michal Karpinskiac116df2018-12-10 17:51:42 +00001186 mAllowBackgroundActivityStartsTokens.remove(entity);
1187 mWindowProcessController.setAllowBackgroundActivityStarts(
1188 !mAllowBackgroundActivityStartsTokens.isEmpty());
1189 }
1190
Michal Karpinskib7daac22019-03-25 10:12:41 +00001191 void addBoundClientUids(ArraySet<Integer> clientUids) {
1192 mBoundClientUids.addAll(clientUids);
1193 mWindowProcessController.setBoundClientUids(mBoundClientUids);
1194 }
1195
1196 void updateBoundClientUids() {
1197 if (services.isEmpty()) {
1198 clearBoundClientUids();
1199 return;
1200 }
1201 // grab a set of clientUids of all connections of all services
1202 ArraySet<Integer> boundClientUids = new ArraySet<>();
1203 final int K = services.size();
1204 for (int j = 0; j < K; j++) {
1205 ArrayMap<IBinder, ArrayList<ConnectionRecord>> conns =
1206 services.valueAt(j).getConnections();
1207 final int N = conns.size();
1208 for (int conni = 0; conni < N; conni++) {
1209 ArrayList<ConnectionRecord> c = conns.valueAt(conni);
1210 for (int i = 0; i < c.size(); i++) {
1211 boundClientUids.add(c.get(i).clientUid);
1212 }
1213 }
1214 }
1215 mBoundClientUids = boundClientUids;
1216 mWindowProcessController.setBoundClientUids(mBoundClientUids);
1217 }
1218
1219 void addBoundClientUidsOfNewService(ServiceRecord sr) {
1220 if (sr == null) {
1221 return;
1222 }
1223 ArrayMap<IBinder, ArrayList<ConnectionRecord>> conns = sr.getConnections();
1224 for (int conni = conns.size() - 1; conni >= 0; conni--) {
1225 ArrayList<ConnectionRecord> c = conns.valueAt(conni);
1226 for (int i = 0; i < c.size(); i++) {
1227 mBoundClientUids.add(c.get(i).clientUid);
1228 }
1229 }
1230 mWindowProcessController.setBoundClientUids(mBoundClientUids);
1231 }
1232
1233 void clearBoundClientUids() {
1234 mBoundClientUids.clear();
1235 mWindowProcessController.setBoundClientUids(mBoundClientUids);
1236 }
1237
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001238 void setActiveInstrumentation(ActiveInstrumentation instr) {
1239 mInstr = instr;
Michal Karpinski4bc56492019-01-31 12:07:33 +00001240 boolean isInstrumenting = instr != null;
1241 mWindowProcessController.setInstrumenting(isInstrumenting,
1242 isInstrumenting && instr.mHasBackgroundActivityStartsPermission);
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001243 }
1244
1245 ActiveInstrumentation getActiveInstrumentation() {
1246 return mInstr;
1247 }
1248
Wale Ogunwale31913b52018-10-13 08:29:31 -07001249 void setCurRawAdj(int curRawAdj) {
1250 mCurRawAdj = curRawAdj;
1251 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1252 }
1253
1254 int getCurRawAdj() {
1255 return mCurRawAdj;
1256 }
1257
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001258 @Override
1259 public void clearProfilerIfNeeded() {
1260 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001261 if (mService.mProfileData.getProfileProc() == null
1262 || mService.mProfileData.getProfilerInfo() == null
1263 || mService.mProfileData.getProfileProc() != this) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001264 return;
1265 }
1266 mService.clearProfilerLocked();
1267 }
1268 }
1269
1270 @Override
1271 public void updateServiceConnectionActivities() {
1272 synchronized (mService) {
1273 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1274 }
1275 }
1276
1277 @Override
1278 public void setPendingUiClean(boolean pendingUiClean) {
1279 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001280 mPendingUiClean = pendingUiClean;
1281 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001282 }
1283 }
1284
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001285 boolean hasPendingUiClean() {
1286 return mPendingUiClean;
1287 }
1288
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001289 @Override
1290 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1291 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001292 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001293 forceProcessStateUpTo(newState);
1294 }
1295 }
1296
1297 @Override
Riddle Hsu17e38422019-04-12 16:55:11 +08001298 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean activityChange,
1299 boolean updateOomAdj) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001300 synchronized (mService) {
1301 if (updateServiceConnectionActivities) {
1302 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1303 }
Riddle Hsu17e38422019-04-12 16:55:11 +08001304 mService.mProcessList.updateLruProcessLocked(this, activityChange, null /* client */);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001305 if (updateOomAdj) {
1306 mService.updateOomAdjLocked();
1307 }
1308 }
1309 }
1310
1311 @Override
Riddle Hsuaaef7312019-01-24 19:00:58 +08001312 public boolean isRemoved() {
1313 return removed;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001314 }
1315
Wale Ogunwale86b74462018-07-02 08:42:43 -07001316 /**
1317 * Returns the total time (in milliseconds) spent executing in both user and system code.
1318 * Safe to call without lock held.
1319 */
Wale Ogunwale9c103022018-10-18 07:44:54 -07001320 @Override
Wale Ogunwale86b74462018-07-02 08:42:43 -07001321 public long getCpuTime() {
1322 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1323 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001324
Wale Ogunwale9c103022018-10-18 07:44:54 -07001325 @Override
Riddle Hsu17e38422019-04-12 16:55:11 +08001326 public void onStartActivity(int topProcessState, boolean setProfileProc, String packageName,
1327 long versionCode) {
Wale Ogunwale9c103022018-10-18 07:44:54 -07001328 synchronized (mService) {
1329 waitingToKill = null;
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001330 if (setProfileProc) {
1331 mService.mProfileData.setProfileProc(this);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001332 }
Riddle Hsu17e38422019-04-12 16:55:11 +08001333 if (packageName != null) {
1334 addPackage(packageName, versionCode, mService.mProcessStats);
1335 }
Wale Ogunwale9c103022018-10-18 07:44:54 -07001336
Riddle Hsu17e38422019-04-12 16:55:11 +08001337 // Update oom adj first, we don't want the additional states are involved in this round.
1338 updateProcessInfo(false /* updateServiceConnectionActivities */,
1339 true /* activityChange */, true /* updateOomAdj */);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001340 hasShownUi = true;
1341 setPendingUiClean(true);
1342 forceProcessStateUpTo(topProcessState);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001343 }
1344 }
1345
1346 @Override
1347 public void appDied() {
1348 synchronized (mService) {
1349 mService.appDiedLocked(this);
1350 }
1351 }
1352
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001353 public long getInputDispatchingTimeout() {
1354 return mWindowProcessController.getInputDispatchingTimeout();
1355 }
1356
Yang Lu732d6382018-11-05 07:53:12 -08001357 public int getProcessClassEnum() {
1358 if (pid == MY_PID) {
1359 return ServerProtoEnums.SYSTEM_SERVER;
1360 }
1361 if (info == null) {
1362 return ServerProtoEnums.ERROR_SOURCE_UNKNOWN;
1363 }
1364 return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP :
1365 ServerProtoEnums.DATA_APP;
1366 }
1367
Yunfan Chen585f2932019-01-29 16:04:45 +09001368 /**
1369 * Unless configured otherwise, swallow ANRs in background processes & kill the process.
1370 * Non-private access is for tests only.
1371 */
1372 @VisibleForTesting
1373 boolean isSilentAnr() {
1374 return !getShowBackground() && !isInterestingForBackgroundTraces();
1375 }
1376
1377 /** Non-private access is for tests only. */
1378 @VisibleForTesting
1379 List<ProcessRecord> getLruProcessList() {
1380 return mService.mProcessList.mLruProcesses;
1381 }
1382
1383 /** Non-private access is for tests only. */
1384 @VisibleForTesting
1385 boolean isMonitorCpuUsage() {
1386 return mService.MONITOR_CPU_USAGE;
1387 }
1388
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001389 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1390 String parentShortComponentName, WindowProcessController parentProcess,
1391 boolean aboveSystem, String annotation) {
1392 ArrayList<Integer> firstPids = new ArrayList<>(5);
1393 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1394
Wale Ogunwalee2172292018-10-25 10:11:10 -07001395 mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true));
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001396
1397 long anrTime = SystemClock.uptimeMillis();
Yunfan Chen585f2932019-01-29 16:04:45 +09001398 if (isMonitorCpuUsage()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001399 mService.updateCpuStatsNow();
1400 }
1401
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001402 synchronized (mService) {
1403 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
Wale Ogunwale387b34c2018-10-25 19:59:40 -07001404 if (mService.mAtmInternal.isShuttingDown()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001405 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1406 return;
1407 } else if (isNotResponding()) {
1408 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1409 return;
1410 } else if (isCrashing()) {
1411 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1412 return;
1413 } else if (killedByAm) {
1414 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1415 return;
1416 } else if (killed) {
1417 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1418 return;
1419 }
1420
1421 // In case we come through here for the same app before completing
1422 // this one, mark as anring now so we will bail out.
1423 setNotResponding(true);
1424
1425 // Log the ANR to the event log.
1426 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1427 annotation);
1428
1429 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1430 firstPids.add(pid);
1431
1432 // Don't dump other PIDs if it's a background ANR
Yunfan Chen585f2932019-01-29 16:04:45 +09001433 if (!isSilentAnr()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001434 int parentPid = pid;
1435 if (parentProcess != null && parentProcess.getPid() > 0) {
1436 parentPid = parentProcess.getPid();
1437 }
1438 if (parentPid != pid) firstPids.add(parentPid);
1439
1440 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1441
Yunfan Chen585f2932019-01-29 16:04:45 +09001442 for (int i = getLruProcessList().size() - 1; i >= 0; i--) {
1443 ProcessRecord r = getLruProcessList().get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001444 if (r != null && r.thread != null) {
1445 int myPid = r.pid;
1446 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1447 if (r.isPersistent()) {
1448 firstPids.add(myPid);
1449 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1450 } else if (r.treatLikeActivity) {
1451 firstPids.add(myPid);
1452 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1453 } else {
1454 lastPids.put(myPid, Boolean.TRUE);
1455 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1456 }
1457 }
1458 }
1459 }
1460 }
1461 }
1462
1463 // Log the ANR to the main log.
1464 StringBuilder info = new StringBuilder();
1465 info.setLength(0);
1466 info.append("ANR in ").append(processName);
1467 if (activityShortComponentName != null) {
1468 info.append(" (").append(activityShortComponentName).append(")");
1469 }
1470 info.append("\n");
1471 info.append("PID: ").append(pid).append("\n");
1472 if (annotation != null) {
1473 info.append("Reason: ").append(annotation).append("\n");
1474 }
1475 if (parentShortComponentName != null
1476 && parentShortComponentName.equals(activityShortComponentName)) {
1477 info.append("Parent: ").append(parentShortComponentName).append("\n");
1478 }
1479
1480 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1481
1482 // don't dump native PIDs for background ANRs unless it is the process of interest
1483 String[] nativeProcs = null;
Yunfan Chen585f2932019-01-29 16:04:45 +09001484 if (isSilentAnr()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001485 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1486 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1487 nativeProcs = new String[] { processName };
1488 break;
1489 }
1490 }
1491 } else {
1492 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1493 }
1494
1495 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1496 ArrayList<Integer> nativePids = null;
1497
1498 if (pids != null) {
1499 nativePids = new ArrayList<>(pids.length);
1500 for (int i : pids) {
1501 nativePids.add(i);
1502 }
1503 }
1504
1505 // For background ANRs, don't pass the ProcessCpuTracker to
1506 // avoid spending 1/2 second collecting stats to rank lastPids.
1507 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
Yunfan Chen585f2932019-01-29 16:04:45 +09001508 (isSilentAnr()) ? null : processCpuTracker, (isSilentAnr()) ? null : lastPids,
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001509 nativePids);
1510
1511 String cpuInfo = null;
Yunfan Chen585f2932019-01-29 16:04:45 +09001512 if (isMonitorCpuUsage()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001513 mService.updateCpuStatsNow();
1514 synchronized (mService.mProcessCpuTracker) {
1515 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1516 }
1517 info.append(processCpuTracker.printCurrentLoad());
1518 info.append(cpuInfo);
1519 }
1520
1521 info.append(processCpuTracker.printCurrentState(anrTime));
1522
1523 Slog.e(TAG, info.toString());
1524 if (tracesFile == null) {
1525 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1526 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1527 }
1528
1529 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1530 activityShortComponentName == null ? "unknown": activityShortComponentName,
1531 annotation,
1532 (this.info != null) ? (this.info.isInstantApp()
1533 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1534 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1535 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1536 isInterestingToUserLocked()
1537 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
Yang Lu732d6382018-11-05 07:53:12 -08001538 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
1539 getProcessClassEnum(),
1540 (this.info != null) ? this.info.packageName : "");
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001541 final ProcessRecord parentPr = parentProcess != null
1542 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001543 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001544 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001545
Wale Ogunwalee2172292018-10-25 10:11:10 -07001546 if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true),
1547 () -> {
1548 synchronized (mService) {
1549 mService.mServices.scheduleServiceTimeoutLocked(this);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001550 }
Wale Ogunwalee2172292018-10-25 10:11:10 -07001551 })) {
1552 return;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001553 }
1554
1555 synchronized (mService) {
Yunfan Chen585f2932019-01-29 16:04:45 +09001556 // mBatteryStatsService can be null if the AMS is constructed with injector only. This
1557 // will only happen in tests.
1558 if (mService.mBatteryStatsService != null) {
1559 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1560 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001561
Yunfan Chen585f2932019-01-29 16:04:45 +09001562 if (isSilentAnr()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001563 kill("bg anr", true);
1564 return;
1565 }
1566
1567 // Set the app's notResponding state, and look up the errorReportReceiver
1568 makeAppNotRespondingLocked(activityShortComponentName,
1569 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1570
Yunfan Chen585f2932019-01-29 16:04:45 +09001571 // mUiHandler can be null if the AMS is constructed with injector only. This will only
1572 // happen in tests.
1573 if (mService.mUiHandler != null) {
1574 // Bring up the infamous App Not Responding dialog
1575 Message msg = Message.obtain();
1576 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1577 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001578
Yunfan Chen585f2932019-01-29 16:04:45 +09001579 mService.mUiHandler.sendMessage(msg);
1580 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001581 }
1582 }
1583
1584 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1585 setNotResponding(true);
Yunfan Chen585f2932019-01-29 16:04:45 +09001586 // mAppErrors can be null if the AMS is constructed with injector only. This will only
1587 // happen in tests.
1588 if (mService.mAppErrors != null) {
1589 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1590 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1591 activity, shortMsg, longMsg, null);
1592 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001593 startAppProblemLocked();
1594 getWindowProcessController().stopFreezingActivities();
1595 }
1596
1597 void startAppProblemLocked() {
1598 // If this app is not running under the current user, then we can't give it a report button
1599 // because that would require launching the report UI under a different user.
1600 errorReportReceiver = null;
1601
1602 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1603 if (this.userId == userId) {
1604 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1605 mService.mContext, info.packageName, info.flags);
1606 }
1607 }
1608 mService.skipCurrentReceiverLocked(this);
1609 }
1610
1611 private boolean isInterestingForBackgroundTraces() {
1612 // The system_server is always considered interesting.
1613 if (pid == MY_PID) {
1614 return true;
1615 }
1616
1617 // A package is considered interesting if any of the following is true :
1618 //
1619 // - It's displaying an activity.
1620 // - It's the SystemUI.
1621 // - It has an overlay or a top UI visible.
1622 //
1623 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1624 // process is a bit of a kludge, but the same pattern seems repeated at
1625 // several places in the system server.
1626 return isInterestingToUserLocked() ||
1627 (info != null && "com.android.systemui".equals(info.packageName))
1628 || (hasTopUi() || hasOverlayUi());
1629 }
Yunfan Chen585f2932019-01-29 16:04:45 +09001630
1631 private boolean getShowBackground() {
1632 return Settings.Secure.getInt(mService.mContext.getContentResolver(),
1633 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635}