Fix sim pin lock preference disappear in dual sim.
If one sim hide the preference and another one show the preference, the preference always hide. The root cause is config value is wrong. It should get config with subid. Bug: 149800931 Test: make RunSettingsRoboTests ROBOTEST_FILTER=SimLockPreferenceControllerTest Change-Id: I91b551bc363b8ecb0a4b6b40e9de79c74ccd76fd
This commit is contained in:
@@ -28,6 +28,8 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -53,6 +55,7 @@ import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.network.ProxySubscriptionManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -220,8 +223,30 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
final int numSims = mProxySubscriptionMgr.getActiveSubscriptionInfoCountMax();
|
||||
final List<SubscriptionInfo> subInfoList =
|
||||
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
||||
mSlotId = 0;
|
||||
if (numSims > 1) {
|
||||
final List<SubscriptionInfo> componenterList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < numSims; ++i) {
|
||||
final SubscriptionInfo subInfo =
|
||||
getActiveSubscriptionInfoForSimSlotIndex(subInfoList, i);
|
||||
final CarrierConfigManager carrierConfigManager = getContext().getSystemService(
|
||||
CarrierConfigManager.class);
|
||||
final PersistableBundle bundle = carrierConfigManager.getConfigForSubId(
|
||||
subInfo.getSubscriptionId());
|
||||
if (bundle != null
|
||||
&& !bundle.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
|
||||
componenterList.add(subInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (componenterList.size() == 0) {
|
||||
Log.e(TAG, "onCreateView: no sim info");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (componenterList.size() > 1) {
|
||||
final View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
|
||||
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
||||
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
||||
@@ -236,25 +261,22 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
||||
mTabHost.setOnTabChangedListener(mTabListener);
|
||||
mTabHost.clearAllTabs();
|
||||
|
||||
final List<SubscriptionInfo> subInfoList =
|
||||
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
||||
for (int i = 0; i < numSims; ++i) {
|
||||
final SubscriptionInfo subInfo =
|
||||
getActiveSubscriptionInfoForSimSlotIndex(subInfoList, i);
|
||||
mTabHost.addTab(buildTabSpec(String.valueOf(i),
|
||||
for (SubscriptionInfo subInfo : componenterList) {
|
||||
int slot = subInfo.getSimSlotIndex();
|
||||
mTabHost.addTab(buildTabSpec(String.valueOf(slot),
|
||||
String.valueOf(subInfo == null
|
||||
? getContext().getString(R.string.sim_editor_title, i + 1)
|
||||
: subInfo.getDisplayName())));
|
||||
? getContext().getString(R.string.sim_editor_title, slot + 1)
|
||||
: subInfo.getDisplayName())));
|
||||
}
|
||||
final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(
|
||||
subInfoList, mSlotId);
|
||||
mSubId = sir.getSubscriptionId();
|
||||
|
||||
mSubId = componenterList.get(0).getSubscriptionId();
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_TAB)) {
|
||||
mTabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB));
|
||||
}
|
||||
return view;
|
||||
} else {
|
||||
mSlotId = componenterList.get(0).getSimSlotIndex();
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
@@ -52,13 +52,19 @@ public class SimLockPreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final PersistableBundle b = mCarrierConfigManager.getConfig();
|
||||
final boolean IsAdmin = mUserManager.isAdminUser();
|
||||
if (!IsAdmin || !isSimIccReady() ||
|
||||
b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
|
||||
final List<SubscriptionInfo> subInfoList =
|
||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
|
||||
if (subInfoList == null) {
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
return AVAILABLE;
|
||||
|
||||
final boolean isAdmin = mUserManager.isAdminUser();
|
||||
if (isAdmin && (!isHideSimLockSetting(subInfoList))) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,34 +84,37 @@ public class SimLockPreferenceController extends BasePreferenceController {
|
||||
private boolean isSimReady() {
|
||||
final List<SubscriptionInfo> subInfoList =
|
||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subInfoList != null) {
|
||||
for (SubscriptionInfo subInfo : subInfoList) {
|
||||
final int simState = mTelephonyManager.getSimState(subInfo.getSimSlotIndex());
|
||||
if ((simState != TelephonyManager.SIM_STATE_ABSENT) &&
|
||||
(simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
|
||||
return true;
|
||||
}
|
||||
if (subInfoList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (SubscriptionInfo subInfo : subInfoList) {
|
||||
final int simState = mTelephonyManager.getSimState(subInfo.getSimSlotIndex());
|
||||
if ((simState != TelephonyManager.SIM_STATE_ABSENT)
|
||||
&& (simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a there is a Slot that has Icc
|
||||
*/
|
||||
private boolean isSimIccReady() {
|
||||
final List<SubscriptionInfo> subInfoList =
|
||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
private boolean isHideSimLockSetting(List<SubscriptionInfo> subInfoList) {
|
||||
if (subInfoList == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subInfoList != null) {
|
||||
for (SubscriptionInfo subInfo : subInfoList) {
|
||||
mTelephonyManager = mTelephonyManager
|
||||
.createForSubscriptionId(subInfo.getSimSlotIndex());
|
||||
if (mTelephonyManager.hasIccCard()) {
|
||||
return true;
|
||||
}
|
||||
for (SubscriptionInfo subInfo : subInfoList) {
|
||||
final TelephonyManager telephonyManager = mTelephonyManager
|
||||
.createForSubscriptionId(subInfo.getSubscriptionId());
|
||||
final PersistableBundle bundle = mCarrierConfigManager.getConfigForSubId(
|
||||
subInfo.getSubscriptionId());
|
||||
if (telephonyManager.hasIccCard() && bundle != null
|
||||
&& !bundle.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
|
||||
// one or more sims show sim lock setting UI.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -103,7 +103,7 @@ public class SimLockPreferenceControllerTest {
|
||||
setupMockIcc();
|
||||
final PersistableBundle pb = new PersistableBundle();
|
||||
pb.putBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL, true);
|
||||
when(mCarrierManager.getConfig()).thenReturn(pb);
|
||||
when(mCarrierManager.getConfigForSubId(anyInt())).thenReturn(pb);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
|
||||
@@ -114,7 +114,7 @@ public class SimLockPreferenceControllerTest {
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
setupMockIcc();
|
||||
final PersistableBundle pb = new PersistableBundle();
|
||||
when(mCarrierManager.getConfig()).thenReturn(pb);
|
||||
when(mCarrierManager.getConfigForSubId(anyInt())).thenReturn(pb);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
|
Reference in New Issue
Block a user