[ActivityManager] Avoid NullPointerException if no
crash info
Symptom:
This issue happens because the ANR process got killed
(because it crashed) before the ANR dialog dismissed.
In that case, the process record is marked as crashed
(ProcessRecord.crashing = true). When the ANR dialog
dismissed by user, it will cause NullPointerException
when writeToParcel while performing IPC because there
is no crash info (ApplicationErrorReport.crashInfo = null)
Solution:
Check crashinfo before access it
Change-Id: I2995de57684c1e13aab8297f5eea1e82ca3b7ad8
diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java
index 6c2511e..8692336 100644
--- a/core/java/android/app/ApplicationErrorReport.java
+++ b/core/java/android/app/ApplicationErrorReport.java
@@ -235,10 +235,13 @@
dest.writeString(processName);
dest.writeLong(time);
dest.writeInt(systemApp ? 1 : 0);
+ dest.writeInt(crashInfo != null ? 1 : 0);
switch (type) {
case TYPE_CRASH:
- crashInfo.writeToParcel(dest, flags);
+ if (crashInfo != null) {
+ crashInfo.writeToParcel(dest, flags);
+ }
break;
case TYPE_ANR:
anrInfo.writeToParcel(dest, flags);
@@ -259,10 +262,11 @@
processName = in.readString();
time = in.readLong();
systemApp = in.readInt() == 1;
+ boolean hasCrashInfo = in.readInt() == 1;
switch (type) {
case TYPE_CRASH:
- crashInfo = new CrashInfo(in);
+ crashInfo = hasCrashInfo ? new CrashInfo(in) : null;
anrInfo = null;
batteryInfo = null;
runningServiceInfo = null;