blob: 28195ce158e1c2f192ce9cc47b51f12b89d8f84d [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 Hackborndd71fc82009-12-16 19:24:32 -080031import android.os.SystemClock;
Dianne Hackborn1655be42009-05-08 14:29:01 -070032import android.util.PrintWriterPrinter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34import java.io.PrintWriter;
35import java.util.ArrayList;
36import java.util.HashMap;
37import java.util.HashSet;
38
39/**
40 * Full information about a particular process that
41 * is currently running.
42 */
43class ProcessRecord implements Watchdog.PssRequestor {
44 final BatteryStatsImpl.Uid.Proc batteryStats; // where to collect runtime statistics
45 final ApplicationInfo info; // all about the first app in the process
46 final String processName; // name of the process
47 // List of packages running in the process
48 final HashSet<String> pkgList = new HashSet();
49 IApplicationThread thread; // the actual proc... may be null only if
50 // 'persistent' is true (in which case we
51 // are in the process of launching the app)
52 int pid; // The process of this application; 0 if none
53 boolean starting; // True if the process is being started
Dianne Hackborndd71fc82009-12-16 19:24:32 -080054 long lastActivityTime; // For managing the LRU list
55 long lruWeight; // Weight for ordering in LRU list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 int maxAdj; // Maximum OOM adjustment for this process
57 int hiddenAdj; // If hidden, this is the adjustment to use
58 int curRawAdj; // Current OOM unlimited adjustment for this process
59 int setRawAdj; // Last set OOM unlimited adjustment for this process
60 int curAdj; // Current OOM adjustment for this process
61 int setAdj; // Last set OOM adjustment for this process
Dianne Hackborn06de2ea2009-05-21 12:56:43 -070062 int curSchedGroup; // Currently desired scheduling class
63 int setSchedGroup; // Last set to background scheduling class
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 boolean setIsForeground; // Running foreground UI when last set?
65 boolean foregroundServices; // Running any services that are foreground?
66 boolean bad; // True if disabled in the bad process list
67 IBinder forcingToForeground;// Token that is forcing this process to be foreground
68 int adjSeq; // Sequence id for identifying repeated trav
69 ComponentName instrumentationClass;// class installed to instrument app
Dianne Hackborn1655be42009-05-08 14:29:01 -070070 ApplicationInfo instrumentationInfo; // the application being instrumented
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 String instrumentationProfileFile; // where to save profiling
72 IInstrumentationWatcher instrumentationWatcher; // who is waiting
73 Bundle instrumentationArguments;// as given to us
74 ComponentName instrumentationResultClass;// copy of instrumentationClass
75 BroadcastRecord curReceiver;// receiver currently running in the app
76 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -070077 long lastLowMemory; // When we last told the app that memory is low
78 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -080079 boolean empty; // Is this an empty background process?
80 boolean hidden; // Is this a hidden process?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 int lastPss; // Last pss size reported by app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070082 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070083 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070084 Object adjSource; // Debugging: option dependent object.
85 Object adjTarget; // Debugging: target component impacting oom_adj.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87 // contains HistoryRecord objects
88 final ArrayList activities = new ArrayList();
89 // all ServiceRecord running in this process
90 final HashSet services = new HashSet();
91 // services that are currently executing code (need to remain foreground).
92 final HashSet<ServiceRecord> executingServices
93 = new HashSet<ServiceRecord>();
94 // All ConnectionRecord this process holds
95 final HashSet<ConnectionRecord> connections
96 = new HashSet<ConnectionRecord>();
97 // all IIntentReceivers that are registered from this process.
98 final HashSet<ReceiverList> receivers = new HashSet<ReceiverList>();
99 // class (String) -> ContentProviderRecord
100 final HashMap pubProviders = new HashMap();
101 // All ContentProviderRecord process is using
Dianne Hackborn0c3154d2009-10-06 17:18:05 -0700102 final HashMap<ContentProviderRecord, Integer> conProviders
103 = new HashMap<ContentProviderRecord, Integer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104
105 boolean persistent; // always keep this application running?
106 boolean crashing; // are we in the process of crashing?
107 Dialog crashDialog; // dialog being displayed due to crash.
108 boolean notResponding; // does the app have a not responding dialog?
109 Dialog anrDialog; // dialog being displayed due to app not resp.
110 boolean removed; // has app package been removed from device?
111 boolean debugging; // was app launched for debugging?
112 int persistentActivities; // number of activities that are persistent
113 boolean waitedForDebugger; // has process show wait for debugger dialog?
114 Dialog waitDialog; // current wait for debugger dialog
115
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800116 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700117 String stringName; // caching of toString() result.
118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 // These reports are generated & stored when an app gets into an error condition.
120 // They will be "null" when all is OK.
121 ActivityManager.ProcessErrorStateInfo crashingReport;
122 ActivityManager.ProcessErrorStateInfo notRespondingReport;
123
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200124 // Who will be notified of the error. This is usually an activity in the
125 // app that installed the package.
126 ComponentName errorReportReceiver;
127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 void dump(PrintWriter pw, String prefix) {
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800129 long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700130 if (info.className != null) {
131 pw.print(prefix); pw.print("class="); pw.println(info.className);
132 }
133 if (info.manageSpaceActivityName != null) {
134 pw.print(prefix); pw.print("manageSpaceActivityName=");
135 pw.println(info.manageSpaceActivityName);
136 }
137 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
138 pw.print(" publicDir="); pw.print(info.publicSourceDir);
139 pw.print(" data="); pw.println(info.dataDir);
140 pw.print(prefix); pw.print("packageList="); pw.println(pkgList);
141 if (instrumentationClass != null || instrumentationProfileFile != null
142 || instrumentationArguments != null) {
143 pw.print(prefix); pw.print("instrumentationClass=");
144 pw.print(instrumentationClass);
145 pw.print(" instrumentationProfileFile=");
146 pw.println(instrumentationProfileFile);
147 pw.print(prefix); pw.print("instrumentationArguments=");
148 pw.println(instrumentationArguments);
Dianne Hackborn1655be42009-05-08 14:29:01 -0700149 pw.print(prefix); pw.print("instrumentationInfo=");
150 pw.println(instrumentationInfo);
151 if (instrumentationInfo != null) {
152 instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
153 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700154 }
155 pw.print(prefix); pw.print("thread="); pw.print(thread);
156 pw.print(" curReceiver="); pw.println(curReceiver);
157 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
158 pw.print(starting); pw.print(" lastPss="); pw.println(lastPss);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800159 pw.print(prefix); pw.print("lastActivityTime="); pw.print(lastActivityTime);
160 pw.print(" lruWeight="); pw.println(lruWeight);
161 pw.print(" hidden="); pw.print(hidden);
162 pw.print(" empty="); pw.println(empty);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700163 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
164 pw.print(" hidden="); pw.print(hiddenAdj);
165 pw.print(" curRaw="); pw.print(curRawAdj);
166 pw.print(" setRaw="); pw.print(setRawAdj);
167 pw.print(" cur="); pw.print(curAdj);
168 pw.print(" set="); pw.println(setAdj);
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700169 pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
170 pw.print(" setSchedGroup="); pw.println(setSchedGroup);
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700171 pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700172 pw.print(" foregroundServices="); pw.print(foregroundServices);
173 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
174 pw.print(prefix); pw.print("persistent="); pw.print(persistent);
175 pw.print(" removed="); pw.print(removed);
176 pw.print(" persistentActivities="); pw.println(persistentActivities);
177 if (debugging || crashing || crashDialog != null || notResponding
178 || anrDialog != null || bad) {
179 pw.print(prefix); pw.print("debugging="); pw.print(debugging);
180 pw.print(" crashing="); pw.print(crashing);
181 pw.print(" "); pw.print(crashDialog);
182 pw.print(" notResponding="); pw.print(notResponding);
183 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200184 pw.print(" bad="); pw.print(bad);
185
186 // crashing or notResponding is always set before errorReportReceiver
187 if (errorReportReceiver != null) {
188 pw.print(" errorReportReceiver=");
189 pw.print(errorReportReceiver.flattenToShortString());
190 }
191 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700192 }
193 if (activities.size() > 0) {
194 pw.print(prefix); pw.print("activities="); pw.println(activities);
195 }
196 if (services.size() > 0) {
197 pw.print(prefix); pw.print("services="); pw.println(services);
198 }
199 if (executingServices.size() > 0) {
200 pw.print(prefix); pw.print("executingServices="); pw.println(executingServices);
201 }
202 if (connections.size() > 0) {
203 pw.print(prefix); pw.print("connections="); pw.println(connections);
204 }
205 if (pubProviders.size() > 0) {
206 pw.print(prefix); pw.print("pubProviders="); pw.println(pubProviders);
207 }
208 if (conProviders.size() > 0) {
209 pw.print(prefix); pw.print("conProviders="); pw.println(conProviders);
210 }
211 if (receivers.size() > 0) {
212 pw.print(prefix); pw.print("receivers="); pw.println(receivers);
213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
215
216 ProcessRecord(BatteryStatsImpl.Uid.Proc _batteryStats, IApplicationThread _thread,
217 ApplicationInfo _info, String _processName) {
218 batteryStats = _batteryStats;
219 info = _info;
220 processName = _processName;
221 pkgList.add(_info.packageName);
222 thread = _thread;
223 maxAdj = ActivityManagerService.EMPTY_APP_ADJ;
224 hiddenAdj = ActivityManagerService.HIDDEN_APP_MIN_ADJ;
225 curRawAdj = setRawAdj = -100;
226 curAdj = setAdj = -100;
227 persistent = false;
228 removed = false;
229 persistentActivities = 0;
230 }
231
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700232 public void setPid(int _pid) {
233 pid = _pid;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800234 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700235 stringName = null;
236 }
237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 /**
239 * This method returns true if any of the activities within the process record are interesting
240 * to the user. See HistoryRecord.isInterestingToUserLocked()
241 */
242 public boolean isInterestingToUserLocked() {
243 final int size = activities.size();
244 for (int i = 0 ; i < size ; i++) {
245 HistoryRecord r = (HistoryRecord) activities.get(i);
246 if (r.isInterestingToUserLocked()) {
247 return true;
248 }
249 }
250 return false;
251 }
252
253 public void stopFreezingAllLocked() {
254 int i = activities.size();
255 while (i > 0) {
256 i--;
257 ((HistoryRecord)activities.get(i)).stopFreezingScreenLocked(true);
258 }
259 }
260
261 public void requestPss() {
262 IApplicationThread localThread = thread;
263 if (localThread != null) {
264 try {
265 localThread.requestPss();
266 } catch (RemoteException e) {
267 }
268 }
269 }
270
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800271 public String toShortString() {
272 if (shortStringName != null) {
273 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700274 }
275 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800276 toShortString(sb);
277 return shortStringName = sb.toString();
278 }
279
280 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700281 sb.append(Integer.toHexString(System.identityHashCode(this)));
282 sb.append(' ');
283 sb.append(pid);
284 sb.append(':');
285 sb.append(processName);
286 sb.append('/');
287 sb.append(info.uid);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800288 }
289
290 public String toString() {
291 if (stringName != null) {
292 return stringName;
293 }
294 StringBuilder sb = new StringBuilder(128);
295 sb.append("ProcessRecord{");
296 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700297 sb.append('}');
298 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 }
300
301 /*
302 * Return true if package has been added false if not
303 */
304 public boolean addPackage(String pkg) {
305 if (!pkgList.contains(pkg)) {
306 pkgList.add(pkg);
307 return true;
308 }
309 return false;
310 }
311
312 /*
313 * Delete all packages from list except the package indicated in info
314 */
315 public void resetPackageList() {
316 pkgList.clear();
317 pkgList.add(info.packageName);
318 }
319
320 public String[] getPackageList() {
321 int size = pkgList.size();
322 if (size == 0) {
323 return null;
324 }
325 String list[] = new String[size];
326 pkgList.toArray(list);
327 return list;
328 }
329}