blob: 2e6ce6e3ebb93410da729bb70e2e5d91d388e207 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 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
17package com.android.phone;
18
19import android.app.Activity;
Steve Statia7bee4652024-02-27 17:48:05 +000020import android.content.Context;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.os.AsyncResult;
22import android.os.Bundle;
23import android.os.Handler;
24import android.os.Message;
Steve Statia7bee4652024-02-27 17:48:05 +000025import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.text.TextUtils;
27import android.text.method.DigitsKeyListener;
28import android.util.Log;
29import android.view.View;
30import android.widget.EditText;
31import android.widget.LinearLayout;
32import android.widget.TextView;
33
34import com.android.internal.telephony.CommandException;
35import com.android.internal.telephony.Phone;
36
37/**
38 * UI to enable/disable the ICC PIN.
39 */
40public class EnableIccPinScreen extends Activity {
41 private static final String LOG_TAG = PhoneGlobals.LOG_TAG;
42
43 private static final int ENABLE_ICC_PIN_COMPLETE = 100;
44 private static final boolean DBG = false;
45
Steve Statia7bee4652024-02-27 17:48:05 +000046 private UserManager mUserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047 private LinearLayout mPinFieldContainer;
48 private EditText mPinField;
49 private TextView mStatusField;
50 private boolean mEnable;
51 private Phone mPhone;
Steve Statia7bee4652024-02-27 17:48:05 +000052 private boolean mDisallowedConfig = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053
54 private Handler mHandler = new Handler() {
55 public void handleMessage(Message msg) {
56 switch (msg.what) {
57 case ENABLE_ICC_PIN_COMPLETE:
58 AsyncResult ar = (AsyncResult) msg.obj;
59 handleResult(ar);
60 break;
61 }
62
63 return;
64 }
65 };
66
67 @Override
68 protected void onCreate(Bundle icicle) {
69 super.onCreate(icicle);
70
Tyler Gunn662cb392025-01-17 23:34:46 +000071 getWindow().addSystemFlags(
72 android.view.WindowManager.LayoutParams
73 .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
74
Steve Statia7bee4652024-02-27 17:48:05 +000075 mUserManager = this.getSystemService(UserManager.class);
76 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
77 mDisallowedConfig = true;
78 }
79
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080 setContentView(R.layout.enable_sim_pin_screen);
81 setupView();
82
83 mPhone = PhoneGlobals.getPhone();
84 mEnable = !mPhone.getIccCard().getIccLockEnabled();
85
86 int id = mEnable ? R.string.enable_sim_pin : R.string.disable_sim_pin;
87 setTitle(getResources().getText(id));
88 }
89
90 private void setupView() {
91 mPinField = (EditText) findViewById(R.id.pin);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 mPinFieldContainer = (LinearLayout) findViewById(R.id.pinc);
93 mStatusField = (TextView) findViewById(R.id.status);
Steve Statia7bee4652024-02-27 17:48:05 +000094
95 if (mDisallowedConfig) {
96 mPinField.setEnabled(false);
97 mPinField.setAlpha(.5f);
98
99 mPinFieldContainer.setEnabled(false);
100 mPinFieldContainer.setAlpha(.5f);
101 } else {
102 mPinField.setKeyListener(DigitsKeyListener.getInstance());
103 mPinField.setMovementMethod(null);
104 mPinField.setOnClickListener(mClicked);
105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 }
107
108 private void showStatus(CharSequence statusMsg) {
109 if (statusMsg != null) {
110 mStatusField.setText(statusMsg);
111 mStatusField.setVisibility(View.VISIBLE);
112 mPinFieldContainer.setVisibility(View.GONE);
113 } else {
114 mPinFieldContainer.setVisibility(View.VISIBLE);
115 mStatusField.setVisibility(View.GONE);
116 }
117 }
118
119 private String getPin() {
120 return mPinField.getText().toString();
121 }
122
123 private void enableIccPin() {
124 Message callback = Message.obtain(mHandler, ENABLE_ICC_PIN_COMPLETE);
125 if (DBG) log("enableIccPin:");
126 mPhone.getIccCard().setIccLockEnabled(mEnable, getPin(), callback);
127 if (DBG) log("enableIccPin: please wait...");
128 }
129
130 private void handleResult(AsyncResult ar) {
131 if (ar.exception == null) {
132 if (DBG) log("handleResult: success!");
133 showStatus(getResources().getText(
134 mEnable ? R.string.enable_pin_ok : R.string.disable_pin_ok));
135 } else if (ar.exception instanceof CommandException
136 /* && ((CommandException)ar.exception).getCommandError() ==
137 CommandException.Error.GENERIC_FAILURE */ ) {
138 if (DBG) log("handleResult: failed!");
139 showStatus(getResources().getText(
140 R.string.pin_failed));
141 }
142
143 mHandler.postDelayed(new Runnable() {
144 public void run() {
145 finish();
146 }
147 }, 3000);
148 }
149
150 private View.OnClickListener mClicked = new View.OnClickListener() {
151 public void onClick(View v) {
152 if (TextUtils.isEmpty(mPinField.getText())) {
153 return;
154 }
155
156 showStatus(getResources().getText(
157 R.string.enable_in_progress));
158
159 enableIccPin();
160 }
161 };
162
163 private void log(String msg) {
164 Log.d(LOG_TAG, "[EnableIccPin] " + msg);
165 }
166}