1 /*
2  * Copyright (C) 2017 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 
24 import androidx.appcompat.app.AlertDialog;
25 import androidx.fragment.app.Fragment;
26 import androidx.fragment.app.FragmentManager;
27 
28 import com.android.settings.R;
29 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
30 
31 public class ClearAdbKeysWarningDialog extends InstrumentedDialogFragment implements
32         DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
33 
34     public static final String TAG = "ClearAdbKeysDlg";
35 
show(Fragment host)36     public static void show(Fragment host) {
37         final FragmentManager manager = host.getActivity().getSupportFragmentManager();
38         if (manager.findFragmentByTag(TAG) == null) {
39             final ClearAdbKeysWarningDialog dialog =
40                     new ClearAdbKeysWarningDialog();
41             dialog.setTargetFragment(host, 0 /* requestCode */);
42             dialog.show(manager, TAG);
43         }
44     }
45 
46     @Override
getMetricsCategory()47     public int getMetricsCategory() {
48         return SettingsEnums.DIALOG_CLEAR_ADB_KEYS;
49     }
50 
51     @Override
onCreateDialog(Bundle savedInstanceState)52     public Dialog onCreateDialog(Bundle savedInstanceState) {
53         return new AlertDialog.Builder(getActivity())
54                 .setMessage(R.string.adb_keys_warning_message)
55                 .setPositiveButton(android.R.string.ok, this /* onClickListener */)
56                 .setNegativeButton(android.R.string.cancel, null /* onClickListener */)
57                 .create();
58     }
59 
60     @Override
onClick(DialogInterface dialog, int which)61     public void onClick(DialogInterface dialog, int which) {
62         final AdbClearKeysDialogHost host = (AdbClearKeysDialogHost) getTargetFragment();
63         if (host == null) {
64             return;
65         }
66         host.onAdbClearKeysDialogConfirmed();
67     }
68 }
69