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.getWarningState; 20 import static com.android.shell.BugreportPrefs.setWarningState; 21 import static com.android.shell.BugreportProgressService.sendShareIntent; 22 23 import android.app.AlertDialog; 24 import android.content.DialogInterface; 25 import android.content.Intent; 26 import android.os.Build; 27 import android.os.Bundle; 28 import android.view.LayoutInflater; 29 import android.view.WindowManager; 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 // Don't allow overlay windows. 49 getWindow().addSystemFlags( 50 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 51 52 mSendIntent = getIntent().getParcelableExtra(Intent.EXTRA_INTENT); 53 54 if (mSendIntent != null) { 55 // We need to touch the extras to unpack them so they get migrated to 56 // ClipData correctly. 57 mSendIntent.hasExtra(Intent.EXTRA_STREAM); 58 } 59 60 final AlertController.AlertParams ap = mAlertParams; 61 ap.mView = LayoutInflater.from(this).inflate(R.layout.confirm_repeat, null); 62 ap.mPositiveButtonText = getString(android.R.string.ok); 63 ap.mNegativeButtonText = getString(android.R.string.cancel); 64 ap.mPositiveButtonListener = this; 65 ap.mNegativeButtonListener = this; 66 67 mConfirmRepeat = (CheckBox) ap.mView.findViewById(android.R.id.checkbox); 68 69 int bugreportStateUnknown = getResources().getInteger( 70 com.android.internal.R.integer.bugreport_state_unknown); 71 int bugreportStateHide = getResources().getInteger( 72 com.android.internal.R.integer.bugreport_state_hide); 73 int bugreportStateShow = getResources().getInteger( 74 com.android.internal.R.integer.bugreport_state_show); 75 76 final int state = getWarningState(this, bugreportStateUnknown); 77 final boolean checked; 78 if (Build.IS_USER) { 79 checked = state == bugreportStateHide; // Only checks if specifically set to. 80 } else { 81 checked = state != bugreportStateShow; // Checks by default. 82 } 83 mConfirmRepeat.setChecked(checked); 84 85 setupAlert(); 86 } 87 88 @Override onClick(DialogInterface dialog, int which)89 public void onClick(DialogInterface dialog, int which) { 90 int bugreportStateHide = getResources().getInteger( 91 com.android.internal.R.integer.bugreport_state_hide); 92 int bugreportStateShow = getResources().getInteger( 93 com.android.internal.R.integer.bugreport_state_show); 94 if (which == AlertDialog.BUTTON_POSITIVE) { 95 // Remember confirm state, and launch target 96 setWarningState(this, mConfirmRepeat.isChecked() ? bugreportStateHide 97 : bugreportStateShow); 98 if (mSendIntent != null) { 99 sendShareIntent(this, mSendIntent); 100 } 101 } 102 103 finish(); 104 } 105 } 106