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