• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.AlertDialog;
20 import android.app.Dialog;
21 import android.app.Fragment;
22 import android.app.FragmentManager;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 
26 import com.android.internal.logging.nano.MetricsProto;
27 import com.android.settings.R;
28 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
29 
30 public class EnableOemUnlockSettingWarningDialog extends InstrumentedDialogFragment implements
31         DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
32 
33     public static final String TAG = "EnableOemUnlockDlg";
34 
show(Fragment host)35     public static void show(Fragment host) {
36         final FragmentManager manager = host.getActivity().getFragmentManager();
37         if (manager.findFragmentByTag(TAG) == null) {
38             final EnableOemUnlockSettingWarningDialog dialog =
39                     new EnableOemUnlockSettingWarningDialog();
40             dialog.setTargetFragment(host, 0 /* requestCode */);
41             dialog.show(manager, TAG);
42         }
43     }
44 
45     @Override
getMetricsCategory()46     public int getMetricsCategory() {
47         return MetricsProto.MetricsEvent.DIALOG_ENABLE_OEM_UNLOCKING;
48     }
49 
50     @Override
onCreateDialog(Bundle savedInstanceState)51     public Dialog onCreateDialog(Bundle savedInstanceState) {
52         return new AlertDialog.Builder(getActivity())
53                 .setTitle(R.string.confirm_enable_oem_unlock_title)
54                 .setMessage(R.string.confirm_enable_oem_unlock_text)
55                 .setPositiveButton(R.string.enable_text, this /* onClickListener */)
56                 .setNegativeButton(android.R.string.cancel, this /* onClickListener */)
57                 .create();
58     }
59 
60     @Override
onClick(DialogInterface dialog, int which)61     public void onClick(DialogInterface dialog, int which) {
62         final OemUnlockDialogHost host = (OemUnlockDialogHost) getTargetFragment();
63         if (host == null) {
64             return;
65         }
66         if (which == DialogInterface.BUTTON_POSITIVE) {
67             host.onOemUnlockDialogConfirmed();
68         } else {
69             host.onOemUnlockDialogDismissed();
70         }
71     }
72 
73     @Override
onDismiss(DialogInterface dialog)74     public void onDismiss(DialogInterface dialog) {
75         super.onDismiss(dialog);
76         final OemUnlockDialogHost host = (OemUnlockDialogHost) getTargetFragment();
77         if (host == null) {
78             return;
79         }
80         host.onOemUnlockDialogDismissed();
81     }
82 }
83