blob: a0b3dc0452acdb33ba34e2bfbf7891bcb5487948 [file] [log] [blame]
Jacek Surazskif5b9c722009-05-18 12:09:59 +02001/*
2 * Copyright (C) 2008 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 android.app;
18
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080019import android.content.ComponentName;
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.ApplicationInfo;
23import android.content.pm.PackageManager;
24import android.content.pm.ResolveInfo;
Jeff Sharkeyf5299f12017-03-17 10:25:07 -060025import android.os.Binder;
Jacek Surazskif5b9c722009-05-18 12:09:59 +020026import android.os.Parcel;
27import android.os.Parcelable;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080028import android.os.SystemProperties;
29import android.provider.Settings;
Jacek Surazskif5b9c722009-05-18 12:09:59 +020030import android.util.Printer;
Dianne Hackborn73d6a822014-09-29 10:52:47 -070031import android.util.Slog;
Garfield Tan2746ab52018-07-25 12:33:01 -070032
Dianne Hackborn8c841092013-06-24 13:46:13 -070033import com.android.internal.util.FastPrintWriter;
Brad Fitzpatrick5b747192010-07-12 11:05:38 -070034
Dan Egnorb7f03672009-12-09 16:22:32 -080035import java.io.PrintWriter;
36import java.io.StringWriter;
Jacek Surazskif5b9c722009-05-18 12:09:59 +020037
38/**
39 * Describes an application error.
40 *
41 * A report has a type, which is one of
42 * <ul>
Dianne Hackborn271c2fe2011-08-09 19:35:13 -070043 * <li> {@link #TYPE_NONE} uninitialized instance of {@link ApplicationErrorReport}.
Jacek Surazskif5b9c722009-05-18 12:09:59 +020044 * <li> {@link #TYPE_CRASH} application crash. Information about the crash
45 * is stored in {@link #crashInfo}.
46 * <li> {@link #TYPE_ANR} application not responding. Information about the
47 * ANR is stored in {@link #anrInfo}.
Dianne Hackborn271c2fe2011-08-09 19:35:13 -070048 * <li> {@link #TYPE_BATTERY} user reported application is using too much
49 * battery. Information about the battery use is stored in {@link #batteryInfo}.
50 * <li> {@link #TYPE_RUNNING_SERVICE} user reported application is leaving an
51 * unneeded serive running. Information about the battery use is stored in
52 * {@link #runningServiceInfo}.
Jacek Surazskif5b9c722009-05-18 12:09:59 +020053 * </ul>
Jacek Surazskif5b9c722009-05-18 12:09:59 +020054 */
55
56public class ApplicationErrorReport implements Parcelable {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080057 // System property defining error report receiver for system apps
58 static final String SYSTEM_APPS_ERROR_RECEIVER_PROPERTY = "ro.error.receiver.system.apps";
59
60 // System property defining default error report receiver
61 static final String DEFAULT_ERROR_RECEIVER_PROPERTY = "ro.error.receiver.default";
62
Jacek Surazskif5b9c722009-05-18 12:09:59 +020063 /**
64 * Uninitialized error report.
65 */
66 public static final int TYPE_NONE = 0;
67
68 /**
69 * An error report about an application crash.
70 */
71 public static final int TYPE_CRASH = 1;
72
73 /**
74 * An error report about an application that's not responding.
75 */
76 public static final int TYPE_ANR = 2;
77
78 /**
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080079 * An error report about an application that's consuming too much battery.
80 */
81 public static final int TYPE_BATTERY = 3;
82
83 /**
Brad Fitzpatrickcb9ceb12010-07-29 14:29:02 -070084 * A report from a user to a developer about a running service that the
85 * user doesn't think should be running.
Dianne Hackborn14bfa392010-07-24 19:58:06 -070086 */
87 public static final int TYPE_RUNNING_SERVICE = 5;
88
89 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +020090 * Type of this report. Can be one of {@link #TYPE_NONE},
Brad Fitzpatrickcb9ceb12010-07-29 14:29:02 -070091 * {@link #TYPE_CRASH}, {@link #TYPE_ANR}, {@link #TYPE_BATTERY},
92 * or {@link #TYPE_RUNNING_SERVICE}.
Jacek Surazskif5b9c722009-05-18 12:09:59 +020093 */
94 public int type;
95
96 /**
97 * Package name of the application.
98 */
99 public String packageName;
100
101 /**
102 * Package name of the application which installed the application this
103 * report pertains to.
Dirk Dougherty4d7bc6552012-01-27 17:56:49 -0800104 * This identifies which market the application came from.
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200105 */
106 public String installerPackageName;
107
108 /**
109 * Process name of the application.
110 */
111 public String processName;
112
113 /**
114 * Time at which the error occurred.
115 */
116 public long time;
117
118 /**
Jacek Surazskie0ee6ef2010-01-07 16:23:03 +0100119 * Set if the app is on the system image.
120 */
121 public boolean systemApp;
122
123 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200124 * If this report is of type {@link #TYPE_CRASH}, contains an instance
125 * of CrashInfo describing the crash; otherwise null.
126 */
127 public CrashInfo crashInfo;
128
129 /**
130 * If this report is of type {@link #TYPE_ANR}, contains an instance
131 * of AnrInfo describing the ANR; otherwise null.
132 */
133 public AnrInfo anrInfo;
134
135 /**
Jacek Surazski151de3d2010-02-26 22:52:44 +0100136 * If this report is of type {@link #TYPE_BATTERY}, contains an instance
137 * of BatteryInfo; otherwise null.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800138 */
Jacek Surazski151de3d2010-02-26 22:52:44 +0100139 public BatteryInfo batteryInfo;
Brad Fitzpatrickcb9ceb12010-07-29 14:29:02 -0700140
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800141 /**
Dianne Hackborn14bfa392010-07-24 19:58:06 -0700142 * If this report is of type {@link #TYPE_RUNNING_SERVICE}, contains an instance
143 * of RunningServiceInfo; otherwise null.
144 */
145 public RunningServiceInfo runningServiceInfo;
146
147 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200148 * Create an uninitialized instance of {@link ApplicationErrorReport}.
149 */
150 public ApplicationErrorReport() {
151 }
152
153 /**
154 * Create an instance of {@link ApplicationErrorReport} initialized from
155 * a parcel.
156 */
157 ApplicationErrorReport(Parcel in) {
Jacek Surazski28b0e5d2009-05-25 17:56:41 +0200158 readFromParcel(in);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200159 }
160
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800161 public static ComponentName getErrorReportReceiver(Context context,
162 String packageName, int appFlags) {
163 // check if error reporting is enabled in secure settings
Jeff Sharkey625239a2012-09-26 22:03:49 -0700164 int enabled = Settings.Global.getInt(context.getContentResolver(),
165 Settings.Global.SEND_ACTION_APP_ERROR, 0);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800166 if (enabled == 0) {
167 return null;
168 }
169
170 PackageManager pm = context.getPackageManager();
171
172 // look for receiver in the installer package
louis_changbd4a9a02014-07-31 10:47:45 +0800173 String candidate = null;
174 ComponentName result = null;
175
176 try {
177 candidate = pm.getInstallerPackageName(packageName);
178 } catch (IllegalArgumentException e) {
179 // the package could already removed
180 }
181
182 if (candidate != null) {
183 result = getErrorReportReceiver(pm, packageName, candidate);
184 if (result != null) {
185 return result;
186 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800187 }
188
189 // if the error app is on the system image, look for system apps
190 // error receiver
191 if ((appFlags&ApplicationInfo.FLAG_SYSTEM) != 0) {
192 candidate = SystemProperties.get(SYSTEM_APPS_ERROR_RECEIVER_PROPERTY);
193 result = getErrorReportReceiver(pm, packageName, candidate);
194 if (result != null) {
195 return result;
196 }
197 }
198
199 // if there is a default receiver, try that
200 candidate = SystemProperties.get(DEFAULT_ERROR_RECEIVER_PROPERTY);
201 return getErrorReportReceiver(pm, packageName, candidate);
202 }
Jacek Surazski87d0b2f2010-08-02 13:03:35 +0200203
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800204 /**
205 * Return activity in receiverPackage that handles ACTION_APP_ERROR.
206 *
Madan Ankapuraae96f632010-06-18 18:16:58 -0700207 * @param pm PackageManager instance
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800208 * @param errorPackage package which caused the error
209 * @param receiverPackage candidate package to receive the error
210 * @return activity component within receiverPackage which handles
211 * ACTION_APP_ERROR, or null if not found
212 */
213 static ComponentName getErrorReportReceiver(PackageManager pm, String errorPackage,
214 String receiverPackage) {
215 if (receiverPackage == null || receiverPackage.length() == 0) {
216 return null;
217 }
218
219 // break the loop if it's the error report receiver package that crashed
220 if (receiverPackage.equals(errorPackage)) {
221 return null;
222 }
223
224 Intent intent = new Intent(Intent.ACTION_APP_ERROR);
225 intent.setPackage(receiverPackage);
226 ResolveInfo info = pm.resolveActivity(intent, 0);
227 if (info == null || info.activityInfo == null) {
228 return null;
229 }
230 return new ComponentName(receiverPackage, info.activityInfo.name);
231 }
232
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200233 public void writeToParcel(Parcel dest, int flags) {
234 dest.writeInt(type);
235 dest.writeString(packageName);
236 dest.writeString(installerPackageName);
237 dest.writeString(processName);
238 dest.writeLong(time);
Jacek Surazskie0ee6ef2010-01-07 16:23:03 +0100239 dest.writeInt(systemApp ? 1 : 0);
louis_chang3d86b882015-04-08 18:04:11 +0800240 dest.writeInt(crashInfo != null ? 1 : 0);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200241
242 switch (type) {
243 case TYPE_CRASH:
louis_chang3d86b882015-04-08 18:04:11 +0800244 if (crashInfo != null) {
245 crashInfo.writeToParcel(dest, flags);
246 }
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200247 break;
248 case TYPE_ANR:
249 anrInfo.writeToParcel(dest, flags);
250 break;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800251 case TYPE_BATTERY:
Jacek Surazski151de3d2010-02-26 22:52:44 +0100252 batteryInfo.writeToParcel(dest, flags);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800253 break;
Dianne Hackborn14bfa392010-07-24 19:58:06 -0700254 case TYPE_RUNNING_SERVICE:
255 runningServiceInfo.writeToParcel(dest, flags);
256 break;
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200257 }
258 }
259
Jacek Surazskifd0bdcc2009-05-27 14:45:48 +0200260 public void readFromParcel(Parcel in) {
Jacek Surazski28b0e5d2009-05-25 17:56:41 +0200261 type = in.readInt();
262 packageName = in.readString();
263 installerPackageName = in.readString();
264 processName = in.readString();
265 time = in.readLong();
Jacek Surazskie0ee6ef2010-01-07 16:23:03 +0100266 systemApp = in.readInt() == 1;
louis_chang3d86b882015-04-08 18:04:11 +0800267 boolean hasCrashInfo = in.readInt() == 1;
Jacek Surazski28b0e5d2009-05-25 17:56:41 +0200268
269 switch (type) {
270 case TYPE_CRASH:
louis_chang3d86b882015-04-08 18:04:11 +0800271 crashInfo = hasCrashInfo ? new CrashInfo(in) : null;
Jacek Surazski28b0e5d2009-05-25 17:56:41 +0200272 anrInfo = null;
Jacek Surazski151de3d2010-02-26 22:52:44 +0100273 batteryInfo = null;
Dianne Hackborn14bfa392010-07-24 19:58:06 -0700274 runningServiceInfo = null;
Jacek Surazski28b0e5d2009-05-25 17:56:41 +0200275 break;
276 case TYPE_ANR:
277 anrInfo = new AnrInfo(in);
278 crashInfo = null;
Jacek Surazski151de3d2010-02-26 22:52:44 +0100279 batteryInfo = null;
Dianne Hackborn14bfa392010-07-24 19:58:06 -0700280 runningServiceInfo = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800281 break;
282 case TYPE_BATTERY:
Jacek Surazski151de3d2010-02-26 22:52:44 +0100283 batteryInfo = new BatteryInfo(in);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800284 anrInfo = null;
285 crashInfo = null;
Dianne Hackborn14bfa392010-07-24 19:58:06 -0700286 runningServiceInfo = null;
287 break;
288 case TYPE_RUNNING_SERVICE:
289 batteryInfo = null;
290 anrInfo = null;
291 crashInfo = null;
292 runningServiceInfo = new RunningServiceInfo(in);
Jacek Surazski28b0e5d2009-05-25 17:56:41 +0200293 break;
294 }
295 }
296
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200297 /**
298 * Describes an application crash.
299 */
300 public static class CrashInfo {
301 /**
302 * Class name of the exception that caused the crash.
303 */
304 public String exceptionClassName;
305
306 /**
Jacek Surazskif829a782009-06-11 22:47:02 +0200307 * Message stored in the exception.
308 */
309 public String exceptionMessage;
310
311 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200312 * File which the exception was thrown from.
313 */
314 public String throwFileName;
315
316 /**
317 * Class which the exception was thrown from.
318 */
319 public String throwClassName;
320
321 /**
322 * Method which the exception was thrown from.
323 */
324 public String throwMethodName;
325
326 /**
Jacek Surazski5a123732009-06-23 14:57:08 +0200327 * Line number the exception was thrown from.
328 */
329 public int throwLineNumber;
330
331 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200332 * Stack trace.
333 */
334 public String stackTrace;
335
336 /**
Garfield Tan2746ab52018-07-25 12:33:01 -0700337 * Crash tag for some context.
338 * @hide
339 */
340 public String crashTag;
341
342 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200343 * Create an uninitialized instance of CrashInfo.
344 */
345 public CrashInfo() {
346 }
347
348 /**
Dan Egnorb7f03672009-12-09 16:22:32 -0800349 * Create an instance of CrashInfo initialized from an exception.
350 */
351 public CrashInfo(Throwable tr) {
352 StringWriter sw = new StringWriter();
Dianne Hackborn8c841092013-06-24 13:46:13 -0700353 PrintWriter pw = new FastPrintWriter(sw, false, 256);
354 tr.printStackTrace(pw);
355 pw.flush();
Adrian Roos732ae952016-07-01 13:11:18 -0700356 stackTrace = sanitizeString(sw.toString());
Dan Egnor60d87622009-12-16 16:32:58 -0800357 exceptionMessage = tr.getMessage();
Dan Egnorb7f03672009-12-09 16:22:32 -0800358
359 // Populate fields with the "root cause" exception
Dianne Hackborn8e8d65f2011-08-11 19:36:18 -0700360 Throwable rootTr = tr;
Dan Egnorb7f03672009-12-09 16:22:32 -0800361 while (tr.getCause() != null) {
362 tr = tr.getCause();
Dianne Hackborn8e8d65f2011-08-11 19:36:18 -0700363 if (tr.getStackTrace() != null && tr.getStackTrace().length > 0) {
364 rootTr = tr;
365 }
Dan Egnorb7f03672009-12-09 16:22:32 -0800366 String msg = tr.getMessage();
367 if (msg != null && msg.length() > 0) {
368 exceptionMessage = msg;
369 }
370 }
371
Dianne Hackborn8e8d65f2011-08-11 19:36:18 -0700372 exceptionClassName = rootTr.getClass().getName();
373 if (rootTr.getStackTrace().length > 0) {
374 StackTraceElement trace = rootTr.getStackTrace()[0];
375 throwFileName = trace.getFileName();
376 throwClassName = trace.getClassName();
377 throwMethodName = trace.getMethodName();
378 throwLineNumber = trace.getLineNumber();
379 } else {
380 throwFileName = "unknown";
381 throwClassName = "unknown";
382 throwMethodName = "unknown";
383 throwLineNumber = 0;
384 }
Adrian Roos732ae952016-07-01 13:11:18 -0700385
386 exceptionMessage = sanitizeString(exceptionMessage);
387 }
388
Jeff Sharkey58f27b52016-12-06 16:47:00 -0700389 /** {@hide} */
390 public void appendStackTrace(String tr) {
391 stackTrace = sanitizeString(stackTrace + tr);
392 }
393
Adrian Roos732ae952016-07-01 13:11:18 -0700394 /**
395 * Ensure that the string is of reasonable size, truncating from the middle if needed.
396 */
397 private String sanitizeString(String s) {
398 int prefixLength = 10 * 1024;
399 int suffixLength = 10 * 1024;
400 int acceptableLength = prefixLength + suffixLength;
401
402 if (s != null && s.length() > acceptableLength) {
403 String replacement =
404 "\n[TRUNCATED " + (s.length() - acceptableLength) + " CHARS]\n";
405
406 StringBuilder sb = new StringBuilder(acceptableLength + replacement.length());
407 sb.append(s.substring(0, prefixLength));
408 sb.append(replacement);
409 sb.append(s.substring(s.length() - suffixLength));
410 return sb.toString();
411 }
412 return s;
Dan Egnorb7f03672009-12-09 16:22:32 -0800413 }
414
415 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200416 * Create an instance of CrashInfo initialized from a Parcel.
417 */
418 public CrashInfo(Parcel in) {
419 exceptionClassName = in.readString();
Jacek Surazskif829a782009-06-11 22:47:02 +0200420 exceptionMessage = in.readString();
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200421 throwFileName = in.readString();
422 throwClassName = in.readString();
423 throwMethodName = in.readString();
Jacek Surazski5a123732009-06-23 14:57:08 +0200424 throwLineNumber = in.readInt();
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200425 stackTrace = in.readString();
Garfield Tan2746ab52018-07-25 12:33:01 -0700426 crashTag = in.readString();
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200427 }
428
429 /**
430 * Save a CrashInfo instance to a parcel.
431 */
432 public void writeToParcel(Parcel dest, int flags) {
Dianne Hackborn73d6a822014-09-29 10:52:47 -0700433 int start = dest.dataPosition();
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200434 dest.writeString(exceptionClassName);
Jacek Surazskif829a782009-06-11 22:47:02 +0200435 dest.writeString(exceptionMessage);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200436 dest.writeString(throwFileName);
437 dest.writeString(throwClassName);
438 dest.writeString(throwMethodName);
Jacek Surazski5a123732009-06-23 14:57:08 +0200439 dest.writeInt(throwLineNumber);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200440 dest.writeString(stackTrace);
Garfield Tan2746ab52018-07-25 12:33:01 -0700441 dest.writeString(crashTag);
Dianne Hackborn73d6a822014-09-29 10:52:47 -0700442 int total = dest.dataPosition()-start;
Jeff Sharkeyf5299f12017-03-17 10:25:07 -0600443 if (Binder.CHECK_PARCEL_SIZE && total > 20*1024) {
Dianne Hackborn73d6a822014-09-29 10:52:47 -0700444 Slog.d("Error", "ERR: exClass=" + exceptionClassName);
445 Slog.d("Error", "ERR: exMsg=" + exceptionMessage);
446 Slog.d("Error", "ERR: file=" + throwFileName);
447 Slog.d("Error", "ERR: class=" + throwClassName);
448 Slog.d("Error", "ERR: method=" + throwMethodName + " line=" + throwLineNumber);
449 Slog.d("Error", "ERR: stack=" + stackTrace);
450 Slog.d("Error", "ERR: TOTAL BYTES WRITTEN: " + (dest.dataPosition()-start));
451 }
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200452 }
453
454 /**
455 * Dump a CrashInfo instance to a Printer.
456 */
457 public void dump(Printer pw, String prefix) {
458 pw.println(prefix + "exceptionClassName: " + exceptionClassName);
Jacek Surazskif829a782009-06-11 22:47:02 +0200459 pw.println(prefix + "exceptionMessage: " + exceptionMessage);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200460 pw.println(prefix + "throwFileName: " + throwFileName);
461 pw.println(prefix + "throwClassName: " + throwClassName);
462 pw.println(prefix + "throwMethodName: " + throwMethodName);
Jacek Surazski5a123732009-06-23 14:57:08 +0200463 pw.println(prefix + "throwLineNumber: " + throwLineNumber);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200464 pw.println(prefix + "stackTrace: " + stackTrace);
465 }
466 }
467
468 /**
Sudheer Shankafc46e9b2016-10-21 17:55:27 -0700469 * Parcelable version of {@link CrashInfo}
470 *
471 * @hide
472 */
473 public static class ParcelableCrashInfo extends CrashInfo implements Parcelable {
474 /**
475 * Create an uninitialized instance of CrashInfo.
476 */
477 public ParcelableCrashInfo() {
478 }
479
480 /**
481 * Create an instance of CrashInfo initialized from an exception.
482 */
483 public ParcelableCrashInfo(Throwable tr) {
484 super(tr);
485 }
486
487 public ParcelableCrashInfo(Parcel in) {
488 super(in);
489 }
490
491 public int describeContents() {
492 return 0;
493 }
494
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700495 public static final @android.annotation.NonNull Parcelable.Creator<ParcelableCrashInfo> CREATOR =
Sudheer Shankafc46e9b2016-10-21 17:55:27 -0700496 new Parcelable.Creator<ParcelableCrashInfo>() {
497 @Override
498 public ParcelableCrashInfo createFromParcel(Parcel in) {
499 return new ParcelableCrashInfo(in);
500 }
501
502 @Override
503 public ParcelableCrashInfo[] newArray(int size) {
504 return new ParcelableCrashInfo[size];
505 }
506 };
507 }
508
509 /**
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200510 * Describes an application not responding error.
511 */
512 public static class AnrInfo {
513 /**
514 * Activity name.
515 */
516 public String activity;
517
518 /**
519 * Description of the operation that timed out.
520 */
521 public String cause;
522
523 /**
524 * Additional info, including CPU stats.
525 */
526 public String info;
527
528 /**
529 * Create an uninitialized instance of AnrInfo.
530 */
531 public AnrInfo() {
532 }
533
534 /**
535 * Create an instance of AnrInfo initialized from a Parcel.
536 */
537 public AnrInfo(Parcel in) {
538 activity = in.readString();
539 cause = in.readString();
540 info = in.readString();
541 }
542
543 /**
544 * Save an AnrInfo instance to a parcel.
545 */
546 public void writeToParcel(Parcel dest, int flags) {
547 dest.writeString(activity);
548 dest.writeString(cause);
549 dest.writeString(info);
550 }
551
552 /**
553 * Dump an AnrInfo instance to a Printer.
554 */
555 public void dump(Printer pw, String prefix) {
556 pw.println(prefix + "activity: " + activity);
557 pw.println(prefix + "cause: " + cause);
558 pw.println(prefix + "info: " + info);
559 }
560 }
561
Jacek Surazski151de3d2010-02-26 22:52:44 +0100562 /**
563 * Describes a battery usage report.
564 */
565 public static class BatteryInfo {
566 /**
567 * Percentage of the battery that was used up by the process.
568 */
569 public int usagePercent;
570
571 /**
572 * Duration in microseconds over which the process used the above
573 * percentage of battery.
574 */
575 public long durationMicros;
576
577 /**
578 * Dump of various info impacting battery use.
579 */
580 public String usageDetails;
581
582 /**
583 * Checkin details.
584 */
585 public String checkinDetails;
586
587 /**
588 * Create an uninitialized instance of BatteryInfo.
589 */
590 public BatteryInfo() {
591 }
592
593 /**
594 * Create an instance of BatteryInfo initialized from a Parcel.
595 */
596 public BatteryInfo(Parcel in) {
597 usagePercent = in.readInt();
598 durationMicros = in.readLong();
599 usageDetails = in.readString();
600 checkinDetails = in.readString();
601 }
602
603 /**
604 * Save a BatteryInfo instance to a parcel.
605 */
606 public void writeToParcel(Parcel dest, int flags) {
607 dest.writeInt(usagePercent);
608 dest.writeLong(durationMicros);
609 dest.writeString(usageDetails);
610 dest.writeString(checkinDetails);
611 }
612
613 /**
614 * Dump a BatteryInfo instance to a Printer.
615 */
616 public void dump(Printer pw, String prefix) {
617 pw.println(prefix + "usagePercent: " + usagePercent);
618 pw.println(prefix + "durationMicros: " + durationMicros);
619 pw.println(prefix + "usageDetails: " + usageDetails);
620 pw.println(prefix + "checkinDetails: " + checkinDetails);
621 }
622 }
623
Dianne Hackborn14bfa392010-07-24 19:58:06 -0700624 /**
625 * Describes a running service report.
626 */
627 public static class RunningServiceInfo {
628 /**
629 * Duration in milliseconds that the service has been running.
630 */
631 public long durationMillis;
632
633 /**
634 * Dump of debug information about the service.
635 */
636 public String serviceDetails;
637
638 /**
639 * Create an uninitialized instance of RunningServiceInfo.
640 */
641 public RunningServiceInfo() {
642 }
643
644 /**
645 * Create an instance of RunningServiceInfo initialized from a Parcel.
646 */
647 public RunningServiceInfo(Parcel in) {
648 durationMillis = in.readLong();
649 serviceDetails = in.readString();
650 }
651
652 /**
653 * Save a RunningServiceInfo instance to a parcel.
654 */
655 public void writeToParcel(Parcel dest, int flags) {
656 dest.writeLong(durationMillis);
657 dest.writeString(serviceDetails);
658 }
659
660 /**
661 * Dump a BatteryInfo instance to a Printer.
662 */
663 public void dump(Printer pw, String prefix) {
664 pw.println(prefix + "durationMillis: " + durationMillis);
665 pw.println(prefix + "serviceDetails: " + serviceDetails);
666 }
667 }
668
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700669 public static final @android.annotation.NonNull Parcelable.Creator<ApplicationErrorReport> CREATOR
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200670 = new Parcelable.Creator<ApplicationErrorReport>() {
671 public ApplicationErrorReport createFromParcel(Parcel source) {
672 return new ApplicationErrorReport(source);
673 }
674
675 public ApplicationErrorReport[] newArray(int size) {
676 return new ApplicationErrorReport[size];
677 }
678 };
679
680 public int describeContents() {
681 return 0;
682 }
683
684 /**
685 * Dump the report to a Printer.
686 */
687 public void dump(Printer pw, String prefix) {
688 pw.println(prefix + "type: " + type);
689 pw.println(prefix + "packageName: " + packageName);
690 pw.println(prefix + "installerPackageName: " + installerPackageName);
691 pw.println(prefix + "processName: " + processName);
692 pw.println(prefix + "time: " + time);
Jacek Surazskie0ee6ef2010-01-07 16:23:03 +0100693 pw.println(prefix + "systemApp: " + systemApp);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200694
695 switch (type) {
696 case TYPE_CRASH:
697 crashInfo.dump(pw, prefix);
698 break;
699 case TYPE_ANR:
700 anrInfo.dump(pw, prefix);
701 break;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800702 case TYPE_BATTERY:
Jacek Surazski151de3d2010-02-26 22:52:44 +0100703 batteryInfo.dump(pw, prefix);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800704 break;
Jacek Surazski87d0b2f2010-08-02 13:03:35 +0200705 case TYPE_RUNNING_SERVICE:
706 runningServiceInfo.dump(pw, prefix);
707 break;
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200708 }
709 }
710}