Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.phone; |
| 18 | |
| 19 | import android.app.Activity; |
Steve Statia | 7bee465 | 2024-02-27 17:48:05 +0000 | [diff] [blame] | 20 | import android.content.Context; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.os.AsyncResult; |
| 22 | import android.os.Bundle; |
| 23 | import android.os.Handler; |
| 24 | import android.os.Message; |
Steve Statia | 7bee465 | 2024-02-27 17:48:05 +0000 | [diff] [blame] | 25 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.text.TextUtils; |
| 27 | import android.text.method.DigitsKeyListener; |
| 28 | import android.util.Log; |
| 29 | import android.view.View; |
| 30 | import android.widget.EditText; |
| 31 | import android.widget.LinearLayout; |
| 32 | import android.widget.TextView; |
| 33 | |
| 34 | import com.android.internal.telephony.CommandException; |
| 35 | import com.android.internal.telephony.Phone; |
| 36 | |
| 37 | /** |
| 38 | * UI to enable/disable the ICC PIN. |
| 39 | */ |
| 40 | public 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 Statia | 7bee465 | 2024-02-27 17:48:05 +0000 | [diff] [blame] | 46 | private UserManager mUserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | private LinearLayout mPinFieldContainer; |
| 48 | private EditText mPinField; |
| 49 | private TextView mStatusField; |
| 50 | private boolean mEnable; |
| 51 | private Phone mPhone; |
Steve Statia | 7bee465 | 2024-02-27 17:48:05 +0000 | [diff] [blame] | 52 | private boolean mDisallowedConfig = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | |
| 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 Gunn | 662cb39 | 2025-01-17 23:34:46 +0000 | [diff] [blame] | 71 | getWindow().addSystemFlags( |
| 72 | android.view.WindowManager.LayoutParams |
| 73 | .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); |
| 74 | |
Steve Statia | 7bee465 | 2024-02-27 17:48:05 +0000 | [diff] [blame] | 75 | mUserManager = this.getSystemService(UserManager.class); |
| 76 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
| 77 | mDisallowedConfig = true; |
| 78 | } |
| 79 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | 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 Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | mPinFieldContainer = (LinearLayout) findViewById(R.id.pinc); |
| 93 | mStatusField = (TextView) findViewById(R.id.status); |
Steve Statia | 7bee465 | 2024-02-27 17:48:05 +0000 | [diff] [blame] | 94 | |
| 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 Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 106 | } |
| 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 | } |