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