From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dmitry Muhomor Date: Mon, 8 Aug 2022 19:03:37 +0300 Subject: [PATCH] add an option to show the details of an application error to the user Adds a "Show details" item to crash and ANR (app not responding) dialogs that takes the user to a SystemUI activity which shows the error details and allows to copy them to the clipboard or to export them via the standard sharing UI. --- .../android/app/ApplicationErrorReport.java | 29 +++++++++++++++++-- core/res/res/layout/app_anr_dialog.xml | 4 +-- core/res/res/layout/app_error_dialog.xml | 4 +-- core/res/res/values/strings.xml | 2 ++ core/res/res/values/symbols.xml | 3 ++ .../java/com/android/server/am/AppErrors.java | 1 + 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java index 9cea5e8ef4cf..a8f51104d0fa 100644 --- a/core/java/android/app/ApplicationErrorReport.java +++ b/core/java/android/app/ApplicationErrorReport.java @@ -25,6 +25,8 @@ import android.content.pm.ResolveInfo; import android.os.Binder; import android.os.Parcel; import android.os.Parcelable; +import android.os.Process; +import android.os.SystemClock; import android.os.SystemProperties; import android.provider.Settings; import android.util.Printer; @@ -98,6 +100,9 @@ public class ApplicationErrorReport implements Parcelable { */ public String packageName; + /** @hide */ + public long packageVersion; + /** * Package name of the application which installed the application this * report pertains to. @@ -162,13 +167,19 @@ public class ApplicationErrorReport implements Parcelable { String packageName, int appFlags) { // check if error reporting is enabled in secure settings int enabled = Settings.Global.getInt(context.getContentResolver(), - Settings.Global.SEND_ACTION_APP_ERROR, 0); + Settings.Global.SEND_ACTION_APP_ERROR, 1); if (enabled == 0) { return null; } PackageManager pm = context.getPackageManager(); + ComponentName logViewerApp = getErrorReportReceiver(pm, packageName, + android.ext.LogViewerApp.getPackageName()); + if (logViewerApp != null) { + return logViewerApp; + } + // look for receiver in the installer package String candidate = null; ComponentName result = null; @@ -233,6 +244,7 @@ public class ApplicationErrorReport implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(type); dest.writeString(packageName); + dest.writeLong(packageVersion); dest.writeString(installerPackageName); dest.writeString(processName); dest.writeLong(time); @@ -260,6 +272,7 @@ public class ApplicationErrorReport implements Parcelable { public void readFromParcel(Parcel in) { type = in.readInt(); packageName = in.readString(); + packageVersion = in.readLong(); installerPackageName = in.readString(); processName = in.readString(); time = in.readLong(); @@ -345,6 +358,11 @@ public class ApplicationErrorReport implements Parcelable { */ public String crashTag; + /** @hide */ + public long processUptimeMs; + /** @hide */ + public long processStartupLatencyMs; + /** * Create an uninitialized instance of CrashInfo. */ @@ -398,6 +416,9 @@ public class ApplicationErrorReport implements Parcelable { } exceptionMessage = sanitizeString(exceptionMessage); + + processUptimeMs = SystemClock.elapsedRealtime() - Process.getStartElapsedRealtime(); + processStartupLatencyMs = Process.getStartElapsedRealtime() - Process.getStartRequestedElapsedRealtime(); } /** {@hide} */ @@ -439,6 +460,8 @@ public class ApplicationErrorReport implements Parcelable { throwLineNumber = in.readInt(); stackTrace = in.readString(); crashTag = in.readString(); + processUptimeMs = in.readLong(); + processStartupLatencyMs = in.readLong(); } /** @@ -455,6 +478,8 @@ public class ApplicationErrorReport implements Parcelable { dest.writeInt(throwLineNumber); dest.writeString(stackTrace); dest.writeString(crashTag); + dest.writeLong(processUptimeMs); + dest.writeLong(processStartupLatencyMs); int total = dest.dataPosition()-start; if (Binder.CHECK_PARCEL_SIZE && total > 20*1024) { Slog.d("Error", "ERR: exHandler=" + exceptionHandlerClassName); @@ -704,7 +729,7 @@ public class ApplicationErrorReport implements Parcelable { */ public void dump(Printer pw, String prefix) { pw.println(prefix + "type: " + type); - pw.println(prefix + "packageName: " + packageName); + pw.println(prefix + "packageName: " + packageName + ":" + packageVersion); pw.println(prefix + "installerPackageName: " + installerPackageName); pw.println(prefix + "processName: " + processName); pw.println(prefix + "time: " + time); diff --git a/core/res/res/layout/app_anr_dialog.xml b/core/res/res/layout/app_anr_dialog.xml index 5ad0f4c0f6cc..ad3a2d2991de 100644 --- a/core/res/res/layout/app_anr_dialog.xml +++ b/core/res/res/layout/app_anr_dialog.xml @@ -41,8 +41,8 @@ android:id="@+id/aerr_report" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/aerr_report" - android:drawableStart="@drawable/ic_feedback" + android:text="@string/aerr_show_details" + android:drawableStart="@drawable/ic_info_outline_24" style="@style/aerr_list_item" /> diff --git a/core/res/res/layout/app_error_dialog.xml b/core/res/res/layout/app_error_dialog.xml index c3b149a1e295..a47b82018377 100644 --- a/core/res/res/layout/app_error_dialog.xml +++ b/core/res/res/layout/app_error_dialog.xml @@ -52,8 +52,8 @@ android:id="@+id/aerr_report" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/aerr_report" - android:drawableStart="@drawable/ic_feedback" + android:text="@string/aerr_show_details" + android:drawableStart="@drawable/ic_info_outline_24" style="@style/aerr_list_item" />