To fix bug, summary is wrong if nr_enabled_bool=false

The carrier config nr_enabled_bool is false, preferred network mode
should hide 5G UI. This bug is that the summary show 5G item when
nr_enabled_bool is false.
Solution: if nr_enabled_bool is false, it checks capability and then
removes 5G capability of network mode.

Bug: 170460943
Test: make RunSettingsRoboTests ROBOTEST_FILTER=\
EnabledNetworkModePreferenceControllerTest   (PASS)
Change-Id: I3f7d41c196569c0cb61e89cfc270b957e2f0add5
This commit is contained in:
SongFerngWang
2020-10-20 18:37:39 +08:00
committed by SongFerng Wang
parent e0c58e9b1b
commit 706036e5b3
2 changed files with 69 additions and 2 deletions

View File

@@ -365,9 +365,15 @@ public class EnabledNetworkModePreferenceController extends
}
private int getPreferredNetworkMode() {
return Settings.Global.getInt(mContext.getContentResolver(),
int networkMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
TelephonyManager.DEFAULT_PREFERRED_NETWORK_MODE);
if (!showNrList()) {
Log.d(LOG_TAG, "Network mode :" + networkMode + " reduce NR");
networkMode = reduceNrToLteNetworkType(networkMode);
}
Log.d(LOG_TAG, "getPreferredNetworkMode: " + networkMode);
return networkMode;
}
private EnabledNetworks getEnabledNetworkType() {
@@ -635,6 +641,40 @@ public class EnabledNetworkModePreferenceController extends
}
}
/**
* Transform NR5G network mode to LTE network mode.
*
* @param networkType an 5G network mode.
* @return the corresponding network mode without 5G.
*/
private static int reduceNrToLteNetworkType(int networkType) {
switch(networkType) {
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE:
return TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO:
return TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA:
return TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA:
return TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_WCDMA:
return TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA:
return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM:
return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA:
return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA:
return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA;
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
return TelephonyManagerConstants
.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
default:
return networkType; // do nothing
}
}
private void setPreferenceValueAndSummary() {
setPreferenceValueAndSummary(getPreferredNetworkMode());
}

View File

@@ -221,6 +221,28 @@ public class EnabledNetworkModePreferenceControllerTest {
TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
}
@Test
public void updateState_NrEnableBoolFalse_5gOptionHidden() {
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_NR_ENABLED_BOOL, false);
mController.init(mLifecycle, SUB_ID);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(
TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
assertThat(mPreference.getEntryValues())
.asList()
.doesNotContain(
String.valueOf(TelephonyManager.NETWORK_MODE_NR_LTE_GSM_WCDMA));
}
@Test
public void updateState_GlobalDisAllowed5g_GlobalWithoutNR() {
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
@@ -393,6 +415,11 @@ public class EnabledNetworkModePreferenceControllerTest {
} else if (networkMode == TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA) {
mockPhoneType(TelephonyManager.PHONE_TYPE_GSM);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, true);
} else if (networkMode
== TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA) {
mockPhoneType(TelephonyManager.PHONE_TYPE_GSM);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL, true);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL, true);
}
}
@@ -407,6 +434,6 @@ public class EnabledNetworkModePreferenceControllerTest {
}
private void mockPhoneType(int phoneType) {
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
doReturn(phoneType).when(mTelephonyManager).getPhoneType();
}
}