Home | History | Annotate | Download | only in settings
      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 
     19 import android.app.ActivityManager;
     20 import android.app.AlertDialog.Builder;
     21 import android.content.Context;
     22 import android.content.DialogInterface;
     23 import android.os.RemoteException;
     24 import android.util.AttributeSet;
     25 import android.util.Log;
     26 import android.view.View;
     27 import android.widget.CheckedTextView;
     28 import android.widget.TextView;
     29 
     30 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     31 import com.android.settings.overlay.FeatureFactory;
     32 import com.android.settingslib.CustomDialogPreference;
     33 
     34 public class BugreportPreference extends CustomDialogPreference {
     35 
     36     private static final String TAG = "BugreportPreference";
     37 
     38     private CheckedTextView mInteractiveTitle;
     39     private TextView mInteractiveSummary;
     40     private CheckedTextView mFullTitle;
     41     private TextView mFullSummary;
     42 
     43     public BugreportPreference(Context context, AttributeSet attrs) {
     44         super(context, attrs);
     45     }
     46 
     47     @Override
     48     protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) {
     49         super.onPrepareDialogBuilder(builder, listener);
     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 
     75         builder.setPositiveButton(com.android.internal.R.string.report, listener);
     76         builder.setView(dialogView);
     77     }
     78 
     79     @Override
     80     protected void onClick(DialogInterface dialog, int which) {
     81         if (which == DialogInterface.BUTTON_POSITIVE) {
     82 
     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);
     89             } else {
     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);
     94             }
     95         }
     96     }
     97 
     98     private void takeBugreport(int bugreportType) {
     99         try {
    100             ActivityManager.getService().requestBugReport(bugreportType);
    101         } catch (RemoteException e) {
    102             Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e);
    103         }
    104     }
    105 }
    106