[packages/apps/Settings] Settings: add skip sim pin feature
What's in this commit: 1, add menu item to show SIM PIN unlock UI.
This commit is contained in:
1
packages/apps/Settings/AndroidManifest.xml
Executable file → Normal file
1
packages/apps/Settings/AndroidManifest.xml
Executable file → Normal file
@ -1098,6 +1098,7 @@
|
||||
<activity android:name="IccLockSettings"
|
||||
android:label="@string/sim_lock_settings"
|
||||
android:theme="@style/Theme.SubSettingsDialogWhenLarge"
|
||||
android:configChanges="mnc|mcc"
|
||||
android:process="com.android.phone">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@ -38,4 +38,14 @@
|
||||
<string name="limit_animation">限制窗口动画效果</string>
|
||||
<string name="limit_animation_summary">不显示窗口切换的动画效果</string>
|
||||
<string name="power_save_tips">提示</string>
|
||||
|
||||
<!-- unlock sim pin strings -->
|
||||
<string name="sim_absent">无SIM卡</string>
|
||||
<string name="sim_off">SIM卡关闭</string>
|
||||
<string name="sim_unlocked">SIM 已解锁</string>
|
||||
<string name="sim_unlock_puk_toggle">"SIM PUK 锁定"</string>
|
||||
<string name="sim_puk_lock_on">"输入PUK码解锁手机"</string>
|
||||
<string name="sim_unlock_pin_toggle">"SIM PIN 锁定"</string>
|
||||
<string name="sim_pin_lock_on">"输入PIN码解锁手机"</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -38,4 +38,14 @@
|
||||
<string name="limit_animation">限制視窗動畫效果</string>
|
||||
<string name="limit_animation_summary">不顯示視窗切換的動畫效果</string>
|
||||
<string name="power_save_tips">提示</string>
|
||||
|
||||
<!-- unlock sim pin strings -->
|
||||
<string name="sim_absent">無SIM卡</string>
|
||||
<string name="sim_off">SIM卡關閉</string>
|
||||
<string name="sim_unlocked">SIM 已解鎖</string>
|
||||
<string name="sim_unlock_puk_toggle">"SIM PUK 鎖定"</string>
|
||||
<string name="sim_puk_lock_on">"輸入PUK码解鎖手機"</string>
|
||||
<string name="sim_unlock_pin_toggle">"SIM PIN 鎖定"</string>
|
||||
<string name="sim_pin_lock_on">"輸入PIN码解鎖手機"</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -38,4 +38,14 @@
|
||||
<string name="limit_animation">No animation transaction</string>
|
||||
<string name="limit_animation_summary">Window animation transaction will be disabled</string>
|
||||
<string name="power_save_tips">Tips</string>
|
||||
|
||||
<!-- unlock sim pin strings -->
|
||||
<string name="sim_absent">No SIM inserted</string>
|
||||
<string name="sim_off">SIM is off</string>
|
||||
<string name="sim_unlocked">SIM is unlocked</string>
|
||||
<string name="sim_unlock_puk_toggle">"Unlock PIN"</string>
|
||||
<string name="sim_puk_lock_on">"Click to input PUK"</string>
|
||||
<string name="sim_unlock_pin_toggle">"Unlock SIM"</string>
|
||||
<string name="sim_pin_lock_on">"Click to input PIN"</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -18,6 +18,12 @@
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/sim_lock_settings">
|
||||
|
||||
<Preference
|
||||
android:key="sim_unlock_toggle"
|
||||
android:title="@string/sim_unlock_puk_toggle"
|
||||
android:summaryOn="@string/sim_puk_lock_on"
|
||||
/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="sim_toggle"
|
||||
android:title="@string/sim_pin_toggle"
|
||||
|
||||
@ -42,7 +42,9 @@ import android.widget.TabHost.TabSpec;
|
||||
import android.widget.TabWidget;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.telephony.IccCard;
|
||||
import com.android.internal.telephony.Phone;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.internal.telephony.PhoneFactory;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
|
||||
@ -76,6 +78,7 @@ public class IccLockSettings extends PreferenceActivity
|
||||
// Keys in xml file
|
||||
private static final String PIN_DIALOG = "sim_pin";
|
||||
private static final String PIN_TOGGLE = "sim_toggle";
|
||||
private static final String SIM_UNLOCK_TOGGLE = "sim_unlock_toggle";
|
||||
// Keys in icicle
|
||||
private static final String DIALOG_STATE = "dialogState";
|
||||
private static final String DIALOG_PIN = "dialogPin";
|
||||
@ -107,9 +110,12 @@ public class IccLockSettings extends PreferenceActivity
|
||||
|
||||
private EditPinPreference mPinDialog;
|
||||
private SwitchPreference mPinToggle;
|
||||
private Preference mUnlockToggle;
|
||||
|
||||
private Resources mRes;
|
||||
|
||||
private boolean mSkipSimPinFeatureEnabled = false;
|
||||
|
||||
// For async handler to identify request type
|
||||
private static final int MSG_ENABLE_ICC_PIN_COMPLETE = 100;
|
||||
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
|
||||
@ -174,6 +180,14 @@ public class IccLockSettings extends PreferenceActivity
|
||||
|
||||
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
|
||||
mPinToggle = (SwitchPreference) findPreference(PIN_TOGGLE);
|
||||
mUnlockToggle = (Preference) findPreference(SIM_UNLOCK_TOGGLE);
|
||||
|
||||
mSkipSimPinFeatureEnabled = getResources().getBoolean(com.android.internal.R.bool.config_imc_feature_skip_sim_pin);
|
||||
if (!mSkipSimPinFeatureEnabled) {
|
||||
getPreferenceScreen().removePreference(mUnlockToggle);
|
||||
mUnlockToggle = null;
|
||||
}
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(DIALOG_STATE)) {
|
||||
mDialogState = savedInstanceState.getInt(DIALOG_STATE);
|
||||
mPin = savedInstanceState.getString(DIALOG_PIN);
|
||||
@ -232,6 +246,45 @@ public class IccLockSettings extends PreferenceActivity
|
||||
updatePreferences();
|
||||
}
|
||||
|
||||
private void updateUnLockToggle() {
|
||||
switch (getSimState()) {
|
||||
case TelephonyManager.SIM_STATE_ABSENT:
|
||||
boolean isSimOff = false;
|
||||
if (mPhone != null) {
|
||||
isSimOff = mPhone.isSimOff();
|
||||
}
|
||||
if (isSimOff) {
|
||||
mUnlockToggle.setTitle(R.string.sim_off);
|
||||
mUnlockToggle.setEnabled(true);
|
||||
mUnlockToggle.setSelectable(true);
|
||||
} else {
|
||||
mUnlockToggle.setTitle(R.string.sim_absent);
|
||||
mUnlockToggle.setEnabled(false);
|
||||
mUnlockToggle.setSelectable(false);
|
||||
}
|
||||
mUnlockToggle.setSummary(null);
|
||||
break;
|
||||
case TelephonyManager.SIM_STATE_PUK_REQUIRED:
|
||||
mUnlockToggle.setTitle(R.string.sim_unlock_puk_toggle);
|
||||
mUnlockToggle.setSummary(R.string.sim_puk_lock_on);
|
||||
mUnlockToggle.setEnabled(true);
|
||||
mUnlockToggle.setSelectable(true);
|
||||
break;
|
||||
case TelephonyManager.SIM_STATE_PIN_REQUIRED:
|
||||
mUnlockToggle.setTitle(R.string.sim_unlock_pin_toggle);
|
||||
mUnlockToggle.setSummary(R.string.sim_pin_lock_on);
|
||||
mUnlockToggle.setEnabled(true);
|
||||
mUnlockToggle.setSelectable(true);
|
||||
break;
|
||||
default:
|
||||
mUnlockToggle.setTitle(R.string.sim_unlocked);
|
||||
mUnlockToggle.setSummary(null);
|
||||
mUnlockToggle.setEnabled(false);
|
||||
mUnlockToggle.setSelectable(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreferences() {
|
||||
mPinDialog.setEnabled(mPhone != null);
|
||||
mPinToggle.setEnabled(mPhone != null);
|
||||
@ -239,12 +292,49 @@ public class IccLockSettings extends PreferenceActivity
|
||||
if (mPhone != null) {
|
||||
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled());
|
||||
}
|
||||
|
||||
if (mSkipSimPinFeatureEnabled) {
|
||||
updateUnLockToggle();
|
||||
}
|
||||
}
|
||||
|
||||
private int getSimState() {
|
||||
int state = TelephonyManager.SIM_STATE_UNKNOWN;
|
||||
|
||||
if (mPhone != null) {
|
||||
IccCard icc = mPhone.getIccCard();
|
||||
if (icc != null) {
|
||||
state = icc.getState().ordinal();
|
||||
} else {
|
||||
Log.e(TAG, "getSimState() - mPhone.getIccCard() is null");
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "getSimState() - mPhone is null");
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private boolean isSimState(int state) {
|
||||
return state == getSimState();
|
||||
}
|
||||
|
||||
private boolean isPukLocked() {
|
||||
return isSimState(TelephonyManager.SIM_STATE_PUK_REQUIRED);
|
||||
}
|
||||
|
||||
private boolean isPinLocked() {
|
||||
return isSimState(TelephonyManager.SIM_STATE_PIN_REQUIRED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mSkipSimPinFeatureEnabled) {
|
||||
updatePreferences();
|
||||
}
|
||||
|
||||
// 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);
|
||||
@ -392,6 +482,12 @@ public class IccLockSettings extends PreferenceActivity
|
||||
} else if (preference == mPinDialog) {
|
||||
mDialogState = ICC_OLD_MODE;
|
||||
return false;
|
||||
} else if (preference == mUnlockToggle) {
|
||||
if (isPukLocked()) {
|
||||
showUnlockDialog(TelephonyManager.SIM_STATE_PUK_REQUIRED);
|
||||
} else if (isPinLocked()) {
|
||||
showUnlockDialog(TelephonyManager.SIM_STATE_PIN_REQUIRED);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -494,4 +590,33 @@ public class IccLockSettings extends PreferenceActivity
|
||||
return mTabHost.newTabSpec(tag).setIndicator(title).setContent(
|
||||
mEmptyTabContent);
|
||||
}
|
||||
|
||||
private void showUnlockDialog(int type) {
|
||||
if (DBG) Log.d(TAG, "Enter showUnlockDialog type=" + type);
|
||||
if (mPhone == null) {
|
||||
Log.e(TAG, "mPhone is null");
|
||||
return;
|
||||
}
|
||||
|
||||
int subId = mPhone.getSubId();
|
||||
if (DBG) Log.d(TAG, "subId=" + subId);
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
Log.e(TAG, "invalid subId:" + subId);
|
||||
return;
|
||||
}
|
||||
|
||||
int slotId = SubscriptionManager.getSlotId(subId);
|
||||
if (DBG) Log.d(TAG, "slotId=" + slotId);
|
||||
if (!SubscriptionManager.isValidSlotId(slotId)) {
|
||||
Log.e(TAG, "invalid slotId:" + slotId);
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(TelephonyIntents.ACTION_SHOW_PIN_PUK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
|
||||
Intent. FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
intent.putExtra("type", type);
|
||||
intent.putExtra(PhoneConstants.SLOT_KEY, slotId);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user