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, 50 DialogInterface.OnClickListener listener) { 51 super.onPrepareDialogBuilder(builder, listener); 52 53 final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null); 54 mInteractiveTitle = (CheckedTextView) dialogView 55 .findViewById(R.id.bugreport_option_interactive_title); 56 mInteractiveSummary = (TextView) dialogView 57 .findViewById(R.id.bugreport_option_interactive_summary); 58 mFullTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_full_title); 59 mFullSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_full_summary); 60 final View.OnClickListener l = new View.OnClickListener() { 61 62 @Override 63 public void onClick(View v) { 64 if (v == mFullTitle || v == mFullSummary) { 65 mInteractiveTitle.setChecked(false); 66 mFullTitle.setChecked(true); 67 } 68 if (v == mInteractiveTitle || v == mInteractiveSummary) { 69 mInteractiveTitle.setChecked(true); 70 mFullTitle.setChecked(false); 71 } 72 } 73 }; 74 mInteractiveTitle.setOnClickListener(l); 75 mFullTitle.setOnClickListener(l); 76 mInteractiveSummary.setOnClickListener(l); 77 mFullSummary.setOnClickListener(l); 78 79 builder.setPositiveButton(com.android.internal.R.string.report, listener); 80 builder.setView(dialogView); 81 } 82 83 @Override onClick(DialogInterface dialog, int which)84 protected void onClick(DialogInterface dialog, int which) { 85 if (which == DialogInterface.BUTTON_POSITIVE) { 86 87 final Context context = getContext(); 88 if (mFullTitle.isChecked()) { 89 Log.v(TAG, "Taking full bugreport right away"); 90 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().action(context, 91 SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_FULL); 92 try { 93 ActivityManager.getService().requestFullBugReport(); 94 } catch (RemoteException e) { 95 Log.e(TAG, "error taking bugreport (bugreportType=Full)", e); 96 } 97 } else { 98 Log.v(TAG, "Taking interactive bugreport right away"); 99 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().action(context, 100 SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE); 101 try { 102 ActivityManager.getService().requestInteractiveBugReport(); 103 } catch (RemoteException e) { 104 Log.e(TAG, "error taking bugreport (bugreportType=Interactive)", e); 105 } 106 } 107 } 108 } 109 } 110