1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings; 18 19 import android.app.ActivityManager; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.content.DialogInterface; 23 import android.os.RemoteException; 24 import android.util.AttributeSet; 25 import android.util.Log; 26 import android.view.View; 27 import android.widget.CheckedTextView; 28 import android.widget.TextView; 29 30 import androidx.appcompat.app.AlertDialog.Builder; 31 32 import com.android.settings.overlay.FeatureFactory; 33 import com.android.settingslib.CustomDialogPreferenceCompat; 34 35 public class BugreportPreference extends CustomDialogPreferenceCompat { 36 37 private static final String TAG = "BugreportPreference"; 38 39 private CheckedTextView mInteractiveTitle; 40 private TextView mInteractiveSummary; 41 private CheckedTextView mFullTitle; 42 private TextView mFullSummary; 43 BugreportPreference(Context context, AttributeSet attrs)44 public BugreportPreference(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 } 47 48 @Override onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener)49 protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) { 50 super.onPrepareDialogBuilder(builder, listener); 51 52 final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null); 53 mInteractiveTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_interactive_title); 54 mInteractiveSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_interactive_summary); 55 mFullTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_full_title); 56 mFullSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_full_summary); 57 final View.OnClickListener l = new View.OnClickListener() { 58 59 @Override 60 public void onClick(View v) { 61 if (v == mFullTitle || v == mFullSummary) { 62 mInteractiveTitle.setChecked(false); 63 mFullTitle.setChecked(true); 64 } 65 if (v == mInteractiveTitle || v == mInteractiveSummary) { 66 mInteractiveTitle.setChecked(true); 67 mFullTitle.setChecked(false); 68 } 69 } 70 }; 71 mInteractiveTitle.setOnClickListener(l); 72 mFullTitle.setOnClickListener(l); 73 mInteractiveSummary.setOnClickListener(l); 74 mFullSummary.setOnClickListener(l); 75 76 builder.setPositiveButton(com.android.internal.R.string.report, listener); 77 builder.setView(dialogView); 78 } 79 80 @Override onClick(DialogInterface dialog, int which)81 protected void onClick(DialogInterface dialog, int which) { 82 if (which == DialogInterface.BUTTON_POSITIVE) { 83 84 final Context context = getContext(); 85 if (mFullTitle.isChecked()) { 86 Log.v(TAG, "Taking full bugreport right away"); 87 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, 88 SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_FULL); 89 takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL); 90 } else { 91 Log.v(TAG, "Taking interactive bugreport right away"); 92 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, 93 SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE); 94 takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE); 95 } 96 } 97 } 98 takeBugreport(int bugreportType)99 private void takeBugreport(int bugreportType) { 100 try { 101 ActivityManager.getService().requestBugReport(bugreportType); 102 } catch (RemoteException e) { 103 Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e); 104 } 105 } 106 } 107