blob: 6f0a562eb819918ab3728f624600d26b8bbcee0b [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;
Joe Onorato57190282016-04-20 15:37:49 -070035import android.os.Binder;
Yunfan Chen75157d72018-07-27 14:47:21 +090036import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.os.IBinder;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070038import android.os.Message;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080039import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070040import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070041import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070042import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070043import android.os.UserHandle;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070044import android.provider.Settings;
Yang Lu732d6382018-11-05 07:53:12 -080045import android.server.ServerProtoEnums;
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;
Sudheer Shanka87915d62018-11-06 10:57:35 -080060import com.android.internal.os.Zygote;
Wale Ogunwale59507092018-10-29 09:00:30 -070061import com.android.server.wm.WindowProcessController;
62import com.android.server.wm.WindowProcessListener;
Yunfan Chen75157d72018-07-27 14:47:21 +090063
Wale Ogunwale51cc98a2018-10-15 10:41:05 -070064import java.io.File;
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
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800148 long lastCompactTime; // The last time that this process was compacted
149 int reqCompactAction; // The most recent compaction action requested for this app.
150 int lastCompactAction; // The most recent compaction action performed for this app.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700151 private int mCurSchedGroup; // Currently desired scheduling class
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700152 int setSchedGroup; // Last set to background scheduling class
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700153 int trimMemoryLevel; // Last selected memory trimming level
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700154 private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700155 private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
Amith Yamasani08888c02018-12-07 09:38:25 -0800156 private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation
riddle_hsu6793fc32015-03-31 11:54:14 +0800157 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
158 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Dianne Hackborne17b4452018-01-10 13:15:40 -0800159 int pssStatType; // The type of stat collection that we are currently requesting
Tim Murray33eb07f2016-06-10 10:03:20 -0700160 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
161 int renderThreadTid; // TID for RenderThread
Dianne Hackborna631d562018-11-20 15:58:15 -0800162 ServiceRecord connectionService; // Service that applied current connectionGroup/Importance
163 int connectionGroup; // Last group set by a connection
164 int connectionImportance; // Last importance set by a connection
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700165 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700166 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700167 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700168 private boolean mHasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700169 boolean hasStartedServices; // Are there any started services running in this process?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700170 private boolean mHasForegroundServices; // Running any services that are foreground?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700171 private boolean mHasForegroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700172 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700173 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700174 boolean hasShownUi; // Has UI been shown in this process since it was started?
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700175 private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user
Wale Ogunwaled993a572017-02-05 13:52:09 -0800176 // is interacting with? E.g. The status bar when it is expanded, but
177 // not when it is minimized. When true the
178 // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
179 // scheduling group to boost performance.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700180 private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that
Wale Ogunwaled993a572017-02-05 13:52:09 -0800181 // overlays on-top of activity UIs on screen. E.g. display a window
182 // of type
183 // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
184 // When true the process will oom adj score will be set to
185 // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
186 // of the process getting killed.
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100187 boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true
188 // the process will be set to use the
189 // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
190 // performance, as well as oom adj score will be set to
191 // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
192 // of the process getting killed.
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700193 private boolean mPendingUiClean; // Want to clean up resources from showing UI?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700194 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700195 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700197 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700198 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700199 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700200 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600201 boolean unlocked; // True when proc was started in user unlocked state
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700202 private long mInteractionEventTime; // The time we sent the last interaction event
203 private long mFgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700204 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
Dianne Hackbornf965f402017-05-04 23:27:23 -0700205 Object forcingToImportant; // Token that is forcing this process to be important
Dianne Hackborn906497c2010-05-10 15:57:38 -0700206 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
Tim Murrayb52f0002018-05-02 15:14:35 -0700207 int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles
208 boolean containsCycle; // Whether this app has encountered a cycle in the most recent update
Dianne Hackborn906497c2010-05-10 15:57:38 -0700209 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700210 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700211 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700212 private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in
213 // process.
214 private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached
yangzhenyud509bc92016-08-31 18:26:46 +0800215 final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700216 private long mWhenUnimportant; // When (uptime) the process last became unimportant
Dianne Hackborn287952c2010-09-22 22:34:31 -0700217 long lastCpuTime; // How long proc has run CPU at last check
218 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700220 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800221 long lastProviderTime; // The last time someone else was using a provider in this process.
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700222 long lastTopTime; // The last time the process was in the TOP state or greater.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700223 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800224 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700225 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700226 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700227 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700228 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700229 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700230 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100231 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
232
Dianne Hackborn8c76d912018-08-23 15:20:05 -0700233 // Cache of last retrieve memory info and uptime, to throttle how frequently
234 // apps can requyest it.
235 Debug.MemoryInfo lastMemInfo;
236 long lastMemInfoTime;
237
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700238 // Controller for driving the process state on the window manager side.
239 final private WindowProcessController mWindowProcessController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700241 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700243 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700245 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700247 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700249 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700251 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Michal Karpinskiac116df2018-12-10 17:51:42 +0000252 // A set of tokens that currently contribute to this process being temporarily whitelisted
253 // to start activities even if it's not in the foreground
254 final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700255
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400256 String isolatedEntryPoint; // Class to run on start if this is a special isolated process.
257 String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main().
258
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700259 boolean execServicesFg; // do we need to be executing services in the foreground?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700260 private boolean mPersistent;// always keep this application running?
261 private boolean mCrashing; // are we in the process of crashing?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700263 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700264 private boolean mNotResponding; // does the app have a not responding dialog?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 Dialog anrDialog; // dialog being displayed due to app not resp.
266 boolean removed; // has app package been removed from device?
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700267 private boolean mDebugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 boolean waitedForDebugger; // has process show wait for debugger dialog?
269 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700270
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800271 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700272 String stringName; // caching of toString() result.
Sudheer Shankaf6690102017-10-16 10:20:32 -0700273 boolean pendingStart; // Process start is pending.
274 long startSeq; // Seq no. indicating the latest process start associated with
275 // this process record.
Sudheer Shanka87915d62018-11-06 10:57:35 -0800276 int mountMode; // Indicates how the external storage was mounted for this process.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 // These reports are generated & stored when an app gets into an error condition.
279 // They will be "null" when all is OK.
280 ActivityManager.ProcessErrorStateInfo crashingReport;
281 ActivityManager.ProcessErrorStateInfo notRespondingReport;
282
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200283 // Who will be notified of the error. This is usually an activity in the
284 // app that installed the package.
285 ComponentName errorReportReceiver;
286
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700287 // Process is currently hosting a backup agent for backup or restore
288 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700289 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
290 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700291
Sudheer Shankaf6690102017-10-16 10:20:32 -0700292 // Params used in starting this process.
293 String hostingType;
294 String hostingNameStr;
295 String seInfo;
296 long startTime;
297 // This will be same as {@link #uid} usually except for some apps used during factory testing.
298 int startUid;
299
300 void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo,
301 long startTime) {
302 this.startUid = startUid;
303 this.hostingType = hostingType;
304 this.hostingNameStr = hostingNameStr;
305 this.seInfo = seInfo;
306 this.startTime = startTime;
307 }
308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700310 final long nowUptime = SystemClock.uptimeMillis();
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700311
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800312 pw.print(prefix); pw.print("user #"); pw.print(userId);
313 pw.print(" uid="); pw.print(info.uid);
314 if (uid != info.uid) {
315 pw.print(" ISOLATED uid="); pw.print(uid);
316 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800317 pw.print(" gids={");
318 if (gids != null) {
319 for (int gi=0; gi<gids.length; gi++) {
320 if (gi != 0) pw.print(", ");
321 pw.print(gids[gi]);
322
323 }
324 }
325 pw.println("}");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700326 pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800327 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700328 if (info.className != null) {
329 pw.print(prefix); pw.print("class="); pw.println(info.className);
330 }
331 if (info.manageSpaceActivityName != null) {
332 pw.print(prefix); pw.print("manageSpaceActivityName=");
333 pw.println(info.manageSpaceActivityName);
334 }
Yunfan Chen75157d72018-07-27 14:47:21 +0900335
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700336 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
337 pw.print(" publicDir="); pw.print(info.publicSourceDir);
338 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700339 pw.print(prefix); pw.print("packageList={");
340 for (int i=0; i<pkgList.size(); i++) {
341 if (i > 0) pw.print(", ");
342 pw.print(pkgList.keyAt(i));
343 }
344 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700345 if (pkgDeps != null) {
346 pw.print(prefix); pw.print("packageDependencies={");
347 for (int i=0; i<pkgDeps.size(); i++) {
348 if (i > 0) pw.print(", ");
349 pw.print(pkgDeps.valueAt(i));
350 }
351 pw.println("}");
352 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700353 pw.print(prefix); pw.print("compat="); pw.println(compat);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700354 if (mInstr != null) {
355 pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700356 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700357 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700358 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700359 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700360 pw.print(prefix); pw.print("lastActivityTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700361 TimeUtils.formatDuration(lastActivityTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700362 pw.print(" lastPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700363 TimeUtils.formatDuration(lastPssTime, nowUptime, pw);
Dianne Hackborne17b4452018-01-10 13:15:40 -0800364 pw.print(" pssStatType="); pw.print(pssStatType);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700365 pw.print(" nextPssTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700366 TimeUtils.formatDuration(nextPssTime, nowUptime, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700367 pw.println();
368 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
369 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800370 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800371 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800372 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800373 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800374 pw.println();
Dianne Hackborne17b4452018-01-10 13:15:40 -0800375 pw.print(prefix); pw.print("procStateMemTracker: ");
376 procStateMemTracker.dumpLine(pw);
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700377 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800378 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700379 if (serviceb) {
380 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
381 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
382 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700383 if (notCachedSinceIdle) {
384 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700385 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700386 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700387 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Wale Ogunwale31913b52018-10-13 08:29:31 -0700388 pw.print(" curRaw="); pw.print(mCurRawAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700389 pw.print(" setRaw="); pw.print(setRawAdj);
390 pw.print(" cur="); pw.print(curAdj);
391 pw.print(" set="); pw.println(setAdj);
Tim Murray0b1c8aa2018-11-20 10:28:38 -0800392 pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime);
393 pw.print(" lastCompactAction="); pw.print(lastCompactAction);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700394 pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700395 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700396 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700397 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700398 pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700399 pw.print(" mRepProcState="); pw.print(mRepProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700400 pw.print(" pssProcState="); pw.print(pssProcState);
401 pw.print(" setProcState="); pw.print(setProcState);
402 pw.print(" lastStateTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700403 TimeUtils.formatDuration(lastStateTime, nowUptime, pw);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700404 pw.println();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700405 if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700406 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700407 pw.print(" pendingUiClean="); pw.print(mPendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700408 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
409 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700410 }
Dianne Hackborna631d562018-11-20 15:58:15 -0800411 if (connectionService != null || connectionGroup != 0) {
412 pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup);
413 pw.print(" Importance="); pw.print(connectionImportance);
414 pw.print(" Service="); pw.println(connectionService);
415 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700416 if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) {
417 pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
418 pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100419 pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation);
Dianne Hackborna1baf732017-05-25 15:33:53 -0700420 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700421 if (mHasForegroundServices || forcingToImportant != null) {
422 pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices);
Dianne Hackbornf965f402017-05-04 23:27:23 -0700423 pw.print(" forcingToImportant="); pw.println(forcingToImportant);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700424 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700425 if (reportedInteraction || mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700426 pw.print(prefix); pw.print("reportedInteraction=");
427 pw.print(reportedInteraction);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700428 if (mInteractionEventTime != 0) {
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800429 pw.print(" time=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700430 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800431 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700432 if (mFgInteractionTime != 0) {
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700433 pw.print(" fgInteractionTime=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700434 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700435 }
436 pw.println();
437 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700438 if (mPersistent || removed) {
439 pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700440 pw.print(" removed="); pw.println(removed);
441 }
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700442 if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) {
443 pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities);
444 pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700445 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700446 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800447 if (lastProviderTime > 0) {
448 pw.print(prefix); pw.print("lastProviderTime=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700449 TimeUtils.formatDuration(lastProviderTime, nowUptime, pw);
Dianne Hackborn1a405642015-11-04 12:32:45 -0800450 pw.println();
451 }
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700452 if (lastTopTime > 0) {
453 pw.print(prefix); pw.print("lastTopTime=");
454 TimeUtils.formatDuration(lastTopTime, nowUptime, pw);
455 pw.println();
456 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700457 if (hasStartedServices) {
458 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
459 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700460 if (pendingStart) {
461 pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart);
462 }
463 pw.print(prefix); pw.print("startSeq="); pw.println(startSeq);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800464 pw.print(prefix); pw.print("mountMode="); pw.println(
465 DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode));
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700466 if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700467 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700468 if (lastCpuTime > 0) {
469 pw.print(" timeUsed=");
470 TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw);
471 }
472 pw.print(" whenUnimportant=");
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700473 TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700474 pw.println();
Dianne Hackborn287952c2010-09-22 22:34:31 -0700475 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700476 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700477 TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700478 pw.print(" lastLowMemory=");
Dianne Hackbornffca58b2017-05-24 16:15:45 -0700479 TimeUtils.formatDuration(lastLowMemory, nowUptime, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700480 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700481 if (killed || killedByAm || waitingToKill != null) {
482 pw.print(prefix); pw.print("killed="); pw.print(killed);
483 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700484 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700485 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700486 if (mDebugging || mCrashing || crashDialog != null || mNotResponding
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700487 || anrDialog != null || bad) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700488 pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700489 pw.print(" mCrashing="); pw.print(mCrashing);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700490 pw.print(" "); pw.print(crashDialog);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700491 pw.print(" mNotResponding="); pw.print(mNotResponding);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700492 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200493 pw.print(" bad="); pw.print(bad);
494
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700495 // mCrashing or mNotResponding is always set before errorReportReceiver
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200496 if (errorReportReceiver != null) {
497 pw.print(" errorReportReceiver=");
498 pw.print(errorReportReceiver.flattenToShortString());
499 }
500 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700501 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700502 if (whitelistManager) {
503 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
504 }
Torne (Richard Coles)466cbe42017-05-31 14:09:14 -0400505 if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) {
506 pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint);
507 pw.print(prefix); pw.print("isolatedEntryPointArgs=");
508 pw.println(Arrays.toString(isolatedEntryPointArgs));
509 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700510 mWindowProcessController.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700511 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700512 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700513 for (int i=0; i<services.size(); i++) {
514 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700515 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700516 }
517 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700518 pw.print(prefix); pw.print("Executing Services (fg=");
519 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700520 for (int i=0; i<executingServices.size(); i++) {
521 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700522 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700523 }
524 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700525 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700526 for (int i=0; i<connections.size(); i++) {
527 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700528 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700529 }
530 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700531 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700532 for (int i=0; i<pubProviders.size(); i++) {
533 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
534 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700535 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700536 }
537 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700538 pw.print(prefix); pw.println("Connected Providers:");
539 for (int i=0; i<conProviders.size(); i++) {
540 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
541 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700542 }
yangzhenyud509bc92016-08-31 18:26:46 +0800543 if (!curReceivers.isEmpty()) {
544 pw.print(prefix); pw.println("Current Receivers:");
545 for (int i=0; i < curReceivers.size(); i++) {
546 pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i));
547 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700548 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700549 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700550 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700551 for (int i=0; i<receivers.size(); i++) {
552 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700553 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700556
Bookatz152623f2018-07-23 15:57:44 -0700557 ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700558 int _uid) {
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700559 mService = _service;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800561 isolated = _info.uid != _uid;
562 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700563 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 processName = _processName;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700565 maxAdj = ProcessList.UNKNOWN_ADJ;
Wale Ogunwale31913b52018-10-13 08:29:31 -0700566 mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700567 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700568 mPersistent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700570 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700571 mWindowProcessController = new WindowProcessController(
Wale Ogunwale387b34c2018-10-25 19:59:40 -0700572 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700573 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
575
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700576 public void setPid(int _pid) {
577 pid = _pid;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700578 mWindowProcessController.setPid(pid);
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700579 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800580 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700581 stringName = null;
582 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700583
584 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
585 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700586 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700587 if (origBase != null) {
588 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700589 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700590 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
591 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
592 uid, processName, pkgList.keyAt(ipkg),
593 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
594 pkgList.valueAt(ipkg).appVersion);
595 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700596 origBase.makeInactive();
597 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800598 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700599 info.longVersionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700600 baseProcessTracker.makeActive();
601 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700602 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
603 if (holder.state != null && holder.state != origBase) {
604 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700605 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800606 tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid,
Patrick Baumannc2def582018-04-04 12:14:15 -0700607 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700608 if (holder.state != baseProcessTracker) {
609 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700610 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700611 }
612 }
613 thread = _thread;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700614 mWindowProcessController.setThread(thread);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700615 }
616
617 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700618 thread = null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700619 mWindowProcessController.setThread(null);
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700620 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700621 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700622 if (origBase != null) {
623 origBase.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700624 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700625 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
626 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
627 uid, processName, pkgList.keyAt(ipkg),
628 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
629 pkgList.valueAt(ipkg).appVersion);
630 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700631 origBase.makeInactive();
632 }
633 baseProcessTracker = null;
634 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700635 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
636 if (holder.state != null && holder.state != origBase) {
637 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700638 }
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700639 holder.pkg = null;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700640 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700641 }
642 }
643 }
644
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700645 boolean hasActivities() {
646 return mWindowProcessController.hasActivities();
647 }
648
649 void clearActivities() {
650 mWindowProcessController.clearActivities();
651 }
652
653 boolean hasActivitiesOrRecentTasks() {
654 return mWindowProcessController.hasActivitiesOrRecentTasks();
655 }
656
657 boolean hasRecentTasks() {
658 return mWindowProcessController.hasRecentTasks();
659 }
660
661 void clearRecentTasks() {
662 mWindowProcessController.clearRecentTasks();
Dianne Hackborn68a06332017-11-15 17:54:18 -0800663 }
664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 /**
666 * This method returns true if any of the activities within the process record are interesting
667 * to the user. See HistoryRecord.isInterestingToUserLocked()
668 */
669 public boolean isInterestingToUserLocked() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700670 if (mWindowProcessController.isInterestingToUser()) {
671 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 }
Narayan Kamatha22d9fb2017-04-26 15:14:26 +0100673
674 final int servicesSize = services.size();
675 for (int i = 0; i < servicesSize; i++) {
676 ServiceRecord r = services.valueAt(i);
677 if (r.isForeground) {
678 return true;
679 }
680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 return false;
682 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800683
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700684 public void unlinkDeathRecipient() {
685 if (deathRecipient != null && thread != null) {
686 thread.asBinder().unlinkToDeath(deathRecipient, 0);
687 }
688 deathRecipient = null;
689 }
690
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700691 void updateHasAboveClientLocked() {
692 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700693 for (int i=connections.size()-1; i>=0; i--) {
694 ConnectionRecord cr = connections.valueAt(i);
695 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
696 hasAboveClient = true;
697 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700698 }
699 }
700 }
701
Dianne Hackbornc8230512013-07-13 21:32:12 -0700702 int modifyRawOomAdj(int adj) {
703 if (hasAboveClient) {
704 // If this process has bound to any services with BIND_ABOVE_CLIENT,
705 // then we need to drop its adjustment to be lower than the service's
706 // in order to honor the request. We want to drop it by one adjustment
707 // level... but there is special meaning applied to various levels so
708 // we will skip some of them.
709 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
710 // System process will not get dropped, ever
711 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
712 adj = ProcessList.VISIBLE_APP_ADJ;
713 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
714 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
715 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
716 adj = ProcessList.CACHED_APP_MIN_ADJ;
717 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
718 adj++;
719 }
720 }
721 return adj;
722 }
723
Joe Onorato57190282016-04-20 15:37:49 -0700724 void scheduleCrash(String message) {
725 // Checking killedbyAm should keep it from showing the crash dialog if the process
726 // was already dead for a good / normal reason.
727 if (!killedByAm) {
728 if (thread != null) {
729 if (pid == Process.myPid()) {
730 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
731 return;
732 }
733 long ident = Binder.clearCallingIdentity();
734 try {
735 thread.scheduleCrash(message);
736 } catch (RemoteException e) {
737 // If it's already dead our work is done. If it's wedged just kill it.
738 // We won't get the crash dialog or the error reporting.
739 kill("scheduleCrash for '" + message + "' failed", true);
740 } finally {
741 Binder.restoreCallingIdentity(ident);
742 }
743 }
744 }
745 }
746
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700747 void kill(String reason, boolean noisy) {
748 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700749 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborne9d9b4b2018-03-28 13:51:46 -0700750 if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
751 mService.reportUidInfoMessageLocked(TAG,
752 "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
753 info.uid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700754 }
Sudheer Shankaf6690102017-10-16 10:20:32 -0700755 if (pid > 0) {
756 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
757 Process.killProcessQuiet(pid);
Amith Yamasani98a00922018-08-21 12:50:30 -0400758 ProcessList.killProcessGroup(uid, pid);
Sudheer Shankaf6690102017-10-16 10:20:32 -0700759 } else {
760 pendingStart = false;
761 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700762 if (!mPersistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700763 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700764 killedByAm = true;
765 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700766 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700767 }
768 }
769
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700770 @Override
Yi Jin129fc6c2017-09-28 15:48:38 -0700771 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800772 writeToProto(proto, fieldId, -1);
773 }
774
775 public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700776 long token = proto.start(fieldId);
777 proto.write(ProcessRecordProto.PID, pid);
778 proto.write(ProcessRecordProto.PROCESS_NAME, processName);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800779 proto.write(ProcessRecordProto.UID, info.uid);
780 if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
Yi Jin129fc6c2017-09-28 15:48:38 -0700781 proto.write(ProcessRecordProto.USER_ID, userId);
782 proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800783 }
784 if (uid != info.uid) {
785 proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
Yi Jin129fc6c2017-09-28 15:48:38 -0700786 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700787 proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800788 if (lruIndex >= 0) {
789 proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
790 }
Yi Jin129fc6c2017-09-28 15:48:38 -0700791 proto.end(token);
792 }
793
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800794 public String toShortString() {
795 if (shortStringName != null) {
796 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700797 }
798 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800799 toShortString(sb);
800 return shortStringName = sb.toString();
801 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700802
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800803 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700804 sb.append(pid);
805 sb.append(':');
806 sb.append(processName);
807 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800808 if (info.uid < Process.FIRST_APPLICATION_UID) {
809 sb.append(uid);
810 } else {
811 sb.append('u');
812 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700813 int appId = UserHandle.getAppId(info.uid);
814 if (appId >= Process.FIRST_APPLICATION_UID) {
815 sb.append('a');
816 sb.append(appId - Process.FIRST_APPLICATION_UID);
817 } else {
818 sb.append('s');
819 sb.append(appId);
820 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800821 if (uid != info.uid) {
822 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700823 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800824 }
825 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800826 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700827
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800828 public String toString() {
829 if (stringName != null) {
830 return stringName;
831 }
832 StringBuilder sb = new StringBuilder(128);
833 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700834 sb.append(Integer.toHexString(System.identityHashCode(this)));
835 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800836 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700837 sb.append('}');
838 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700840
841 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700842 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700843 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700844 sb.append(' ');
845 if (adjTarget instanceof ComponentName) {
846 sb.append(((ComponentName)adjTarget).flattenToShortString());
847 } else if (adjTarget != null) {
848 sb.append(adjTarget.toString());
849 } else {
850 sb.append("{null}");
851 }
852 sb.append("<=");
853 if (adjSource instanceof ProcessRecord) {
854 sb.append("Proc{");
855 sb.append(((ProcessRecord)adjSource).toShortString());
856 sb.append("}");
857 } else if (adjSource != null) {
858 sb.append(adjSource.toString());
859 } else {
860 sb.append("{null}");
861 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700862 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700863 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700864 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700865 }
866
Wale Ogunwale9c103022018-10-18 07:44:54 -0700867 @Override
868 public void addPackage(String pkg, long versionCode) {
869 synchronized (mService) {
870 addPackage(pkg, versionCode, mService.mProcessStats);
871 }
872 }
873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 /*
875 * Return true if package has been added false if not
876 */
Dianne Hackborn3accca02013-09-20 09:32:11 -0700877 public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700878 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700879 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
880 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700881 if (baseProcessTracker != null) {
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800882 tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
883 processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700884 pkgList.put(pkg, holder);
885 if (holder.state != baseProcessTracker) {
886 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700887 }
888 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700889 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 return true;
892 }
893 return false;
894 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700895
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700896 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700897 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
898 if (hasStartedServices) {
899 return ProcessList.SERVICE_B_ADJ;
900 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700901 }
902 return setAdj;
903 }
904
Dianne Hackborna413dc02013-07-12 12:02:55 -0700905 public void forceProcessStateUpTo(int newState) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700906 if (mRepProcState > newState) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700907 mRepProcState = newState;
908 setCurProcState(newState);
Amith Yamasani08888c02018-12-07 09:38:25 -0800909 setCurRawProcState(newState);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700910 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
911 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
912 uid, processName, pkgList.keyAt(ipkg),
913 ActivityManager.processStateAmToProto(mRepProcState),
914 pkgList.valueAt(ipkg).appVersion);
915 }
Dianne Hackborna413dc02013-07-12 12:02:55 -0700916 }
917 }
918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 /*
920 * Delete all packages from list except the package indicated in info
921 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700922 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700923 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700924 if (baseProcessTracker != null) {
925 long now = SystemClock.uptimeMillis();
926 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700927 tracker.getMemFactorLocked(), now, pkgList.mPkgList);
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700928 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
929 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
930 uid, processName, pkgList.keyAt(ipkg),
931 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
932 pkgList.valueAt(ipkg).appVersion);
933 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700934 if (N != 1) {
935 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700936 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
937 if (holder.state != null && holder.state != baseProcessTracker) {
938 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700939 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700940
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700941 }
942 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700943 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
Patrick Baumannc2def582018-04-04 12:14:15 -0700944 info.longVersionCode);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800945 tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700946 info.longVersionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700947 pkgList.put(info.packageName, holder);
Dianne Hackborn2aec55a2018-06-26 10:35:35 -0700948 if (holder.state != baseProcessTracker) {
949 holder.state.makeActive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700950 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700951 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700952 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700953 pkgList.clear();
Patrick Baumannc2def582018-04-04 12:14:15 -0700954 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 public String[] getPackageList() {
959 int size = pkgList.size();
960 if (size == 0) {
961 return null;
962 }
963 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700964 for (int i=0; i<pkgList.size(); i++) {
965 list[i] = pkgList.keyAt(i);
966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 return list;
968 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700969
970 WindowProcessController getWindowProcessController() {
971 return mWindowProcessController;
972 }
973
974 void setCurrentSchedulingGroup(int curSchedGroup) {
975 mCurSchedGroup = curSchedGroup;
976 mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup);
977 }
978
979 int getCurrentSchedulingGroup() {
980 return mCurSchedGroup;
981 }
982
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700983 void setCurProcState(int curProcState) {
984 mCurProcState = curProcState;
985 mWindowProcessController.setCurrentProcState(mCurProcState);
986 }
987
988 int getCurProcState() {
989 return mCurProcState;
990 }
991
Amith Yamasani08888c02018-12-07 09:38:25 -0800992 void setCurRawProcState(int curRawProcState) {
993 mCurRawProcState = curRawProcState;
994 }
995
996 int getCurRawProcState() {
997 return mCurRawProcState;
998 }
999
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001000 void setReportedProcState(int repProcState) {
1001 mRepProcState = repProcState;
Chenjie Yubd1a28f2018-07-17 14:55:19 -07001002 for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) {
1003 StatsLog.write(StatsLog.PROCESS_STATE_CHANGED,
1004 uid, processName, pkgList.keyAt(ipkg),
1005 ActivityManager.processStateAmToProto(mRepProcState),
1006 pkgList.valueAt(ipkg).appVersion);
1007 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001008 mWindowProcessController.setReportedProcState(repProcState);
1009 }
1010
1011 int getReportedProcState() {
1012 return mRepProcState;
1013 }
1014
1015 void setCrashing(boolean crashing) {
1016 mCrashing = crashing;
1017 mWindowProcessController.setCrashing(crashing);
1018 }
1019
1020 boolean isCrashing() {
1021 return mCrashing;
1022 }
1023
1024 void setNotResponding(boolean notResponding) {
1025 mNotResponding = notResponding;
1026 mWindowProcessController.setNotResponding(notResponding);
1027 }
1028
1029 boolean isNotResponding() {
1030 return mNotResponding;
1031 }
1032
1033 void setPersistent(boolean persistent) {
1034 mPersistent = persistent;
1035 mWindowProcessController.setPersistent(persistent);
1036 }
1037
1038 boolean isPersistent() {
1039 return mPersistent;
1040 }
1041
1042 public void setRequiredAbi(String requiredAbi) {
1043 mRequiredAbi = requiredAbi;
1044 mWindowProcessController.setRequiredAbi(requiredAbi);
1045 }
1046
1047 String getRequiredAbi() {
1048 return mRequiredAbi;
1049 }
1050
1051 void setHasForegroundServices(boolean hasForegroundServices) {
1052 mHasForegroundServices = hasForegroundServices;
1053 mWindowProcessController.setHasForegroundServices(hasForegroundServices);
1054 }
1055
1056 boolean hasForegroundServices() {
1057 return mHasForegroundServices;
1058 }
1059
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001060 void setHasForegroundActivities(boolean hasForegroundActivities) {
1061 mHasForegroundActivities = hasForegroundActivities;
1062 mWindowProcessController.setHasForegroundActivities(hasForegroundActivities);
1063 }
1064
1065 boolean hasForegroundActivities() {
1066 return mHasForegroundActivities;
1067 }
1068
1069 void setHasClientActivities(boolean hasClientActivities) {
1070 mHasClientActivities = hasClientActivities;
1071 mWindowProcessController.setHasClientActivities(hasClientActivities);
1072 }
1073
1074 boolean hasClientActivities() {
1075 return mHasClientActivities;
1076 }
1077
1078 void setHasTopUi(boolean hasTopUi) {
1079 mHasTopUi = hasTopUi;
1080 mWindowProcessController.setHasTopUi(hasTopUi);
1081 }
1082
1083 boolean hasTopUi() {
1084 return mHasTopUi;
1085 }
1086
1087 void setHasOverlayUi(boolean hasOverlayUi) {
1088 mHasOverlayUi = hasOverlayUi;
1089 mWindowProcessController.setHasOverlayUi(hasOverlayUi);
1090 }
1091
1092 boolean hasOverlayUi() {
1093 return mHasOverlayUi;
1094 }
1095
1096 void setInteractionEventTime(long interactionEventTime) {
1097 mInteractionEventTime = interactionEventTime;
1098 mWindowProcessController.setInteractionEventTime(interactionEventTime);
1099 }
1100
1101 long getInteractionEventTime() {
1102 return mInteractionEventTime;
1103 }
1104
1105 void setFgInteractionTime(long fgInteractionTime) {
1106 mFgInteractionTime = fgInteractionTime;
1107 mWindowProcessController.setFgInteractionTime(fgInteractionTime);
1108 }
1109
1110 long getFgInteractionTime() {
1111 return mFgInteractionTime;
1112 }
1113
1114 void setWhenUnimportant(long whenUnimportant) {
1115 mWhenUnimportant = whenUnimportant;
1116 mWindowProcessController.setWhenUnimportant(whenUnimportant);
1117 }
1118
1119 long getWhenUnimportant() {
1120 return mWhenUnimportant;
1121 }
1122
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001123 void setDebugging(boolean debugging) {
1124 mDebugging = debugging;
1125 mWindowProcessController.setDebugging(debugging);
1126 }
1127
1128 boolean isDebugging() {
1129 return mDebugging;
1130 }
1131
1132 void setUsingWrapper(boolean usingWrapper) {
1133 mUsingWrapper = usingWrapper;
1134 mWindowProcessController.setUsingWrapper(usingWrapper);
1135 }
1136
1137 boolean isUsingWrapper() {
1138 return mUsingWrapper;
1139 }
1140
Michal Karpinskiac116df2018-12-10 17:51:42 +00001141 void addAllowBackgroundActivityStartsToken(Binder entity) {
1142 mAllowBackgroundActivityStartsTokens.add(entity);
1143 mWindowProcessController.setAllowBackgroundActivityStarts(true);
1144 }
1145
1146 void removeAllowBackgroundActivityStartsToken(Binder entity) {
1147 mAllowBackgroundActivityStartsTokens.remove(entity);
1148 mWindowProcessController.setAllowBackgroundActivityStarts(
1149 !mAllowBackgroundActivityStartsTokens.isEmpty());
1150 }
1151
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001152 void setActiveInstrumentation(ActiveInstrumentation instr) {
1153 mInstr = instr;
1154 mWindowProcessController.setInstrumenting(instr != null);
1155 }
1156
1157 ActiveInstrumentation getActiveInstrumentation() {
1158 return mInstr;
1159 }
1160
Wale Ogunwale31913b52018-10-13 08:29:31 -07001161 void setCurRawAdj(int curRawAdj) {
1162 mCurRawAdj = curRawAdj;
1163 mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
1164 }
1165
1166 int getCurRawAdj() {
1167 return mCurRawAdj;
1168 }
1169
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001170 @Override
1171 public void clearProfilerIfNeeded() {
1172 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001173 if (mService.mProfileData.getProfileProc() == null
1174 || mService.mProfileData.getProfilerInfo() == null
1175 || mService.mProfileData.getProfileProc() != this) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001176 return;
1177 }
1178 mService.clearProfilerLocked();
1179 }
1180 }
1181
1182 @Override
1183 public void updateServiceConnectionActivities() {
1184 synchronized (mService) {
1185 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1186 }
1187 }
1188
1189 @Override
1190 public void setPendingUiClean(boolean pendingUiClean) {
1191 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001192 mPendingUiClean = pendingUiClean;
1193 mWindowProcessController.setPendingUiClean(pendingUiClean);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001194 }
1195 }
1196
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001197 boolean hasPendingUiClean() {
1198 return mPendingUiClean;
1199 }
1200
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001201 @Override
1202 public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1203 synchronized (mService) {
Wale Ogunwale342fbe92018-10-09 08:44:10 -07001204 setPendingUiClean(true);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001205 forceProcessStateUpTo(newState);
1206 }
1207 }
1208
1209 @Override
1210 public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru,
1211 boolean activityChange, boolean updateOomAdj) {
1212 synchronized (mService) {
1213 if (updateServiceConnectionActivities) {
1214 mService.mServices.updateServiceConnectionActivitiesLocked(this);
1215 }
1216 if (updateLru) {
Amith Yamasani98a00922018-08-21 12:50:30 -04001217 mService.mProcessList.updateLruProcessLocked(this, activityChange, null);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001218 }
1219 if (updateOomAdj) {
1220 mService.updateOomAdjLocked();
1221 }
1222 }
1223 }
1224
1225 @Override
1226 public void setRemoved(boolean removed) {
1227 synchronized (mService) {
1228 this.removed = removed;
1229 }
1230 }
1231
Wale Ogunwale86b74462018-07-02 08:42:43 -07001232 /**
1233 * Returns the total time (in milliseconds) spent executing in both user and system code.
1234 * Safe to call without lock held.
1235 */
Wale Ogunwale9c103022018-10-18 07:44:54 -07001236 @Override
Wale Ogunwale86b74462018-07-02 08:42:43 -07001237 public long getCpuTime() {
1238 return mService.mProcessCpuTracker.getCpuTimeForPid(pid);
1239 }
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001240
Wale Ogunwale9c103022018-10-18 07:44:54 -07001241 @Override
1242 public void clearWaitingToKill() {
1243 synchronized (mService) {
1244 waitingToKill = null;
1245 }
1246 }
1247
1248 @Override
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001249 public void onStartActivity(int topProcessState, boolean setProfileProc) {
Wale Ogunwale9c103022018-10-18 07:44:54 -07001250 synchronized (mService) {
Wale Ogunwale1f5e53d2018-11-05 05:12:46 -08001251 if (setProfileProc) {
1252 mService.mProfileData.setProfileProc(this);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001253 }
1254
1255 hasShownUi = true;
1256 setPendingUiClean(true);
1257 forceProcessStateUpTo(topProcessState);
Wale Ogunwale9c103022018-10-18 07:44:54 -07001258 }
1259 }
1260
1261 @Override
1262 public void appDied() {
1263 synchronized (mService) {
1264 mService.appDiedLocked(this);
1265 }
1266 }
1267
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001268 public long getInputDispatchingTimeout() {
1269 return mWindowProcessController.getInputDispatchingTimeout();
1270 }
1271
Yang Lu732d6382018-11-05 07:53:12 -08001272 public int getProcessClassEnum() {
1273 if (pid == MY_PID) {
1274 return ServerProtoEnums.SYSTEM_SERVER;
1275 }
1276 if (info == null) {
1277 return ServerProtoEnums.ERROR_SOURCE_UNKNOWN;
1278 }
1279 return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP :
1280 ServerProtoEnums.DATA_APP;
1281 }
1282
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001283 void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo,
1284 String parentShortComponentName, WindowProcessController parentProcess,
1285 boolean aboveSystem, String annotation) {
1286 ArrayList<Integer> firstPids = new ArrayList<>(5);
1287 SparseArray<Boolean> lastPids = new SparseArray<>(20);
1288
Wale Ogunwalee2172292018-10-25 10:11:10 -07001289 mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true));
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001290
1291 long anrTime = SystemClock.uptimeMillis();
1292 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1293 mService.updateCpuStatsNow();
1294 }
1295
1296 // Unless configured otherwise, swallow ANRs in background processes & kill the process.
1297 boolean showBackground = Settings.Secure.getInt(mService.mContext.getContentResolver(),
1298 Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
1299
1300 boolean isSilentANR;
1301
1302 synchronized (mService) {
1303 // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
Wale Ogunwale387b34c2018-10-25 19:59:40 -07001304 if (mService.mAtmInternal.isShuttingDown()) {
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001305 Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation);
1306 return;
1307 } else if (isNotResponding()) {
1308 Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation);
1309 return;
1310 } else if (isCrashing()) {
1311 Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation);
1312 return;
1313 } else if (killedByAm) {
1314 Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation);
1315 return;
1316 } else if (killed) {
1317 Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation);
1318 return;
1319 }
1320
1321 // In case we come through here for the same app before completing
1322 // this one, mark as anring now so we will bail out.
1323 setNotResponding(true);
1324
1325 // Log the ANR to the event log.
1326 EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags,
1327 annotation);
1328
1329 // Dump thread traces as quickly as we can, starting with "interesting" processes.
1330 firstPids.add(pid);
1331
1332 // Don't dump other PIDs if it's a background ANR
1333 isSilentANR = !showBackground && !isInterestingForBackgroundTraces();
1334 if (!isSilentANR) {
1335 int parentPid = pid;
1336 if (parentProcess != null && parentProcess.getPid() > 0) {
1337 parentPid = parentProcess.getPid();
1338 }
1339 if (parentPid != pid) firstPids.add(parentPid);
1340
1341 if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID);
1342
Amith Yamasani98a00922018-08-21 12:50:30 -04001343 for (int i = mService.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
1344 ProcessRecord r = mService.mProcessList.mLruProcesses.get(i);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001345 if (r != null && r.thread != null) {
1346 int myPid = r.pid;
1347 if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) {
1348 if (r.isPersistent()) {
1349 firstPids.add(myPid);
1350 if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
1351 } else if (r.treatLikeActivity) {
1352 firstPids.add(myPid);
1353 if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
1354 } else {
1355 lastPids.put(myPid, Boolean.TRUE);
1356 if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
1357 }
1358 }
1359 }
1360 }
1361 }
1362 }
1363
1364 // Log the ANR to the main log.
1365 StringBuilder info = new StringBuilder();
1366 info.setLength(0);
1367 info.append("ANR in ").append(processName);
1368 if (activityShortComponentName != null) {
1369 info.append(" (").append(activityShortComponentName).append(")");
1370 }
1371 info.append("\n");
1372 info.append("PID: ").append(pid).append("\n");
1373 if (annotation != null) {
1374 info.append("Reason: ").append(annotation).append("\n");
1375 }
1376 if (parentShortComponentName != null
1377 && parentShortComponentName.equals(activityShortComponentName)) {
1378 info.append("Parent: ").append(parentShortComponentName).append("\n");
1379 }
1380
1381 ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
1382
1383 // don't dump native PIDs for background ANRs unless it is the process of interest
1384 String[] nativeProcs = null;
1385 if (isSilentANR) {
1386 for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) {
1387 if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) {
1388 nativeProcs = new String[] { processName };
1389 break;
1390 }
1391 }
1392 } else {
1393 nativeProcs = NATIVE_STACKS_OF_INTEREST;
1394 }
1395
1396 int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs);
1397 ArrayList<Integer> nativePids = null;
1398
1399 if (pids != null) {
1400 nativePids = new ArrayList<>(pids.length);
1401 for (int i : pids) {
1402 nativePids.add(i);
1403 }
1404 }
1405
1406 // For background ANRs, don't pass the ProcessCpuTracker to
1407 // avoid spending 1/2 second collecting stats to rank lastPids.
1408 File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
1409 (isSilentANR) ? null : processCpuTracker, (isSilentANR) ? null : lastPids,
1410 nativePids);
1411
1412 String cpuInfo = null;
1413 if (ActivityManagerService.MONITOR_CPU_USAGE) {
1414 mService.updateCpuStatsNow();
1415 synchronized (mService.mProcessCpuTracker) {
1416 cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime);
1417 }
1418 info.append(processCpuTracker.printCurrentLoad());
1419 info.append(cpuInfo);
1420 }
1421
1422 info.append(processCpuTracker.printCurrentState(anrTime));
1423
1424 Slog.e(TAG, info.toString());
1425 if (tracesFile == null) {
1426 // There is no trace file, so dump (only) the alleged culprit's threads to the log
1427 Process.sendSignal(pid, Process.SIGNAL_QUIT);
1428 }
1429
1430 StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName,
1431 activityShortComponentName == null ? "unknown": activityShortComponentName,
1432 annotation,
1433 (this.info != null) ? (this.info.isInstantApp()
1434 ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE
1435 : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE)
1436 : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE,
1437 isInterestingToUserLocked()
1438 ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
Yang Lu732d6382018-11-05 07:53:12 -08001439 : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
1440 getProcessClassEnum(),
1441 (this.info != null) ? this.info.packageName : "");
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001442 final ProcessRecord parentPr = parentProcess != null
1443 ? (ProcessRecord) parentProcess.mOwner : null;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001444 mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
Wale Ogunwale97b2b742018-10-18 08:08:54 -07001445 parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001446
Wale Ogunwalee2172292018-10-25 10:11:10 -07001447 if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true),
1448 () -> {
1449 synchronized (mService) {
1450 mService.mServices.scheduleServiceTimeoutLocked(this);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001451 }
Wale Ogunwalee2172292018-10-25 10:11:10 -07001452 })) {
1453 return;
Wale Ogunwale51cc98a2018-10-15 10:41:05 -07001454 }
1455
1456 synchronized (mService) {
1457 mService.mBatteryStatsService.noteProcessAnr(processName, uid);
1458
1459 if (isSilentANR) {
1460 kill("bg anr", true);
1461 return;
1462 }
1463
1464 // Set the app's notResponding state, and look up the errorReportReceiver
1465 makeAppNotRespondingLocked(activityShortComponentName,
1466 annotation != null ? "ANR " + annotation : "ANR", info.toString());
1467
1468 // Bring up the infamous App Not Responding dialog
1469 Message msg = Message.obtain();
1470 msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
1471 msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem);
1472
1473 mService.mUiHandler.sendMessage(msg);
1474 }
1475 }
1476
1477 private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) {
1478 setNotResponding(true);
1479 notRespondingReport = mService.mAppErrors.generateProcessError(this,
1480 ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
1481 activity, shortMsg, longMsg, null);
1482 startAppProblemLocked();
1483 getWindowProcessController().stopFreezingActivities();
1484 }
1485
1486 void startAppProblemLocked() {
1487 // If this app is not running under the current user, then we can't give it a report button
1488 // because that would require launching the report UI under a different user.
1489 errorReportReceiver = null;
1490
1491 for (int userId : mService.mUserController.getCurrentProfileIds()) {
1492 if (this.userId == userId) {
1493 errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
1494 mService.mContext, info.packageName, info.flags);
1495 }
1496 }
1497 mService.skipCurrentReceiverLocked(this);
1498 }
1499
1500 private boolean isInterestingForBackgroundTraces() {
1501 // The system_server is always considered interesting.
1502 if (pid == MY_PID) {
1503 return true;
1504 }
1505
1506 // A package is considered interesting if any of the following is true :
1507 //
1508 // - It's displaying an activity.
1509 // - It's the SystemUI.
1510 // - It has an overlay or a top UI visible.
1511 //
1512 // NOTE: The check whether a given ProcessRecord belongs to the systemui
1513 // process is a bit of a kludge, but the same pattern seems repeated at
1514 // several places in the system server.
1515 return isInterestingToUserLocked() ||
1516 (info != null && "com.android.systemui".equals(info.packageName))
1517 || (hasTopUi() || hasOverlayUi());
1518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519}