From d9e1df58be2882d025aa0585e0258742afad21cb Mon Sep 17 00:00:00 2001 From: mukesh agrawal Date: Mon, 22 Jan 2018 14:07:31 -0800 Subject: [PATCH] ActivityManager: add API for wifi bug report Under certain (limited) conditions, we would like to automatically trigger a bug report to help diagnose Wifi problems. The regular bugreport can't be used for this purpose, as it takes a long time to generate. To support lightweight auto-bug generation, add a Wifi-specific bugreport. Bug: 69934148 Test: manual Manual test ----------- - boot walleye - enable wifi - connect to googleguest $ adb root $ adb shell pkill -f 'wifi@' - notice "Bug report #1 captured" notification $ adb pull '/data/user_de/0/com.android.shell/files/bugreports $ unzip bugreports/*.zip $ grep "was the duration of 'DUMPSTATE'" bugreport*.txt -> ------ 1.548s was the duration of 'DUMPSTATE' ------ Change-Id: If657eb8f61b16cefe717c977663438c28f515bd7 --- core/java/android/app/ActivityManager.java | 9 ++++- core/java/android/app/IActivityManager.aidl | 14 ++++++++ .../server/am/ActivityManagerService.java | 35 ++++++++++++++++--- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 455458436c2f2..3e98de92c7d1e 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -181,7 +181,8 @@ public class ActivityManager { BUGREPORT_OPTION_INTERACTIVE, BUGREPORT_OPTION_REMOTE, BUGREPORT_OPTION_WEAR, - BUGREPORT_OPTION_TELEPHONY + BUGREPORT_OPTION_TELEPHONY, + BUGREPORT_OPTION_WIFI }) public @interface BugreportMode {} /** @@ -215,6 +216,12 @@ public class ActivityManager { */ public static final int BUGREPORT_OPTION_TELEPHONY = 4; + /** + * Takes a lightweight bugreport that only includes a few sections related to Wifi. + * @hide + */ + public static final int BUGREPORT_OPTION_WIFI = 5; + /** * {@code * } name for a 'home' Activity that declares a package that is to be diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index 04ee77d764aa9..7043a7a89c124 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -357,6 +357,20 @@ interface IActivityManager { */ void requestTelephonyBugReport(in String shareTitle, in String shareDescription); + /** + * Deprecated - This method is only used by Wifi, and it will soon be replaced by a proper + * bug report API. + * + * Takes a minimal bugreport of Wifi-related state. + * + * @param shareTitle should be a valid legible string less than 50 chars long + * @param shareDescription should be less than 91 bytes when encoded into UTF-8 format + * + * @throws IllegalArgumentException if shareTitle or shareDescription is too big or if the + * parameters cannot be encoding to an UTF-8 charset. + */ + void requestWifiBugReport(in String shareTitle, in String shareDescription); + long inputDispatchingTimedOut(int pid, boolean aboveSystem, in String reason); void clearPendingBackup(); Intent getIntentForIntentSender(in IIntentSender sender); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 1eec982a0a9af..efd0f349f04c0 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13088,6 +13088,9 @@ public class ActivityManagerService extends IActivityManager.Stub case ActivityManager.BUGREPORT_OPTION_TELEPHONY: extraOptions = "bugreporttelephony"; break; + case ActivityManager.BUGREPORT_OPTION_WIFI: + extraOptions = "bugreportwifi"; + break; default: throw new IllegalArgumentException("Provided bugreport type is not correct, value: " + bugreportType); @@ -13109,9 +13112,8 @@ public class ActivityManagerService extends IActivityManager.Stub * No new code should be calling it. */ @Deprecated - @Override - public void requestTelephonyBugReport(String shareTitle, String shareDescription) { - + private void requestBugReportWithDescription(String shareTitle, String shareDescription, + int bugreportType) { if (!TextUtils.isEmpty(shareTitle)) { if (shareTitle.length() > MAX_BUGREPORT_TITLE_SIZE) { String errorStr = "shareTitle should be less than " + @@ -13140,9 +13142,34 @@ public class ActivityManagerService extends IActivityManager.Stub Slog.d(TAG, "Bugreport notification title " + shareTitle + " description " + shareDescription); - requestBugReport(ActivityManager.BUGREPORT_OPTION_TELEPHONY); + requestBugReport(bugreportType); } + /** + * @deprecated This method is only used by a few internal components and it will soon be + * replaced by a proper bug report API (which will be restricted to a few, pre-defined apps). + * No new code should be calling it. + */ + @Deprecated + @Override + public void requestTelephonyBugReport(String shareTitle, String shareDescription) { + requestBugReportWithDescription(shareTitle, shareDescription, + ActivityManager.BUGREPORT_OPTION_TELEPHONY); + } + + /** + * @deprecated This method is only used by a few internal components and it will soon be + * replaced by a proper bug report API (which will be restricted to a few, pre-defined apps). + * No new code should be calling it. + */ + @Deprecated + @Override + public void requestWifiBugReport(String shareTitle, String shareDescription) { + requestBugReportWithDescription(shareTitle, shareDescription, + ActivityManager.BUGREPORT_OPTION_WIFI); + } + + public static long getInputDispatchingTimeoutLocked(ActivityRecord r) { return r != null ? getInputDispatchingTimeoutLocked(r.app) : KEY_DISPATCHING_TIMEOUT; }