1 /* 2 * Copyright 2018 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.settings.development; 18 19 import android.app.Dialog; 20 import android.app.settings.SettingsEnums; 21 import android.content.DialogInterface; 22 import android.os.Bundle; 23 import android.os.PowerManager; 24 25 import androidx.appcompat.app.AlertDialog; 26 import androidx.fragment.app.FragmentManager; 27 28 import com.android.settings.R; 29 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 30 31 /** 32 * The a2dp/LE audio offload and LE audio feature switch should reboot the device to take effect, 33 * the dialog is to ask the user to reboot the device after a2dp/LE audio offload and LE audio 34 * feature user preference changed 35 */ 36 public class BluetoothRebootDialog extends InstrumentedDialogFragment 37 implements DialogInterface.OnClickListener { 38 39 public static final String TAG = "BluetoothReboot"; 40 41 /** 42 * The function to show the Reboot Dialog. 43 */ show(DevelopmentSettingsDashboardFragment host)44 public static void show(DevelopmentSettingsDashboardFragment host) { 45 final FragmentManager manager = host.getActivity().getSupportFragmentManager(); 46 if (manager.findFragmentByTag(TAG) == null) { 47 final BluetoothRebootDialog dialog = 48 new BluetoothRebootDialog(); 49 dialog.setTargetFragment(host, 0 /* requestCode */); 50 dialog.show(manager, TAG); 51 } 52 } 53 54 @Override getMetricsCategory()55 public int getMetricsCategory() { 56 return SettingsEnums.DIALOG_BLUETOOTH_DISABLE_A2DP_HW_OFFLOAD; 57 } 58 59 @Override onCreateDialog(Bundle savedInstanceState)60 public Dialog onCreateDialog(Bundle savedInstanceState) { 61 return new AlertDialog.Builder(getActivity()) 62 .setMessage(R.string.bluetooth_disable_hw_offload_dialog_message) 63 .setTitle(R.string.bluetooth_disable_hw_offload_dialog_title) 64 .setPositiveButton( 65 R.string.bluetooth_disable_hw_offload_dialog_confirm, this) 66 .setNegativeButton( 67 R.string.bluetooth_disable_hw_offload_dialog_cancel, this) 68 .create(); 69 } 70 71 @Override onClick(DialogInterface dialog, int which)72 public void onClick(DialogInterface dialog, int which) { 73 final OnRebootDialogListener host = 74 (OnRebootDialogListener) getTargetFragment(); 75 if (host == null) { 76 return; 77 } 78 if (which == DialogInterface.BUTTON_POSITIVE) { 79 host.onRebootDialogConfirmed(); 80 PowerManager pm = getContext().getSystemService(PowerManager.class); 81 pm.reboot(null); 82 } else { 83 host.onRebootDialogCanceled(); 84 } 85 } 86 87 /** 88 * The interface for the RebootDialogListener to provide the action as the 89 * confirmed or canceled clicked. 90 */ 91 public interface OnRebootDialogListener { 92 /** 93 * Called when the user presses reboot on the warning dialog. 94 */ onRebootDialogConfirmed()95 void onRebootDialogConfirmed(); 96 97 /** 98 * Called when the user presses cancel on the warning dialog. 99 */ onRebootDialogCanceled()100 void onRebootDialogCanceled(); 101 } 102 } 103