Show/hide 5G preferred network type also consider allowed_network_type

1. The carrier or privileged apps will enable/disable network types on
the device, so Settings references the allowed network type to show/hide
5G preferred network type option.

2. For mainline, copy the getNetworkTypeFromRaf() from RadioFamily to
Settings.

Bug: 136730709
Test: Manual test & EnabledNetworkModePreferenceControllerTest
1. Enable allowed_network_type
2. Disable allowed_network_type
Merged-In: I493f2a2c7f4bc32b3fcb8ab2bace5839d8667bd5

Change-Id: Id591f454a60d0ba08c3fc4a2ffe40836dafeb5f0
This commit is contained in:
Josh Hou
2019-11-06 19:53:44 +08:00
committed by Bonian Chen
parent d1998a6fe8
commit abe032ea66
4 changed files with 161 additions and 157 deletions

View File

@@ -153,8 +153,9 @@ public class EnabledNetworkModePreferenceControllerTest {
public void init_initDisplay5gList_returnTrue() {
long testBitmask = TelephonyManager.NETWORK_TYPE_BITMASK_NR
| TelephonyManager.NETWORK_TYPE_BITMASK_LTE;
long allowedNetworkTypes = -1;
doReturn(testBitmask).when(mTelephonyManager).getSupportedRadioAccessFamily();
doReturn(allowedNetworkTypes).when(mTelephonyManager).getAllowedNetworkTypes();
mController.init(mLifecycle, SUB_ID);
assertThat(mController.mDisplay5gList).isTrue();
@@ -171,6 +172,8 @@ public class EnabledNetworkModePreferenceControllerTest {
@Test
public void updateState_updateByNetworkMode() {
long allowedNetworkTypes = -1;
doReturn(allowedNetworkTypes).when(mTelephonyManager).getAllowedNetworkTypes();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
@@ -184,6 +187,8 @@ public class EnabledNetworkModePreferenceControllerTest {
@Test
public void updateState_updateByNetworkMode_useDefaultValue() {
long allowedNetworkTypes = -1;
doReturn(allowedNetworkTypes).when(mTelephonyManager).getAllowedNetworkTypes();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
@@ -399,9 +404,8 @@ public class EnabledNetworkModePreferenceControllerTest {
mController.onPreferenceChange(mPreference,
String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isEqualTo(
TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
}
@Test
@@ -412,14 +416,15 @@ public class EnabledNetworkModePreferenceControllerTest {
mController.onPreferenceChange(mPreference,
String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isNotEqualTo(
TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
assertThat(mPreference.getValue()).isNotEqualTo(
String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
}
@Test
public void preferredNetworkModeNotification_preferenceUpdates() {
PreferenceScreen screen = mock(PreferenceScreen.class);
long allowedNetworkTypes = -1;
doReturn(allowedNetworkTypes).when(mTelephonyManager).getAllowedNetworkTypes();
doReturn(mPreference).when(screen).findPreference(KEY);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,