blob: dad383dff22f5cd152bb3d1c405fb157f5fb18b7 [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;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080020import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
21import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
22
Dianne Hackbornc8230512013-07-13 21:32:12 -070023import android.util.ArraySet;
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -080024import android.util.DebugUtils;
Dianne Hackborn89ad4562014-08-24 16:45:38 -070025import android.util.EventLog;
26import android.util.Slog;
Joe Onorato4eb64fd2016-03-21 15:30:09 -070027import com.android.internal.app.procstats.ProcessStats;
28import com.android.internal.app.procstats.ProcessState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import com.android.internal.os.BatteryStatsImpl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
31import android.app.ActivityManager;
32import android.app.Dialog;
33import android.app.IApplicationThread;
34import android.app.IInstrumentationWatcher;
Svetoslav Ganov80943d82013-01-02 10:25:37 -080035import android.app.IUiAutomationConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.ComponentName;
Dianne Hackbornc68c9132011-07-29 01:25:18 -070037import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.content.pm.ApplicationInfo;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040039import android.content.res.CompatibilityInfo;
Joe Onorato57190282016-04-20 15:37:49 -070040import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.Bundle;
42import android.os.IBinder;
Dianne Hackborna0c283e2012-02-09 10:47:01 -080043import android.os.Process;
Joe Onorato57190282016-04-20 15:37:49 -070044import android.os.RemoteException;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070045import android.os.SystemClock;
Yusuke Satocf4b2542015-06-17 00:21:28 -070046import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070047import android.os.UserHandle;
Dianne Hackborn390517b2013-05-30 15:03:32 -070048import android.util.ArrayMap;
Dianne Hackborn1655be42009-05-08 14:29:01 -070049import android.util.PrintWriterPrinter;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070050import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import java.io.PrintWriter;
53import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
55/**
56 * Full information about a particular process that
57 * is currently running.
58 */
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070059final class ProcessRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080060 private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
61
Adam Lesinski2cd3fb52013-11-18 12:23:26 -080062 private final BatteryStatsImpl mBatteryStats; // where to collect runtime statistics
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 final ApplicationInfo info; // all about the first app in the process
Dianne Hackborna0c283e2012-02-09 10:47:01 -080064 final boolean isolated; // true if this is a special isolated process
65 final int uid; // uid of process; may be different from 'info' if isolated
66 final int userId; // user of process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 final String processName; // name of the process
68 // List of packages running in the process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -070069 final ArrayMap<String, ProcessStats.ProcessStateHolder> pkgList = new ArrayMap<>();
70 UidRecord uidRecord; // overall state of process's uid.
Dianne Hackbornfee756f2014-07-16 17:31:10 -070071 ArraySet<String> pkgDeps; // additional packages we have a dependency on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 IApplicationThread thread; // the actual proc... may be null only if
73 // 'persistent' is true (in which case we
74 // are in the process of launching the app)
Joe Onorato4eb64fd2016-03-21 15:30:09 -070075 ProcessState baseProcessTracker;
Dianne Hackborn099bc622014-01-22 13:39:16 -080076 BatteryStatsImpl.Uid.Proc curProcBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 int pid; // The process of this application; 0 if none
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -070078 String procStatFile; // path to /proc/<pid>/stat
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -080079 int[] gids; // The gids this process was launched with
80 String requiredAbi; // The ABI this process was launched with
81 String instructionSet; // The instruction set this process was launched with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -080083 long lastActivityTime; // For managing the LRU list
Dianne Hackbornf1cca182013-08-01 10:50:28 -070084 long lastPssTime; // Last time we retrieved PSS data
85 long nextPssTime; // Next time we want to request PSS data
86 long lastStateTime; // Last time setProcState changed
Dianne Hackborn35f72be2013-09-16 10:57:39 -070087 long initialIdlePss; // Initial memory pss of process for idle maintenance.
88 long lastPss; // Last computed memory pss.
Thierry Strudelf0a44182016-01-07 18:08:04 -080089 long lastSwapPss; // Last computed SwapPss.
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -070090 long lastCachedPss; // Last computed pss when in cached state.
Thierry Strudelf0a44182016-01-07 18:08:04 -080091 long lastCachedSwapPss; // Last computed SwapPss when in cached state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 int maxAdj; // Maximum OOM adjustment for this process
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 int curRawAdj; // Current OOM unlimited adjustment for this process
94 int setRawAdj; // Last set OOM unlimited adjustment for this process
95 int curAdj; // Current OOM adjustment for this process
96 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -070097 int verifiedAdj; // The last adjustment that was verified as actually being set
Dianne Hackborn06de2ea2009-05-21 12:56:43 -070098 int curSchedGroup; // Currently desired scheduling class
99 int setSchedGroup; // Last set to background scheduling class
Srinath Sridharane535a582016-06-27 18:13:47 -0700100 int vrThreadTid; // Thread currently set for VR scheduling
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700101 int trimMemoryLevel; // Last selected memory trimming level
riddle_hsu6793fc32015-03-31 11:54:14 +0800102 int curProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
103 int repProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
104 int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
105 int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
Tim Murray33eb07f2016-06-10 10:03:20 -0700106 int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER
107 int renderThreadTid; // TID for RenderThread
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700108 boolean serviceb; // Process currently is on the service B list
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700109 boolean serviceHighRam; // We are forcing to service B list due to its RAM use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 boolean setIsForeground; // Running foreground UI when last set?
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700111 boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700112 boolean hasClientActivities; // Are there any client services with activities?
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700113 boolean hasStartedServices; // Are there any started services running in this process?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 boolean foregroundServices; // Running any services that are foreground?
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700115 boolean foregroundActivities; // Running any activities that are foreground?
Dianne Hackborn684bf342014-04-29 17:56:57 -0700116 boolean repForegroundActivities; // Last reported foreground activities.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700117 boolean systemNoUi; // This is a system process, but not currently showing UI.
Dianne Hackbornf0754f5b2011-07-21 16:02:07 -0700118 boolean hasShownUi; // Has UI been shown in this process since it was started?
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700119 boolean pendingUiClean; // Want to clean up resources from showing UI?
120 boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700121 boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 boolean bad; // True if disabled in the bad process list
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700123 boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
Dianne Hackbornd4125632014-09-22 12:52:49 -0700124 boolean killed; // True once we know the process has been killed
Dianne Hackbornc8230512013-07-13 21:32:12 -0700125 boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700126 boolean reportedInteraction;// Whether we have told usage stats about it being an interaction
Jeff Sharkeybd91e2f2016-03-22 15:32:31 -0600127 boolean unlocked; // True when proc was started in user unlocked state
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800128 long interactionEventTime; // The time we sent the last interaction event
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700129 long fgInteractionTime; // When we became foreground for interaction purposes
Dianne Hackborn9357b112013-10-03 18:27:48 -0700130 String waitingToKill; // Process is waiting to be killed when in the bg, and reason
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 IBinder forcingToForeground;// Token that is forcing this process to be foreground
Dianne Hackborn906497c2010-05-10 15:57:38 -0700132 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
133 int lruSeq; // Sequence id for identifying LRU update cycles
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700134 CompatibilityInfo compat; // last used compatibility mode
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700135 IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 ComponentName instrumentationClass;// class installed to instrument app
Dianne Hackborn1655be42009-05-08 14:29:01 -0700137 ApplicationInfo instrumentationInfo; // the application being instrumented
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 String instrumentationProfileFile; // where to save profiling
139 IInstrumentationWatcher instrumentationWatcher; // who is waiting
Svetoslav Ganov80943d82013-01-02 10:25:37 -0800140 IUiAutomationConnection instrumentationUiAutomationConnection; // Connection to use the UI introspection APIs.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 Bundle instrumentationArguments;// as given to us
142 ComponentName instrumentationResultClass;// copy of instrumentationClass
Jeff Brown3f9dd282011-07-08 20:02:19 -0700143 boolean usingWrapper; // Set to true when process was launched with a wrapper attached
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 BroadcastRecord curReceiver;// receiver currently running in the app
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700145 long lastWakeTime; // How long proc held wake lock at last check
Dianne Hackborn287952c2010-09-22 22:34:31 -0700146 long lastCpuTime; // How long proc has run CPU at last check
147 long curCpuTime; // How long proc has run CPU most recently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700149 long lastLowMemory; // When we last told the app that memory is low
Dianne Hackborn1a405642015-11-04 12:32:45 -0800150 long lastProviderTime; // The last time someone else was using a provider in this process.
Dianne Hackbornfd12af42009-08-27 00:44:33 -0700151 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800152 boolean empty; // Is this an empty background process?
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -0700153 boolean cached; // Is this a cached process?
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700154 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700155 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700156 Object adjSource; // Debugging: option dependent object.
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700157 int adjSourceProcState; // Debugging: proc state of adjSource's process.
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700158 Object adjTarget; // Debugging: target component impacting oom_adj.
Primiano Tucci810c0522014-07-25 18:03:16 +0100159 Runnable crashHandler; // Optional local handler to be invoked in the process crash.
160
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700161 // all activities running in the process
162 final ArrayList<ActivityRecord> activities = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 // all ServiceRecord running in this process
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700164 final ArraySet<ServiceRecord> services = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 // services that are currently executing code (need to remain foreground).
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700166 final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 // All ConnectionRecord this process holds
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700168 final ArraySet<ConnectionRecord> connections = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 // all IIntentReceivers that are registered from this process.
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700170 final ArraySet<ReceiverList> receivers = new ArraySet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 // class (String) -> ContentProviderRecord
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700172 final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 // All ContentProviderRecord process is using
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700174 final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700175
176 boolean execServicesFg; // do we need to be executing services in the foreground?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 boolean persistent; // always keep this application running?
178 boolean crashing; // are we in the process of crashing?
179 Dialog crashDialog; // dialog being displayed due to crash.
Christopher Tate58d380d2013-03-19 13:10:03 -0700180 boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 boolean notResponding; // does the app have a not responding dialog?
182 Dialog anrDialog; // dialog being displayed due to app not resp.
183 boolean removed; // has app package been removed from device?
184 boolean debugging; // was app launched for debugging?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 boolean waitedForDebugger; // has process show wait for debugger dialog?
186 Dialog waitDialog; // current wait for debugger dialog
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700187
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800188 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700189 String stringName; // caching of toString() result.
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 // These reports are generated & stored when an app gets into an error condition.
192 // They will be "null" when all is OK.
193 ActivityManager.ProcessErrorStateInfo crashingReport;
194 ActivityManager.ProcessErrorStateInfo notRespondingReport;
195
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200196 // Who will be notified of the error. This is usually an activity in the
197 // app that installed the package.
198 ComponentName errorReportReceiver;
199
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700200 // Process is currently hosting a backup agent for backup or restore
201 public boolean inFullBackup;
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700202 // App is allowed to manage whitelists such as temporary Power Save mode whitelist.
203 boolean whitelistManager;
Amith Yamasanib5f3b5c2016-05-16 14:23:04 -0700204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700206 final long now = SystemClock.uptimeMillis();
207
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800208 pw.print(prefix); pw.print("user #"); pw.print(userId);
209 pw.print(" uid="); pw.print(info.uid);
210 if (uid != info.uid) {
211 pw.print(" ISOLATED uid="); pw.print(uid);
212 }
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800213 pw.print(" gids={");
214 if (gids != null) {
215 for (int gi=0; gi<gids.length; gi++) {
216 if (gi != 0) pw.print(", ");
217 pw.print(gids[gi]);
218
219 }
220 }
221 pw.println("}");
222 pw.print(prefix); pw.print("requiredAbi="); pw.print(requiredAbi);
223 pw.print(" instructionSet="); pw.println(instructionSet);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700224 if (info.className != null) {
225 pw.print(prefix); pw.print("class="); pw.println(info.className);
226 }
227 if (info.manageSpaceActivityName != null) {
228 pw.print(prefix); pw.print("manageSpaceActivityName=");
229 pw.println(info.manageSpaceActivityName);
230 }
231 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
232 pw.print(" publicDir="); pw.print(info.publicSourceDir);
233 pw.print(" data="); pw.println(info.dataDir);
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700234 pw.print(prefix); pw.print("packageList={");
235 for (int i=0; i<pkgList.size(); i++) {
236 if (i > 0) pw.print(", ");
237 pw.print(pkgList.keyAt(i));
238 }
239 pw.println("}");
Dianne Hackbornfee756f2014-07-16 17:31:10 -0700240 if (pkgDeps != null) {
241 pw.print(prefix); pw.print("packageDependencies={");
242 for (int i=0; i<pkgDeps.size(); i++) {
243 if (i > 0) pw.print(", ");
244 pw.print(pkgDeps.valueAt(i));
245 }
246 pw.println("}");
247 }
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700248 pw.print(prefix); pw.print("compat="); pw.println(compat);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700249 if (instrumentationClass != null || instrumentationProfileFile != null
250 || instrumentationArguments != null) {
251 pw.print(prefix); pw.print("instrumentationClass=");
252 pw.print(instrumentationClass);
253 pw.print(" instrumentationProfileFile=");
254 pw.println(instrumentationProfileFile);
255 pw.print(prefix); pw.print("instrumentationArguments=");
256 pw.println(instrumentationArguments);
Dianne Hackborn1655be42009-05-08 14:29:01 -0700257 pw.print(prefix); pw.print("instrumentationInfo=");
258 pw.println(instrumentationInfo);
259 if (instrumentationInfo != null) {
260 instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
261 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700262 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700263 pw.print(prefix); pw.print("thread="); pw.println(thread);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700264 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700265 pw.println(starting);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700266 pw.print(prefix); pw.print("lastActivityTime=");
267 TimeUtils.formatDuration(lastActivityTime, now, pw);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700268 pw.print(" lastPssTime=");
269 TimeUtils.formatDuration(lastPssTime, now, pw);
270 pw.print(" nextPssTime=");
271 TimeUtils.formatDuration(nextPssTime, now, pw);
272 pw.println();
273 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
274 pw.print(" lruSeq="); pw.print(lruSeq);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800275 pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800276 pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800277 pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024);
Thierry Strudelf0a44182016-01-07 18:08:04 -0800278 pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024);
Dianne Hackbornb9a5e4a2015-03-03 17:04:12 -0800279 pw.println();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700280 pw.print(prefix); pw.print("cached="); pw.print(cached);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800281 pw.print(" empty="); pw.println(empty);
Dianne Hackborncbd9a522013-09-24 23:10:14 -0700282 if (serviceb) {
283 pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
284 pw.print(" serviceHighRam="); pw.println(serviceHighRam);
285 }
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700286 if (notCachedSinceIdle) {
287 pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle);
Dianne Hackborn3bc8f78d2013-09-19 13:34:35 -0700288 pw.print(" initialIdlePss="); pw.println(initialIdlePss);
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700289 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700290 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700291 pw.print(" curRaw="); pw.print(curRawAdj);
292 pw.print(" setRaw="); pw.print(setRawAdj);
293 pw.print(" cur="); pw.print(curAdj);
294 pw.print(" set="); pw.println(setAdj);
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700295 pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700296 pw.print(" setSchedGroup="); pw.print(setSchedGroup);
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700297 pw.print(" systemNoUi="); pw.print(systemNoUi);
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700298 pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
Srinath Sridharane535a582016-06-27 18:13:47 -0700299 pw.print(prefix); pw.print("vrThreadTid="); pw.print(vrThreadTid);
Dianne Hackborna413dc02013-07-12 12:02:55 -0700300 pw.print(prefix); pw.print("curProcState="); pw.print(curProcState);
Dianne Hackbornc8230512013-07-13 21:32:12 -0700301 pw.print(" repProcState="); pw.print(repProcState);
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700302 pw.print(" pssProcState="); pw.print(pssProcState);
303 pw.print(" setProcState="); pw.print(setProcState);
304 pw.print(" lastStateTime=");
305 TimeUtils.formatDuration(lastStateTime, now, pw);
306 pw.println();
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700307 if (hasShownUi || pendingUiClean || hasAboveClient || treatLikeActivity) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700308 pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi);
309 pw.print(" pendingUiClean="); pw.print(pendingUiClean);
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700310 pw.print(" hasAboveClient="); pw.print(hasAboveClient);
311 pw.print(" treatLikeActivity="); pw.println(treatLikeActivity);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700312 }
313 if (setIsForeground || foregroundServices || forcingToForeground != null) {
314 pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground);
315 pw.print(" foregroundServices="); pw.print(foregroundServices);
316 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
317 }
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700318 if (reportedInteraction || fgInteractionTime != 0) {
319 pw.print(prefix); pw.print("reportedInteraction=");
320 pw.print(reportedInteraction);
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800321 if (interactionEventTime != 0) {
322 pw.print(" time=");
323 TimeUtils.formatDuration(interactionEventTime, SystemClock.elapsedRealtime(), pw);
324 }
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700325 if (fgInteractionTime != 0) {
326 pw.print(" fgInteractionTime=");
327 TimeUtils.formatDuration(fgInteractionTime, SystemClock.elapsedRealtime(), pw);
328 }
329 pw.println();
330 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700331 if (persistent || removed) {
332 pw.print(prefix); pw.print("persistent="); pw.print(persistent);
333 pw.print(" removed="); pw.println(removed);
334 }
Dianne Hackborn684bf342014-04-29 17:56:57 -0700335 if (hasClientActivities || foregroundActivities || repForegroundActivities) {
Dianne Hackborndb926082013-10-31 16:32:44 -0700336 pw.print(prefix); pw.print("hasClientActivities="); pw.print(hasClientActivities);
Dianne Hackborn684bf342014-04-29 17:56:57 -0700337 pw.print(" foregroundActivities="); pw.print(foregroundActivities);
338 pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")");
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700339 }
Dianne Hackborn1a405642015-11-04 12:32:45 -0800340 if (lastProviderTime > 0) {
341 pw.print(prefix); pw.print("lastProviderTime=");
342 TimeUtils.formatDuration(lastProviderTime, now, pw);
343 pw.println();
344 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700345 if (hasStartedServices) {
346 pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices);
347 }
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700348 if (setProcState >= ActivityManager.PROCESS_STATE_SERVICE) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700349 long wtime;
Adam Lesinski2cd3fb52013-11-18 12:23:26 -0800350 synchronized (mBatteryStats) {
351 wtime = mBatteryStats.getProcessWakeTime(info.uid,
Dianne Hackborn287952c2010-09-22 22:34:31 -0700352 pid, SystemClock.elapsedRealtime());
353 }
Dianne Hackborn287952c2010-09-22 22:34:31 -0700354 pw.print(prefix); pw.print("lastWakeTime="); pw.print(lastWakeTime);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700355 pw.print(" timeUsed=");
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700356 TimeUtils.formatDuration(wtime-lastWakeTime, pw); pw.println("");
Dianne Hackborn287952c2010-09-22 22:34:31 -0700357 pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime);
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700358 pw.print(" timeUsed=");
Dianne Hackborn287952c2010-09-22 22:34:31 -0700359 TimeUtils.formatDuration(curCpuTime-lastCpuTime, pw); pw.println("");
360 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -0700361 pw.print(prefix); pw.print("lastRequestedGc=");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700362 TimeUtils.formatDuration(lastRequestedGc, now, pw);
363 pw.print(" lastLowMemory=");
364 TimeUtils.formatDuration(lastLowMemory, now, pw);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700365 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackbornd4125632014-09-22 12:52:49 -0700366 if (killed || killedByAm || waitingToKill != null) {
367 pw.print(prefix); pw.print("killed="); pw.print(killed);
368 pw.print(" killedByAm="); pw.print(killedByAm);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700369 pw.print(" waitingToKill="); pw.println(waitingToKill);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700370 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700371 if (debugging || crashing || crashDialog != null || notResponding
372 || anrDialog != null || bad) {
373 pw.print(prefix); pw.print("debugging="); pw.print(debugging);
374 pw.print(" crashing="); pw.print(crashing);
375 pw.print(" "); pw.print(crashDialog);
376 pw.print(" notResponding="); pw.print(notResponding);
377 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200378 pw.print(" bad="); pw.print(bad);
379
380 // crashing or notResponding is always set before errorReportReceiver
381 if (errorReportReceiver != null) {
382 pw.print(" errorReportReceiver=");
383 pw.print(errorReportReceiver.flattenToShortString());
384 }
385 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700386 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700387 if (whitelistManager) {
388 pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager);
389 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700390 if (activities.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700391 pw.print(prefix); pw.println("Activities:");
392 for (int i=0; i<activities.size(); i++) {
393 pw.print(prefix); pw.print(" - "); pw.println(activities.get(i));
394 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700395 }
396 if (services.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700397 pw.print(prefix); pw.println("Services:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700398 for (int i=0; i<services.size(); i++) {
399 pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700400 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700401 }
402 if (executingServices.size() > 0) {
Dianne Hackbornbf36ee22013-07-26 18:24:10 -0700403 pw.print(prefix); pw.print("Executing Services (fg=");
404 pw.print(execServicesFg); pw.println(")");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700405 for (int i=0; i<executingServices.size(); i++) {
406 pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700407 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700408 }
409 if (connections.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700410 pw.print(prefix); pw.println("Connections:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700411 for (int i=0; i<connections.size(); i++) {
412 pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700413 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700414 }
415 if (pubProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700416 pw.print(prefix); pw.println("Published Providers:");
Dianne Hackborn390517b2013-05-30 15:03:32 -0700417 for (int i=0; i<pubProviders.size(); i++) {
418 pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i));
419 pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700420 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700421 }
422 if (conProviders.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700423 pw.print(prefix); pw.println("Connected Providers:");
424 for (int i=0; i<conProviders.size(); i++) {
425 pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString());
426 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700427 }
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700428 if (curReceiver != null) {
429 pw.print(prefix); pw.print("curReceiver="); pw.println(curReceiver);
430 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700431 if (receivers.size() > 0) {
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700432 pw.print(prefix); pw.println("Receivers:");
Dianne Hackbornc8230512013-07-13 21:32:12 -0700433 for (int i=0; i<receivers.size(); i++) {
434 pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i));
Dianne Hackborn6ae8d182012-05-23 13:12:42 -0700435 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700438
Adam Lesinski2cd3fb52013-11-18 12:23:26 -0800439 ProcessRecord(BatteryStatsImpl _batteryStats, ApplicationInfo _info,
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700440 String _processName, int _uid) {
Adam Lesinski2cd3fb52013-11-18 12:23:26 -0800441 mBatteryStats = _batteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 info = _info;
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800443 isolated = _info.uid != _uid;
444 uid = _uid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700445 userId = UserHandle.getUserId(_uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 processName = _processName;
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700447 pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.versionCode));
Dianne Hackbornc8230512013-07-13 21:32:12 -0700448 maxAdj = ProcessList.UNKNOWN_ADJ;
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700449 curRawAdj = setRawAdj = ProcessList.INVALID_ADJ;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700450 curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 persistent = false;
452 removed = false;
Dianne Hackbornf1cca182013-08-01 10:50:28 -0700453 lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 }
455
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700456 public void setPid(int _pid) {
457 pid = _pid;
Dianne Hackborn4de5a3a2016-06-20 15:20:15 -0700458 procStatFile = null;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800459 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700460 stringName = null;
461 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700462
463 public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
464 if (thread == null) {
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700465 final ProcessState origBase = baseProcessTracker;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700466 if (origBase != null) {
467 origBase.setState(ProcessStats.STATE_NOTHING,
468 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList);
469 origBase.makeInactive();
470 }
Ronnie Leng4c5c6f42015-03-25 10:57:24 -0500471 baseProcessTracker = tracker.getProcessStateLocked(info.packageName, uid,
Dianne Hackborn8472e612014-01-23 17:57:20 -0800472 info.versionCode, processName);
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700473 baseProcessTracker.makeActive();
474 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700475 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
476 if (holder.state != null && holder.state != origBase) {
477 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700478 }
Ronnie Leng4c5c6f42015-03-25 10:57:24 -0500479 holder.state = tracker.getProcessStateLocked(pkgList.keyAt(i), uid,
Dianne Hackborn8472e612014-01-23 17:57:20 -0800480 info.versionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700481 if (holder.state != baseProcessTracker) {
482 holder.state.makeActive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700483 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700484 }
485 }
486 thread = _thread;
487 }
488
489 public void makeInactive(ProcessStatsService tracker) {
Dianne Hackborn53459a72013-09-17 17:14:57 -0700490 thread = null;
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700491 final ProcessState origBase = baseProcessTracker;
Dianne Hackborn53459a72013-09-17 17:14:57 -0700492 if (origBase != null) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700493 if (origBase != null) {
494 origBase.setState(ProcessStats.STATE_NOTHING,
495 tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList);
496 origBase.makeInactive();
497 }
498 baseProcessTracker = null;
499 for (int i=0; i<pkgList.size(); i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700500 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
501 if (holder.state != null && holder.state != origBase) {
502 holder.state.makeInactive();
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700503 }
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700504 holder.state = null;
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700505 }
506 }
507 }
508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 /**
510 * This method returns true if any of the activities within the process record are interesting
511 * to the user. See HistoryRecord.isInterestingToUserLocked()
512 */
513 public boolean isInterestingToUserLocked() {
514 final int size = activities.size();
515 for (int i = 0 ; i < size ; i++) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700516 ActivityRecord r = activities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 if (r.isInterestingToUserLocked()) {
518 return true;
519 }
520 }
521 return false;
522 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 public void stopFreezingAllLocked() {
525 int i = activities.size();
526 while (i > 0) {
527 i--;
Dianne Hackborn860755f2010-06-03 18:47:52 -0700528 activities.get(i).stopFreezingScreenLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 }
530 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800531
Dianne Hackborn1b64e0d2011-07-17 15:23:59 -0700532 public void unlinkDeathRecipient() {
533 if (deathRecipient != null && thread != null) {
534 thread.asBinder().unlinkToDeath(deathRecipient, 0);
535 }
536 deathRecipient = null;
537 }
538
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700539 void updateHasAboveClientLocked() {
540 hasAboveClient = false;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700541 for (int i=connections.size()-1; i>=0; i--) {
542 ConnectionRecord cr = connections.valueAt(i);
543 if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) {
544 hasAboveClient = true;
545 break;
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700546 }
547 }
548 }
549
Dianne Hackbornc8230512013-07-13 21:32:12 -0700550 int modifyRawOomAdj(int adj) {
551 if (hasAboveClient) {
552 // If this process has bound to any services with BIND_ABOVE_CLIENT,
553 // then we need to drop its adjustment to be lower than the service's
554 // in order to honor the request. We want to drop it by one adjustment
555 // level... but there is special meaning applied to various levels so
556 // we will skip some of them.
557 if (adj < ProcessList.FOREGROUND_APP_ADJ) {
558 // System process will not get dropped, ever
559 } else if (adj < ProcessList.VISIBLE_APP_ADJ) {
560 adj = ProcessList.VISIBLE_APP_ADJ;
561 } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) {
562 adj = ProcessList.PERCEPTIBLE_APP_ADJ;
563 } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
564 adj = ProcessList.CACHED_APP_MIN_ADJ;
565 } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) {
566 adj++;
567 }
568 }
569 return adj;
570 }
571
Joe Onorato57190282016-04-20 15:37:49 -0700572 void scheduleCrash(String message) {
573 // Checking killedbyAm should keep it from showing the crash dialog if the process
574 // was already dead for a good / normal reason.
575 if (!killedByAm) {
576 if (thread != null) {
577 if (pid == Process.myPid()) {
578 Slog.w(TAG, "scheduleCrash: trying to crash system process!");
579 return;
580 }
581 long ident = Binder.clearCallingIdentity();
582 try {
583 thread.scheduleCrash(message);
584 } catch (RemoteException e) {
585 // If it's already dead our work is done. If it's wedged just kill it.
586 // We won't get the crash dialog or the error reporting.
587 kill("scheduleCrash for '" + message + "' failed", true);
588 } finally {
589 Binder.restoreCallingIdentity(ident);
590 }
591 }
592 }
593 }
594
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700595 void kill(String reason, boolean noisy) {
596 if (!killedByAm) {
Yusuke Satocf4b2542015-06-17 00:21:28 -0700597 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700598 if (noisy) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800599 Slog.i(TAG, "Killing " + toShortString() + " (adj " + setAdj + "): " + reason);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700600 }
601 EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
602 Process.killProcessQuiet(pid);
Christopher Tateea33b942016-03-29 15:55:45 -0700603 ActivityManagerService.killProcessGroup(uid, pid);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700604 if (!persistent) {
Dianne Hackbornd4125632014-09-22 12:52:49 -0700605 killed = true;
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700606 killedByAm = true;
607 }
Yusuke Satocf4b2542015-06-17 00:21:28 -0700608 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
Dianne Hackborn89ad4562014-08-24 16:45:38 -0700609 }
610 }
611
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800612 public String toShortString() {
613 if (shortStringName != null) {
614 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700615 }
616 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800617 toShortString(sb);
618 return shortStringName = sb.toString();
619 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700620
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800621 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700622 sb.append(pid);
623 sb.append(':');
624 sb.append(processName);
625 sb.append('/');
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800626 if (info.uid < Process.FIRST_APPLICATION_UID) {
627 sb.append(uid);
628 } else {
629 sb.append('u');
630 sb.append(userId);
Dianne Hackborna4cc2052013-07-08 17:31:25 -0700631 int appId = UserHandle.getAppId(info.uid);
632 if (appId >= Process.FIRST_APPLICATION_UID) {
633 sb.append('a');
634 sb.append(appId - Process.FIRST_APPLICATION_UID);
635 } else {
636 sb.append('s');
637 sb.append(appId);
638 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800639 if (uid != info.uid) {
640 sb.append('i');
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700641 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
Dianne Hackborna0c283e2012-02-09 10:47:01 -0800642 }
643 }
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800644 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700645
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800646 public String toString() {
647 if (stringName != null) {
648 return stringName;
649 }
650 StringBuilder sb = new StringBuilder(128);
651 sb.append("ProcessRecord{");
Dianne Hackbornce86ba82011-07-13 19:33:41 -0700652 sb.append(Integer.toHexString(System.identityHashCode(this)));
653 sb.append(' ');
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800654 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700655 sb.append('}');
656 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 }
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700658
659 public String makeAdjReason() {
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700660 if (adjSource != null || adjTarget != null) {
Dianne Hackborn8e692572013-09-10 19:06:15 -0700661 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700662 sb.append(' ');
663 if (adjTarget instanceof ComponentName) {
664 sb.append(((ComponentName)adjTarget).flattenToShortString());
665 } else if (adjTarget != null) {
666 sb.append(adjTarget.toString());
667 } else {
668 sb.append("{null}");
669 }
670 sb.append("<=");
671 if (adjSource instanceof ProcessRecord) {
672 sb.append("Proc{");
673 sb.append(((ProcessRecord)adjSource).toShortString());
674 sb.append("}");
675 } else if (adjSource != null) {
676 sb.append(adjSource.toString());
677 } else {
678 sb.append("{null}");
679 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700680 return sb.toString();
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700681 }
Dianne Hackborn8e692572013-09-10 19:06:15 -0700682 return null;
Dianne Hackborn9210bc82013-09-05 12:31:16 -0700683 }
684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 /*
686 * Return true if package has been added false if not
687 */
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700688 public boolean addPackage(String pkg, int versionCode, ProcessStatsService tracker) {
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700689 if (!pkgList.containsKey(pkg)) {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700690 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
691 versionCode);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700692 if (baseProcessTracker != null) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700693 holder.state = tracker.getProcessStateLocked(
Ronnie Leng4c5c6f42015-03-25 10:57:24 -0500694 pkg, uid, versionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700695 pkgList.put(pkg, holder);
696 if (holder.state != baseProcessTracker) {
697 holder.state.makeActive();
Dianne Hackborn53459a72013-09-17 17:14:57 -0700698 }
699 } else {
Dianne Hackborn3251b902014-06-20 14:40:53 -0700700 pkgList.put(pkg, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 return true;
703 }
704 return false;
705 }
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700706
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700707 public int getSetAdjWithServices() {
Dianne Hackborn20cdcee2013-07-10 18:47:04 -0700708 if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
709 if (hasStartedServices) {
710 return ProcessList.SERVICE_B_ADJ;
711 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700712 }
713 return setAdj;
714 }
715
Dianne Hackborna413dc02013-07-12 12:02:55 -0700716 public void forceProcessStateUpTo(int newState) {
717 if (repProcState > newState) {
718 curProcState = repProcState = newState;
719 }
720 }
721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 /*
723 * Delete all packages from list except the package indicated in info
724 */
Dianne Hackbornd2932242013-08-05 18:18:42 -0700725 public void resetPackageList(ProcessStatsService tracker) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700726 final int N = pkgList.size();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700727 if (baseProcessTracker != null) {
728 long now = SystemClock.uptimeMillis();
729 baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
730 tracker.getMemFactorLocked(), now, pkgList);
731 if (N != 1) {
732 for (int i=0; i<N; i++) {
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700733 ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
734 if (holder.state != null && holder.state != baseProcessTracker) {
735 holder.state.makeInactive();
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700736 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700737
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700738 }
739 pkgList.clear();
Joe Onorato4eb64fd2016-03-21 15:30:09 -0700740 ProcessState ps = tracker.getProcessStateLocked(
Ronnie Leng4c5c6f42015-03-25 10:57:24 -0500741 info.packageName, uid, info.versionCode, processName);
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700742 ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
743 info.versionCode);
744 holder.state = ps;
745 pkgList.put(info.packageName, holder);
Dianne Hackborn53459a72013-09-17 17:14:57 -0700746 if (ps != baseProcessTracker) {
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700747 ps.makeActive();
748 }
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -0700749 }
Dianne Hackborne56c2c32013-09-17 10:56:49 -0700750 } else if (N != 1) {
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700751 pkgList.clear();
Dianne Hackbornf7097a52014-05-13 09:56:14 -0700752 pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.versionCode));
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700753 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 }
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 public String[] getPackageList() {
757 int size = pkgList.size();
758 if (size == 0) {
759 return null;
760 }
761 String list[] = new String[size];
Dianne Hackborn78a369c2013-06-11 17:10:32 -0700762 for (int i=0; i<pkgList.size(); i++) {
763 list[i] = pkgList.keyAt(i);
764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 return list;
766 }
767}