blob: af4230dbdda81ef0b0643e23b6af058008e223f5 [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;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040034import android.content.res.CompatibilityInfo;
Yunfan Chen75157d72018-07-27 14:47:21 +090035import android.content.res.Configuration;
Joe Onorato57190282016-04-20 15:37:49 -070036import android.os.Binder;
Yunfan Chen75157d72018-07-27 14:47:21 +090037import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.IBinder;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070039import android.os.Message;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080040import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070041import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070042import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070043import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070044import android.os.UserHandle;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070045import android.provider.Settings;
Dianne Hackborn390517b2013-05-30 15:03:32 -070046import android.util.ArrayMap;
Yunfan Chen75157d72018-07-27 14:47:21 +090047import android.util.ArraySet;
48import android.util.DebugUtils;
49import android.util.EventLog;
50import android.util.Slog;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070051import android.util.SparseArray;
Chenjie Yubd1a28f2018-07-17 14:55:19 -070052import android.util.StatsLog;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070053import android.util.TimeUtils;
Yi Jin129fc6c2017-09-28 15:48:38 -070054import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
Yunfan Chen75157d72018-07-27 14:47:21 +090056import com.android.internal.app.procstats.ProcessState;
57import com.android.internal.app.procstats.ProcessStats;
58import com.android.internal.os.BatteryStatsImpl;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070059import com.android.internal.os.ProcessCpuTracker;
60import com.android.server.Watchdog;
Yunfan Chen75157d72018-07-27 14:47:21 +090061
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070062import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import java.io.PrintWriter;
64import java.util.ArrayList;
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -040065import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
67/**
68 * Full information about a particular process that
69 * is currently running.
70 */
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070071final class ProcessRecord implements WindowProcessListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080072 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
73
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -070074 private final ActivityManagerService mService; // where we came from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080076 final boolean isolated; // true if this is a special isolated process
77 final int uid; // uid of process; may be different from 'info' if isolated
78 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 final String processName; // name of the process
80 // List of packages running in the process
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070081 final PackageList pkgList = new PackageList();
82 final class PackageList {
83 final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>();
84
85 ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) {
86 mWindowProcessController.addPackage(key);
87 return mPkgList.put(key, value);
88 }
89
90 void clear() {
91 mPkgList.clear();
92 mWindowProcessController.clearPackageList();
93 }
94
95 int size() {
96 return mPkgList.size();
97 }
98
99 String keyAt(int index) {
100 return mPkgList.keyAt(index);
101 }
102
103 public ProcessStats.ProcessStateHolder valueAt(int index) {
104 return mPkgList.valueAt(index);
105 }
106
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700107 ProcessStats.ProcessStateHolder get(String pkgName) {
108 return mPkgList.get(pkgName);
109 }
110
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700111 boolean containsKey(Object key) {
112 return mPkgList.containsKey(key);
113 }
114 }
115
Dianne Hackborne17b4452018-01-10 13:15:40 -0800116 final ProcessList.ProcStateMemTracker procStateMemTracker
117 = new ProcessList.ProcStateMemTracker();
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700118 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700119 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 IApplicationThread thread; // the actual proc... may be null only if
121 // 'persistent' is true (in which case we
122 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700123 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -0800124 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700126 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800127 int[] gids; // The gids this process was launched with
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700128 private String mRequiredAbi;// The ABI this process was launched with
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800129 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800131 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700132 long lastPssTime; // Last time we retrieved PSS data
133 long nextPssTime; // Next time we want to request PSS data
134 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700135 long initialIdlePss; // Initial memory pss of process for idle maintenance.
136 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800137 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700138 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800139 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 int maxAdj; // Maximum OOM adjustment for this process
Wale Ogunwale31913b52018-10-13 08:29:31 -0700141 private int mCurRawAdj; // Current OOM unlimited adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 int setRawAdj; // Last set OOM unlimited adjustment for this process
143 int curAdj; // Current OOM adjustment for this process
144 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700145 int verifiedAdj; // The last adjustment that was verified as actually being set
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700146 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700147 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700148 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700149 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700150 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
riddle_hsu6793fc32015-03-31 11:54:14 +0800151 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
152 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800153 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700154 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
155 int renderThreadTid; // TID for RenderThread
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700156 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700157 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700158 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700159 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700160 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700161 private boolean mHasForegroundServices; // Running any services that are foreground?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700162 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700163 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700164 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700165 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700166 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800167 // is interacting with? E.g. The status bar when it is expanded, but
168 // not when it is minimized. When true the
169 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
170 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700171 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800172 // overlays on-top of activity UIs on screen. E.g. display a window
173 // of type
174 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
175 // When true the process will oom adj score will be set to
176 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
177 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100178 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
179 // the process will be set to use the
180 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
181 // performance, as well as oom adj score will be set to
182 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
183 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700184 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700185 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700186 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700188 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700189 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700190 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700191 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600192 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700193 private long mInteractionEventTime; // The time we sent the last interaction event
194 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700195 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700196 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700197 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700198 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
199 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700200 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700201 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700202 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700203 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
204 // process.
205 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800206 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700207 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700208 long lastCpuTime; // How long proc has run CPU at last check
209 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700211 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800212 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700213 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700214 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800215 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700216 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700217 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700218 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700219 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700220 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700221 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100222 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
223
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700224 // Cache of last retrieve memory info and uptime, to throttle how frequently
225 // apps can requyest it.
226 Debug.MemoryInfo lastMemInfo;
227 long lastMemInfoTime;
228
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700229 // Controller for driving the process state on the window manager side.
230 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700232 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700234 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700236 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700238 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700240 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700242 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700243
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400244 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
245 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
246
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700247 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700248 private boolean mPersistent;// always keep this application running?
249 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700251 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700252 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 Dialog anrDialog; // dialog being displayed due to app not resp.
254 boolean removed; // has app package been removed from device?
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700255 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 boolean waitedForDebugger; // has process show wait for debugger dialog?
257 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700258
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800259 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700260 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700261 boolean pendingStart; // Process start is pending.
262 long startSeq; // Seq no. indicating the latest process start associated with
263 // this process record.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 // These reports are generated & stored when an app gets into an error condition.
266 // They will be "null" when all is OK.
267 ActivityManager.ProcessErrorStateInfo crashingReport;
268 ActivityManager.ProcessErrorStateInfo notRespondingReport;
269
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200270 // Who will be notified of the error. This is usually an activity in the
271 // app that installed the package.
272 ComponentName errorReportReceiver;
273
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700274 // Process is currently hosting a backup agent for backup or restore
275 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700276 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
277 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700278
Sudheer Shankaf6690102017-10-16 10:20:32 -0700279 // Params used in starting this process.
280 String hostingType;
281 String hostingNameStr;
282 String seInfo;
283 long startTime;
284 // This will be same as {@link #uid} usually except for some apps used during factory testing.
285 int startUid;
286
287 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
288 long startTime) {
289 this.startUid = startUid;
290 this.hostingType = hostingType;
291 this.hostingNameStr = hostingNameStr;
292 this.seInfo = seInfo;
293 this.startTime = startTime;
294 }
295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700297 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700298
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800299 pw.print(prefix); pw.print("user #"); pw.print(userId);
300 pw.print(" uid="); pw.print(info.uid);
301 if (uid != info.uid) {
302 pw.print(" ISOLATED uid="); pw.print(uid);
303 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800304 pw.print(" gids={");
305 if (gids != null) {
306 for (int gi=0; gi<gids.length; gi++) {
307 if (gi != 0) pw.print(", ");
308 pw.print(gids[gi]);
309
310 }
311 }
312 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700313 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800314 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700315 if (info.className != null) {
316 pw.print(prefix); pw.print("class="); pw.println(info.className);
317 }
318 if (info.manageSpaceActivityName != null) {
319 pw.print(prefix); pw.print("manageSpaceActivityName=");
320 pw.println(info.manageSpaceActivityName);
321 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900322
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700323 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
324 pw.print(" publicDir="); pw.print(info.publicSourceDir);
325 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700326 pw.print(prefix); pw.print("packageList={");
327 for (int i=0; i<pkgList.size(); i++) {
328 if (i > 0) pw.print(", ");
329 pw.print(pkgList.keyAt(i));
330 }
331 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700332 if (pkgDeps != null) {
333 pw.print(prefix); pw.print("packageDependencies={");
334 for (int i=0; i<pkgDeps.size(); i++) {
335 if (i > 0) pw.print(", ");
336 pw.print(pkgDeps.valueAt(i));
337 }
338 pw.println("}");
339 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700340 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700341 if (mInstr != null) {
342 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700343 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700344 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700345 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700346 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700347 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700348 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700349 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700350 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800351 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700352 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700353 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700354 pw.println();
355 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
356 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800357 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800358 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800359 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800360 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800361 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800362 pw.print(prefix); pw.print("procStateMemTracker: ");
363 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700364 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800365 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700366 if (serviceb) {
367 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
368 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
369 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700370 if (notCachedSinceIdle) {
371 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700372 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700373 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700374 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700375 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700376 pw.print(" setRaw="); pw.print(setRawAdj);
377 pw.print(" cur="); pw.print(curAdj);
378 pw.print(" set="); pw.println(setAdj);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700379 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700380 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700381 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700382 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700383 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700384 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700385 pw.print(" pssProcState="); pw.print(pssProcState);
386 pw.print(" setProcState="); pw.print(setProcState);
387 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700388 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700389 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700390 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700391 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700392 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700393 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
394 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700395 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700396 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
397 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
398 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100399 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700400 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700401 if (mHasForegroundServices || forcingToImportant != null) {
402 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700403 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700404 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700405 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700406 pw.print(prefix); pw.print("reportedInteraction=");
407 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700408 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800409 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700410 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800411 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700412 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700413 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700414 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700415 }
416 pw.println();
417 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700418 if (mPersistent || removed) {
419 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700420 pw.print(" removed="); pw.println(removed);
421 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700422 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
423 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
424 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700425 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700426 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800427 if (lastProviderTime > 0) {
428 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700429 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800430 pw.println();
431 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700432 if (lastTopTime > 0) {
433 pw.print(prefix); pw.print("lastTopTime=");
434 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
435 pw.println();
436 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700437 if (hasStartedServices) {
438 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
439 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700440 if (pendingStart) {
441 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
442 }
443 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700444 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700445 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700446 if (lastCpuTime > 0) {
447 pw.print(" timeUsed=");
448 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
449 }
450 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700451 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700452 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700453 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700454 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700455 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700456 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700457 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700458 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700459 if (killed || killedByAm || waitingToKill != null) {
460 pw.print(prefix); pw.print("killed="); pw.print(killed);
461 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700462 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700463 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700464 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700465 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700466 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700467 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700468 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700469 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700470 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200471 pw.print(" bad="); pw.print(bad);
472
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700473 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200474 if (errorReportReceiver != null) {
475 pw.print(" errorReportReceiver=");
476 pw.print(errorReportReceiver.flattenToShortString());
477 }
478 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700479 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700480 if (whitelistManager) {
481 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
482 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400483 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
484 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
485 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
486 pw.println(Arrays.toString(isolatedEntryPointArgs));
487 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700488 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700489 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700490 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700491 for (int i=0; i<services.size(); i++) {
492 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700493 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700494 }
495 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700496 pw.print(prefix); pw.print("Executing Services (fg=");
497 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700498 for (int i=0; i<executingServices.size(); i++) {
499 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700500 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700501 }
502 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700503 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700504 for (int i=0; i<connections.size(); i++) {
505 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700506 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700507 }
508 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700509 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700510 for (int i=0; i<pubProviders.size(); i++) {
511 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
512 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700513 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700514 }
515 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700516 pw.print(prefix); pw.println("Connected Providers:");
517 for (int i=0; i<conProviders.size(); i++) {
518 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
519 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700520 }
yangzhenyud509bc92016-08-31 18:26:46 +0800521 if (!curReceivers.isEmpty()) {
522 pw.print(prefix); pw.println("Current Receivers:");
523 for (int i=0; i < curReceivers.size(); i++) {
524 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
525 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700526 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700527 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700528 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700529 for (int i=0; i<receivers.size(); i++) {
530 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700531 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700534
Bookatz152623f2018-07-23 15:57:44 -0700535 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Yunfan Chen75157d72018-07-27 14:47:21 +0900536 int _uid, Configuration config) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700537 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800539 isolated = _info.uid != _uid;
540 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700541 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700543 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700544 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700545 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700546 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700548 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700549 mWindowProcessController = new WindowProcessController(
Yunfan Chen75157d72018-07-27 14:47:21 +0900550 mService.mActivityTaskManager, info, processName, uid, userId, this, this, config);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700551 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 }
553
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700554 public void setPid(int _pid) {
555 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700556 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700557 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800558 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700559 stringName = null;
560 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700561
562 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
563 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700564 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700565 if (origBase != null) {
566 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700567 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700568 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
569 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
570 uid, processName, pkgList.keyAt(ipkg),
571 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
572 pkgList.valueAt(ipkg).appVersion);
573 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700574 origBase.makeInactive();
575 }
Ronnie Leng4c5c6f42015-03-25 10:57:24 -0500576 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700577 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700578 baseProcessTracker.makeActive();
579 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700580 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
581 if (holder.state != null && holder.state != origBase) {
582 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700583 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700584 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700585 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700586 if (holder.state != baseProcessTracker) {
587 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700588 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700589 }
590 }
591 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700592 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700593 }
594
595 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700596 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700597 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700598 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700599 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700600 if (origBase != null) {
601 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700602 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700603 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
604 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
605 uid, processName, pkgList.keyAt(ipkg),
606 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
607 pkgList.valueAt(ipkg).appVersion);
608 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700609 origBase.makeInactive();
610 }
611 baseProcessTracker = null;
612 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700613 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
614 if (holder.state != null && holder.state != origBase) {
615 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700616 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700617 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700618 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700619 }
620 }
621 }
622
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700623 boolean hasActivities() {
624 return mWindowProcessController.hasActivities();
625 }
626
627 void clearActivities() {
628 mWindowProcessController.clearActivities();
629 }
630
631 boolean hasActivitiesOrRecentTasks() {
632 return mWindowProcessController.hasActivitiesOrRecentTasks();
633 }
634
635 boolean hasRecentTasks() {
636 return mWindowProcessController.hasRecentTasks();
637 }
638
639 void clearRecentTasks() {
640 mWindowProcessController.clearRecentTasks();
Dianne Hackborn68a06332017-11-15 17:54:18 -0800641 }
642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 /**
644 * This method returns true if any of the activities within the process record are interesting
645 * to the user. See HistoryRecord.isInterestingToUserLocked()
646 */
647 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700648 if (mWindowProcessController.isInterestingToUser()) {
649 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100651
652 final int servicesSize = services.size();
653 for (int i = 0; i < servicesSize; i++) {
654 ServiceRecord r = services.valueAt(i);
655 if (r.isForeground) {
656 return true;
657 }
658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 return false;
660 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800661
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700662 public void unlinkDeathRecipient() {
663 if (deathRecipient != null && thread != null) {
664 thread.asBinder().unlinkToDeath(deathRecipient, 0);
665 }
666 deathRecipient = null;
667 }
668
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700669 void updateHasAboveClientLocked() {
670 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700671 for (int i=connections.size()-1; i>=0; i--) {
672 ConnectionRecord cr = connections.valueAt(i);
673 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
674 hasAboveClient = true;
675 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700676 }
677 }
678 }
679
Dianne Hackbornc8230512013-07-13 21:32:12 -0700680 int modifyRawOomAdj(int adj) {
681 if (hasAboveClient) {
682 // If this process has bound to any services with BIND_ABOVE_CLIENT,
683 // then we need to drop its adjustment to be lower than the service's
684 // in order to honor the request. We want to drop it by one adjustment
685 // level... but there is special meaning applied to various levels so
686 // we will skip some of them.
687 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
688 // System process will not get dropped, ever
689 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
690 adj = ProcessList.VISIBLE_APP_ADJ;
691 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
692 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
693 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
694 adj = ProcessList.CACHED_APP_MIN_ADJ;
695 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
696 adj++;
697 }
698 }
699 return adj;
700 }
701
Joe Onorato57190282016-04-20 15:37:49 -0700702 void scheduleCrash(String message) {
703 // Checking killedbyAm should keep it from showing the crash dialog if the process
704 // was already dead for a good / normal reason.
705 if (!killedByAm) {
706 if (thread != null) {
707 if (pid == Process.myPid()) {
708 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
709 return;
710 }
711 long ident = Binder.clearCallingIdentity();
712 try {
713 thread.scheduleCrash(message);
714 } catch (RemoteException e) {
715 // If it's already dead our work is done. If it's wedged just kill it.
716 // We won't get the crash dialog or the error reporting.
717 kill("scheduleCrash for '" + message + "' failed", true);
718 } finally {
719 Binder.restoreCallingIdentity(ident);
720 }
721 }
722 }
723 }
724
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700725 void kill(String reason, boolean noisy) {
726 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700727 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700728 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
729 mService.reportUidInfoMessageLocked(TAG,
730 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
731 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700732 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700733 if (pid > 0) {
734 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
735 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400736 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700737 } else {
738 pendingStart = false;
739 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700740 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700741 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700742 killedByAm = true;
743 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700744 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700745 }
746 }
747
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700748 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700749 public void writeToProto(ProtoOutputStream proto, long fieldId) {
750 long token = proto.start(fieldId);
751 proto.write(ProcessRecordProto.PID, pid);
752 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
753 if (info.uid < Process.FIRST_APPLICATION_UID) {
754 proto.write(ProcessRecordProto.UID, uid);
755 } else {
756 proto.write(ProcessRecordProto.USER_ID, userId);
757 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
758 if (uid != info.uid) {
759 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
760 }
761 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700762 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Yi Jin129fc6c2017-09-28 15:48:38 -0700763 proto.end(token);
764 }
765
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800766 public String toShortString() {
767 if (shortStringName != null) {
768 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700769 }
770 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800771 toShortString(sb);
772 return shortStringName = sb.toString();
773 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700774
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800775 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700776 sb.append(pid);
777 sb.append(':');
778 sb.append(processName);
779 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800780 if (info.uid < Process.FIRST_APPLICATION_UID) {
781 sb.append(uid);
782 } else {
783 sb.append('u');
784 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700785 int appId = UserHandle.getAppId(info.uid);
786 if (appId >= Process.FIRST_APPLICATION_UID) {
787 sb.append('a');
788 sb.append(appId - Process.FIRST_APPLICATION_UID);
789 } else {
790 sb.append('s');
791 sb.append(appId);
792 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800793 if (uid != info.uid) {
794 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700795 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800796 }
797 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800798 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700799
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800800 public String toString() {
801 if (stringName != null) {
802 return stringName;
803 }
804 StringBuilder sb = new StringBuilder(128);
805 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700806 sb.append(Integer.toHexString(System.identityHashCode(this)));
807 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800808 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700809 sb.append('}');
810 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700812
813 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700814 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700815 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700816 sb.append(' ');
817 if (adjTarget instanceof ComponentName) {
818 sb.append(((ComponentName)adjTarget).flattenToShortString());
819 } else if (adjTarget != null) {
820 sb.append(adjTarget.toString());
821 } else {
822 sb.append("{null}");
823 }
824 sb.append("<=");
825 if (adjSource instanceof ProcessRecord) {
826 sb.append("Proc{");
827 sb.append(((ProcessRecord)adjSource).toShortString());
828 sb.append("}");
829 } else if (adjSource != null) {
830 sb.append(adjSource.toString());
831 } else {
832 sb.append("{null}");
833 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700834 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700835 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700836 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700837 }
838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 /*
840 * Return true if package has been added false if not
841 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700842 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700843 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700844 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
845 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700846 if (baseProcessTracker != null) {
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700847 tracker.updateProcessStateHolderLocked(holder, pkg, uid, versionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700848 pkgList.put(pkg, holder);
849 if (holder.state != baseProcessTracker) {
850 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700851 }
852 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700853 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 return true;
856 }
857 return false;
858 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700859
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700860 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700861 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
862 if (hasStartedServices) {
863 return ProcessList.SERVICE_B_ADJ;
864 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700865 }
866 return setAdj;
867 }
868
Dianne Hackborna413dc02013-07-12 12:02:55 -0700869 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700870 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700871 mRepProcState = newState;
872 setCurProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700873 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
874 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
875 uid, processName, pkgList.keyAt(ipkg),
876 ActivityManager.processStateAmToProto(mRepProcState),
877 pkgList.valueAt(ipkg).appVersion);
878 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700879 }
880 }
881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 /*
883 * Delete all packages from list except the package indicated in info
884 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700885 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700886 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700887 if (baseProcessTracker != null) {
888 long now = SystemClock.uptimeMillis();
889 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700890 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700891 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
892 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
893 uid, processName, pkgList.keyAt(ipkg),
894 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
895 pkgList.valueAt(ipkg).appVersion);
896 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700897 if (N != 1) {
898 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700899 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
900 if (holder.state != null && holder.state != baseProcessTracker) {
901 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700902 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700903
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700904 }
905 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700906 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700907 info.longVersionCode);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700908 tracker.updateProcessStateHolderLocked(holder, info.packageName, uid,
909 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700910 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700911 if (holder.state != baseProcessTracker) {
912 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700913 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700914 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700915 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700916 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700917 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 public String[] getPackageList() {
922 int size = pkgList.size();
923 if (size == 0) {
924 return null;
925 }
926 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700927 for (int i=0; i<pkgList.size(); i++) {
928 list[i] = pkgList.keyAt(i);
929 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 return list;
931 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700932
933 WindowProcessController getWindowProcessController() {
934 return mWindowProcessController;
935 }
936
937 void setCurrentSchedulingGroup(int curSchedGroup) {
938 mCurSchedGroup = curSchedGroup;
939 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
940 }
941
942 int getCurrentSchedulingGroup() {
943 return mCurSchedGroup;
944 }
945
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700946 void setCurProcState(int curProcState) {
947 mCurProcState = curProcState;
948 mWindowProcessController.setCurrentProcState(mCurProcState);
949 }
950
951 int getCurProcState() {
952 return mCurProcState;
953 }
954
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700955 void setReportedProcState(int repProcState) {
956 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700957 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
958 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
959 uid, processName, pkgList.keyAt(ipkg),
960 ActivityManager.processStateAmToProto(mRepProcState),
961 pkgList.valueAt(ipkg).appVersion);
962 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700963 mWindowProcessController.setReportedProcState(repProcState);
964 }
965
966 int getReportedProcState() {
967 return mRepProcState;
968 }
969
970 void setCrashing(boolean crashing) {
971 mCrashing = crashing;
972 mWindowProcessController.setCrashing(crashing);
973 }
974
975 boolean isCrashing() {
976 return mCrashing;
977 }
978
979 void setNotResponding(boolean notResponding) {
980 mNotResponding = notResponding;
981 mWindowProcessController.setNotResponding(notResponding);
982 }
983
984 boolean isNotResponding() {
985 return mNotResponding;
986 }
987
988 void setPersistent(boolean persistent) {
989 mPersistent = persistent;
990 mWindowProcessController.setPersistent(persistent);
991 }
992
993 boolean isPersistent() {
994 return mPersistent;
995 }
996
997 public void setRequiredAbi(String requiredAbi) {
998 mRequiredAbi = requiredAbi;
999 mWindowProcessController.setRequiredAbi(requiredAbi);
1000 }
1001
1002 String getRequiredAbi() {
1003 return mRequiredAbi;
1004 }
1005
1006 void setHasForegroundServices(boolean hasForegroundServices) {
1007 mHasForegroundServices = hasForegroundServices;
1008 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1009 }
1010
1011 boolean hasForegroundServices() {
1012 return mHasForegroundServices;
1013 }
1014
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001015 void setHasForegroundActivities(boolean hasForegroundActivities) {
1016 mHasForegroundActivities = hasForegroundActivities;
1017 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1018 }
1019
1020 boolean hasForegroundActivities() {
1021 return mHasForegroundActivities;
1022 }
1023
1024 void setHasClientActivities(boolean hasClientActivities) {
1025 mHasClientActivities = hasClientActivities;
1026 mWindowProcessController.setHasClientActivities(hasClientActivities);
1027 }
1028
1029 boolean hasClientActivities() {
1030 return mHasClientActivities;
1031 }
1032
1033 void setHasTopUi(boolean hasTopUi) {
1034 mHasTopUi = hasTopUi;
1035 mWindowProcessController.setHasTopUi(hasTopUi);
1036 }
1037
1038 boolean hasTopUi() {
1039 return mHasTopUi;
1040 }
1041
1042 void setHasOverlayUi(boolean hasOverlayUi) {
1043 mHasOverlayUi = hasOverlayUi;
1044 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1045 }
1046
1047 boolean hasOverlayUi() {
1048 return mHasOverlayUi;
1049 }
1050
1051 void setInteractionEventTime(long interactionEventTime) {
1052 mInteractionEventTime = interactionEventTime;
1053 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1054 }
1055
1056 long getInteractionEventTime() {
1057 return mInteractionEventTime;
1058 }
1059
1060 void setFgInteractionTime(long fgInteractionTime) {
1061 mFgInteractionTime = fgInteractionTime;
1062 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1063 }
1064
1065 long getFgInteractionTime() {
1066 return mFgInteractionTime;
1067 }
1068
1069 void setWhenUnimportant(long whenUnimportant) {
1070 mWhenUnimportant = whenUnimportant;
1071 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1072 }
1073
1074 long getWhenUnimportant() {
1075 return mWhenUnimportant;
1076 }
1077
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001078 void setDebugging(boolean debugging) {
1079 mDebugging = debugging;
1080 mWindowProcessController.setDebugging(debugging);
1081 }
1082
1083 boolean isDebugging() {
1084 return mDebugging;
1085 }
1086
1087 void setUsingWrapper(boolean usingWrapper) {
1088 mUsingWrapper = usingWrapper;
1089 mWindowProcessController.setUsingWrapper(usingWrapper);
1090 }
1091
1092 boolean isUsingWrapper() {
1093 return mUsingWrapper;
1094 }
1095
1096 void setActiveInstrumentation(ActiveInstrumentation instr) {
1097 mInstr = instr;
1098 mWindowProcessController.setInstrumenting(instr != null);
1099 }
1100
1101 ActiveInstrumentation getActiveInstrumentation() {
1102 return mInstr;
1103 }
1104
Wale Ogunwale31913b52018-10-13 08:29:31 -07001105 void setCurRawAdj(int curRawAdj) {
1106 mCurRawAdj = curRawAdj;
1107 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1108 }
1109
1110 int getCurRawAdj() {
1111 return mCurRawAdj;
1112 }
1113
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001114 @Override
1115 public void clearProfilerIfNeeded() {
1116 synchronized (mService) {
1117 if (mService.mProfileProc == null || mService.mProfilerInfo == null
1118 || mService.mProfileProc != this) {
1119 return;
1120 }
1121 mService.clearProfilerLocked();
1122 }
1123 }
1124
1125 @Override
1126 public void updateServiceConnectionActivities() {
1127 synchronized (mService) {
1128 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1129 }
1130 }
1131
1132 @Override
1133 public void setPendingUiClean(boolean pendingUiClean) {
1134 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001135 mPendingUiClean = pendingUiClean;
1136 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001137 }
1138 }
1139
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001140 boolean hasPendingUiClean() {
1141 return mPendingUiClean;
1142 }
1143
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001144 @Override
1145 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1146 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001147 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001148 forceProcessStateUpTo(newState);
1149 }
1150 }
1151
1152 @Override
1153 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru,
1154 boolean activityChange, boolean updateOomAdj) {
1155 synchronized (mService) {
1156 if (updateServiceConnectionActivities) {
1157 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1158 }
1159 if (updateLru) {
Amith Yamasani98a00922018-08-21 12:50:30 -04001160 mService.mProcessList.updateLruProcessLocked(this, activityChange, null);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001161 }
1162 if (updateOomAdj) {
1163 mService.updateOomAdjLocked();
1164 }
1165 }
1166 }
1167
1168 @Override
1169 public void setRemoved(boolean removed) {
1170 synchronized (mService) {
1171 this.removed = removed;
1172 }
1173 }
1174
Wale Ogunwale86b74462018-07-02 08:42:43 -07001175 /**
1176 * Returns the total time (in milliseconds) spent executing in both user and system code.
1177 * Safe to call without lock held.
1178 */
1179 public long getCpuTime() {
1180 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1181 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001182
1183 public long getInputDispatchingTimeout() {
1184 return mWindowProcessController.getInputDispatchingTimeout();
1185 }
1186
1187 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1188 String parentShortComponentName, WindowProcessController parentProcess,
1189 boolean aboveSystem, String annotation) {
1190 ArrayList<Integer> firstPids = new ArrayList<>(5);
1191 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1192
1193 if (mService.mActivityTaskManager.mController != null) {
1194 try {
1195 // 0 == continue, -1 = kill process immediately
1196 int res = mService.mActivityTaskManager.mController.appEarlyNotResponding(
1197 processName, pid, annotation);
1198 if (res < 0 && pid != MY_PID) {
1199 kill("anr", true);
1200 }
1201 } catch (RemoteException e) {
1202 mService.mActivityTaskManager.mController = null;
1203 Watchdog.getInstance().setActivityController(null);
1204 }
1205 }
1206
1207 long anrTime = SystemClock.uptimeMillis();
1208 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1209 mService.updateCpuStatsNow();
1210 }
1211
1212 // Unless configured otherwise, swallow ANRs in background processes & kill the process.
1213 boolean showBackground = Settings.Secure.getInt(mService.mContext.getContentResolver(),
1214 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1215
1216 boolean isSilentANR;
1217
1218 synchronized (mService) {
1219 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
1220 if (mService.mActivityTaskManager.mShuttingDown) {
1221 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1222 return;
1223 } else if (isNotResponding()) {
1224 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1225 return;
1226 } else if (isCrashing()) {
1227 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1228 return;
1229 } else if (killedByAm) {
1230 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1231 return;
1232 } else if (killed) {
1233 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1234 return;
1235 }
1236
1237 // In case we come through here for the same app before completing
1238 // this one, mark as anring now so we will bail out.
1239 setNotResponding(true);
1240
1241 // Log the ANR to the event log.
1242 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1243 annotation);
1244
1245 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1246 firstPids.add(pid);
1247
1248 // Don't dump other PIDs if it's a background ANR
1249 isSilentANR = !showBackground && !isInterestingForBackgroundTraces();
1250 if (!isSilentANR) {
1251 int parentPid = pid;
1252 if (parentProcess != null && parentProcess.getPid() > 0) {
1253 parentPid = parentProcess.getPid();
1254 }
1255 if (parentPid != pid) firstPids.add(parentPid);
1256
1257 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1258
Amith Yamasani98a00922018-08-21 12:50:30 -04001259 for (int i = mService.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
1260 ProcessRecord r = mService.mProcessList.mLruProcesses.get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001261 if (r != null && r.thread != null) {
1262 int myPid = r.pid;
1263 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1264 if (r.isPersistent()) {
1265 firstPids.add(myPid);
1266 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1267 } else if (r.treatLikeActivity) {
1268 firstPids.add(myPid);
1269 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1270 } else {
1271 lastPids.put(myPid, Boolean.TRUE);
1272 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1273 }
1274 }
1275 }
1276 }
1277 }
1278 }
1279
1280 // Log the ANR to the main log.
1281 StringBuilder info = new StringBuilder();
1282 info.setLength(0);
1283 info.append("ANR in ").append(processName);
1284 if (activityShortComponentName != null) {
1285 info.append(" (").append(activityShortComponentName).append(")");
1286 }
1287 info.append("\n");
1288 info.append("PID: ").append(pid).append("\n");
1289 if (annotation != null) {
1290 info.append("Reason: ").append(annotation).append("\n");
1291 }
1292 if (parentShortComponentName != null
1293 && parentShortComponentName.equals(activityShortComponentName)) {
1294 info.append("Parent: ").append(parentShortComponentName).append("\n");
1295 }
1296
1297 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1298
1299 // don't dump native PIDs for background ANRs unless it is the process of interest
1300 String[] nativeProcs = null;
1301 if (isSilentANR) {
1302 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1303 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1304 nativeProcs = new String[] { processName };
1305 break;
1306 }
1307 }
1308 } else {
1309 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1310 }
1311
1312 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1313 ArrayList<Integer> nativePids = null;
1314
1315 if (pids != null) {
1316 nativePids = new ArrayList<>(pids.length);
1317 for (int i : pids) {
1318 nativePids.add(i);
1319 }
1320 }
1321
1322 // For background ANRs, don't pass the ProcessCpuTracker to
1323 // avoid spending 1/2 second collecting stats to rank lastPids.
1324 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
1325 (isSilentANR) ? null : processCpuTracker, (isSilentANR) ? null : lastPids,
1326 nativePids);
1327
1328 String cpuInfo = null;
1329 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1330 mService.updateCpuStatsNow();
1331 synchronized (mService.mProcessCpuTracker) {
1332 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1333 }
1334 info.append(processCpuTracker.printCurrentLoad());
1335 info.append(cpuInfo);
1336 }
1337
1338 info.append(processCpuTracker.printCurrentState(anrTime));
1339
1340 Slog.e(TAG, info.toString());
1341 if (tracesFile == null) {
1342 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1343 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1344 }
1345
1346 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1347 activityShortComponentName == null ? "unknown": activityShortComponentName,
1348 annotation,
1349 (this.info != null) ? (this.info.isInstantApp()
1350 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1351 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1352 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1353 isInterestingToUserLocked()
1354 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
1355 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND);
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001356 final ProcessRecord parentPr = parentProcess != null
1357 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001358 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001359 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001360
1361 if (mService.mActivityTaskManager.mController != null) {
1362 try {
1363 // 0 == show dialog, 1 = keep waiting, -1 = kill process immediately
1364 int res = mService.mActivityTaskManager.mController.appNotResponding(
1365 processName, pid, info.toString());
1366 if (res != 0) {
1367 if (res < 0 && pid != MY_PID) {
1368 kill("anr", true);
1369 } else {
1370 synchronized (mService) {
1371 mService.mServices.scheduleServiceTimeoutLocked(this);
1372 }
1373 }
1374 return;
1375 }
1376 } catch (RemoteException e) {
1377 mService.mActivityTaskManager.mController = null;
1378 Watchdog.getInstance().setActivityController(null);
1379 }
1380 }
1381
1382 synchronized (mService) {
1383 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1384
1385 if (isSilentANR) {
1386 kill("bg anr", true);
1387 return;
1388 }
1389
1390 // Set the app's notResponding state, and look up the errorReportReceiver
1391 makeAppNotRespondingLocked(activityShortComponentName,
1392 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1393
1394 // Bring up the infamous App Not Responding dialog
1395 Message msg = Message.obtain();
1396 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1397 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
1398
1399 mService.mUiHandler.sendMessage(msg);
1400 }
1401 }
1402
1403 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1404 setNotResponding(true);
1405 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1406 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1407 activity, shortMsg, longMsg, null);
1408 startAppProblemLocked();
1409 getWindowProcessController().stopFreezingActivities();
1410 }
1411
1412 void startAppProblemLocked() {
1413 // If this app is not running under the current user, then we can't give it a report button
1414 // because that would require launching the report UI under a different user.
1415 errorReportReceiver = null;
1416
1417 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1418 if (this.userId == userId) {
1419 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1420 mService.mContext, info.packageName, info.flags);
1421 }
1422 }
1423 mService.skipCurrentReceiverLocked(this);
1424 }
1425
1426 private boolean isInterestingForBackgroundTraces() {
1427 // The system_server is always considered interesting.
1428 if (pid == MY_PID) {
1429 return true;
1430 }
1431
1432 // A package is considered interesting if any of the following is true :
1433 //
1434 // - It's displaying an activity.
1435 // - It's the SystemUI.
1436 // - It has an overlay or a top UI visible.
1437 //
1438 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1439 // process is a bit of a kludge, but the same pattern seems repeated at
1440 // several places in the system server.
1441 return isInterestingToUserLocked() ||
1442 (info != null && "com.android.systemui".equals(info.packageName))
1443 || (hasTopUi() || hasOverlayUi());
1444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445}