Merge "Fix 5636798: Watch for SIM state changes in IccSettings." into ics-mr1
This commit is contained in:
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.AsyncResult;
|
import android.os.AsyncResult;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -30,6 +33,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.android.internal.telephony.Phone;
|
import com.android.internal.telephony.Phone;
|
||||||
import com.android.internal.telephony.PhoneFactory;
|
import com.android.internal.telephony.PhoneFactory;
|
||||||
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the preference screen to enable/disable ICC lock and
|
* Implements the preference screen to enable/disable ICC lock and
|
||||||
@@ -40,7 +44,7 @@ import com.android.internal.telephony.PhoneFactory;
|
|||||||
* these operations.
|
* these operations.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IccLockSettings extends PreferenceActivity
|
public class IccLockSettings extends PreferenceActivity
|
||||||
implements EditPinPreference.OnPinEnteredListener {
|
implements EditPinPreference.OnPinEnteredListener {
|
||||||
|
|
||||||
private static final int OFF_MODE = 0;
|
private static final int OFF_MODE = 0;
|
||||||
@@ -52,7 +56,7 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
private static final int ICC_NEW_MODE = 3;
|
private static final int ICC_NEW_MODE = 3;
|
||||||
// State when entering the new pin - second time
|
// State when entering the new pin - second time
|
||||||
private static final int ICC_REENTER_MODE = 4;
|
private static final int ICC_REENTER_MODE = 4;
|
||||||
|
|
||||||
// Keys in xml file
|
// Keys in xml file
|
||||||
private static final String PIN_DIALOG = "sim_pin";
|
private static final String PIN_DIALOG = "sim_pin";
|
||||||
private static final String PIN_TOGGLE = "sim_toggle";
|
private static final String PIN_TOGGLE = "sim_toggle";
|
||||||
@@ -66,55 +70,68 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
// (ex. portrait<-->landscape) during change PIN code
|
// (ex. portrait<-->landscape) during change PIN code
|
||||||
private static final String OLD_PINCODE = "oldPinCode";
|
private static final String OLD_PINCODE = "oldPinCode";
|
||||||
private static final String NEW_PINCODE = "newPinCode";
|
private static final String NEW_PINCODE = "newPinCode";
|
||||||
|
|
||||||
private static final int MIN_PIN_LENGTH = 4;
|
private static final int MIN_PIN_LENGTH = 4;
|
||||||
private static final int MAX_PIN_LENGTH = 8;
|
private static final int MAX_PIN_LENGTH = 8;
|
||||||
// Which dialog to show next when popped up
|
// Which dialog to show next when popped up
|
||||||
private int mDialogState = OFF_MODE;
|
private int mDialogState = OFF_MODE;
|
||||||
|
|
||||||
private String mPin;
|
private String mPin;
|
||||||
private String mOldPin;
|
private String mOldPin;
|
||||||
private String mNewPin;
|
private String mNewPin;
|
||||||
private String mError;
|
private String mError;
|
||||||
// Are we trying to enable or disable ICC lock?
|
// Are we trying to enable or disable ICC lock?
|
||||||
private boolean mToState;
|
private boolean mToState;
|
||||||
|
|
||||||
private Phone mPhone;
|
private Phone mPhone;
|
||||||
|
|
||||||
private EditPinPreference mPinDialog;
|
private EditPinPreference mPinDialog;
|
||||||
private CheckBoxPreference mPinToggle;
|
private CheckBoxPreference mPinToggle;
|
||||||
|
|
||||||
private Resources mRes;
|
private Resources mRes;
|
||||||
|
|
||||||
// For async handler to identify request type
|
// For async handler to identify request type
|
||||||
private static final int ENABLE_ICC_PIN_COMPLETE = 100;
|
private static final int MSG_ENABLE_ICC_PIN_COMPLETE = 100;
|
||||||
private static final int CHANGE_ICC_PIN_COMPLETE = 101;
|
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
|
||||||
|
private static final int MSG_SIM_STATE_CHANGED = 102;
|
||||||
|
|
||||||
// For replies from IccCard interface
|
// For replies from IccCard interface
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
AsyncResult ar = (AsyncResult) msg.obj;
|
AsyncResult ar = (AsyncResult) msg.obj;
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case ENABLE_ICC_PIN_COMPLETE:
|
case MSG_ENABLE_ICC_PIN_COMPLETE:
|
||||||
iccLockChanged(ar.exception == null);
|
iccLockChanged(ar.exception == null);
|
||||||
break;
|
break;
|
||||||
case CHANGE_ICC_PIN_COMPLETE:
|
case MSG_CHANGE_ICC_PIN_COMPLETE:
|
||||||
iccPinChanged(ar.exception == null);
|
iccPinChanged(ar.exception == null);
|
||||||
break;
|
break;
|
||||||
|
case MSG_SIM_STATE_CHANGED:
|
||||||
|
updatePreferences();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final BroadcastReceiver mSimStateReceiver = new BroadcastReceiver() {
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final String action = intent.getAction();
|
||||||
|
if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_SIM_STATE_CHANGED));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// For top-level settings screen to query
|
// For top-level settings screen to query
|
||||||
static boolean isIccLockEnabled() {
|
static boolean isIccLockEnabled() {
|
||||||
return PhoneFactory.getDefaultPhone().getIccCard().getIccLockEnabled();
|
return PhoneFactory.getDefaultPhone().getIccCard().getIccLockEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getSummary(Context context) {
|
static String getSummary(Context context) {
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
String summary = isIccLockEnabled()
|
String summary = isIccLockEnabled()
|
||||||
? res.getString(R.string.sim_lock_on)
|
? res.getString(R.string.sim_lock_on)
|
||||||
: res.getString(R.string.sim_lock_off);
|
: res.getString(R.string.sim_lock_off);
|
||||||
return summary;
|
return summary;
|
||||||
@@ -158,20 +175,28 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
mPinDialog.setOnPinEnteredListener(this);
|
mPinDialog.setOnPinEnteredListener(this);
|
||||||
|
|
||||||
// Don't need any changes to be remembered
|
// Don't need any changes to be remembered
|
||||||
getPreferenceScreen().setPersistent(false);
|
getPreferenceScreen().setPersistent(false);
|
||||||
|
|
||||||
mPhone = PhoneFactory.getDefaultPhone();
|
mPhone = PhoneFactory.getDefaultPhone();
|
||||||
mRes = getResources();
|
mRes = getResources();
|
||||||
|
updatePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updatePreferences() {
|
||||||
|
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled());
|
// ACTION_SIM_STATE_CHANGED is sticky, so we'll receive current state after this call,
|
||||||
|
// which will call updatePreferences().
|
||||||
|
final IntentFilter filter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
|
||||||
|
registerReceiver(mSimStateReceiver, filter);
|
||||||
|
|
||||||
if (mDialogState != OFF_MODE) {
|
if (mDialogState != OFF_MODE) {
|
||||||
showPinDialog();
|
showPinDialog();
|
||||||
} else {
|
} else {
|
||||||
@@ -179,7 +204,13 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
resetDialogState();
|
resetDialogState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
unregisterReceiver(mSimStateReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle out) {
|
protected void onSaveInstanceState(Bundle out) {
|
||||||
// Need to store this state for slider open/close
|
// Need to store this state for slider open/close
|
||||||
@@ -219,17 +250,17 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setDialogValues();
|
setDialogValues();
|
||||||
|
|
||||||
mPinDialog.showPinDialog();
|
mPinDialog.showPinDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDialogValues() {
|
private void setDialogValues() {
|
||||||
mPinDialog.setText(mPin);
|
mPinDialog.setText(mPin);
|
||||||
String message = "";
|
String message = "";
|
||||||
switch (mDialogState) {
|
switch (mDialogState) {
|
||||||
case ICC_LOCK_MODE:
|
case ICC_LOCK_MODE:
|
||||||
message = mRes.getString(R.string.sim_enter_pin);
|
message = mRes.getString(R.string.sim_enter_pin);
|
||||||
mPinDialog.setDialogTitle(mToState
|
mPinDialog.setDialogTitle(mToState
|
||||||
? mRes.getString(R.string.sim_enable_sim_lock)
|
? mRes.getString(R.string.sim_enable_sim_lock)
|
||||||
: mRes.getString(R.string.sim_disable_sim_lock));
|
: mRes.getString(R.string.sim_disable_sim_lock));
|
||||||
break;
|
break;
|
||||||
@@ -258,7 +289,7 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
resetDialogState();
|
resetDialogState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mPin = preference.getText();
|
mPin = preference.getText();
|
||||||
if (!reasonablePin(mPin)) {
|
if (!reasonablePin(mPin)) {
|
||||||
// inject error message and display dialog again
|
// inject error message and display dialog again
|
||||||
@@ -296,13 +327,13 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||||
if (preference == mPinToggle) {
|
if (preference == mPinToggle) {
|
||||||
// Get the new, preferred state
|
// Get the new, preferred state
|
||||||
mToState = mPinToggle.isChecked();
|
mToState = mPinToggle.isChecked();
|
||||||
// Flip it back and pop up pin dialog
|
// Flip it back and pop up pin dialog
|
||||||
mPinToggle.setChecked(!mToState);
|
mPinToggle.setChecked(!mToState);
|
||||||
mDialogState = ICC_LOCK_MODE;
|
mDialogState = ICC_LOCK_MODE;
|
||||||
showPinDialog();
|
showPinDialog();
|
||||||
} else if (preference == mPinDialog) {
|
} else if (preference == mPinDialog) {
|
||||||
@@ -313,13 +344,13 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tryChangeIccLockState() {
|
private void tryChangeIccLockState() {
|
||||||
// Try to change icc lock. If it succeeds, toggle the lock state and
|
// Try to change icc lock. If it succeeds, toggle the lock state and
|
||||||
// reset dialog state. Else inject error message and show dialog again.
|
// reset dialog state. Else inject error message and show dialog again.
|
||||||
Message callback = Message.obtain(mHandler, ENABLE_ICC_PIN_COMPLETE);
|
Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE);
|
||||||
mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback);
|
mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void iccLockChanged(boolean success) {
|
private void iccLockChanged(boolean success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
mPinToggle.setChecked(mToState);
|
mPinToggle.setChecked(mToState);
|
||||||
@@ -345,7 +376,7 @@ public class IccLockSettings extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tryChangePin() {
|
private void tryChangePin() {
|
||||||
Message callback = Message.obtain(mHandler, CHANGE_ICC_PIN_COMPLETE);
|
Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE);
|
||||||
mPhone.getIccCard().changeIccLockPassword(mOldPin,
|
mPhone.getIccCard().changeIccLockPassword(mOldPin,
|
||||||
mNewPin, callback);
|
mNewPin, callback);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user