blob: d05b44ba76e5cbfdbc53449f56776a9d5fc8a862 [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
47 final HashSet<String> pkgList = new HashSet();
48 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
53 int maxAdj; // Maximum OOM adjustment for this process
54 int hiddenAdj; // If hidden, this is the adjustment to use
55 int curRawAdj; // Current OOM unlimited adjustment for this process
56 int setRawAdj; // Last set OOM unlimited adjustment for this process
57 int curAdj; // Current OOM adjustment for this process
58 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn06de2ea2009-05-21 12:56:43 -070059 int curSchedGroup; // Currently desired scheduling class
60 int setSchedGroup; // Last set to background scheduling class
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 boolean setIsForeground; // Running foreground UI when last set?
62 boolean foregroundServices; // Running any services that are foreground?
63 boolean bad; // True if disabled in the bad process list
64 IBinder forcingToForeground;// Token that is forcing this process to be foreground
65 int adjSeq; // Sequence id for identifying repeated trav
66 ComponentName instrumentationClass;// class installed to instrument app
Dianne Hackborn1655be42009-05-08 14:29:01 -070067 ApplicationInfo instrumentationInfo; // the application being instrumented
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 String instrumentationProfileFile; // where to save profiling
69 IInstrumentationWatcher instrumentationWatcher; // who is waiting
70 Bundle instrumentationArguments;// as given to us
71 ComponentName instrumentationResultClass;// copy of instrumentationClass
72 BroadcastRecord curReceiver;// receiver currently running in the app
73 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -070074 long lastLowMemory; // When we last told the app that memory is low
75 boolean reportLowMemory; // Set to true when waiting to report low mem
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 int lastPss; // Last pss size reported by app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070077 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070078 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070079 Object adjSource; // Debugging: option dependent object.
80 Object adjTarget; // Debugging: target component impacting oom_adj.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
82 // contains HistoryRecord objects
83 final ArrayList activities = new ArrayList();
84 // all ServiceRecord running in this process
85 final HashSet services = new HashSet();
86 // services that are currently executing code (need to remain foreground).
87 final HashSet<ServiceRecord> executingServices
88 = new HashSet<ServiceRecord>();
89 // All ConnectionRecord this process holds
90 final HashSet<ConnectionRecord> connections
91 = new HashSet<ConnectionRecord>();
92 // all IIntentReceivers that are registered from this process.
93 final HashSet<ReceiverList> receivers = new HashSet<ReceiverList>();
94 // class (String) -> ContentProviderRecord
95 final HashMap pubProviders = new HashMap();
96 // All ContentProviderRecord process is using
97 final HashSet conProviders = new HashSet();
98
99 boolean persistent; // always keep this application running?
100 boolean crashing; // are we in the process of crashing?
101 Dialog crashDialog; // dialog being displayed due to crash.
102 boolean notResponding; // does the app have a not responding dialog?
103 Dialog anrDialog; // dialog being displayed due to app not resp.
104 boolean removed; // has app package been removed from device?
105 boolean debugging; // was app launched for debugging?
106 int persistentActivities; // number of activities that are persistent
107 boolean waitedForDebugger; // has process show wait for debugger dialog?
108 Dialog waitDialog; // current wait for debugger dialog
109
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700110 String stringName; // caching of toString() result.
111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 // These reports are generated & stored when an app gets into an error condition.
113 // They will be "null" when all is OK.
114 ActivityManager.ProcessErrorStateInfo crashingReport;
115 ActivityManager.ProcessErrorStateInfo notRespondingReport;
116
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200117 // Who will be notified of the error. This is usually an activity in the
118 // app that installed the package.
119 ComponentName errorReportReceiver;
120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700122 if (info.className != null) {
123 pw.print(prefix); pw.print("class="); pw.println(info.className);
124 }
125 if (info.manageSpaceActivityName != null) {
126 pw.print(prefix); pw.print("manageSpaceActivityName=");
127 pw.println(info.manageSpaceActivityName);
128 }
129 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
130 pw.print(" publicDir="); pw.print(info.publicSourceDir);
131 pw.print(" data="); pw.println(info.dataDir);
132 pw.print(prefix); pw.print("packageList="); pw.println(pkgList);
133 if (instrumentationClass != null || instrumentationProfileFile != null
134 || instrumentationArguments != null) {
135 pw.print(prefix); pw.print("instrumentationClass=");
136 pw.print(instrumentationClass);
137 pw.print(" instrumentationProfileFile=");
138 pw.println(instrumentationProfileFile);
139 pw.print(prefix); pw.print("instrumentationArguments=");
140 pw.println(instrumentationArguments);
Dianne Hackborn1655be42009-05-08 14:29:01 -0700141 pw.print(prefix); pw.print("instrumentationInfo=");
142 pw.println(instrumentationInfo);
143 if (instrumentationInfo != null) {
144 instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
145 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700146 }
147 pw.print(prefix); pw.print("thread="); pw.print(thread);
148 pw.print(" curReceiver="); pw.println(curReceiver);
149 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
150 pw.print(starting); pw.print(" lastPss="); pw.println(lastPss);
151 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
152 pw.print(" hidden="); pw.print(hiddenAdj);
153 pw.print(" curRaw="); pw.print(curRawAdj);
154 pw.print(" setRaw="); pw.print(setRawAdj);
155 pw.print(" cur="); pw.print(curAdj);
156 pw.print(" set="); pw.println(setAdj);
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700157 pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
158 pw.print(" setSchedGroup="); pw.println(setSchedGroup);
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700159 pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700160 pw.print(" foregroundServices="); pw.print(foregroundServices);
161 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
162 pw.print(prefix); pw.print("persistent="); pw.print(persistent);
163 pw.print(" removed="); pw.print(removed);
164 pw.print(" persistentActivities="); pw.println(persistentActivities);
165 if (debugging || crashing || crashDialog != null || notResponding
166 || anrDialog != null || bad) {
167 pw.print(prefix); pw.print("debugging="); pw.print(debugging);
168 pw.print(" crashing="); pw.print(crashing);
169 pw.print(" "); pw.print(crashDialog);
170 pw.print(" notResponding="); pw.print(notResponding);
171 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200172 pw.print(" bad="); pw.print(bad);
173
174 // crashing or notResponding is always set before errorReportReceiver
175 if (errorReportReceiver != null) {
176 pw.print(" errorReportReceiver=");
177 pw.print(errorReportReceiver.flattenToShortString());
178 }
179 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700180 }
181 if (activities.size() > 0) {
182 pw.print(prefix); pw.print("activities="); pw.println(activities);
183 }
184 if (services.size() > 0) {
185 pw.print(prefix); pw.print("services="); pw.println(services);
186 }
187 if (executingServices.size() > 0) {
188 pw.print(prefix); pw.print("executingServices="); pw.println(executingServices);
189 }
190 if (connections.size() > 0) {
191 pw.print(prefix); pw.print("connections="); pw.println(connections);
192 }
193 if (pubProviders.size() > 0) {
194 pw.print(prefix); pw.print("pubProviders="); pw.println(pubProviders);
195 }
196 if (conProviders.size() > 0) {
197 pw.print(prefix); pw.print("conProviders="); pw.println(conProviders);
198 }
199 if (receivers.size() > 0) {
200 pw.print(prefix); pw.print("receivers="); pw.println(receivers);
201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 }
203
204 ProcessRecord(BatteryStatsImpl.Uid.Proc _batteryStats, IApplicationThread _thread,
205 ApplicationInfo _info, String _processName) {
206 batteryStats = _batteryStats;
207 info = _info;
208 processName = _processName;
209 pkgList.add(_info.packageName);
210 thread = _thread;
211 maxAdj = ActivityManagerService.EMPTY_APP_ADJ;
212 hiddenAdj = ActivityManagerService.HIDDEN_APP_MIN_ADJ;
213 curRawAdj = setRawAdj = -100;
214 curAdj = setAdj = -100;
215 persistent = false;
216 removed = false;
217 persistentActivities = 0;
218 }
219
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700220 public void setPid(int _pid) {
221 pid = _pid;
222 stringName = null;
223 }
224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 /**
226 * This method returns true if any of the activities within the process record are interesting
227 * to the user. See HistoryRecord.isInterestingToUserLocked()
228 */
229 public boolean isInterestingToUserLocked() {
230 final int size = activities.size();
231 for (int i = 0 ; i < size ; i++) {
232 HistoryRecord r = (HistoryRecord) activities.get(i);
233 if (r.isInterestingToUserLocked()) {
234 return true;
235 }
236 }
237 return false;
238 }
239
240 public void stopFreezingAllLocked() {
241 int i = activities.size();
242 while (i > 0) {
243 i--;
244 ((HistoryRecord)activities.get(i)).stopFreezingScreenLocked(true);
245 }
246 }
247
248 public void requestPss() {
249 IApplicationThread localThread = thread;
250 if (localThread != null) {
251 try {
252 localThread.requestPss();
253 } catch (RemoteException e) {
254 }
255 }
256 }
257
258 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700259 if (stringName != null) {
260 return stringName;
261 }
262 StringBuilder sb = new StringBuilder(128);
263 sb.append("ProcessRecord{");
264 sb.append(Integer.toHexString(System.identityHashCode(this)));
265 sb.append(' ');
266 sb.append(pid);
267 sb.append(':');
268 sb.append(processName);
269 sb.append('/');
270 sb.append(info.uid);
271 sb.append('}');
272 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 }
274
275 /*
276 * Return true if package has been added false if not
277 */
278 public boolean addPackage(String pkg) {
279 if (!pkgList.contains(pkg)) {
280 pkgList.add(pkg);
281 return true;
282 }
283 return false;
284 }
285
286 /*
287 * Delete all packages from list except the package indicated in info
288 */
289 public void resetPackageList() {
290 pkgList.clear();
291 pkgList.add(info.packageName);
292 }
293
294 public String[] getPackageList() {
295 int size = pkgList.size();
296 if (size == 0) {
297 return null;
298 }
299 String list[] = new String[size];
300 pkgList.toArray(list);
301 return list;
302 }
303}