blob: bb87ad031ad57eedb5e61655b68e2ebbd73b141c [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;
Wale Ogunwale9c103022018-10-18 07:44:54 -070031import android.app.ProfilerInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.content.ComponentName;
Dianne Hackbornc68c9132011-07-29 01:25:18 -070033import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.content.pm.ApplicationInfo;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040035import android.content.res.CompatibilityInfo;
Joe Onorato57190282016-04-20 15:37:49 -070036import android.os.Binder;
Yunfan Chen75157d72018-07-27 14:47:21 +090037import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.IBinder;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070039import android.os.Message;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080040import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070041import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070042import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070043import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070044import android.os.UserHandle;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070045import android.provider.Settings;
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;
Wale Ogunwale59507092018-10-29 09:00:30 -070060import com.android.server.wm.WindowProcessController;
61import com.android.server.wm.WindowProcessListener;
Yunfan Chen75157d72018-07-27 14:47:21 +090062
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070063import java.io.File;
Wale Ogunwale9c103022018-10-18 07:44:54 -070064import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import java.io.PrintWriter;
66import java.util.ArrayList;
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -040067import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068
69/**
70 * Full information about a particular process that
71 * is currently running.
72 */
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070073final class ProcessRecord implements WindowProcessListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080074 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
75
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -070076 private final ActivityManagerService mService; // where we came from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080078 final boolean isolated; // true if this is a special isolated process
79 final int uid; // uid of process; may be different from 'info' if isolated
80 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 final String processName; // name of the process
82 // List of packages running in the process
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070083 final PackageList pkgList = new PackageList();
84 final class PackageList {
85 final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>();
86
87 ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) {
88 mWindowProcessController.addPackage(key);
89 return mPkgList.put(key, value);
90 }
91
92 void clear() {
93 mPkgList.clear();
94 mWindowProcessController.clearPackageList();
95 }
96
97 int size() {
98 return mPkgList.size();
99 }
100
101 String keyAt(int index) {
102 return mPkgList.keyAt(index);
103 }
104
105 public ProcessStats.ProcessStateHolder valueAt(int index) {
106 return mPkgList.valueAt(index);
107 }
108
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700109 ProcessStats.ProcessStateHolder get(String pkgName) {
110 return mPkgList.get(pkgName);
111 }
112
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700113 boolean containsKey(Object key) {
114 return mPkgList.containsKey(key);
115 }
116 }
117
Dianne Hackborne17b4452018-01-10 13:15:40 -0800118 final ProcessList.ProcStateMemTracker procStateMemTracker
119 = new ProcessList.ProcStateMemTracker();
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700120 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700121 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 IApplicationThread thread; // the actual proc... may be null only if
123 // 'persistent' is true (in which case we
124 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700125 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -0800126 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700128 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800129 int[] gids; // The gids this process was launched with
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700130 private String mRequiredAbi;// The ABI this process was launched with
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800131 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800133 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700134 long lastPssTime; // Last time we retrieved PSS data
135 long nextPssTime; // Next time we want to request PSS data
136 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700137 long initialIdlePss; // Initial memory pss of process for idle maintenance.
138 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800139 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700140 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -0800141 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 int maxAdj; // Maximum OOM adjustment for this process
Wale Ogunwale31913b52018-10-13 08:29:31 -0700143 private int mCurRawAdj; // Current OOM unlimited adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 int setRawAdj; // Last set OOM unlimited adjustment for this process
145 int curAdj; // Current OOM adjustment for this process
146 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700147 int verifiedAdj; // The last adjustment that was verified as actually being set
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700148 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700149 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700150 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700151 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700152 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
riddle_hsu6793fc32015-03-31 11:54:14 +0800153 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
154 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800155 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700156 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
157 int renderThreadTid; // TID for RenderThread
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700158 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700159 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700160 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700161 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700162 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700163 private boolean mHasForegroundServices; // Running any services that are foreground?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700164 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700165 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700166 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700167 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700168 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800169 // is interacting with? E.g. The status bar when it is expanded, but
170 // not when it is minimized. When true the
171 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
172 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700173 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800174 // overlays on-top of activity UIs on screen. E.g. display a window
175 // of type
176 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
177 // When true the process will oom adj score will be set to
178 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
179 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100180 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
181 // the process will be set to use the
182 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
183 // performance, as well as oom adj score will be set to
184 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
185 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700186 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700187 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700188 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700190 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700191 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700192 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700193 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600194 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700195 private long mInteractionEventTime; // The time we sent the last interaction event
196 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700197 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700198 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700199 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700200 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
201 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700202 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700203 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700204 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700205 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
206 // process.
207 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800208 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700209 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700210 long lastCpuTime; // How long proc has run CPU at last check
211 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700213 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800214 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700215 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700216 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800217 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700218 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700219 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700220 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700221 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700222 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700223 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100224 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
225
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700226 // Cache of last retrieve memory info and uptime, to throttle how frequently
227 // apps can requyest it.
228 Debug.MemoryInfo lastMemInfo;
229 long lastMemInfoTime;
230
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700231 // Controller for driving the process state on the window manager side.
232 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700234 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700236 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700238 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700240 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700242 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700244 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700245
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400246 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
247 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
248
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700249 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700250 private boolean mPersistent;// always keep this application running?
251 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700253 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700254 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 Dialog anrDialog; // dialog being displayed due to app not resp.
256 boolean removed; // has app package been removed from device?
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700257 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 boolean waitedForDebugger; // has process show wait for debugger dialog?
259 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700260
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800261 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700262 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700263 boolean pendingStart; // Process start is pending.
264 long startSeq; // Seq no. indicating the latest process start associated with
265 // this process record.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 // These reports are generated & stored when an app gets into an error condition.
268 // They will be "null" when all is OK.
269 ActivityManager.ProcessErrorStateInfo crashingReport;
270 ActivityManager.ProcessErrorStateInfo notRespondingReport;
271
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200272 // Who will be notified of the error. This is usually an activity in the
273 // app that installed the package.
274 ComponentName errorReportReceiver;
275
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700276 // Process is currently hosting a backup agent for backup or restore
277 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700278 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
279 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700280
Sudheer Shankaf6690102017-10-16 10:20:32 -0700281 // Params used in starting this process.
282 String hostingType;
283 String hostingNameStr;
284 String seInfo;
285 long startTime;
286 // This will be same as {@link #uid} usually except for some apps used during factory testing.
287 int startUid;
288
289 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
290 long startTime) {
291 this.startUid = startUid;
292 this.hostingType = hostingType;
293 this.hostingNameStr = hostingNameStr;
294 this.seInfo = seInfo;
295 this.startTime = startTime;
296 }
297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700299 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700300
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800301 pw.print(prefix); pw.print("user #"); pw.print(userId);
302 pw.print(" uid="); pw.print(info.uid);
303 if (uid != info.uid) {
304 pw.print(" ISOLATED uid="); pw.print(uid);
305 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800306 pw.print(" gids={");
307 if (gids != null) {
308 for (int gi=0; gi<gids.length; gi++) {
309 if (gi != 0) pw.print(", ");
310 pw.print(gids[gi]);
311
312 }
313 }
314 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700315 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800316 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700317 if (info.className != null) {
318 pw.print(prefix); pw.print("class="); pw.println(info.className);
319 }
320 if (info.manageSpaceActivityName != null) {
321 pw.print(prefix); pw.print("manageSpaceActivityName=");
322 pw.println(info.manageSpaceActivityName);
323 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900324
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700325 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
326 pw.print(" publicDir="); pw.print(info.publicSourceDir);
327 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700328 pw.print(prefix); pw.print("packageList={");
329 for (int i=0; i<pkgList.size(); i++) {
330 if (i > 0) pw.print(", ");
331 pw.print(pkgList.keyAt(i));
332 }
333 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700334 if (pkgDeps != null) {
335 pw.print(prefix); pw.print("packageDependencies={");
336 for (int i=0; i<pkgDeps.size(); i++) {
337 if (i > 0) pw.print(", ");
338 pw.print(pkgDeps.valueAt(i));
339 }
340 pw.println("}");
341 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700342 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700343 if (mInstr != null) {
344 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700345 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700346 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700347 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700348 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700349 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700350 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700351 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700352 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800353 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700354 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700355 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700356 pw.println();
357 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
358 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800359 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800360 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800361 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800362 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800363 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800364 pw.print(prefix); pw.print("procStateMemTracker: ");
365 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700366 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800367 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700368 if (serviceb) {
369 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
370 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
371 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700372 if (notCachedSinceIdle) {
373 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700374 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700375 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700376 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700377 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700378 pw.print(" setRaw="); pw.print(setRawAdj);
379 pw.print(" cur="); pw.print(curAdj);
380 pw.print(" set="); pw.println(setAdj);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700381 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700382 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700383 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700384 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700385 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700386 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700387 pw.print(" pssProcState="); pw.print(pssProcState);
388 pw.print(" setProcState="); pw.print(setProcState);
389 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700390 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700391 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700392 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700393 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700394 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700395 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
396 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700397 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700398 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
399 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
400 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100401 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700402 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700403 if (mHasForegroundServices || forcingToImportant != null) {
404 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700405 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700406 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700407 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700408 pw.print(prefix); pw.print("reportedInteraction=");
409 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700410 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800411 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700412 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800413 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700414 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700415 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700416 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700417 }
418 pw.println();
419 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700420 if (mPersistent || removed) {
421 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700422 pw.print(" removed="); pw.println(removed);
423 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700424 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
425 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
426 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700427 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700428 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800429 if (lastProviderTime > 0) {
430 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700431 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800432 pw.println();
433 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700434 if (lastTopTime > 0) {
435 pw.print(prefix); pw.print("lastTopTime=");
436 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
437 pw.println();
438 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700439 if (hasStartedServices) {
440 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
441 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700442 if (pendingStart) {
443 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
444 }
445 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700446 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700447 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700448 if (lastCpuTime > 0) {
449 pw.print(" timeUsed=");
450 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
451 }
452 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700453 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700454 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700455 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700456 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700457 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700458 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700459 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700460 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700461 if (killed || killedByAm || waitingToKill != null) {
462 pw.print(prefix); pw.print("killed="); pw.print(killed);
463 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700464 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700465 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700466 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700467 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700468 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700469 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700470 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700471 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700472 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200473 pw.print(" bad="); pw.print(bad);
474
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700475 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200476 if (errorReportReceiver != null) {
477 pw.print(" errorReportReceiver=");
478 pw.print(errorReportReceiver.flattenToShortString());
479 }
480 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700481 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700482 if (whitelistManager) {
483 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
484 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400485 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
486 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
487 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
488 pw.println(Arrays.toString(isolatedEntryPointArgs));
489 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700490 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700491 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700492 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700493 for (int i=0; i<services.size(); i++) {
494 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700495 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700496 }
497 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700498 pw.print(prefix); pw.print("Executing Services (fg=");
499 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700500 for (int i=0; i<executingServices.size(); i++) {
501 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700502 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700503 }
504 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700505 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700506 for (int i=0; i<connections.size(); i++) {
507 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700508 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700509 }
510 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700511 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700512 for (int i=0; i<pubProviders.size(); i++) {
513 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
514 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700515 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700516 }
517 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700518 pw.print(prefix); pw.println("Connected Providers:");
519 for (int i=0; i<conProviders.size(); i++) {
520 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
521 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700522 }
yangzhenyud509bc92016-08-31 18:26:46 +0800523 if (!curReceivers.isEmpty()) {
524 pw.print(prefix); pw.println("Current Receivers:");
525 for (int i=0; i < curReceivers.size(); i++) {
526 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
527 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700528 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700529 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700530 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700531 for (int i=0; i<receivers.size(); i++) {
532 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700533 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700536
Bookatz152623f2018-07-23 15:57:44 -0700537 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700538 int _uid) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700539 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800541 isolated = _info.uid != _uid;
542 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700543 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700545 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700546 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700547 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700548 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700550 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700551 mWindowProcessController = new WindowProcessController(
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700552 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700553 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 }
555
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700556 public void setPid(int _pid) {
557 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700558 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700559 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800560 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700561 stringName = null;
562 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700563
564 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
565 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700566 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700567 if (origBase != null) {
568 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700569 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700570 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
571 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
572 uid, processName, pkgList.keyAt(ipkg),
573 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
574 pkgList.valueAt(ipkg).appVersion);
575 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700576 origBase.makeInactive();
577 }
Ronnie Leng4c5c6f42015-03-25 10:57:24 -0500578 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700579 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700580 baseProcessTracker.makeActive();
581 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700582 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
583 if (holder.state != null && holder.state != origBase) {
584 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700585 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700586 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700587 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700588 if (holder.state != baseProcessTracker) {
589 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700590 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700591 }
592 }
593 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700594 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700595 }
596
597 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700598 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700599 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700600 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700601 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700602 if (origBase != null) {
603 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700604 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700605 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
606 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
607 uid, processName, pkgList.keyAt(ipkg),
608 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
609 pkgList.valueAt(ipkg).appVersion);
610 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700611 origBase.makeInactive();
612 }
613 baseProcessTracker = null;
614 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700615 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
616 if (holder.state != null && holder.state != origBase) {
617 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700618 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700619 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700620 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700621 }
622 }
623 }
624
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700625 boolean hasActivities() {
626 return mWindowProcessController.hasActivities();
627 }
628
629 void clearActivities() {
630 mWindowProcessController.clearActivities();
631 }
632
633 boolean hasActivitiesOrRecentTasks() {
634 return mWindowProcessController.hasActivitiesOrRecentTasks();
635 }
636
637 boolean hasRecentTasks() {
638 return mWindowProcessController.hasRecentTasks();
639 }
640
641 void clearRecentTasks() {
642 mWindowProcessController.clearRecentTasks();
Dianne Hackborn68a06332017-11-15 17:54:18 -0800643 }
644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 /**
646 * This method returns true if any of the activities within the process record are interesting
647 * to the user. See HistoryRecord.isInterestingToUserLocked()
648 */
649 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700650 if (mWindowProcessController.isInterestingToUser()) {
651 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100653
654 final int servicesSize = services.size();
655 for (int i = 0; i < servicesSize; i++) {
656 ServiceRecord r = services.valueAt(i);
657 if (r.isForeground) {
658 return true;
659 }
660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 return false;
662 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800663
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700664 public void unlinkDeathRecipient() {
665 if (deathRecipient != null && thread != null) {
666 thread.asBinder().unlinkToDeath(deathRecipient, 0);
667 }
668 deathRecipient = null;
669 }
670
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700671 void updateHasAboveClientLocked() {
672 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700673 for (int i=connections.size()-1; i>=0; i--) {
674 ConnectionRecord cr = connections.valueAt(i);
675 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
676 hasAboveClient = true;
677 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700678 }
679 }
680 }
681
Dianne Hackbornc8230512013-07-13 21:32:12 -0700682 int modifyRawOomAdj(int adj) {
683 if (hasAboveClient) {
684 // If this process has bound to any services with BIND_ABOVE_CLIENT,
685 // then we need to drop its adjustment to be lower than the service's
686 // in order to honor the request. We want to drop it by one adjustment
687 // level... but there is special meaning applied to various levels so
688 // we will skip some of them.
689 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
690 // System process will not get dropped, ever
691 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
692 adj = ProcessList.VISIBLE_APP_ADJ;
693 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
694 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
695 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
696 adj = ProcessList.CACHED_APP_MIN_ADJ;
697 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
698 adj++;
699 }
700 }
701 return adj;
702 }
703
Joe Onorato57190282016-04-20 15:37:49 -0700704 void scheduleCrash(String message) {
705 // Checking killedbyAm should keep it from showing the crash dialog if the process
706 // was already dead for a good / normal reason.
707 if (!killedByAm) {
708 if (thread != null) {
709 if (pid == Process.myPid()) {
710 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
711 return;
712 }
713 long ident = Binder.clearCallingIdentity();
714 try {
715 thread.scheduleCrash(message);
716 } catch (RemoteException e) {
717 // If it's already dead our work is done. If it's wedged just kill it.
718 // We won't get the crash dialog or the error reporting.
719 kill("scheduleCrash for '" + message + "' failed", true);
720 } finally {
721 Binder.restoreCallingIdentity(ident);
722 }
723 }
724 }
725 }
726
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700727 void kill(String reason, boolean noisy) {
728 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700729 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700730 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
731 mService.reportUidInfoMessageLocked(TAG,
732 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
733 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700734 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700735 if (pid > 0) {
736 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
737 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400738 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700739 } else {
740 pendingStart = false;
741 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700742 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700743 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700744 killedByAm = true;
745 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700746 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700747 }
748 }
749
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700750 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700751 public void writeToProto(ProtoOutputStream proto, long fieldId) {
752 long token = proto.start(fieldId);
753 proto.write(ProcessRecordProto.PID, pid);
754 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
755 if (info.uid < Process.FIRST_APPLICATION_UID) {
756 proto.write(ProcessRecordProto.UID, uid);
757 } else {
758 proto.write(ProcessRecordProto.USER_ID, userId);
759 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
760 if (uid != info.uid) {
761 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
762 }
763 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700764 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Yi Jin129fc6c2017-09-28 15:48:38 -0700765 proto.end(token);
766 }
767
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800768 public String toShortString() {
769 if (shortStringName != null) {
770 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700771 }
772 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800773 toShortString(sb);
774 return shortStringName = sb.toString();
775 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700776
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800777 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700778 sb.append(pid);
779 sb.append(':');
780 sb.append(processName);
781 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800782 if (info.uid < Process.FIRST_APPLICATION_UID) {
783 sb.append(uid);
784 } else {
785 sb.append('u');
786 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700787 int appId = UserHandle.getAppId(info.uid);
788 if (appId >= Process.FIRST_APPLICATION_UID) {
789 sb.append('a');
790 sb.append(appId - Process.FIRST_APPLICATION_UID);
791 } else {
792 sb.append('s');
793 sb.append(appId);
794 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800795 if (uid != info.uid) {
796 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700797 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800798 }
799 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800800 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700801
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800802 public String toString() {
803 if (stringName != null) {
804 return stringName;
805 }
806 StringBuilder sb = new StringBuilder(128);
807 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700808 sb.append(Integer.toHexString(System.identityHashCode(this)));
809 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800810 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700811 sb.append('}');
812 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700814
815 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700816 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700817 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700818 sb.append(' ');
819 if (adjTarget instanceof ComponentName) {
820 sb.append(((ComponentName)adjTarget).flattenToShortString());
821 } else if (adjTarget != null) {
822 sb.append(adjTarget.toString());
823 } else {
824 sb.append("{null}");
825 }
826 sb.append("<=");
827 if (adjSource instanceof ProcessRecord) {
828 sb.append("Proc{");
829 sb.append(((ProcessRecord)adjSource).toShortString());
830 sb.append("}");
831 } else if (adjSource != null) {
832 sb.append(adjSource.toString());
833 } else {
834 sb.append("{null}");
835 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700836 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700837 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700838 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700839 }
840
Wale Ogunwale9c103022018-10-18 07:44:54 -0700841 @Override
842 public void addPackage(String pkg, long versionCode) {
843 synchronized (mService) {
844 addPackage(pkg, versionCode, mService.mProcessStats);
845 }
846 }
847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 /*
849 * Return true if package has been added false if not
850 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700851 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700852 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700853 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
854 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700855 if (baseProcessTracker != null) {
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700856 tracker.updateProcessStateHolderLocked(holder, pkg, uid, versionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700857 pkgList.put(pkg, holder);
858 if (holder.state != baseProcessTracker) {
859 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700860 }
861 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700862 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700863 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 return true;
865 }
866 return false;
867 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700868
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700869 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700870 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
871 if (hasStartedServices) {
872 return ProcessList.SERVICE_B_ADJ;
873 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700874 }
875 return setAdj;
876 }
877
Dianne Hackborna413dc02013-07-12 12:02:55 -0700878 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700879 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700880 mRepProcState = newState;
881 setCurProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700882 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
883 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
884 uid, processName, pkgList.keyAt(ipkg),
885 ActivityManager.processStateAmToProto(mRepProcState),
886 pkgList.valueAt(ipkg).appVersion);
887 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700888 }
889 }
890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 /*
892 * Delete all packages from list except the package indicated in info
893 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700894 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700895 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700896 if (baseProcessTracker != null) {
897 long now = SystemClock.uptimeMillis();
898 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700899 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700900 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
901 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
902 uid, processName, pkgList.keyAt(ipkg),
903 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
904 pkgList.valueAt(ipkg).appVersion);
905 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700906 if (N != 1) {
907 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700908 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
909 if (holder.state != null && holder.state != baseProcessTracker) {
910 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700911 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700912
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700913 }
914 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700915 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700916 info.longVersionCode);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700917 tracker.updateProcessStateHolderLocked(holder, info.packageName, uid,
918 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700919 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700920 if (holder.state != baseProcessTracker) {
921 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700922 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700923 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700924 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700925 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700926 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 public String[] getPackageList() {
931 int size = pkgList.size();
932 if (size == 0) {
933 return null;
934 }
935 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700936 for (int i=0; i<pkgList.size(); i++) {
937 list[i] = pkgList.keyAt(i);
938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 return list;
940 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700941
942 WindowProcessController getWindowProcessController() {
943 return mWindowProcessController;
944 }
945
946 void setCurrentSchedulingGroup(int curSchedGroup) {
947 mCurSchedGroup = curSchedGroup;
948 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
949 }
950
951 int getCurrentSchedulingGroup() {
952 return mCurSchedGroup;
953 }
954
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700955 void setCurProcState(int curProcState) {
956 mCurProcState = curProcState;
957 mWindowProcessController.setCurrentProcState(mCurProcState);
958 }
959
960 int getCurProcState() {
961 return mCurProcState;
962 }
963
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700964 void setReportedProcState(int repProcState) {
965 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700966 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
967 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
968 uid, processName, pkgList.keyAt(ipkg),
969 ActivityManager.processStateAmToProto(mRepProcState),
970 pkgList.valueAt(ipkg).appVersion);
971 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700972 mWindowProcessController.setReportedProcState(repProcState);
973 }
974
975 int getReportedProcState() {
976 return mRepProcState;
977 }
978
979 void setCrashing(boolean crashing) {
980 mCrashing = crashing;
981 mWindowProcessController.setCrashing(crashing);
982 }
983
984 boolean isCrashing() {
985 return mCrashing;
986 }
987
988 void setNotResponding(boolean notResponding) {
989 mNotResponding = notResponding;
990 mWindowProcessController.setNotResponding(notResponding);
991 }
992
993 boolean isNotResponding() {
994 return mNotResponding;
995 }
996
997 void setPersistent(boolean persistent) {
998 mPersistent = persistent;
999 mWindowProcessController.setPersistent(persistent);
1000 }
1001
1002 boolean isPersistent() {
1003 return mPersistent;
1004 }
1005
1006 public void setRequiredAbi(String requiredAbi) {
1007 mRequiredAbi = requiredAbi;
1008 mWindowProcessController.setRequiredAbi(requiredAbi);
1009 }
1010
1011 String getRequiredAbi() {
1012 return mRequiredAbi;
1013 }
1014
1015 void setHasForegroundServices(boolean hasForegroundServices) {
1016 mHasForegroundServices = hasForegroundServices;
1017 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1018 }
1019
1020 boolean hasForegroundServices() {
1021 return mHasForegroundServices;
1022 }
1023
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001024 void setHasForegroundActivities(boolean hasForegroundActivities) {
1025 mHasForegroundActivities = hasForegroundActivities;
1026 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1027 }
1028
1029 boolean hasForegroundActivities() {
1030 return mHasForegroundActivities;
1031 }
1032
1033 void setHasClientActivities(boolean hasClientActivities) {
1034 mHasClientActivities = hasClientActivities;
1035 mWindowProcessController.setHasClientActivities(hasClientActivities);
1036 }
1037
1038 boolean hasClientActivities() {
1039 return mHasClientActivities;
1040 }
1041
1042 void setHasTopUi(boolean hasTopUi) {
1043 mHasTopUi = hasTopUi;
1044 mWindowProcessController.setHasTopUi(hasTopUi);
1045 }
1046
1047 boolean hasTopUi() {
1048 return mHasTopUi;
1049 }
1050
1051 void setHasOverlayUi(boolean hasOverlayUi) {
1052 mHasOverlayUi = hasOverlayUi;
1053 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1054 }
1055
1056 boolean hasOverlayUi() {
1057 return mHasOverlayUi;
1058 }
1059
1060 void setInteractionEventTime(long interactionEventTime) {
1061 mInteractionEventTime = interactionEventTime;
1062 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1063 }
1064
1065 long getInteractionEventTime() {
1066 return mInteractionEventTime;
1067 }
1068
1069 void setFgInteractionTime(long fgInteractionTime) {
1070 mFgInteractionTime = fgInteractionTime;
1071 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1072 }
1073
1074 long getFgInteractionTime() {
1075 return mFgInteractionTime;
1076 }
1077
1078 void setWhenUnimportant(long whenUnimportant) {
1079 mWhenUnimportant = whenUnimportant;
1080 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1081 }
1082
1083 long getWhenUnimportant() {
1084 return mWhenUnimportant;
1085 }
1086
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001087 void setDebugging(boolean debugging) {
1088 mDebugging = debugging;
1089 mWindowProcessController.setDebugging(debugging);
1090 }
1091
1092 boolean isDebugging() {
1093 return mDebugging;
1094 }
1095
1096 void setUsingWrapper(boolean usingWrapper) {
1097 mUsingWrapper = usingWrapper;
1098 mWindowProcessController.setUsingWrapper(usingWrapper);
1099 }
1100
1101 boolean isUsingWrapper() {
1102 return mUsingWrapper;
1103 }
1104
1105 void setActiveInstrumentation(ActiveInstrumentation instr) {
1106 mInstr = instr;
1107 mWindowProcessController.setInstrumenting(instr != null);
1108 }
1109
1110 ActiveInstrumentation getActiveInstrumentation() {
1111 return mInstr;
1112 }
1113
Wale Ogunwale31913b52018-10-13 08:29:31 -07001114 void setCurRawAdj(int curRawAdj) {
1115 mCurRawAdj = curRawAdj;
1116 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1117 }
1118
1119 int getCurRawAdj() {
1120 return mCurRawAdj;
1121 }
1122
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001123 @Override
1124 public void clearProfilerIfNeeded() {
1125 synchronized (mService) {
1126 if (mService.mProfileProc == null || mService.mProfilerInfo == null
1127 || mService.mProfileProc != this) {
1128 return;
1129 }
1130 mService.clearProfilerLocked();
1131 }
1132 }
1133
1134 @Override
1135 public void updateServiceConnectionActivities() {
1136 synchronized (mService) {
1137 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1138 }
1139 }
1140
1141 @Override
1142 public void setPendingUiClean(boolean pendingUiClean) {
1143 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001144 mPendingUiClean = pendingUiClean;
1145 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001146 }
1147 }
1148
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001149 boolean hasPendingUiClean() {
1150 return mPendingUiClean;
1151 }
1152
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001153 @Override
1154 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1155 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001156 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001157 forceProcessStateUpTo(newState);
1158 }
1159 }
1160
1161 @Override
1162 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru,
1163 boolean activityChange, boolean updateOomAdj) {
1164 synchronized (mService) {
1165 if (updateServiceConnectionActivities) {
1166 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1167 }
1168 if (updateLru) {
Amith Yamasani98a00922018-08-21 12:50:30 -04001169 mService.mProcessList.updateLruProcessLocked(this, activityChange, null);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001170 }
1171 if (updateOomAdj) {
1172 mService.updateOomAdjLocked();
1173 }
1174 }
1175 }
1176
1177 @Override
1178 public void setRemoved(boolean removed) {
1179 synchronized (mService) {
1180 this.removed = removed;
1181 }
1182 }
1183
Wale Ogunwale86b74462018-07-02 08:42:43 -07001184 /**
1185 * Returns the total time (in milliseconds) spent executing in both user and system code.
1186 * Safe to call without lock held.
1187 */
Wale Ogunwale9c103022018-10-18 07:44:54 -07001188 @Override
Wale Ogunwale86b74462018-07-02 08:42:43 -07001189 public long getCpuTime() {
1190 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1191 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001192
Wale Ogunwale9c103022018-10-18 07:44:54 -07001193 @Override
1194 public void clearWaitingToKill() {
1195 synchronized (mService) {
1196 waitingToKill = null;
1197 }
1198 }
1199
1200 @Override
1201 public ProfilerInfo onStartActivity(int topProcessState) {
1202 synchronized (mService) {
1203 ProfilerInfo profilerInfo = null;
1204 if (mService.mProfileApp != null && mService.mProfileApp.equals(processName)) {
1205 if (mService.mProfileProc == null || mService.mProfileProc == this) {
1206 mService.mProfileProc = this;
1207 final ProfilerInfo profilerInfoSvc = mService.mProfilerInfo;
1208 if (profilerInfoSvc != null && profilerInfoSvc.profileFile != null) {
1209 if (profilerInfoSvc.profileFd != null) {
1210 try {
1211 profilerInfoSvc.profileFd = profilerInfoSvc.profileFd.dup();
1212 } catch (IOException e) {
1213 profilerInfoSvc.closeFd();
1214 }
1215 }
1216
1217 profilerInfo = new ProfilerInfo(profilerInfoSvc);
1218 }
1219 }
1220 }
1221
1222 hasShownUi = true;
1223 setPendingUiClean(true);
1224 forceProcessStateUpTo(topProcessState);
1225
1226 return profilerInfo;
1227 }
1228 }
1229
1230 @Override
1231 public void appDied() {
1232 synchronized (mService) {
1233 mService.appDiedLocked(this);
1234 }
1235 }
1236
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001237 public long getInputDispatchingTimeout() {
1238 return mWindowProcessController.getInputDispatchingTimeout();
1239 }
1240
1241 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1242 String parentShortComponentName, WindowProcessController parentProcess,
1243 boolean aboveSystem, String annotation) {
1244 ArrayList<Integer> firstPids = new ArrayList<>(5);
1245 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1246
Wale Ogunwalee2172292018-10-25 10:11:10 -07001247 mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true));
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001248
1249 long anrTime = SystemClock.uptimeMillis();
1250 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1251 mService.updateCpuStatsNow();
1252 }
1253
1254 // Unless configured otherwise, swallow ANRs in background processes & kill the process.
1255 boolean showBackground = Settings.Secure.getInt(mService.mContext.getContentResolver(),
1256 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1257
1258 boolean isSilentANR;
1259
1260 synchronized (mService) {
1261 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
Wale Ogunwale387b34c2018-10-25 19:59:40 -07001262 if (mService.mAtmInternal.isShuttingDown()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001263 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1264 return;
1265 } else if (isNotResponding()) {
1266 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1267 return;
1268 } else if (isCrashing()) {
1269 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1270 return;
1271 } else if (killedByAm) {
1272 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1273 return;
1274 } else if (killed) {
1275 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1276 return;
1277 }
1278
1279 // In case we come through here for the same app before completing
1280 // this one, mark as anring now so we will bail out.
1281 setNotResponding(true);
1282
1283 // Log the ANR to the event log.
1284 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1285 annotation);
1286
1287 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1288 firstPids.add(pid);
1289
1290 // Don't dump other PIDs if it's a background ANR
1291 isSilentANR = !showBackground && !isInterestingForBackgroundTraces();
1292 if (!isSilentANR) {
1293 int parentPid = pid;
1294 if (parentProcess != null && parentProcess.getPid() > 0) {
1295 parentPid = parentProcess.getPid();
1296 }
1297 if (parentPid != pid) firstPids.add(parentPid);
1298
1299 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1300
Amith Yamasani98a00922018-08-21 12:50:30 -04001301 for (int i = mService.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
1302 ProcessRecord r = mService.mProcessList.mLruProcesses.get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001303 if (r != null && r.thread != null) {
1304 int myPid = r.pid;
1305 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1306 if (r.isPersistent()) {
1307 firstPids.add(myPid);
1308 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1309 } else if (r.treatLikeActivity) {
1310 firstPids.add(myPid);
1311 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1312 } else {
1313 lastPids.put(myPid, Boolean.TRUE);
1314 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1315 }
1316 }
1317 }
1318 }
1319 }
1320 }
1321
1322 // Log the ANR to the main log.
1323 StringBuilder info = new StringBuilder();
1324 info.setLength(0);
1325 info.append("ANR in ").append(processName);
1326 if (activityShortComponentName != null) {
1327 info.append(" (").append(activityShortComponentName).append(")");
1328 }
1329 info.append("\n");
1330 info.append("PID: ").append(pid).append("\n");
1331 if (annotation != null) {
1332 info.append("Reason: ").append(annotation).append("\n");
1333 }
1334 if (parentShortComponentName != null
1335 && parentShortComponentName.equals(activityShortComponentName)) {
1336 info.append("Parent: ").append(parentShortComponentName).append("\n");
1337 }
1338
1339 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1340
1341 // don't dump native PIDs for background ANRs unless it is the process of interest
1342 String[] nativeProcs = null;
1343 if (isSilentANR) {
1344 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1345 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1346 nativeProcs = new String[] { processName };
1347 break;
1348 }
1349 }
1350 } else {
1351 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1352 }
1353
1354 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1355 ArrayList<Integer> nativePids = null;
1356
1357 if (pids != null) {
1358 nativePids = new ArrayList<>(pids.length);
1359 for (int i : pids) {
1360 nativePids.add(i);
1361 }
1362 }
1363
1364 // For background ANRs, don't pass the ProcessCpuTracker to
1365 // avoid spending 1/2 second collecting stats to rank lastPids.
1366 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
1367 (isSilentANR) ? null : processCpuTracker, (isSilentANR) ? null : lastPids,
1368 nativePids);
1369
1370 String cpuInfo = null;
1371 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1372 mService.updateCpuStatsNow();
1373 synchronized (mService.mProcessCpuTracker) {
1374 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1375 }
1376 info.append(processCpuTracker.printCurrentLoad());
1377 info.append(cpuInfo);
1378 }
1379
1380 info.append(processCpuTracker.printCurrentState(anrTime));
1381
1382 Slog.e(TAG, info.toString());
1383 if (tracesFile == null) {
1384 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1385 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1386 }
1387
1388 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1389 activityShortComponentName == null ? "unknown": activityShortComponentName,
1390 annotation,
1391 (this.info != null) ? (this.info.isInstantApp()
1392 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1393 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1394 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1395 isInterestingToUserLocked()
1396 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
1397 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND);
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001398 final ProcessRecord parentPr = parentProcess != null
1399 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001400 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001401 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001402
Wale Ogunwalee2172292018-10-25 10:11:10 -07001403 if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true),
1404 () -> {
1405 synchronized (mService) {
1406 mService.mServices.scheduleServiceTimeoutLocked(this);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001407 }
Wale Ogunwalee2172292018-10-25 10:11:10 -07001408 })) {
1409 return;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001410 }
1411
1412 synchronized (mService) {
1413 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1414
1415 if (isSilentANR) {
1416 kill("bg anr", true);
1417 return;
1418 }
1419
1420 // Set the app's notResponding state, and look up the errorReportReceiver
1421 makeAppNotRespondingLocked(activityShortComponentName,
1422 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1423
1424 // Bring up the infamous App Not Responding dialog
1425 Message msg = Message.obtain();
1426 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1427 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
1428
1429 mService.mUiHandler.sendMessage(msg);
1430 }
1431 }
1432
1433 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1434 setNotResponding(true);
1435 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1436 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1437 activity, shortMsg, longMsg, null);
1438 startAppProblemLocked();
1439 getWindowProcessController().stopFreezingActivities();
1440 }
1441
1442 void startAppProblemLocked() {
1443 // If this app is not running under the current user, then we can't give it a report button
1444 // because that would require launching the report UI under a different user.
1445 errorReportReceiver = null;
1446
1447 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1448 if (this.userId == userId) {
1449 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1450 mService.mContext, info.packageName, info.flags);
1451 }
1452 }
1453 mService.skipCurrentReceiverLocked(this);
1454 }
1455
1456 private boolean isInterestingForBackgroundTraces() {
1457 // The system_server is always considered interesting.
1458 if (pid == MY_PID) {
1459 return true;
1460 }
1461
1462 // A package is considered interesting if any of the following is true :
1463 //
1464 // - It's displaying an activity.
1465 // - It's the SystemUI.
1466 // - It has an overlay or a top UI visible.
1467 //
1468 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1469 // process is a bit of a kludge, but the same pattern seems repeated at
1470 // several places in the system server.
1471 return isInterestingToUserLocked() ||
1472 (info != null && "com.android.systemui".equals(info.packageName))
1473 || (hasTopUi() || hasOverlayUi());
1474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475}