1 /* 2 * Copyright (C) 2013 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.shell; 18 19 import static com.android.shell.BugreportPrefs.STATE_HIDE; 20 import static com.android.shell.BugreportPrefs.STATE_SHOW; 21 import static com.android.shell.BugreportPrefs.STATE_UNKNOWN; 22 import static com.android.shell.BugreportPrefs.getWarningState; 23 import static com.android.shell.BugreportPrefs.setWarningState; 24 25 import android.app.AlertDialog; 26 import android.content.DialogInterface; 27 import android.content.Intent; 28 import android.os.Bundle; 29 import android.view.LayoutInflater; 30 import android.widget.CheckBox; 31 32 import com.android.internal.app.AlertActivity; 33 import com.android.internal.app.AlertController; 34 35 /** 36 * Dialog that warns about contents of a bugreport. 37 */ 38 public class BugreportWarningActivity extends AlertActivity 39 implements DialogInterface.OnClickListener { 40 41 private Intent mSendIntent; 42 private CheckBox mConfirmRepeat; 43 44 @Override onCreate(Bundle icicle)45 public void onCreate(Bundle icicle) { 46 super.onCreate(icicle); 47 48 mSendIntent = getIntent().getParcelableExtra(Intent.EXTRA_INTENT); 49 50 // We need to touch the extras to unpack them so they get migrated to 51 // ClipData correctly. 52 mSendIntent.hasExtra(Intent.EXTRA_STREAM); 53 54 final AlertController.AlertParams ap = mAlertParams; 55 ap.mView = LayoutInflater.from(this).inflate(R.layout.confirm_repeat, null); 56 ap.mPositiveButtonText = getString(android.R.string.ok); 57 ap.mNegativeButtonText = getString(android.R.string.cancel); 58 ap.mPositiveButtonListener = this; 59 ap.mNegativeButtonListener = this; 60 61 mConfirmRepeat = (CheckBox) ap.mView.findViewById(android.R.id.checkbox); 62 mConfirmRepeat.setChecked(getWarningState(this, STATE_UNKNOWN) == STATE_SHOW); 63 64 setupAlert(); 65 } 66 67 @Override onClick(DialogInterface dialog, int which)68 public void onClick(DialogInterface dialog, int which) { 69 if (which == AlertDialog.BUTTON_POSITIVE) { 70 // Remember confirm state, and launch target 71 setWarningState(this, mConfirmRepeat.isChecked() ? STATE_SHOW : STATE_HIDE); 72 startActivity(mSendIntent); 73 } 74 75 finish(); 76 } 77 } 78