Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 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 | |
Michal Karpinski | c78b926 | 2016-01-05 14:33:07 +0000 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 20 | import android.app.settings.SettingsEnums; |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.DialogInterface; |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 23 | import android.os.RemoteException; |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | import android.view.View; |
| 27 | import android.widget.CheckedTextView; |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 28 | import android.widget.TextView; |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 29 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 30 | import androidx.appcompat.app.AlertDialog.Builder; |
| 31 | |
Fan Zhang | aa71afe | 2016-09-22 10:43:12 -0700 | [diff] [blame] | 32 | import com.android.settings.overlay.FeatureFactory; |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 33 | import com.android.settingslib.CustomDialogPreferenceCompat; |
Felipe Leme | 7b11c50 | 2016-02-22 15:54:04 -0800 | [diff] [blame] | 34 | |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 35 | public class BugreportPreference extends CustomDialogPreferenceCompat { |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 36 | |
| 37 | private static final String TAG = "BugreportPreference"; |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 38 | |
| 39 | private CheckedTextView mInteractiveTitle; |
| 40 | private TextView mInteractiveSummary; |
| 41 | private CheckedTextView mFullTitle; |
| 42 | private TextView mFullSummary; |
| 43 | |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 44 | public BugreportPreference(Context context, AttributeSet attrs) { |
| 45 | super(context, attrs); |
| 46 | } |
| 47 | |
| 48 | @Override |
Abhijeet Kaur | d7e44c7 | 2019-08-22 15:07:55 +0100 | [diff] [blame] | 49 | protected void onPrepareDialogBuilder(Builder builder, |
| 50 | DialogInterface.OnClickListener listener) { |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 51 | super.onPrepareDialogBuilder(builder, listener); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 52 | |
| 53 | final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null); |
Abhijeet Kaur | d7e44c7 | 2019-08-22 15:07:55 +0100 | [diff] [blame] | 54 | mInteractiveTitle = (CheckedTextView) dialogView |
| 55 | .findViewById(R.id.bugreport_option_interactive_title); |
| 56 | mInteractiveSummary = (TextView) dialogView |
| 57 | .findViewById(R.id.bugreport_option_interactive_summary); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 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 | |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 79 | builder.setPositiveButton(com.android.internal.R.string.report, listener); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 80 | builder.setView(dialogView); |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 84 | protected void onClick(DialogInterface dialog, int which) { |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 85 | if (which == DialogInterface.BUTTON_POSITIVE) { |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 86 | |
Felipe Leme | 34c5d3a | 2016-04-25 09:27:40 -0700 | [diff] [blame] | 87 | final Context context = getContext(); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 88 | if (mFullTitle.isChecked()) { |
| 89 | Log.v(TAG, "Taking full bugreport right away"); |
Fan Zhang | aa71afe | 2016-09-22 10:43:12 -0700 | [diff] [blame] | 90 | FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 91 | SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_FULL); |
Abhijeet Kaur | d7e44c7 | 2019-08-22 15:07:55 +0100 | [diff] [blame] | 92 | try { |
| 93 | ActivityManager.getService().requestFullBugReport(); |
| 94 | } catch (RemoteException e) { |
| 95 | Log.e(TAG, "error taking bugreport (bugreportType=Full)", e); |
| 96 | } |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 97 | } else { |
Felipe Leme | fce3e96 | 2016-09-21 10:20:57 -0700 | [diff] [blame] | 98 | Log.v(TAG, "Taking interactive bugreport right away"); |
Fan Zhang | aa71afe | 2016-09-22 10:43:12 -0700 | [diff] [blame] | 99 | FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 100 | SettingsEnums.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE); |
Abhijeet Kaur | d7e44c7 | 2019-08-22 15:07:55 +0100 | [diff] [blame] | 101 | try { |
| 102 | ActivityManager.getService().requestInteractiveBugReport(); |
| 103 | } catch (RemoteException e) { |
| 104 | Log.e(TAG, "error taking bugreport (bugreportType=Interactive)", e); |
| 105 | } |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 109 | } |