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