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.ActivityManagerNative;
21 import android.app.AlertDialog.Builder;
22 import android.content.Context;
23 import android.content.DialogInterface;
24 import android.os.RemoteException;
25 import android.util.AttributeSet;
26 import android.util.Log;
27 import android.view.View;
28 import android.widget.CheckedTextView;
29 import android.widget.TextView;
31 import com.android.internal.logging.MetricsProto.MetricsEvent;
32 import com.android.settings.overlay.FeatureFactory;
34 public class BugreportPreference extends CustomDialogPreference {
36 private static final String TAG = "BugreportPreference";
38 private CheckedTextView mInteractiveTitle;
39 private TextView mInteractiveSummary;
40 private CheckedTextView mFullTitle;
41 private TextView mFullSummary;
43 public BugreportPreference(Context context, AttributeSet attrs) {
44 super(context, attrs);
48 protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) {
49 super.onPrepareDialogBuilder(builder, listener);
51 final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null);
52 mInteractiveTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_interactive_title);
53 mInteractiveSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_interactive_summary);
54 mFullTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_full_title);
55 mFullSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_full_summary);
56 final View.OnClickListener l = new View.OnClickListener() {
59 public void onClick(View v) {
60 if (v == mFullTitle || v == mFullSummary) {
61 mInteractiveTitle.setChecked(false);
62 mFullTitle.setChecked(true);
64 if (v == mInteractiveTitle || v == mInteractiveSummary) {
65 mInteractiveTitle.setChecked(true);
66 mFullTitle.setChecked(false);
70 mInteractiveTitle.setOnClickListener(l);
71 mFullTitle.setOnClickListener(l);
72 mInteractiveSummary.setOnClickListener(l);
73 mFullSummary.setOnClickListener(l);
75 builder.setPositiveButton(com.android.internal.R.string.report, listener);
76 builder.setView(dialogView);
80 protected void onClick(DialogInterface dialog, int which) {
81 if (which == DialogInterface.BUTTON_POSITIVE) {
83 final Context context = getContext();
84 if (mFullTitle.isChecked()) {
85 Log.v(TAG, "Taking full bugreport right away");
86 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
87 MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_FULL);
88 takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL);
90 Log.v(TAG, "Taking interactive bugreport right away");
91 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
92 MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE);
93 takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
98 private void takeBugreport(int bugreportType) {
100 ActivityManagerNative.getDefault().requestBugReport(bugreportType);
101 } catch (RemoteException e) {
102 Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e);