2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.development;
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.content.Context;
22 import android.provider.Settings;
23 import android.support.v14.preference.SwitchPreference;
25 import com.android.settings.R;
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
29 public class EnableAdbPreferenceController extends AbstractEnableAdbPreferenceController
30 implements PreferenceControllerMixin {
32 private Dialog mAdbDialog;
33 private boolean mDialogClicked;
35 public EnableAdbPreferenceController(Context context) {
40 public void showConfirmationDialog(SwitchPreference preference) {
41 mDialogClicked = false;
43 mAdbDialog = new AlertDialog.Builder(mContext).setMessage(
44 mContext.getString(R.string.adb_warning_message))
45 .setTitle(R.string.adb_warning_title)
46 .setPositiveButton(android.R.string.yes, (dialog, which) -> {
47 mDialogClicked = true;
48 writeAdbSetting(true);
50 .setNegativeButton(android.R.string.no, (dialog, which) -> {
51 preference.setChecked(false);
54 mAdbDialog.setOnDismissListener(dialog -> {
55 // Assuming that onClick gets called first
56 if (!mDialogClicked) {
57 preference.setChecked(false);
63 public void dismissDialogs() {
64 if (mAdbDialog != null) {