Merge "[Settings] Avoid crash when switch SIM during PIN lock"
This commit is contained in:
@@ -86,6 +86,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
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";
|
||||||
// Keys in icicle
|
// Keys in icicle
|
||||||
|
private static final String DIALOG_SUB_ID = "dialogSubId";
|
||||||
private static final String DIALOG_STATE = "dialogState";
|
private static final String DIALOG_STATE = "dialogState";
|
||||||
private static final String DIALOG_PIN = "dialogPin";
|
private static final String DIALOG_PIN = "dialogPin";
|
||||||
private static final String DIALOG_ERROR = "dialogError";
|
private static final String DIALOG_ERROR = "dialogError";
|
||||||
@@ -126,7 +127,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
// @see android.widget.Toast$TN
|
// @see android.widget.Toast$TN
|
||||||
private static final long LONG_DURATION_TIMEOUT = 7000;
|
private static final long LONG_DURATION_TIMEOUT = 7000;
|
||||||
|
|
||||||
private int mSlotId;
|
private int mSlotId = -1;
|
||||||
private int mSubId;
|
private int mSubId;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
// For top-level settings screen to query
|
// For top-level settings screen to query
|
||||||
private boolean isIccLockEnabled() {
|
private boolean isIccLockEnabled() {
|
||||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
|
||||||
return mTelephonyManager.isIccLockEnabled();
|
return mTelephonyManager.isIccLockEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,27 +187,13 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
|
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
|
||||||
mPinToggle = (SwitchPreference) findPreference(PIN_TOGGLE);
|
mPinToggle = (SwitchPreference) findPreference(PIN_TOGGLE);
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(DIALOG_STATE)) {
|
if (savedInstanceState != null) {
|
||||||
mDialogState = savedInstanceState.getInt(DIALOG_STATE);
|
if (savedInstanceState.containsKey(DIALOG_STATE)
|
||||||
mPin = savedInstanceState.getString(DIALOG_PIN);
|
&& restoreDialogStates(savedInstanceState)) {
|
||||||
mError = savedInstanceState.getString(DIALOG_ERROR);
|
Log.d(TAG, "onCreate: restore dialog for slotId=" + mSlotId + ", subId=" + mSubId);
|
||||||
mToState = savedInstanceState.getBoolean(ENABLE_TO_STATE);
|
} else if (savedInstanceState.containsKey(CURRENT_TAB)
|
||||||
|
&& restoreTabFocus(savedInstanceState)) {
|
||||||
// Restore inputted PIN code
|
Log.d(TAG, "onCreate: restore focus on slotId=" + mSlotId + ", subId=" + mSubId);
|
||||||
switch (mDialogState) {
|
|
||||||
case ICC_NEW_MODE:
|
|
||||||
mOldPin = savedInstanceState.getString(OLD_PINCODE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ICC_REENTER_MODE:
|
|
||||||
mOldPin = savedInstanceState.getString(OLD_PINCODE);
|
|
||||||
mNewPin = savedInstanceState.getString(NEW_PINCODE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ICC_LOCK_MODE:
|
|
||||||
case ICC_OLD_MODE:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,29 +205,75 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
mRes = getResources();
|
mRes = getResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean restoreDialogStates(Bundle savedInstanceState) {
|
||||||
|
final SubscriptionInfo subInfo = mProxySubscriptionMgr
|
||||||
|
.getActiveSubscriptionInfo(savedInstanceState.getInt(DIALOG_SUB_ID));
|
||||||
|
if (subInfo == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final SubscriptionInfo visibleSubInfo = getVisibleSubscriptionInfoForSimSlotIndex(
|
||||||
|
subInfo.getSimSlotIndex());
|
||||||
|
if (visibleSubInfo == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (visibleSubInfo.getSubscriptionId() != subInfo.getSubscriptionId()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSlotId = subInfo.getSimSlotIndex();
|
||||||
|
mSubId = subInfo.getSubscriptionId();
|
||||||
|
mDialogState = savedInstanceState.getInt(DIALOG_STATE);
|
||||||
|
mPin = savedInstanceState.getString(DIALOG_PIN);
|
||||||
|
mError = savedInstanceState.getString(DIALOG_ERROR);
|
||||||
|
mToState = savedInstanceState.getBoolean(ENABLE_TO_STATE);
|
||||||
|
|
||||||
|
// Restore inputted PIN code
|
||||||
|
switch (mDialogState) {
|
||||||
|
case ICC_NEW_MODE:
|
||||||
|
mOldPin = savedInstanceState.getString(OLD_PINCODE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ICC_REENTER_MODE:
|
||||||
|
mOldPin = savedInstanceState.getString(OLD_PINCODE);
|
||||||
|
mNewPin = savedInstanceState.getString(NEW_PINCODE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean restoreTabFocus(Bundle savedInstanceState) {
|
||||||
|
int slotId = 0;
|
||||||
|
try {
|
||||||
|
slotId = Integer.parseInt(savedInstanceState.getString(CURRENT_TAB));
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final SubscriptionInfo subInfo = getVisibleSubscriptionInfoForSimSlotIndex(slotId);
|
||||||
|
if (subInfo == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSlotId = subInfo.getSimSlotIndex();
|
||||||
|
mSubId = subInfo.getSubscriptionId();
|
||||||
|
if (mTabHost != null) {
|
||||||
|
mTabHost.setCurrentTabByTag(getTagForSlotId(mSlotId));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
final int numSims = mProxySubscriptionMgr.getActiveSubscriptionInfoCountMax();
|
final int numSims = mProxySubscriptionMgr.getActiveSubscriptionInfoCountMax();
|
||||||
final List<SubscriptionInfo> subInfoList =
|
|
||||||
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
|
||||||
mSlotId = 0;
|
|
||||||
final List<SubscriptionInfo> componenterList = new ArrayList<>();
|
final List<SubscriptionInfo> componenterList = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < numSims; ++i) {
|
for (int i = 0; i < numSims; ++i) {
|
||||||
final SubscriptionInfo subInfo =
|
final SubscriptionInfo subInfo = getVisibleSubscriptionInfoForSimSlotIndex(i);
|
||||||
getActiveSubscriptionInfoForSimSlotIndex(subInfoList, i);
|
|
||||||
if (subInfo != null) {
|
if (subInfo != null) {
|
||||||
final CarrierConfigManager carrierConfigManager = getContext().getSystemService(
|
componenterList.add(subInfo);
|
||||||
CarrierConfigManager.class);
|
|
||||||
final PersistableBundle bundle = carrierConfigManager.getConfigForSubId(
|
|
||||||
subInfo.getSubscriptionId());
|
|
||||||
if (bundle != null
|
|
||||||
&& !bundle.getBoolean(CarrierConfigManager
|
|
||||||
.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
|
|
||||||
componenterList.add(subInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,6 +282,12 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mSlotId < 0) {
|
||||||
|
mSlotId = componenterList.get(0).getSimSlotIndex();
|
||||||
|
mSubId = componenterList.get(0).getSubscriptionId();
|
||||||
|
Log.d(TAG, "onCreateView: default slotId=" + mSlotId + ", subId=" + mSubId);
|
||||||
|
}
|
||||||
|
|
||||||
if (componenterList.size() > 1) {
|
if (componenterList.size() > 1) {
|
||||||
final View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
|
final View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
|
||||||
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
||||||
@@ -261,25 +300,21 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
mListView = (ListView) view.findViewById(android.R.id.list);
|
mListView = (ListView) view.findViewById(android.R.id.list);
|
||||||
|
|
||||||
mTabHost.setup();
|
mTabHost.setup();
|
||||||
mTabHost.setOnTabChangedListener(mTabListener);
|
|
||||||
mTabHost.clearAllTabs();
|
mTabHost.clearAllTabs();
|
||||||
|
|
||||||
for (SubscriptionInfo subInfo : componenterList) {
|
for (SubscriptionInfo subInfo : componenterList) {
|
||||||
int slot = subInfo.getSimSlotIndex();
|
final int slot = subInfo.getSimSlotIndex();
|
||||||
mTabHost.addTab(buildTabSpec(String.valueOf(slot),
|
final String tag = getTagForSlotId(slot);
|
||||||
|
mTabHost.addTab(buildTabSpec(tag,
|
||||||
String.valueOf(subInfo == null
|
String.valueOf(subInfo == null
|
||||||
? getContext().getString(R.string.sim_editor_title, slot + 1)
|
? getContext().getString(R.string.sim_editor_title, slot + 1)
|
||||||
: subInfo.getDisplayName())));
|
: subInfo.getDisplayName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
mSubId = componenterList.get(0).getSubscriptionId();
|
mTabHost.setCurrentTabByTag(getTagForSlotId(mSlotId));
|
||||||
|
mTabHost.setOnTabChangedListener(mTabListener);
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_TAB)) {
|
|
||||||
mTabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB));
|
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
} else {
|
} else {
|
||||||
mSlotId = componenterList.get(0).getSimSlotIndex();
|
|
||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,11 +327,17 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private void updatePreferences() {
|
private void updatePreferences() {
|
||||||
|
|
||||||
final List<SubscriptionInfo> subInfoList =
|
final SubscriptionInfo sir = getVisibleSubscriptionInfoForSimSlotIndex(mSlotId);
|
||||||
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
final int subId = (sir != null) ? sir.getSubscriptionId()
|
||||||
final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(subInfoList, mSlotId);
|
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
mSubId = (sir == null) ? SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
|
||||||
: sir.getSubscriptionId();
|
if (mSubId != subId) {
|
||||||
|
mSubId = subId;
|
||||||
|
resetDialogState();
|
||||||
|
if ((mPinDialog != null) && mPinDialog.isDialogOpen()) {
|
||||||
|
mPinDialog.getDialog().dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mPinDialog != null) {
|
if (mPinDialog != null) {
|
||||||
mPinDialog.setEnabled(sir != null);
|
mPinDialog.setEnabled(sir != null);
|
||||||
@@ -351,6 +392,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
// dialog state. In other cases, where this activity manually launches
|
// dialog state. In other cases, where this activity manually launches
|
||||||
// the dialog, store the state of the dialog.
|
// the dialog, store the state of the dialog.
|
||||||
if (mPinDialog.isDialogOpen()) {
|
if (mPinDialog.isDialogOpen()) {
|
||||||
|
out.putInt(DIALOG_SUB_ID, mSubId);
|
||||||
out.putInt(DIALOG_STATE, mDialogState);
|
out.putInt(DIALOG_STATE, mDialogState);
|
||||||
out.putString(DIALOG_PIN, mPinDialog.getEditText().getText().toString());
|
out.putString(DIALOG_PIN, mPinDialog.getEditText().getText().toString());
|
||||||
out.putString(DIALOG_ERROR, mError);
|
out.putString(DIALOG_ERROR, mError);
|
||||||
@@ -366,11 +408,6 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
out.putString(OLD_PINCODE, mOldPin);
|
out.putString(OLD_PINCODE, mOldPin);
|
||||||
out.putString(NEW_PINCODE, mNewPin);
|
out.putString(NEW_PINCODE, mNewPin);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ICC_LOCK_MODE:
|
|
||||||
case ICC_OLD_MODE:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onSaveInstanceState(out);
|
super.onSaveInstanceState(out);
|
||||||
@@ -665,23 +702,50 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
mDialogState = OFF_MODE;
|
mDialogState = OFF_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(
|
private String getTagForSlotId(int slotId) {
|
||||||
List<SubscriptionInfo> subInfoList, int slotId) {
|
return String.valueOf(slotId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getSlotIndexFromTag(String tag) {
|
||||||
|
int slotId = -1;
|
||||||
|
try {
|
||||||
|
slotId = Integer.parseInt(tag);
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
}
|
||||||
|
return slotId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SubscriptionInfo getVisibleSubscriptionInfoForSimSlotIndex(int slotId) {
|
||||||
|
final List<SubscriptionInfo> subInfoList =
|
||||||
|
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
||||||
if (subInfoList == null) {
|
if (subInfoList == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
final CarrierConfigManager carrierConfigManager = getContext().getSystemService(
|
||||||
|
CarrierConfigManager.class);
|
||||||
for (SubscriptionInfo subInfo : subInfoList) {
|
for (SubscriptionInfo subInfo : subInfoList) {
|
||||||
if (subInfo.getSimSlotIndex() == slotId) {
|
if ((isSubscriptionVisible(carrierConfigManager, subInfo)
|
||||||
|
&& (subInfo.getSimSlotIndex() == slotId))) {
|
||||||
return subInfo;
|
return subInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSubscriptionVisible(CarrierConfigManager carrierConfigManager,
|
||||||
|
SubscriptionInfo subInfo) {
|
||||||
|
final PersistableBundle bundle = carrierConfigManager
|
||||||
|
.getConfigForSubId(subInfo.getSubscriptionId());
|
||||||
|
if (bundle == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !bundle.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL);
|
||||||
|
}
|
||||||
|
|
||||||
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
|
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTabChanged(String tabId) {
|
public void onTabChanged(String tabId) {
|
||||||
mSlotId = Integer.parseInt(tabId);
|
mSlotId = getSlotIndexFromTag(tabId);
|
||||||
|
|
||||||
// The User has changed tab; update the body.
|
// The User has changed tab; update the body.
|
||||||
updatePreferences();
|
updatePreferences();
|
||||||
|
Reference in New Issue
Block a user