Revert "EnabledNetworkModePreferenceController Remove AllowedNetworkType"

This reverts commit 259e6288c9.

Reason for revert: Sooraj will implement another API for power manager.
Bug: 156709797
Change-Id: I15ee2799574cdf0318e593500f0dbfbf135d71f8
This commit is contained in:
SongFerng Wang
2020-06-01 02:46:17 +00:00
parent 73b6bfc1e8
commit 893107fc60
2 changed files with 85 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ public class EnabledNetworkModePreferenceControllerTest {
private static final int SUB_ID = 2;
public static final String KEY = "enabled_network";
private static final long ALLOWED_ALL_NETWORK_TYPE = -1;
private static final long DISABLED_5G_NETWORK_TYPE = ~TelephonyManager.NETWORK_TYPE_BITMASK_NR;
@Mock
@@ -97,6 +98,7 @@ public class EnabledNetworkModePreferenceControllerTest {
doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
mPreference = new ListPreference(mContext);
mController = new EnabledNetworkModePreferenceController(mContext, KEY);
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
mockAccessFamily(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
mController.init(mLifecycle, SUB_ID);
mPreference.setKey(mController.getPreferenceKey());
@@ -182,6 +184,76 @@ public class EnabledNetworkModePreferenceControllerTest {
TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
}
@Test
public void updateState_disAllowed5g_5gOptionHidden() {
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
mController.init(mLifecycle, SUB_ID);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getEntryValues())
.asList()
.doesNotContain(
String.valueOf(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
}
@Test
public void updateState_disAllowed5g_selectOn4gOption() {
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
mController.init(mLifecycle, SUB_ID);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(
TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
}
@Test
public void updateState_GlobalDisAllowed5g_GlobalWithoutNR() {
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
mController.init(mLifecycle, SUB_ID);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getEntryValues())
.asList()
.doesNotContain(
String.valueOf(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
}
@Test
public void updateState_GlobalDisAllowed5g_SelectOnGlobal() {
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
mController.init(mLifecycle, SUB_ID);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(
TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
}
@Test
public void updateState_updateByNetworkMode() {
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
@@ -279,6 +351,10 @@ public class EnabledNetworkModePreferenceControllerTest {
}
}
private void mockAllowedNetworkTypes(long allowedNetworkType) {
doReturn(allowedNetworkType).when(mTelephonyManager).getAllowedNetworkTypes();
}
private void mockAccessFamily(int networkMode) {
doReturn(MobileNetworkUtils.getRafFromNetworkType(networkMode))
.when(mTelephonyManager)