2 * Copyright (C) 2006 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.phone;
19 import android.app.Activity;
20 import android.os.AsyncResult;
21 import android.os.Bundle;
22 import android.os.Handler;
23 import android.os.Message;
24 import android.text.TextUtils;
25 import android.text.method.DigitsKeyListener;
26 import android.util.Log;
27 import android.view.View;
28 import android.widget.EditText;
29 import android.widget.LinearLayout;
30 import android.widget.TextView;
32 import com.android.internal.telephony.CommandException;
33 import com.android.internal.telephony.Phone;
34 import com.android.internal.telephony.PhoneFactory;
37 * UI to enable/disable the ICC PIN.
39 public class EnableIccPinScreen extends Activity {
40 private static final String LOG_TAG = PhoneApp.LOG_TAG;
42 private static final int ENABLE_ICC_PIN_COMPLETE = 100;
43 private static final boolean DBG = false;
45 private LinearLayout mPinFieldContainer;
46 private EditText mPinField;
47 private TextView mStatusField;
48 private boolean mEnable;
51 private Handler mHandler = new Handler() {
52 public void handleMessage(Message msg) {
54 case ENABLE_ICC_PIN_COMPLETE:
55 AsyncResult ar = (AsyncResult) msg.obj;
65 protected void onCreate(Bundle icicle) {
66 super.onCreate(icicle);
68 setContentView(R.layout.enable_sim_pin_screen);
71 mPhone = PhoneFactory.getDefaultPhone();
72 mEnable = !mPhone.getIccCard().getIccLockEnabled();
74 int id = mEnable ? R.string.enable_sim_pin : R.string.disable_sim_pin;
75 setTitle(getResources().getText(id));
78 private void setupView() {
79 mPinField = (EditText) findViewById(R.id.pin);
80 mPinField.setKeyListener(DigitsKeyListener.getInstance());
81 mPinField.setMovementMethod(null);
82 mPinField.setOnClickListener(mClicked);
84 mPinFieldContainer = (LinearLayout) findViewById(R.id.pinc);
85 mStatusField = (TextView) findViewById(R.id.status);
88 private void showStatus(CharSequence statusMsg) {
89 if (statusMsg != null) {
90 mStatusField.setText(statusMsg);
91 mStatusField.setVisibility(View.VISIBLE);
92 mPinFieldContainer.setVisibility(View.GONE);
94 mPinFieldContainer.setVisibility(View.VISIBLE);
95 mStatusField.setVisibility(View.GONE);
99 private String getPin() {
100 return mPinField.getText().toString();
103 private void enableIccPin() {
104 Message callback = Message.obtain(mHandler, ENABLE_ICC_PIN_COMPLETE);
105 if (DBG) log("enableIccPin:");
106 mPhone.getIccCard().setIccLockEnabled(mEnable, getPin(), callback);
107 if (DBG) log("enableIccPin: please wait...");
110 private void handleResult(AsyncResult ar) {
111 if (ar.exception == null) {
112 if (DBG) log("handleResult: success!");
113 showStatus(getResources().getText(
114 mEnable ? R.string.enable_pin_ok : R.string.disable_pin_ok));
115 } else if (ar.exception instanceof CommandException
116 /* && ((CommandException)ar.exception).getCommandError() ==
117 CommandException.Error.GENERIC_FAILURE */ ) {
118 if (DBG) log("handleResult: failed!");
119 showStatus(getResources().getText(
120 R.string.pin_failed));
123 mHandler.postDelayed(new Runnable() {
130 private View.OnClickListener mClicked = new View.OnClickListener() {
131 public void onClick(View v) {
132 if (TextUtils.isEmpty(mPinField.getText())) {
136 showStatus(getResources().getText(
137 R.string.enable_in_progress));
143 private void log(String msg) {
144 Log.d(LOG_TAG, "[EnableIccPin] " + msg);