blob: 6371e3a57b27ccecaacc5fee5274e5c8084294ef [file] [log] [blame]
Dianne Hackbornfd8c3152012-07-13 14:26:23 -07001/*
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
17package com.android.settings;
18
Michal Karpinskic78b9262016-01-05 14:33:07 +000019import android.app.ActivityManager;
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070020import android.app.AlertDialog.Builder;
21import android.content.Context;
22import android.content.DialogInterface;
Felipe Leme834496f2015-12-16 10:05:44 -080023import android.os.RemoteException;
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070024import android.util.AttributeSet;
Felipe Leme834496f2015-12-16 10:05:44 -080025import android.util.Log;
26import android.view.View;
27import android.widget.CheckedTextView;
Felipe Leme834496f2015-12-16 10:05:44 -080028import android.widget.TextView;
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070029
Tamas Berghammer265d3c22016-06-22 15:34:45 +010030import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Fan Zhangaa71afe2016-09-22 10:43:12 -070031import com.android.settings.overlay.FeatureFactory;
Juan Lang44828122017-05-10 17:26:02 -070032import com.android.settingslib.CustomDialogPreference;
Felipe Leme7b11c502016-02-22 15:54:04 -080033
Jason Monk39b46742015-09-10 15:52:51 -040034public class BugreportPreference extends CustomDialogPreference {
Felipe Leme834496f2015-12-16 10:05:44 -080035
36 private static final String TAG = "BugreportPreference";
Felipe Leme834496f2015-12-16 10:05:44 -080037
38 private CheckedTextView mInteractiveTitle;
39 private TextView mInteractiveSummary;
40 private CheckedTextView mFullTitle;
41 private TextView mFullSummary;
42
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070043 public BugreportPreference(Context context, AttributeSet attrs) {
44 super(context, attrs);
45 }
46
47 @Override
Jason Monk39b46742015-09-10 15:52:51 -040048 protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) {
49 super.onPrepareDialogBuilder(builder, listener);
Felipe Leme834496f2015-12-16 10:05:44 -080050
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() {
57
58 @Override
59 public void onClick(View v) {
60 if (v == mFullTitle || v == mFullSummary) {
61 mInteractiveTitle.setChecked(false);
62 mFullTitle.setChecked(true);
63 }
64 if (v == mInteractiveTitle || v == mInteractiveSummary) {
65 mInteractiveTitle.setChecked(true);
66 mFullTitle.setChecked(false);
67 }
68 }
69 };
70 mInteractiveTitle.setOnClickListener(l);
71 mFullTitle.setOnClickListener(l);
72 mInteractiveSummary.setOnClickListener(l);
73 mFullSummary.setOnClickListener(l);
74
Jason Monk39b46742015-09-10 15:52:51 -040075 builder.setPositiveButton(com.android.internal.R.string.report, listener);
Felipe Leme834496f2015-12-16 10:05:44 -080076 builder.setView(dialogView);
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070077 }
78
79 @Override
Jason Monk39b46742015-09-10 15:52:51 -040080 protected void onClick(DialogInterface dialog, int which) {
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070081 if (which == DialogInterface.BUTTON_POSITIVE) {
Felipe Leme834496f2015-12-16 10:05:44 -080082
Felipe Leme34c5d3a2016-04-25 09:27:40 -070083 final Context context = getContext();
Felipe Leme834496f2015-12-16 10:05:44 -080084 if (mFullTitle.isChecked()) {
85 Log.v(TAG, "Taking full bugreport right away");
Fan Zhangaa71afe2016-09-22 10:43:12 -070086 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
87 MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_FULL);
Michal Karpinskic78b9262016-01-05 14:33:07 +000088 takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL);
Felipe Leme834496f2015-12-16 10:05:44 -080089 } else {
Felipe Lemefce3e962016-09-21 10:20:57 -070090 Log.v(TAG, "Taking interactive bugreport right away");
Fan Zhangaa71afe2016-09-22 10:43:12 -070091 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
Felipe Leme038bf652016-02-25 11:37:56 -080092 MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE);
Felipe Lemefce3e962016-09-21 10:20:57 -070093 takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
Felipe Leme834496f2015-12-16 10:05:44 -080094 }
95 }
96 }
97
Michal Karpinskic78b9262016-01-05 14:33:07 +000098 private void takeBugreport(int bugreportType) {
Felipe Leme834496f2015-12-16 10:05:44 -080099 try {
Sudheer Shankaacb1a612016-11-10 15:30:14 -0800100 ActivityManager.getService().requestBugReport(bugreportType);
Felipe Leme834496f2015-12-16 10:05:44 -0800101 } catch (RemoteException e) {
Michal Karpinskic78b9262016-01-05 14:33:07 +0000102 Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e);
Dianne Hackbornfd8c3152012-07-13 14:26:23 -0700103 }
104 }
105}