Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2016 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 package com.android.settings;
     17 
     18 import android.annotation.Nullable;
     19 import android.app.Activity;
     20 import android.app.AlertDialog;
     21 import android.app.admin.DevicePolicyManager;
     22 import android.content.DialogInterface;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.os.UserHandle;
     26 import android.util.Log;
     27 import android.widget.LinearLayout;
     28 
     29 import com.android.settings.R;
     30 
     31 /**
     32  * UI for the remote bugreport dialog. Shows one of 3 possible dialogs:
     33  * <ul>
     34  * <li>bugreport is still being taken and can be shared or declined</li>
     35  * <li>bugreport has been taken and can be shared or declined</li>
     36  * <li>bugreport has already been accepted to be shared, but is still being taken</li>
     37  * </ul>
     38  */
     39 public class RemoteBugreportActivity extends Activity {
     40 
     41     private static final String TAG = "RemoteBugreportActivity";
     42 
     43     @Override
     44     protected void onCreate(@Nullable Bundle savedInstanceState) {
     45         super.onCreate(savedInstanceState);
     46 
     47         final int notificationType = getIntent().getIntExtra(
     48                 DevicePolicyManager.EXTRA_BUGREPORT_NOTIFICATION_TYPE, -1);
     49 
     50         if (notificationType == DevicePolicyManager.NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED) {
     51             AlertDialog dialog = new AlertDialog.Builder(this)
     52                     .setMessage(R.string.sharing_remote_bugreport_dialog_message)
     53                     .setOnDismissListener(new DialogInterface.OnDismissListener() {
     54                         @Override
     55                         public void onDismiss(DialogInterface dialog) {
     56                             finish();
     57                         }
     58                     })
     59                     .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
     60                         @Override
     61                         public void onClick(DialogInterface dialog, int which) {
     62                             finish();
     63                         }
     64                     })
     65                     .create();
     66             dialog.show();
     67         } else if (notificationType == DevicePolicyManager.NOTIFICATION_BUGREPORT_STARTED
     68                 || notificationType
     69                         == DevicePolicyManager.NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED) {
     70             AlertDialog dialog = new AlertDialog.Builder(this)
     71                     .setTitle(R.string.share_remote_bugreport_dialog_title)
     72                     .setMessage(notificationType
     73                                     == DevicePolicyManager.NOTIFICATION_BUGREPORT_STARTED
     74                             ? R.string.share_remote_bugreport_dialog_message
     75                             : R.string.share_remote_bugreport_dialog_message_finished)
     76                     .setOnDismissListener(new DialogInterface.OnDismissListener() {
     77                         @Override
     78                         public void onDismiss(DialogInterface dialog) {
     79                             finish();
     80                         }
     81                     })
     82                     .setNegativeButton(R.string.decline_remote_bugreport_action,
     83                             new DialogInterface.OnClickListener() {
     84                         @Override
     85                         public void onClick(DialogInterface dialog, int which) {
     86                             Intent intent = new Intent(
     87                                     DevicePolicyManager.ACTION_BUGREPORT_SHARING_DECLINED);
     88                             RemoteBugreportActivity.this.sendBroadcastAsUser(intent,
     89                                     UserHandle.SYSTEM, android.Manifest.permission.DUMP);
     90                             finish();
     91                         }
     92                     })
     93                     .setPositiveButton(R.string.share_remote_bugreport_action,
     94                             new DialogInterface.OnClickListener() {
     95                         @Override
     96                         public void onClick(DialogInterface dialog, int which) {
     97                             Intent intent = new Intent(
     98                                     DevicePolicyManager.ACTION_BUGREPORT_SHARING_ACCEPTED);
     99                             RemoteBugreportActivity.this.sendBroadcastAsUser(intent,
    100                                     UserHandle.SYSTEM, android.Manifest.permission.DUMP);
    101                             finish();
    102                         }
    103                     })
    104                     .create();
    105             dialog.show();
    106         } else {
    107             Log.e(TAG, "Incorrect dialog type, no dialog shown. Received: " + notificationType);
    108         }
    109     }
    110 }
    111