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; |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 20 | import android.app.AlertDialog.Builder; |
| 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 | |
Tamas Berghammer | 265d3c2 | 2016-06-22 15:34:45 +0100 | [diff] [blame] | 30 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Fan Zhang | aa71afe | 2016-09-22 10:43:12 -0700 | [diff] [blame] | 31 | import com.android.settings.overlay.FeatureFactory; |
Juan Lang | 4482812 | 2017-05-10 17:26:02 -0700 | [diff] [blame] | 32 | import com.android.settingslib.CustomDialogPreference; |
Felipe Leme | 7b11c50 | 2016-02-22 15:54:04 -0800 | [diff] [blame] | 33 | |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 34 | public class BugreportPreference extends CustomDialogPreference { |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 35 | |
| 36 | private static final String TAG = "BugreportPreference"; |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 37 | |
| 38 | private CheckedTextView mInteractiveTitle; |
| 39 | private TextView mInteractiveSummary; |
| 40 | private CheckedTextView mFullTitle; |
| 41 | private TextView mFullSummary; |
| 42 | |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 43 | public BugreportPreference(Context context, AttributeSet attrs) { |
| 44 | super(context, attrs); |
| 45 | } |
| 46 | |
| 47 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 48 | protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) { |
| 49 | super.onPrepareDialogBuilder(builder, listener); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 50 | |
| 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 Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 75 | builder.setPositiveButton(com.android.internal.R.string.report, listener); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 76 | builder.setView(dialogView); |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 80 | protected void onClick(DialogInterface dialog, int which) { |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 81 | if (which == DialogInterface.BUTTON_POSITIVE) { |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 82 | |
Felipe Leme | 34c5d3a | 2016-04-25 09:27:40 -0700 | [diff] [blame] | 83 | final Context context = getContext(); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 84 | if (mFullTitle.isChecked()) { |
| 85 | Log.v(TAG, "Taking full bugreport right away"); |
Fan Zhang | aa71afe | 2016-09-22 10:43:12 -0700 | [diff] [blame] | 86 | FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, |
| 87 | MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_FULL); |
Michal Karpinski | c78b926 | 2016-01-05 14:33:07 +0000 | [diff] [blame] | 88 | takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 89 | } else { |
Felipe Leme | fce3e96 | 2016-09-21 10:20:57 -0700 | [diff] [blame] | 90 | Log.v(TAG, "Taking interactive bugreport right away"); |
Fan Zhang | aa71afe | 2016-09-22 10:43:12 -0700 | [diff] [blame] | 91 | FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, |
Felipe Leme | 038bf65 | 2016-02-25 11:37:56 -0800 | [diff] [blame] | 92 | MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE); |
Felipe Leme | fce3e96 | 2016-09-21 10:20:57 -0700 | [diff] [blame] | 93 | takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
Michal Karpinski | c78b926 | 2016-01-05 14:33:07 +0000 | [diff] [blame] | 98 | private void takeBugreport(int bugreportType) { |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 99 | try { |
Sudheer Shanka | acb1a61 | 2016-11-10 15:30:14 -0800 | [diff] [blame] | 100 | ActivityManager.getService().requestBugReport(bugreportType); |
Felipe Leme | 834496f | 2015-12-16 10:05:44 -0800 | [diff] [blame] | 101 | } catch (RemoteException e) { |
Michal Karpinski | c78b926 | 2016-01-05 14:33:07 +0000 | [diff] [blame] | 102 | Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e); |
Dianne Hackborn | fd8c315 | 2012-07-13 14:26:23 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |