Fields Summary |
---|
private com.android.internal.telephony.Phone | mPhone |
private static final int | EVENT_PIN2_ENTRY_COMPLETEEvents we handle.
The first is used for toggling FDN enable, the second for the PIN change. |
private static final int | EVENT_PIN2_CHANGE_COMPLETE |
private static final String | BUTTON_FDN_ENABLE_KEY |
private static final String | BUTTON_CHANGE_PIN2_KEY |
private EditPinPreference | mButtonEnableFDN |
private EditPinPreference | mButtonChangePin2 |
private String | mOldPin |
private String | mNewPin |
private static final int | PIN_CHANGE_OLD |
private static final int | PIN_CHANGE_NEW |
private static final int | PIN_CHANGE_REENTER |
private static final int | PIN_CHANGE_PUK |
private int | mPinChangeState |
private boolean | mSkipOldPin |
private static final String | SKIP_OLD_PIN_KEY |
private static final String | PIN_CHANGE_STATE_KEY |
private static final String | OLD_PIN_KEY |
private static final String | NEW_PIN_KEY |
private static final String | DIALOG_MESSAGE_KEY |
private static final String | DIALOG_PIN_ENTRY_KEY |
private static final int | MIN_PIN_LENGTH |
private static final int | MAX_PIN_LENGTH |
private android.os.Handler | mFDNHandlerHandler for asynchronous replies from the sim. |
Methods Summary |
---|
private final void | displayMessage(int strId)Display a toast for message, like the rest of the settings.
Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT)
.show();
|
private final void | displayPinChangeDialog()The next two functions are for updating the message field on the dialog.
displayPinChangeDialog(0, true);
|
private final void | displayPinChangeDialog(int strId, boolean shouldDisplay)
int msgId;
switch (mPinChangeState) {
case PIN_CHANGE_OLD:
msgId = R.string.oldPin2Label;
break;
case PIN_CHANGE_NEW:
msgId = R.string.newPin2Label;
break;
case PIN_CHANGE_REENTER:
msgId = R.string.confirmPin2Label;
break;
case PIN_CHANGE_PUK:
default:
msgId = R.string.label_puk2_code;
break;
}
// append the note / additional message, if needed.
if (strId != 0) {
mButtonChangePin2.setDialogMessage(getText(msgId) + "\n" + getText(strId));
} else {
mButtonChangePin2.setDialogMessage(msgId);
}
// only display if requested.
if (shouldDisplay) {
mButtonChangePin2.showPinDialog();
}
|
public void | onCancel(android.content.DialogInterface dialog)Cancel listener for the PUK2 request alert dialog.
// set the state of the preference and then display the dialog.
mPinChangeState = PIN_CHANGE_PUK;
displayPinChangeDialog(0, true);
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
addPreferencesFromResource(R.xml.fdn_setting);
mPhone = PhoneFactory.getDefaultPhone();
//get UI object references
PreferenceScreen prefSet = getPreferenceScreen();
mButtonEnableFDN = (EditPinPreference) prefSet.findPreference(BUTTON_FDN_ENABLE_KEY);
mButtonChangePin2 = (EditPinPreference) prefSet.findPreference(BUTTON_CHANGE_PIN2_KEY);
//assign click listener and update state
mButtonEnableFDN.setOnPinEnteredListener(this);
updateEnableFDN();
mButtonChangePin2.setOnPinEnteredListener(this);
// Only reset the pin change dialog if we're not in the middle of changing it.
if (icicle == null) {
resetPinChangeState();
} else {
mSkipOldPin = icicle.getBoolean(SKIP_OLD_PIN_KEY);
mPinChangeState = icicle.getInt(PIN_CHANGE_STATE_KEY);
mOldPin = icicle.getString(OLD_PIN_KEY);
mNewPin = icicle.getString(NEW_PIN_KEY);
mButtonChangePin2.setDialogMessage(icicle.getString(DIALOG_MESSAGE_KEY));
mButtonChangePin2.setText(icicle.getString(DIALOG_PIN_ENTRY_KEY));
}
|
public void | onPinEntered(EditPinPreference preference, boolean positiveResult)Delegate to the respective handlers.
if (preference == mButtonEnableFDN) {
toggleFDNEnable(positiveResult);
} else if (preference == mButtonChangePin2){
updatePINChangeState(positiveResult);
}
|
protected void | onResume()
super.onResume();
updateEnableFDN();
|
protected void | onSaveInstanceState(android.os.Bundle out)Save the state of the pin change.
super.onSaveInstanceState(out);
out.putBoolean(SKIP_OLD_PIN_KEY, mSkipOldPin);
out.putInt(PIN_CHANGE_STATE_KEY, mPinChangeState);
out.putString(OLD_PIN_KEY, mOldPin);
out.putString(NEW_PIN_KEY, mNewPin);
out.putString(DIALOG_MESSAGE_KEY, mButtonChangePin2.getDialogMessage().toString());
out.putString(DIALOG_PIN_ENTRY_KEY, mButtonChangePin2.getText());
|
private final void | resetPinChangeState()Reset the state of the pin change dialog.
mPinChangeState = PIN_CHANGE_OLD;
displayPinChangeDialog(0, false);
mOldPin = mNewPin = "";
|
private final void | resetPinChangeStateForPUK2()Reset the state of the pin change dialog solely for PUK2 use.
mPinChangeState = PIN_CHANGE_NEW;
displayPinChangeDialog(0, false);
mOldPin = mNewPin = "";
mSkipOldPin = true;
|
private void | toggleFDNEnable(boolean positiveResult)Attempt to toggle FDN activation.
if (!positiveResult) {
return;
}
// validate the pin first, before submitting it to the RIL for FDN enable.
String password = mButtonEnableFDN.getText();
if (validatePin (password, false)) {
// get the relevant data for the sim call
boolean isEnabled = mPhone.getSimCard().getSimFdnEnabled();
Message onComplete = mFDNHandler.obtainMessage(EVENT_PIN2_ENTRY_COMPLETE);
// make fdn request
mPhone.getSimCard().setSimFdnEnabled(!isEnabled, password, onComplete);
} else {
// throw up error if the pin is invalid.
displayMessage(R.string.invalidPin2);
}
mButtonEnableFDN.setText("");
|
private void | updateEnableFDN()Reflect the updated FDN state in the UI.
if (mPhone.getSimCard().getSimFdnEnabled()) {
mButtonEnableFDN.setTitle(R.string.enable_fdn_ok);
mButtonEnableFDN.setSummary(R.string.fdn_enabled);
mButtonEnableFDN.setDialogTitle(R.string.disable_fdn);
} else {
mButtonEnableFDN.setTitle(R.string.disable_fdn_ok);
mButtonEnableFDN.setSummary(R.string.fdn_disabled);
mButtonEnableFDN.setDialogTitle(R.string.enable_fdn);
}
|
private void | updatePINChangeState(boolean positiveResult)Attempt to change the pin.
if (!positiveResult) {
// reset the state on cancel, either to expect PUK2 or PIN2
if (!mSkipOldPin) {
resetPinChangeState();
} else {
resetPinChangeStateForPUK2();
}
return;
}
// Progress through the dialog states, generally in this order:
// 1. Enter old pin
// 2. Enter new pin
// 3. Re-Enter new pin
// While handling any error conditions that may show up in between.
// Also handle the PUK2 entry, if it is requested.
//
// In general, if any invalid entries are made, the dialog re-
// appears with text to indicate what the issue is.
switch (mPinChangeState) {
case PIN_CHANGE_OLD:
mOldPin = mButtonChangePin2.getText();
mButtonChangePin2.setText("");
// if the pin is not valid, display a message and reset the state.
if (validatePin (mOldPin, false)) {
mPinChangeState = PIN_CHANGE_NEW;
displayPinChangeDialog();
} else {
displayPinChangeDialog(R.string.invalidPin2, true);
}
break;
case PIN_CHANGE_NEW:
mNewPin = mButtonChangePin2.getText();
mButtonChangePin2.setText("");
// if the new pin is not valid, display a message and reset the state.
if (validatePin (mNewPin, false)) {
mPinChangeState = PIN_CHANGE_REENTER;
displayPinChangeDialog();
} else {
displayPinChangeDialog(R.string.invalidPin2, true);
}
break;
case PIN_CHANGE_REENTER:
// if the re-entered pin is not valid, display a message and reset the state.
if (!mNewPin.equals(mButtonChangePin2.getText())) {
mPinChangeState = PIN_CHANGE_NEW;
mButtonChangePin2.setText("");
displayPinChangeDialog(R.string.mismatchPin2, true);
} else {
// If the PIN is valid, then we either submit the change PIN request or
// display the PUK2 dialog if we KNOW that we're PUK2 locked.
mButtonChangePin2.setText("");
if (!mSkipOldPin) {
Message onComplete = mFDNHandler.obtainMessage(EVENT_PIN2_CHANGE_COMPLETE);
mPhone.getSimCard().changeSimFdnPassword(mOldPin, mNewPin, onComplete);
} else {
mPinChangeState = PIN_CHANGE_PUK;
displayPinChangeDialog();
}
}
break;
case PIN_CHANGE_PUK: {
// Doh! too many incorrect requests, PUK requested.
// if the pin is not valid, display a message and reset the state.
String puk2 = mButtonChangePin2.getText();
mButtonChangePin2.setText("");
// make sure that the puk is valid before submitting it.
if (validatePin (puk2, true)) {
Message onComplete = mFDNHandler.obtainMessage(EVENT_PIN2_CHANGE_COMPLETE);
mPhone.getSimCard().supplyPuk2(puk2, mNewPin, onComplete);
} else {
displayPinChangeDialog(R.string.invalidPuk2, true);
}
}
break;
}
|
private boolean | validatePin(java.lang.String pin, boolean isPUK)Validate the pin entry.
// for pin, we have 4-8 numbers, or puk, we use only 8.
int pinMinimum = isPUK ? MAX_PIN_LENGTH : MIN_PIN_LENGTH;
// check validity
if (pin == null || pin.length() < pinMinimum || pin.length() > MAX_PIN_LENGTH) {
return false;
} else {
return true;
}
|