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         // We need to touch the extras to unpack them so they get migrated to
58         // ClipData correctly.
59         mSendIntent.hasExtra(Intent.EXTRA_STREAM);
60 
61         final AlertController.AlertParams ap = mAlertParams;
62         ap.mView = LayoutInflater.from(this).inflate(R.layout.confirm_repeat, null);
63         ap.mPositiveButtonText = getString(android.R.string.ok);
64         ap.mNegativeButtonText = getString(android.R.string.cancel);
65         ap.mPositiveButtonListener = this;
66         ap.mNegativeButtonListener = this;
67 
68         mConfirmRepeat = (CheckBox) ap.mView.findViewById(android.R.id.checkbox);
69 
70         final int state = getWarningState(this, STATE_UNKNOWN);
71         final boolean checked;
72         if (Build.IS_USER) {
73             checked = state == STATE_HIDE; // Only checks if specifically set to.
74         } else {
75             checked = state != STATE_SHOW; // Checks by default.
76         }
77         mConfirmRepeat.setChecked(checked);
78 
79         setupAlert();
80     }
81 
82     @Override
onClick(DialogInterface dialog, int which)83     public void onClick(DialogInterface dialog, int which) {
84         if (which == AlertDialog.BUTTON_POSITIVE) {
85             // Remember confirm state, and launch target
86             setWarningState(this, mConfirmRepeat.isChecked() ? STATE_HIDE : STATE_SHOW);
87             sendShareIntent(this, mSendIntent);
88         }
89 
90         finish();
91     }
92 }
93