blob: 73e489f9e9bac5306076c640ca1f5b8cd17e1232 [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 */
Christopher Tatec27181c2010-06-30 14:41:09 -070042class ProcessRecord {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 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
Dianne Hackborn9adb9c32010-08-13 14:09:56 -070077 long lastWakeTime; // How long proc held wake lock at last check
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 long lastRequestedGc; // When we last asked the app to do a gc
Dianne Hackbornfd12af42009-08-27 00:44:33 -070079 long lastLowMemory; // When we last told the app that memory is low
80 boolean reportLowMemory; // Set to true when waiting to report low mem
Dianne Hackborndd71fc82009-12-16 19:24:32 -080081 boolean empty; // Is this an empty background process?
82 boolean hidden; // Is this a hidden process?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 int lastPss; // Last pss size reported by app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070084 String adjType; // Debugging: primary thing impacting oom_adj.
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070085 int adjTypeCode; // Debugging: adj code to report to app.
Dianne Hackbornde42bb62009-08-05 12:26:15 -070086 Object adjSource; // Debugging: option dependent object.
87 Object adjTarget; // Debugging: target component impacting oom_adj.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
89 // contains HistoryRecord objects
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070090 final ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 // all ServiceRecord running in this process
Dianne Hackborn860755f2010-06-03 18:47:52 -070092 final HashSet<ServiceRecord> services = new HashSet<ServiceRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 // services that are currently executing code (need to remain foreground).
94 final HashSet<ServiceRecord> executingServices
95 = new HashSet<ServiceRecord>();
96 // All ConnectionRecord this process holds
97 final HashSet<ConnectionRecord> connections
98 = new HashSet<ConnectionRecord>();
99 // all IIntentReceivers that are registered from this process.
100 final HashSet<ReceiverList> receivers = new HashSet<ReceiverList>();
101 // class (String) -> ContentProviderRecord
Dianne Hackborn860755f2010-06-03 18:47:52 -0700102 final HashMap<String, ContentProviderRecord> pubProviders
103 = new HashMap<String, ContentProviderRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 // All ContentProviderRecord process is using
Dianne Hackborn0c3154d2009-10-06 17:18:05 -0700105 final HashMap<ContentProviderRecord, Integer> conProviders
106 = new HashMap<ContentProviderRecord, Integer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107
108 boolean persistent; // always keep this application running?
109 boolean crashing; // are we in the process of crashing?
110 Dialog crashDialog; // dialog being displayed due to crash.
111 boolean notResponding; // does the app have a not responding dialog?
112 Dialog anrDialog; // dialog being displayed due to app not resp.
113 boolean removed; // has app package been removed from device?
114 boolean debugging; // was app launched for debugging?
115 int persistentActivities; // number of activities that are persistent
116 boolean waitedForDebugger; // has process show wait for debugger dialog?
117 Dialog waitDialog; // current wait for debugger dialog
118
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800119 String shortStringName; // caching of toShortString() result.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700120 String stringName; // caching of toString() result.
121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 // These reports are generated & stored when an app gets into an error condition.
123 // They will be "null" when all is OK.
124 ActivityManager.ProcessErrorStateInfo crashingReport;
125 ActivityManager.ProcessErrorStateInfo notRespondingReport;
126
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200127 // Who will be notified of the error. This is usually an activity in the
128 // app that installed the package.
129 ComponentName errorReportReceiver;
130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700132 if (info.className != null) {
133 pw.print(prefix); pw.print("class="); pw.println(info.className);
134 }
135 if (info.manageSpaceActivityName != null) {
136 pw.print(prefix); pw.print("manageSpaceActivityName=");
137 pw.println(info.manageSpaceActivityName);
138 }
139 pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
140 pw.print(" publicDir="); pw.print(info.publicSourceDir);
141 pw.print(" data="); pw.println(info.dataDir);
142 pw.print(prefix); pw.print("packageList="); pw.println(pkgList);
143 if (instrumentationClass != null || instrumentationProfileFile != null
144 || instrumentationArguments != null) {
145 pw.print(prefix); pw.print("instrumentationClass=");
146 pw.print(instrumentationClass);
147 pw.print(" instrumentationProfileFile=");
148 pw.println(instrumentationProfileFile);
149 pw.print(prefix); pw.print("instrumentationArguments=");
150 pw.println(instrumentationArguments);
Dianne Hackborn1655be42009-05-08 14:29:01 -0700151 pw.print(prefix); pw.print("instrumentationInfo=");
152 pw.println(instrumentationInfo);
153 if (instrumentationInfo != null) {
154 instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
155 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700156 }
157 pw.print(prefix); pw.print("thread="); pw.print(thread);
158 pw.print(" curReceiver="); pw.println(curReceiver);
159 pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting=");
160 pw.print(starting); pw.print(" lastPss="); pw.println(lastPss);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800161 pw.print(prefix); pw.print("lastActivityTime="); pw.print(lastActivityTime);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700162 pw.print(" lruWeight="); pw.print(lruWeight);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800163 pw.print(" hidden="); pw.print(hidden);
164 pw.print(" empty="); pw.println(empty);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700165 pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj);
166 pw.print(" hidden="); pw.print(hiddenAdj);
167 pw.print(" curRaw="); pw.print(curRawAdj);
168 pw.print(" setRaw="); pw.print(setRawAdj);
169 pw.print(" cur="); pw.print(curAdj);
170 pw.print(" set="); pw.println(setAdj);
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700171 pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
172 pw.print(" setSchedGroup="); pw.println(setSchedGroup);
Dianne Hackbornde42bb62009-08-05 12:26:15 -0700173 pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700174 pw.print(" foregroundServices="); pw.print(foregroundServices);
175 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
176 pw.print(prefix); pw.print("persistent="); pw.print(persistent);
177 pw.print(" removed="); pw.print(removed);
178 pw.print(" persistentActivities="); pw.println(persistentActivities);
Dianne Hackborn906497c2010-05-10 15:57:38 -0700179 pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
180 pw.print(" lruSeq="); pw.println(lruSeq);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700181 pw.print(prefix); pw.print("lastWakeTime="); pw.print(lastWakeTime);
182 pw.print(" lastRequestedGc="); pw.print(lastRequestedGc);
183 pw.print(" lastLowMemory="); pw.print(lastLowMemory);
184 pw.print(" reportLowMemory="); pw.println(reportLowMemory);
Dianne Hackborn149427c2010-04-23 14:20:03 -0700185 if (killedBackground) {
186 pw.print(prefix); pw.print("killedBackground="); pw.println(killedBackground);
187 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700188 if (debugging || crashing || crashDialog != null || notResponding
189 || anrDialog != null || bad) {
190 pw.print(prefix); pw.print("debugging="); pw.print(debugging);
191 pw.print(" crashing="); pw.print(crashing);
192 pw.print(" "); pw.print(crashDialog);
193 pw.print(" notResponding="); pw.print(notResponding);
194 pw.print(" " ); pw.print(anrDialog);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200195 pw.print(" bad="); pw.print(bad);
196
197 // crashing or notResponding is always set before errorReportReceiver
198 if (errorReportReceiver != null) {
199 pw.print(" errorReportReceiver=");
200 pw.print(errorReportReceiver.flattenToShortString());
201 }
202 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700203 }
204 if (activities.size() > 0) {
205 pw.print(prefix); pw.print("activities="); pw.println(activities);
206 }
207 if (services.size() > 0) {
208 pw.print(prefix); pw.print("services="); pw.println(services);
209 }
210 if (executingServices.size() > 0) {
211 pw.print(prefix); pw.print("executingServices="); pw.println(executingServices);
212 }
213 if (connections.size() > 0) {
214 pw.print(prefix); pw.print("connections="); pw.println(connections);
215 }
216 if (pubProviders.size() > 0) {
217 pw.print(prefix); pw.print("pubProviders="); pw.println(pubProviders);
218 }
219 if (conProviders.size() > 0) {
220 pw.print(prefix); pw.print("conProviders="); pw.println(conProviders);
221 }
222 if (receivers.size() > 0) {
223 pw.print(prefix); pw.print("receivers="); pw.println(receivers);
224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226
227 ProcessRecord(BatteryStatsImpl.Uid.Proc _batteryStats, IApplicationThread _thread,
228 ApplicationInfo _info, String _processName) {
229 batteryStats = _batteryStats;
230 info = _info;
231 processName = _processName;
232 pkgList.add(_info.packageName);
233 thread = _thread;
234 maxAdj = ActivityManagerService.EMPTY_APP_ADJ;
235 hiddenAdj = ActivityManagerService.HIDDEN_APP_MIN_ADJ;
236 curRawAdj = setRawAdj = -100;
237 curAdj = setAdj = -100;
238 persistent = false;
239 removed = false;
240 persistentActivities = 0;
241 }
242
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700243 public void setPid(int _pid) {
244 pid = _pid;
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800245 shortStringName = null;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700246 stringName = null;
247 }
248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 /**
250 * This method returns true if any of the activities within the process record are interesting
251 * to the user. See HistoryRecord.isInterestingToUserLocked()
252 */
253 public boolean isInterestingToUserLocked() {
254 final int size = activities.size();
255 for (int i = 0 ; i < size ; i++) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700256 ActivityRecord r = activities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 if (r.isInterestingToUserLocked()) {
258 return true;
259 }
260 }
261 return false;
262 }
263
264 public void stopFreezingAllLocked() {
265 int i = activities.size();
266 while (i > 0) {
267 i--;
Dianne Hackborn860755f2010-06-03 18:47:52 -0700268 activities.get(i).stopFreezingScreenLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 }
270 }
271
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800272 public String toShortString() {
273 if (shortStringName != null) {
274 return shortStringName;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700275 }
276 StringBuilder sb = new StringBuilder(128);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800277 toShortString(sb);
278 return shortStringName = sb.toString();
279 }
280
281 void toShortString(StringBuilder sb) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700282 sb.append(Integer.toHexString(System.identityHashCode(this)));
283 sb.append(' ');
284 sb.append(pid);
285 sb.append(':');
286 sb.append(processName);
287 sb.append('/');
288 sb.append(info.uid);
Dianne Hackborndd71fc82009-12-16 19:24:32 -0800289 }
290
291 public String toString() {
292 if (stringName != null) {
293 return stringName;
294 }
295 StringBuilder sb = new StringBuilder(128);
296 sb.append("ProcessRecord{");
297 toShortString(sb);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700298 sb.append('}');
299 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 }
301
302 /*
303 * Return true if package has been added false if not
304 */
305 public boolean addPackage(String pkg) {
306 if (!pkgList.contains(pkg)) {
307 pkgList.add(pkg);
308 return true;
309 }
310 return false;
311 }
312
313 /*
314 * Delete all packages from list except the package indicated in info
315 */
316 public void resetPackageList() {
317 pkgList.clear();
318 pkgList.add(info.packageName);
319 }
320
321 public String[] getPackageList() {
322 int size = pkgList.size();
323 if (size == 0) {
324 return null;
325 }
326 String list[] = new String[size];
327 pkgList.toArray(list);
328 return list;
329 }
330}