blob: 598399a3be9a32476ef746c58c8e346f888a0cf2 [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;
Fan Zhang31b21002019-01-16 13:49:47 -080020import android.app.settings.SettingsEnums;
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070021import 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
Fan Zhang23f8d592018-08-28 15:11:40 -070030import androidx.appcompat.app.AlertDialog.Builder;
31
Fan Zhangaa71afe2016-09-22 10:43:12 -070032import com.android.settings.overlay.FeatureFactory;
tmfang27c84de2018-06-28 11:39:05 +080033import com.android.settingslib.CustomDialogPreferenceCompat;
Felipe Leme7b11c502016-02-22 15:54:04 -080034
tmfang27c84de2018-06-28 11:39:05 +080035public class BugreportPreference extends CustomDialogPreferenceCompat {
Felipe Leme834496f2015-12-16 10:05:44 -080036
37 private static final String TAG = "BugreportPreference";
Felipe Leme834496f2015-12-16 10:05:44 -080038
39 private CheckedTextView mInteractiveTitle;
40 private TextView mInteractiveSummary;
41 private CheckedTextView mFullTitle;
42 private TextView mFullSummary;
43
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070044 public BugreportPreference(Context context, AttributeSet attrs) {
45 super(context, attrs);
46 }
47
48 @Override
Abhijeet Kaurd7e44c72019-08-22 15:07:55 +010049 protected void onPrepareDialogBuilder(Builder builder,
50 DialogInterface.OnClickListener listener) {
Jason Monk39b46742015-09-10 15:52:51 -040051 super.onPrepareDialogBuilder(builder, listener);
Felipe Leme834496f2015-12-16 10:05:44 -080052
53 final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null);
Abhijeet Kaurd7e44c72019-08-22 15:07:55 +010054 mInteractiveTitle = (CheckedTextView) dialogView
55 .findViewById(R.id.bugreport_option_interactive_title);
56 mInteractiveSummary = (TextView) dialogView
57 .findViewById(R.id.bugreport_option_interactive_summary);
Felipe Leme834496f2015-12-16 10:05:44 -080058 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
Jason Monk39b46742015-09-10 15:52:51 -040079 builder.setPositiveButton(com.android.internal.R.string.report, listener);
Felipe Leme834496f2015-12-16 10:05:44 -080080 builder.setView(dialogView);
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070081 }
82
83 @Override
Jason Monk39b46742015-09-10 15:52:51 -040084 protected void onClick(DialogInterface dialog, int which) {
Dianne Hackbornfd8c3152012-07-13 14:26:23 -070085 if (which == DialogInterface.BUTTON_POSITIVE) {
Felipe Leme834496f2015-12-16 10:05:44 -080086
Felipe Leme34c5d3a2016-04-25 09:27:40 -070087 final Context context = getContext();
Felipe Leme834496f2015-12-16 10:05:44 -080088 if (mFullTitle.isChecked()) {
89 Log.v(TAG, "Taking full bugreport right away");
Fan Zhangaa71afe2016-09-22 10:43:12 -070090 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
Fan Zhang31b21002019-01-16 13:49:47 -080091 SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_FULL);
Abhijeet Kaurd7e44c72019-08-22 15:07:55 +010092 try {
93 ActivityManager.getService().requestFullBugReport();
94 } catch (RemoteException e) {
95 Log.e(TAG, "error taking bugreport (bugreportType=Full)", e);
96 }
Felipe Leme834496f2015-12-16 10:05:44 -080097 } else {
Felipe Lemefce3e962016-09-21 10:20:57 -070098 Log.v(TAG, "Taking interactive bugreport right away");
Fan Zhangaa71afe2016-09-22 10:43:12 -070099 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
Fan Zhang31b21002019-01-16 13:49:47 -0800100 SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE);
Abhijeet Kaurd7e44c72019-08-22 15:07:55 +0100101 try {
102 ActivityManager.getService().requestInteractiveBugReport();
103 } catch (RemoteException e) {
104 Log.e(TAG, "error taking bugreport (bugreportType=Interactive)", e);
105 }
Felipe Leme834496f2015-12-16 10:05:44 -0800106 }
107 }
108 }
Dianne Hackbornfd8c3152012-07-13 14:26:23 -0700109}