2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.ActivityManager;
20 import android.app.AlertDialog.Builder;
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;
30 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
31 import com.android.settings.overlay.FeatureFactory;
33 public class BugreportPreference extends CustomDialogPreference {
35 private static final String TAG = "BugreportPreference";
37 private CheckedTextView mInteractiveTitle;
38 private TextView mInteractiveSummary;
39 private CheckedTextView mFullTitle;
40 private TextView mFullSummary;
42 public BugreportPreference(Context context, AttributeSet attrs) {
43 super(context, attrs);
47 protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) {
48 super.onPrepareDialogBuilder(builder, listener);
50 final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null);
51 mInteractiveTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_interactive_title);
52 mInteractiveSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_interactive_summary);
53 mFullTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_full_title);
54 mFullSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_full_summary);
55 final View.OnClickListener l = new View.OnClickListener() {
58 public void onClick(View v) {
59 if (v == mFullTitle || v == mFullSummary) {
60 mInteractiveTitle.setChecked(false);
61 mFullTitle.setChecked(true);
63 if (v == mInteractiveTitle || v == mInteractiveSummary) {
64 mInteractiveTitle.setChecked(true);
65 mFullTitle.setChecked(false);
69 mInteractiveTitle.setOnClickListener(l);
70 mFullTitle.setOnClickListener(l);
71 mInteractiveSummary.setOnClickListener(l);
72 mFullSummary.setOnClickListener(l);
74 builder.setPositiveButton(com.android.internal.R.string.report, listener);
75 builder.setView(dialogView);
79 protected void onClick(DialogInterface dialog, int which) {
80 if (which == DialogInterface.BUTTON_POSITIVE) {
82 final Context context = getContext();
83 if (mFullTitle.isChecked()) {
84 Log.v(TAG, "Taking full bugreport right away");
85 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
86 MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_FULL);
87 takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL);
89 Log.v(TAG, "Taking interactive bugreport right away");
90 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
91 MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE);
92 takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
97 private void takeBugreport(int bugreportType) {
99 ActivityManager.getService().requestBugReport(bugreportType);
100 } catch (RemoteException e) {
101 Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e);