From d7e44c7b3a3b7f9071f9aec798aefb5faac2c6e2 Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Thu, 22 Aug 2019 15:07:55 +0100 Subject: [PATCH] Remove enum logic from callers of requestbugreport() Make callers use wrapper functions in ActivityManagerService.java. The code to send broadcast to trigger API workflow (after checking the API flag) is added in requestBugreport() in ActivityManagerService.java. Remove that logic from this file. Bug: 137825297 Bug: 141355059 Test: builds and full/interactive bugreports work as expected Change-Id: Ibc305e4aca7d38fd4878b60f3f7f8c3274719c13 --- .../android/settings/BugreportPreference.java | 56 ++++++------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/src/com/android/settings/BugreportPreference.java b/src/com/android/settings/BugreportPreference.java index dfefe5ae72f..598399a3be9 100644 --- a/src/com/android/settings/BugreportPreference.java +++ b/src/com/android/settings/BugreportPreference.java @@ -21,30 +21,20 @@ 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; @@ -56,12 +46,15 @@ public class BugreportPreference extends CustomDialogPreferenceCompat { } @Override - protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) { + protected void onPrepareDialogBuilder(Builder builder, + DialogInterface.OnClickListener listener) { super.onPrepareDialogBuilder(builder, listener); final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null); - mInteractiveTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_interactive_title); - mInteractiveSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_interactive_summary); + mInteractiveTitle = (CheckedTextView) dialogView + .findViewById(R.id.bugreport_option_interactive_title); + mInteractiveSummary = (TextView) dialogView + .findViewById(R.id.bugreport_option_interactive_summary); mFullTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_full_title); mFullSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_full_summary); final View.OnClickListener l = new View.OnClickListener() { @@ -96,38 +89,21 @@ public class BugreportPreference extends CustomDialogPreferenceCompat { Log.v(TAG, "Taking full bugreport right away"); FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_FULL); - takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL); + try { + ActivityManager.getService().requestFullBugReport(); + } catch (RemoteException e) { + Log.e(TAG, "error taking bugreport (bugreportType=Full)", e); + } } else { Log.v(TAG, "Taking interactive bugreport right away"); FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE); - takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE); + try { + ActivityManager.getService().requestInteractiveBugReport(); + } catch (RemoteException e) { + Log.e(TAG, "error taking bugreport (bugreportType=Interactive)", e); + } } } } - - private void takeBugreport(int bugreportType) { - try { - 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 true, new workflow using Bugreport - // API is triggered. To switch to the old workflow directly using dumpstate run the - // following commands on the terminal: - // * adb root - // * adb shell setprop settings_use_bugreport_api false - if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.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); - } - } }