• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.phone.settings.fdn;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.app.DialogFragment;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 import android.view.WindowManager;
26 
27 import com.android.phone.R;
28 
29 /**
30  * Dialog Fragment that displays dialogs indicating that PIN2/PUK2 has been locked out.
31  *
32  * 1. When user fails PIN2 authentication and PIN2 is locked, show the dialog indicating that PIN2
33  * is locked and PUK2 must be entered.
34  * 2. When user fails PUK2 authentication and PUK2 is locked, show the dialog indicating that PUK2
35  * is locked and user must contact service provider to unlock PUK2.
36  */
37 public class Pin2LockedDialogFragment extends DialogFragment {
38 
39     static final String TAG_PIN2_LOCKED_DIALOG = "tag_pin2_locked_dialog";
40     static final String KEY_DIALOG_ID = "key_dialog_id";
41 
42     // AlertDialog IDs
43     static final int DIALOG_ID_PUK2_LOCKED_OUT = 10;
44     static final int DIALOG_ID_PUK2_REQUESTED_ON_PIN_ENTRY = 11;
45     static final int DIALOG_ID_PUK2_REQUESTED_ON_PIN_CHANGED = 12;
46 
47     private Listener mListener;
48     private int mId;
49 
50     interface Listener {
onRequestPuk2(int id)51         void onRequestPuk2(int id);
52     }
53 
54     @Override
onCreateDialog(Bundle savedInstanceState)55     public Dialog onCreateDialog(Bundle savedInstanceState) {
56         super.onCreateDialog(savedInstanceState);
57         Activity activity = getActivity();
58         if (!(activity instanceof Listener)) {
59             return null;
60         }
61         mListener = (Listener) activity;
62         mId = getArguments().getInt(KEY_DIALOG_ID);
63 
64         if (mId == DIALOG_ID_PUK2_LOCKED_OUT) {
65             AlertDialog alert = new AlertDialog.Builder(activity)
66                     .setMessage(R.string.puk2_locked)
67                     .setCancelable(true)
68                     .create();
69             alert.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
70             alert.setButton(DialogInterface.BUTTON_NEUTRAL, getText(R.string.ok),
71                     (dialog, which) -> {
72                     });
73             return alert;
74         }
75 
76         if (mId == DIALOG_ID_PUK2_REQUESTED_ON_PIN_CHANGED
77                 || mId == DIALOG_ID_PUK2_REQUESTED_ON_PIN_ENTRY) {
78             AlertDialog alert = new AlertDialog.Builder(activity)
79                     .setMessage(R.string.puk2_requested)
80                     .setCancelable(true)
81                     .create();
82             alert.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
83             alert.setButton(DialogInterface.BUTTON_NEUTRAL, getText(R.string.ok),
84                     (dialog, which) -> {
85                         mListener.onRequestPuk2(mId);
86                         dialog.dismiss();
87                     });
88             return alert;
89         }
90         return null;
91     }
92 
93     @Override
onCancel(DialogInterface dialog)94     public void onCancel(DialogInterface dialog) {
95         if (mId == DIALOG_ID_PUK2_REQUESTED_ON_PIN_CHANGED
96                 || mId == DIALOG_ID_PUK2_REQUESTED_ON_PIN_ENTRY) {
97             mListener.onRequestPuk2(mId);
98         }
99         dialog.dismiss();
100     }
101 }
102 
103