blob: 419dadf022e94c337d8e55e5289c043fbd187c17 [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
59 boolean isForeground; // Is this app running the foreground UI?
60 boolean setIsForeground; // Running foreground UI when last set?
61 boolean foregroundServices; // Running any services that are foreground?
62 boolean bad; // True if disabled in the bad process list
63 IBinder forcingToForeground;// Token that is forcing this process to be foreground
64 int adjSeq; // Sequence id for identifying repeated trav
65 ComponentName instrumentationClass;// class installed to instrument app
Dianne Hackborn1655be42009-05-08 14:29:01 -070066 ApplicationInfo instrumentationInfo; // the application being instrumented
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 String instrumentationProfileFile; // where to save profiling
68 IInstrumentationWatcher instrumentationWatcher; // who is waiting
69 Bundle instrumentationArguments;// as given to us
70 ComponentName instrumentationResultClass;// copy of instrumentationClass
71 BroadcastRecord curReceiver;// receiver currently running in the app
72 long lastRequestedGc; // When we last asked the app to do a gc
73 int lastPss; // Last pss size reported by app.
74
75 // contains HistoryRecord objects
76 final ArrayList activities = new ArrayList();
77 // all ServiceRecord running in this process
78 final HashSet services = new HashSet();
79 // services that are currently executing code (need to remain foreground).
80 final HashSet<ServiceRecord> executingServices
81 = new HashSet<ServiceRecord>();
82 // All ConnectionRecord this process holds
83 final HashSet<ConnectionRecord> connections
84 = new HashSet<ConnectionRecord>();
85 // all IIntentReceivers that are registered from this process.
86 final HashSet<ReceiverList> receivers = new HashSet<ReceiverList>();
87 // class (String) -> ContentProviderRecord
88 final HashMap pubProviders = new HashMap();
89 // All ContentProviderRecord process is using
90 final HashSet conProviders = new HashSet();
91
92 boolean persistent; // always keep this application running?
93 boolean crashing; // are we in the process of crashing?
94 Dialog crashDialog; // dialog being displayed due to crash.
95 boolean notResponding; // does the app have a not responding dialog?
96 Dialog anrDialog; // dialog being displayed due to app not resp.
97 boolean removed; // has app package been removed from device?
98 boolean debugging; // was app launched for debugging?
99 int persistentActivities; // number of activities that are persistent
100 boolean waitedForDebugger; // has process show wait for debugger dialog?
101 Dialog waitDialog; // current wait for debugger dialog
102
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700103 String stringName; // caching of toString() result.
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 // These reports are generated & stored when an app gets into an error condition.
106 // They will be "null" when all is OK.
107 ActivityManager.ProcessErrorStateInfo crashingReport;
108 ActivityManager.ProcessErrorStateInfo notRespondingReport;
109
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200110 // Who will be notified of the error. This is usually an activity in the
111 // app that installed the package.
112 ComponentName errorReportReceiver;
113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700115 if (info.className != null) {
116 pw.print(prefix); pw.print("class="); pw.println(info.className);
117 }
118 if (info.manageSpaceActivityName != null) {
119 pw.print(prefix); pw.print("manageSpaceActivityName=");
120 pw.println(info.manageSpaceActivityName);
121 }
122 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
123 pw.print(" publicDir="); pw.print(info.publicSourceDir);
124 pw.print(" data="); pw.println(info.dataDir);
125 pw.print(prefix); pw.print("packageList="); pw.println(pkgList);
126 if (instrumentationClass != null || instrumentationProfileFile != null
127 || instrumentationArguments != null) {
128 pw.print(prefix); pw.print("instrumentationClass=");
129 pw.print(instrumentationClass);
130 pw.print(" instrumentationProfileFile=");
131 pw.println(instrumentationProfileFile);
132 pw.print(prefix); pw.print("instrumentationArguments=");
133 pw.println(instrumentationArguments);
Dianne Hackborn1655be42009-05-08 14:29:01 -0700134 pw.print(prefix); pw.print("instrumentationInfo=");
135 pw.println(instrumentationInfo);
136 if (instrumentationInfo != null) {
137 instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
138 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700139 }
140 pw.print(prefix); pw.print("thread="); pw.print(thread);
141 pw.print(" curReceiver="); pw.println(curReceiver);
142 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
143 pw.print(starting); pw.print(" lastPss="); pw.println(lastPss);
144 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
145 pw.print(" hidden="); pw.print(hiddenAdj);
146 pw.print(" curRaw="); pw.print(curRawAdj);
147 pw.print(" setRaw="); pw.print(setRawAdj);
148 pw.print(" cur="); pw.print(curAdj);
149 pw.print(" set="); pw.println(setAdj);
150 pw.print(prefix); pw.print("isForeground="); pw.print(isForeground);
151 pw.print(" setIsForeground="); pw.print(setIsForeground);
152 pw.print(" foregroundServices="); pw.print(foregroundServices);
153 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
154 pw.print(prefix); pw.print("persistent="); pw.print(persistent);
155 pw.print(" removed="); pw.print(removed);
156 pw.print(" persistentActivities="); pw.println(persistentActivities);
157 if (debugging || crashing || crashDialog != null || notResponding
158 || anrDialog != null || bad) {
159 pw.print(prefix); pw.print("debugging="); pw.print(debugging);
160 pw.print(" crashing="); pw.print(crashing);
161 pw.print(" "); pw.print(crashDialog);
162 pw.print(" notResponding="); pw.print(notResponding);
163 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200164 pw.print(" bad="); pw.print(bad);
165
166 // crashing or notResponding is always set before errorReportReceiver
167 if (errorReportReceiver != null) {
168 pw.print(" errorReportReceiver=");
169 pw.print(errorReportReceiver.flattenToShortString());
170 }
171 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700172 }
173 if (activities.size() > 0) {
174 pw.print(prefix); pw.print("activities="); pw.println(activities);
175 }
176 if (services.size() > 0) {
177 pw.print(prefix); pw.print("services="); pw.println(services);
178 }
179 if (executingServices.size() > 0) {
180 pw.print(prefix); pw.print("executingServices="); pw.println(executingServices);
181 }
182 if (connections.size() > 0) {
183 pw.print(prefix); pw.print("connections="); pw.println(connections);
184 }
185 if (pubProviders.size() > 0) {
186 pw.print(prefix); pw.print("pubProviders="); pw.println(pubProviders);
187 }
188 if (conProviders.size() > 0) {
189 pw.print(prefix); pw.print("conProviders="); pw.println(conProviders);
190 }
191 if (receivers.size() > 0) {
192 pw.print(prefix); pw.print("receivers="); pw.println(receivers);
193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
196 ProcessRecord(BatteryStatsImpl.Uid.Proc _batteryStats, IApplicationThread _thread,
197 ApplicationInfo _info, String _processName) {
198 batteryStats = _batteryStats;
199 info = _info;
200 processName = _processName;
201 pkgList.add(_info.packageName);
202 thread = _thread;
203 maxAdj = ActivityManagerService.EMPTY_APP_ADJ;
204 hiddenAdj = ActivityManagerService.HIDDEN_APP_MIN_ADJ;
205 curRawAdj = setRawAdj = -100;
206 curAdj = setAdj = -100;
207 persistent = false;
208 removed = false;
209 persistentActivities = 0;
210 }
211
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700212 public void setPid(int _pid) {
213 pid = _pid;
214 stringName = null;
215 }
216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 /**
218 * This method returns true if any of the activities within the process record are interesting
219 * to the user. See HistoryRecord.isInterestingToUserLocked()
220 */
221 public boolean isInterestingToUserLocked() {
222 final int size = activities.size();
223 for (int i = 0 ; i < size ; i++) {
224 HistoryRecord r = (HistoryRecord) activities.get(i);
225 if (r.isInterestingToUserLocked()) {
226 return true;
227 }
228 }
229 return false;
230 }
231
232 public void stopFreezingAllLocked() {
233 int i = activities.size();
234 while (i > 0) {
235 i--;
236 ((HistoryRecord)activities.get(i)).stopFreezingScreenLocked(true);
237 }
238 }
239
240 public void requestPss() {
241 IApplicationThread localThread = thread;
242 if (localThread != null) {
243 try {
244 localThread.requestPss();
245 } catch (RemoteException e) {
246 }
247 }
248 }
249
250 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700251 if (stringName != null) {
252 return stringName;
253 }
254 StringBuilder sb = new StringBuilder(128);
255 sb.append("ProcessRecord{");
256 sb.append(Integer.toHexString(System.identityHashCode(this)));
257 sb.append(' ');
258 sb.append(pid);
259 sb.append(':');
260 sb.append(processName);
261 sb.append('/');
262 sb.append(info.uid);
263 sb.append('}');
264 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 }
266
267 /*
268 * Return true if package has been added false if not
269 */
270 public boolean addPackage(String pkg) {
271 if (!pkgList.contains(pkg)) {
272 pkgList.add(pkg);
273 return true;
274 }
275 return false;
276 }
277
278 /*
279 * Delete all packages from list except the package indicated in info
280 */
281 public void resetPackageList() {
282 pkgList.clear();
283 pkgList.add(info.packageName);
284 }
285
286 public String[] getPackageList() {
287 int size = pkgList.size();
288 if (size == 0) {
289 return null;
290 }
291 String list[] = new String[size];
292 pkgList.toArray(list);
293 return list;
294 }
295}