From c5c84bc405bac2c6afc5b09a20796ab03c3d8e8d Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Thu, 21 Feb 2019 16:20:10 +0000 Subject: [PATCH] Trigger a bugreport directly from shell Send broadcast to shell, so that it makes a call to bugreport API directly. Permission protected call is made so that not any app can send this broadcast intent to shell. Use Settings feature flag to turn on this workflow and leave the old workflow untouched. Bug: 123617758 Test: build and manual test by triggering bugreports from the device Change-Id: Iec43fa1e5e379e2f5520a48f7fe036d59e2a8d28 --- .../android/settings/BugreportPreference.java | 29 ++++++++++++++++++- .../android/settings/core/FeatureFlags.java | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/BugreportPreference.java b/src/com/android/settings/BugreportPreference.java index 1652ad24c7b..f5b739a84e5 100644 --- a/src/com/android/settings/BugreportPreference.java +++ b/src/com/android/settings/BugreportPreference.java @@ -21,20 +21,30 @@ import android.app.settings.SettingsEnums; import android.content.Context; import android.content.DialogInterface; import android.os.RemoteException; +import android.os.BugreportParams; +import android.os.SystemProperties; import android.util.AttributeSet; +import android.util.FeatureFlagUtils; import android.util.Log; import android.view.View; import android.widget.CheckedTextView; import android.widget.TextView; +import android.content.Intent; import androidx.appcompat.app.AlertDialog.Builder; +import com.android.settings.core.FeatureFlags; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.CustomDialogPreferenceCompat; public class BugreportPreference extends CustomDialogPreferenceCompat { private static final String TAG = "BugreportPreference"; + private static final String INTENT_BUGREPORT_REQUESTED = + "com.android.internal.intent.action.BUGREPORT_REQUESTED"; + private static final String EXTRA_ORIGINAL_INTENT = "android.intent.extra.ORIGINAL_INTENT"; + private static final String EXTRA_BUGREPORT_TYPE = "android.intent.extra.BUGREPORT_TYPE"; + private static final String SHELL_APP_PACKAGE = "com.android.shell"; private CheckedTextView mInteractiveTitle; private TextView mInteractiveSummary; @@ -98,7 +108,24 @@ public class BugreportPreference extends CustomDialogPreferenceCompat { private void takeBugreport(int bugreportType) { try { - ActivityManager.getService().requestBugReport(bugreportType); + final Context context = getContext(); + // USE_BUGREPORT_API is a system property flag used to switch back to the old workflow + // using dumpstate. By using the default value as false, old workflow remains + // untouched. To switch to the new workflow using Bugreport API run the following + // commands on the terminal: + // * adb root + // * adb shell setprop settings_call_bugreport_api true + if (FeatureFlagUtils.isEnabled(context, FeatureFlags.USE_BUGREPORT_API)) { + Intent triggerShellBugreport = new Intent(); + triggerShellBugreport.setAction(INTENT_BUGREPORT_REQUESTED); + triggerShellBugreport.setPackage(SHELL_APP_PACKAGE); + triggerShellBugreport.putExtra(EXTRA_BUGREPORT_TYPE, bugreportType); + + // Send broadcast to shell to trigger bugreport using Bugreport API + context.sendBroadcast(triggerShellBugreport); + } else { + ActivityManager.getService().requestBugReport(bugreportType); + } } catch (RemoteException e) { Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e); } diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java index fee9c42a82d..b13d712c8c8 100644 --- a/src/com/android/settings/core/FeatureFlags.java +++ b/src/com/android/settings/core/FeatureFlags.java @@ -21,6 +21,7 @@ package com.android.settings.core; */ public class FeatureFlags { public static final String AUDIO_SWITCHER_SETTINGS = "settings_audio_switcher"; + public static final String USE_BUGREPORT_API = "settings_call_bugreport_api"; public static final String DYNAMIC_SYSTEM = "settings_dynamic_system"; public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid"; public static final String MOBILE_NETWORK_V2 = "settings_mobile_network_v2";