FileDocCategorySizeDatePackage
SimPinUnlockPanel.javaAPI DocAndroid 1.5 API11436Wed May 06 22:42:46 BST 2009com.android.phone

SimPinUnlockPanel

public class SimPinUnlockPanel extends SimPanel
Panel where you enter your PIN to unlock the SIM card.

Fields Summary
private static final boolean
DBG
private static final int
EVENT_SIM_UNLOCKED_RESULT
private SimLockState
mState
private String
mPUKCode
private String
mNewPinCode
private android.widget.EditText
mEntry
private android.widget.TextView
mFailure
private android.widget.TextView
mLabel
private android.widget.TextView
mStatus
private android.widget.Button
mUnlockButton
private android.widget.Button
mDismissButton
private android.widget.LinearLayout
mUnlockPane
private android.widget.LinearLayout
mUnlockInProgressPane
private android.os.Handler
mHandler
View.OnClickListener
mUnlockListener
View.OnClickListener
mDismissListener
Constructors Summary
public SimPinUnlockPanel(android.content.Context context)

        super(context);
    
Methods Summary
com.android.phone.SimPinUnlockPanel$SimLockStategetState()

        return mState;
    
voidhandleFailure()

        if (DBG) log("unlock failed");
        showIncorrectPinMessage();
        mEntry.getText().clear();
        updateState();
        updateView();
    
voidhandleSuccess()

        if (DBG) log("unlock successful!");
        showUnlockSuccess();

        // store the SIM pin in memory, to be used later for keyguard lock
        // and radio reboots.
        PhoneApp.getInstance().setCachedSimPin(mEntry.getText().toString());
    
voidhandleUnlockResult(android.os.AsyncResult ar)

        if (ar.exception == null) {
            handleSuccess();
            return;
        }

        // pin/puk unlock failed!
        if (ar.exception instanceof com.android.internal.telephony.gsm.CommandException &&
                ((CommandException) ar.exception).getCommandError() ==
                    CommandException.Error.PASSWORD_INCORRECT) {
            hidePinUnlockInProgress();
            handleFailure();
        }

        // PENDING: any other failure types?
    
voidhideIncorrectPinMessage()

        mFailure.setVisibility(View.GONE);
    
voidhidePinUnlockInProgress()

        mUnlockInProgressPane.setVisibility(View.GONE);
        mUnlockPane.setVisibility(View.VISIBLE);
    
voidinitView()

        mUnlockPane = (LinearLayout) findViewById(R.id.simPINPane);
        mUnlockInProgressPane = (LinearLayout) findViewById(R.id.progress);

        mEntry = (EditText) findViewById(R.id.entry);
        mEntry.setKeyListener(DialerKeyListener.getInstance());
        mEntry.setMovementMethod(null);
        mEntry.setOnClickListener(mUnlockListener);

        // set up the text watcher
        CharSequence text = mEntry.getText();
        Spannable span = (Spannable) text;
        span.setSpan(new MyTextWatcher(this.getContext()),
                0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

        mFailure = (TextView) findViewById(R.id.failure);
        mLabel = (TextView) findViewById(R.id.label);
        mStatus = (TextView) findViewById(R.id.status);

        mUnlockButton = (Button) findViewById(R.id.unlock);
        mUnlockButton.setOnClickListener(mUnlockListener);

        mDismissButton = (Button) findViewById(R.id.dismiss);

        // if we are using the SIM pin for keyguard password, force the
        // user to enter the correct PIN to proceed. Otherwise, we won't
        // know what the correct keyguard password is.
        mDismissButton.setOnClickListener(mDismissListener);
    
private voidlog(java.lang.String msg)


        
        Log.v(TAG, "[SimPinUnlock] " + msg);
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        setContentView(R.layout.sim_unlock);
        updateState();
        initView();
        updateView();
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }

        return super.onKeyDown(keyCode, event);
    
protected voidonStart()

        super.onStart();
        if (updateState()) {
            updateView(); // need to update the view only if state changed
        }
    
voidsetState(com.android.phone.SimPinUnlockPanel$SimLockState state)

        mState = state;
    
voidshowIncorrectPinMessage()

        CharSequence msg;
        Context context = getContext();

        if (getState() == SimLockState.REQUIRE_PIN) {
            msg = context.getText(R.string.badPin);
        } else {
            msg = context.getText(R.string.badPuk);
        }

        mFailure.setText(msg);
        mFailure.setVisibility(View.VISIBLE);
    
voidshowUnlockInProgress()

        mUnlockInProgressPane.setVisibility(View.VISIBLE);
        mUnlockPane.setVisibility(View.GONE);
    
voidshowUnlockSuccess()

        mStatus.setText(getContext().getText(R.string.pinUnlocked));
        mHandler.postDelayed(
                new Runnable() {
                    public void run() {
                        dismiss();
                    }
                }, 1000);
    
booleanupdateState()

return
Whether the state changed.

        PhoneApp app = PhoneApp.getInstance();
        SimCard simCardInterface = app.phone.getSimCard();

        try {
            if (simCardInterface.getState() == SimCard.State.PUK_REQUIRED) {
                if (getState() != SimLockState.REQUIRE_PUK) {
                    setState(SimLockState.REQUIRE_PUK);
                    return true;
                }
            } else if (getState() != SimLockState.REQUIRE_PIN){
                setState(SimLockState.REQUIRE_PIN);
                return true;
            }
        } catch (Exception ex) {
        }
        return false;
    
voidupdateView()

        Context context = getContext();

        switch (mState) {
            case REQUIRE_PIN:
                mLabel.setText(context.getText(R.string.enterPin));
                break;

            case REQUIRE_PUK:
                mLabel.setText(context.getText(R.string.enterPuk));
                mUnlockButton.setText(
                        context.getText(R.string.buttonTxtContinue));
                break;

            case REQUIRE_NEW_PIN:
                hideIncorrectPinMessage();
                mLabel.setText(context.getText(R.string.enterNewPin));
                break;

            case VERIFY_NEW_PIN:
                mLabel.setText(context.getText(R.string.verifyNewPin));
                break;

            case VERIFY_NEW_PIN_FAILED:
                mLabel.setText(context.getText(R.string.verifyFailed));
                setState(SimLockState.REQUIRE_NEW_PIN);
                break;
        }

        mEntry.getText().clear();
        mEntry.requestFocus(View.FOCUS_FORWARD);
    
private booleanverifyNewPin(java.lang.String pin2)

        if (mNewPinCode.equals(pin2)) {
            return true;
        }

        return false;