blob: 9dda1df86536c45f6e4b0fcdd210f87b99b39feb [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
19import com.android.internal.os.BatteryStatsImpl;
20import com.android.server.Watchdog;
21
22import android.app.ActivityManager;
23import android.app.Dialog;
24import android.app.IApplicationThread;
25import android.app.IInstrumentationWatcher;
26import android.content.ComponentName;
27import android.content.pm.ApplicationInfo;
28import android.os.Bundle;
29import android.os.IBinder;
30import android.os.RemoteException;
Dianne Hackborn1655be42009-05-08 14:29:01 -070031import android.util.PrintWriterPrinter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
33import java.io.PrintWriter;
34import java.util.ArrayList;
35import java.util.HashMap;
36import java.util.HashSet;
37
38/**
39 * Full information about a particular process that
40 * is currently running.
41 */
42class ProcessRecord implements Watchdog.PssRequestor {
43 final BatteryStatsImpl.Uid.Proc batteryStats; // where to collect runtime statistics
44 final ApplicationInfo info; // all about the first app in the process
45 final String processName; // name of the process
46 // List of packages running in the process
Dianne Hackborn860755f2010-06-03 18:47:52 -070047 final HashSet<String> pkgList = new HashSet<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 IApplicationThread thread; // the actual proc... may be null only if
49 // 'persistent' is true (in which case we
50 // are in the process of launching the app)
51 int pid; // The process of this application; 0 if none
52 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -080053 long lastActivityTime; // For managing the LRU list
54 long lruWeight; // Weight for ordering in LRU list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 int maxAdj; // Maximum OOM adjustment for this process
56 int hiddenAdj; // If hidden, this is the adjustment to use
57 int curRawAdj; // Current OOM unlimited adjustment for this process
58 int setRawAdj; // Last set OOM unlimited adjustment for this process
59 int curAdj; // Current OOM adjustment for this process
60 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn06de2ea2009-05-21 12:56:43 -070061 int curSchedGroup; // Currently desired scheduling class
62 int setSchedGroup; // Last set to background scheduling class
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 boolean setIsForeground; // Running foreground UI when last set?
64 boolean foregroundServices; // Running any services that are foreground?
65 boolean bad; // True if disabled in the bad process list
Dianne Hackborn149427c2010-04-23 14:20:03 -070066 boolean killedBackground; // True when proc has been killed due to too many bg
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 IBinder forcingToForeground;// Token that is forcing this process to be foreground
Dianne Hackborn906497c2010-05-10 15:57:38 -070068 int adjSeq; // Sequence id for identifying oom_adj assignment cycles
69 int lruSeq; // Sequence id for identifying LRU update cycles
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 ComponentName instrumentationClass;// class installed to instrument app
Dianne Hackborn1655be42009-05-08 14:29:01 -070071 ApplicationInfo instrumentationInfo; // the application being instrumented
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 String instrumentationProfileFile; // where to save profiling
73 IInstrumentationWatcher instrumentationWatcher; // who is waiting
74 Bundle instrumentationArguments;// as given to us
75 ComponentName instrumentationResultClass;// copy of instrumentationClass
76 BroadcastRecord curReceiver;// receiver currently running in the app
77 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -070078 long lastLowMemory; // When we last told the app that memory is low
79 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -080080 boolean empty; // Is this an empty background process?
81 boolean hidden; // Is this a hidden process?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 int lastPss; // Last pss size reported by app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070083 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070084 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070085 Object adjSource; // Debugging: option dependent object.
86 Object adjTarget; // Debugging: target component impacting oom_adj.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
88 // contains HistoryRecord objects
Dianne Hackborn860755f2010-06-03 18:47:52 -070089 final ArrayList<HistoryRecord> activities = new ArrayList<HistoryRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 // all ServiceRecord running in this process
Dianne Hackborn860755f2010-06-03 18:47:52 -070091 final HashSet<ServiceRecord> services = new HashSet<ServiceRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 // services that are currently executing code (need to remain foreground).
93 final HashSet<ServiceRecord> executingServices
94 = new HashSet<ServiceRecord>();
95 // All ConnectionRecord this process holds
96 final HashSet<ConnectionRecord> connections
97 = new HashSet<ConnectionRecord>();
98 // all IIntentReceivers that are registered from this process.
99 final HashSet<ReceiverList> receivers = new HashSet<ReceiverList>();
100 // class (String) -> ContentProviderRecord
Dianne Hackborn860755f2010-06-03 18:47:52 -0700101 final HashMap<String, ContentProviderRecord> pubProviders
102 = new HashMap<String, ContentProviderRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 // All ContentProviderRecord process is using
Dianne Hackborn0c3154d2009-10-06 17:18:05 -0700104 final HashMap<ContentProviderRecord, Integer> conProviders
105 = new HashMap<ContentProviderRecord, Integer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106
107 boolean persistent; // always keep this application running?
108 boolean crashing; // are we in the process of crashing?
109 Dialog crashDialog; // dialog being displayed due to crash.
110 boolean notResponding; // does the app have a not responding dialog?
111 Dialog anrDialog; // dialog being displayed due to app not resp.
112 boolean removed; // has app package been removed from device?
113 boolean debugging; // was app launched for debugging?
114 int persistentActivities; // number of activities that are persistent
115 boolean waitedForDebugger; // has process show wait for debugger dialog?
116 Dialog waitDialog; // current wait for debugger dialog
117
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800118 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700119 String stringName; // caching of toString() result.
120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 // These reports are generated & stored when an app gets into an error condition.
122 // They will be "null" when all is OK.
123 ActivityManager.ProcessErrorStateInfo crashingReport;
124 ActivityManager.ProcessErrorStateInfo notRespondingReport;
125
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200126 // Who will be notified of the error. This is usually an activity in the
127 // app that installed the package.
128 ComponentName errorReportReceiver;
129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700131 if (info.className != null) {
132 pw.print(prefix); pw.print("class="); pw.println(info.className);
133 }
134 if (info.manageSpaceActivityName != null) {
135 pw.print(prefix); pw.print("manageSpaceActivityName=");
136 pw.println(info.manageSpaceActivityName);
137 }
138 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
139 pw.print(" publicDir="); pw.print(info.publicSourceDir);
140 pw.print(" data="); pw.println(info.dataDir);
141 pw.print(prefix); pw.print("packageList="); pw.println(pkgList);
142 if (instrumentationClass != null || instrumentationProfileFile != null
143 || instrumentationArguments != null) {
144 pw.print(prefix); pw.print("instrumentationClass=");
145 pw.print(instrumentationClass);
146 pw.print(" instrumentationProfileFile=");
147 pw.println(instrumentationProfileFile);
148 pw.print(prefix); pw.print("instrumentationArguments=");
149 pw.println(instrumentationArguments);
Dianne Hackborn1655be42009-05-08 14:29:01 -0700150 pw.print(prefix); pw.print("instrumentationInfo=");
151 pw.println(instrumentationInfo);
152 if (instrumentationInfo != null) {
153 instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
154 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700155 }
156 pw.print(prefix); pw.print("thread="); pw.print(thread);
157 pw.print(" curReceiver="); pw.println(curReceiver);
158 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
159 pw.print(starting); pw.print(" lastPss="); pw.println(lastPss);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800160 pw.print(prefix); pw.print("lastActivityTime="); pw.print(lastActivityTime);
161 pw.print(" lruWeight="); pw.println(lruWeight);
162 pw.print(" hidden="); pw.print(hidden);
163 pw.print(" empty="); pw.println(empty);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700164 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
165 pw.print(" hidden="); pw.print(hiddenAdj);
166 pw.print(" curRaw="); pw.print(curRawAdj);
167 pw.print(" setRaw="); pw.print(setRawAdj);
168 pw.print(" cur="); pw.print(curAdj);
169 pw.print(" set="); pw.println(setAdj);
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700170 pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
171 pw.print(" setSchedGroup="); pw.println(setSchedGroup);
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700172 pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700173 pw.print(" foregroundServices="); pw.print(foregroundServices);
174 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
175 pw.print(prefix); pw.print("persistent="); pw.print(persistent);
176 pw.print(" removed="); pw.print(removed);
177 pw.print(" persistentActivities="); pw.println(persistentActivities);
Dianne Hackborn906497c2010-05-10 15:57:38 -0700178 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
179 pw.print(" lruSeq="); pw.println(lruSeq);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700180 if (killedBackground) {
181 pw.print(prefix); pw.print("killedBackground="); pw.println(killedBackground);
182 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700183 if (debugging || crashing || crashDialog != null || notResponding
184 || anrDialog != null || bad) {
185 pw.print(prefix); pw.print("debugging="); pw.print(debugging);
186 pw.print(" crashing="); pw.print(crashing);
187 pw.print(" "); pw.print(crashDialog);
188 pw.print(" notResponding="); pw.print(notResponding);
189 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200190 pw.print(" bad="); pw.print(bad);
191
192 // crashing or notResponding is always set before errorReportReceiver
193 if (errorReportReceiver != null) {
194 pw.print(" errorReportReceiver=");
195 pw.print(errorReportReceiver.flattenToShortString());
196 }
197 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700198 }
199 if (activities.size() > 0) {
200 pw.print(prefix); pw.print("activities="); pw.println(activities);
201 }
202 if (services.size() > 0) {
203 pw.print(prefix); pw.print("services="); pw.println(services);
204 }
205 if (executingServices.size() > 0) {
206 pw.print(prefix); pw.print("executingServices="); pw.println(executingServices);
207 }
208 if (connections.size() > 0) {
209 pw.print(prefix); pw.print("connections="); pw.println(connections);
210 }
211 if (pubProviders.size() > 0) {
212 pw.print(prefix); pw.print("pubProviders="); pw.println(pubProviders);
213 }
214 if (conProviders.size() > 0) {
215 pw.print(prefix); pw.print("conProviders="); pw.println(conProviders);
216 }
217 if (receivers.size() > 0) {
218 pw.print(prefix); pw.print("receivers="); pw.println(receivers);
219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 }
221
222 ProcessRecord(BatteryStatsImpl.Uid.Proc _batteryStats, IApplicationThread _thread,
223 ApplicationInfo _info, String _processName) {
224 batteryStats = _batteryStats;
225 info = _info;
226 processName = _processName;
227 pkgList.add(_info.packageName);
228 thread = _thread;
229 maxAdj = ActivityManagerService.EMPTY_APP_ADJ;
230 hiddenAdj = ActivityManagerService.HIDDEN_APP_MIN_ADJ;
231 curRawAdj = setRawAdj = -100;
232 curAdj = setAdj = -100;
233 persistent = false;
234 removed = false;
235 persistentActivities = 0;
236 }
237
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700238 public void setPid(int _pid) {
239 pid = _pid;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800240 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700241 stringName = null;
242 }
243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 /**
245 * This method returns true if any of the activities within the process record are interesting
246 * to the user. See HistoryRecord.isInterestingToUserLocked()
247 */
248 public boolean isInterestingToUserLocked() {
249 final int size = activities.size();
250 for (int i = 0 ; i < size ; i++) {
Dianne Hackborn860755f2010-06-03 18:47:52 -0700251 HistoryRecord r = activities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 if (r.isInterestingToUserLocked()) {
253 return true;
254 }
255 }
256 return false;
257 }
258
259 public void stopFreezingAllLocked() {
260 int i = activities.size();
261 while (i > 0) {
262 i--;
Dianne Hackborn860755f2010-06-03 18:47:52 -0700263 activities.get(i).stopFreezingScreenLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 }
265 }
266
267 public void requestPss() {
268 IApplicationThread localThread = thread;
269 if (localThread != null) {
270 try {
271 localThread.requestPss();
272 } catch (RemoteException e) {
273 }
274 }
275 }
276
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800277 public String toShortString() {
278 if (shortStringName != null) {
279 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700280 }
281 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800282 toShortString(sb);
283 return shortStringName = sb.toString();
284 }
285
286 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700287 sb.append(Integer.toHexString(System.identityHashCode(this)));
288 sb.append(' ');
289 sb.append(pid);
290 sb.append(':');
291 sb.append(processName);
292 sb.append('/');
293 sb.append(info.uid);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800294 }
295
296 public String toString() {
297 if (stringName != null) {
298 return stringName;
299 }
300 StringBuilder sb = new StringBuilder(128);
301 sb.append("ProcessRecord{");
302 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700303 sb.append('}');
304 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 }
306
307 /*
308 * Return true if package has been added false if not
309 */
310 public boolean addPackage(String pkg) {
311 if (!pkgList.contains(pkg)) {
312 pkgList.add(pkg);
313 return true;
314 }
315 return false;
316 }
317
318 /*
319 * Delete all packages from list except the package indicated in info
320 */
321 public void resetPackageList() {
322 pkgList.clear();
323 pkgList.add(info.packageName);
324 }
325
326 public String[] getPackageList() {
327 int size = pkgList.size();
328 if (size == 0) {
329 return null;
330 }
331 String list[] = new String[size];
332 pkgList.toArray(list);
333 return list;
334 }
335}