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