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