1 /* 2 * Copyright (C) 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 import android.util.Log; 25 26 import androidx.annotation.VisibleForTesting; 27 import androidx.appcompat.app.AlertDialog; 28 import androidx.fragment.app.Fragment; 29 import androidx.fragment.app.FragmentManager; 30 31 import com.android.settings.R; 32 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 33 34 public class DisableDevSettingsDialogFragment extends InstrumentedDialogFragment 35 implements DialogInterface.OnClickListener { 36 37 public static final String TAG = "DisableDevSettingDlg"; 38 39 @VisibleForTesting newInstance()40 static DisableDevSettingsDialogFragment newInstance() { 41 final DisableDevSettingsDialogFragment dialog = new DisableDevSettingsDialogFragment(); 42 return dialog; 43 } 44 show(DevelopmentSettingsDashboardFragment host)45 public static void show(DevelopmentSettingsDashboardFragment host) { 46 final DisableDevSettingsDialogFragment dialog = new DisableDevSettingsDialogFragment(); 47 dialog.setTargetFragment(host, 0 /* requestCode */); 48 final FragmentManager manager = host.getActivity().getSupportFragmentManager(); 49 dialog.show(manager, TAG); 50 } 51 52 @Override getMetricsCategory()53 public int getMetricsCategory() { 54 return SettingsEnums.DIALOG_DISABLE_DEVELOPMENT_OPTIONS; 55 } 56 57 @Override onCreateDialog(Bundle savedInstanceState)58 public Dialog onCreateDialog(Bundle savedInstanceState) { 59 // Reuse the same text of disable_a2dp_hw_offload_dialog. 60 // The text is generic enough to be used for turning off Dev options. 61 return new AlertDialog.Builder(getActivity()) 62 .setMessage(R.string.bluetooth_disable_a2dp_hw_offload_dialog_message) 63 .setTitle(R.string.bluetooth_disable_a2dp_hw_offload_dialog_title) 64 .setPositiveButton( 65 R.string.bluetooth_disable_a2dp_hw_offload_dialog_confirm, this) 66 .setNegativeButton( 67 R.string.bluetooth_disable_a2dp_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 Fragment fragment = getTargetFragment(); 74 if (!(fragment instanceof DevelopmentSettingsDashboardFragment)){ 75 Log.e(TAG, "getTargetFragment return unexpected type"); 76 } 77 78 final DevelopmentSettingsDashboardFragment host = 79 (DevelopmentSettingsDashboardFragment) fragment; 80 if (which == DialogInterface.BUTTON_POSITIVE) { 81 host.onDisableDevelopmentOptionsConfirmed(); 82 PowerManager pm = getContext().getSystemService(PowerManager.class); 83 pm.reboot(null); 84 } else { 85 host.onDisableDevelopmentOptionsRejected(); 86 } 87 } 88 } 89