Skip to content

Commit

Permalink
Add a config to hide the 3G option at preferred network mode UI
Browse files Browse the repository at this point in the history
Add a config config_display_network_mode_3g_option to hide the 3G
option at preferred network mode UI

Bug: 261615630
Test: build pass. local test pass.
atest EnabledNetworkModePreferenceControllerTest

Change-Id: I4f94971add1d1eddc9f7c7458b8fc8fdcec3935e
(cherry picked from commit f7685dd)
Merged-In: I4f94971add1d1eddc9f7c7458b8fc8fdcec3935e
  • Loading branch information
SongFerngWang committed Feb 8, 2023
1 parent a48f894 commit e85bb50
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 74 deletions.
32 changes: 25 additions & 7 deletions protos/network_mode_choices.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ option java_outer_classname = "NetworkModeChoicesProto";
// EnabledNetworks is a list which tries to categorized the entries of popup menu
// based on carrier network types available to the end user.

// Next tag: 13
// Next tag: 15
// TODO(b/268145152): rename the ENABLED_NETWORKS for good readability.
enum EnabledNetworks {
// No EnabledNetworks specified.
ENABLED_NETWORKS_UNSPECIFIED = 0;
Expand All @@ -17,39 +18,56 @@ enum EnabledNetworks {
ENABLED_NETWORKS_UNKNOWN = 1;

// For the case where CDMA is supported and LTE is not prioritized over
// CDMA.
// CDMA (LTE, 3G, 1x, global).
ENABLED_NETWORKS_CDMA_CHOICES = 2;

// For the case where CDMA is supported and LTE is not available.
// CDMA (3G, 1x)
ENABLED_NETWORKS_CDMA_NO_LTE_CHOICES = 3;

// For the case where CDMA is supported and LTE is available.
// CDMA (LTE, Global)
ENABLED_NETWORKS_CDMA_ONLY_LTE_CHOICES = 4;

// For the case where TDSCDMA is primary network type.
// TDSCDMA (LTE, 3G, 2G)
ENABLED_NETWORKS_TDSCDMA_CHOICES = 5;

// For the case where GSM and LTE options are removed from the menu.
// (3G)
ENABLED_NETWORKS_EXCEPT_GSM_LTE_CHOICES = 6;

// For the case where GSM and 4G options are removed from the menu.
// For the case where GSM option are removed from the menu. The wording of LTE is '4G'.
// (4G, 3G)
ENABLED_NETWORKS_EXCEPT_GSM_4G_CHOICES = 7;

// For the case where GSM is removed from the menu, and both 4G/LTE are not an
// option.
// For the case where GSM option are removed from the menu. The wording of LTE is 'LTE'.
// (LTE, 3G)
ENABLED_NETWORKS_EXCEPT_GSM_CHOICES = 8;

// For the case where LTE is disabled.
// (3G, 3G)
ENABLED_NETWORKS_EXCEPT_LTE_CHOICES = 9;

// For the case where GSM related carrier with 4G/LTE supported.
// For the case where GSM related carrier with 4G/LTE supported. The wording of LTE is '4G'.
// (2G, 3G, 4G)
ENABLED_NETWORKS_4G_CHOICES = 10;

// For the case where GSM related carrier without 4G/LTE supported.
// For the case where GSM related carrier with 4G/LTE supported. The wording of LTE is 'LTE'.
// (2G, 3G, LTE)
ENABLED_NETWORKS_CHOICES = 11;

// For the case where world mode is enabled.
// ("Global", "LTE / CDMA", "LTE / GSM / UMTS")
PREFERRED_NETWORK_MODE_CHOICES_WORLD_MODE = 12;

// For the case where GSM, 3G options are removed from the menu. The wording of LTE is '4G'.
// (4G)
ENABLED_NETWORKS_4G_CHOICES_EXCEPT_GSM_3G = 13;

// For the case where GSM and 3G are removed from the menu. The wording of LTE is 'LTE'.
// (LTE)
ENABLED_NETWORKS_CHOICES_EXCEPT_GSM_3G = 14;
}

// A request for popup menu.
Expand Down
4 changes: 4 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,10 @@
<item>"0"</item>
</string-array>

<string-array name="enabled_networks_except_gsm_3g_values" translatable="false">
<item>"9"</item>
</string-array>

<string-array name="enabled_networks_except_lte_values" translatable="false">
<item>"0"</item>
<item>"1"</item>
Expand Down
2 changes: 2 additions & 0 deletions res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,6 @@
<!-- Control messages displayed during enrollment -->
<bool name="enrollment_message_display_controller_flag">false</bool>

<!-- Whether to display the 3G option at network mode.-->
<bool name="config_display_network_mode_3g_option">true</bool>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public int getAvailabilityStatus(int subId) {

return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}

protected boolean isCallStateIdle() {
return mCallState == TelephonyManager.CALL_STATE_IDLE;
}
Expand Down Expand Up @@ -198,6 +199,9 @@ private final class PreferenceEntriesBuilder {
private boolean mIs5gEntryDisplayed;
private boolean mShow4gForLTE;
private boolean mSupported5gRadioAccessFamily;
private boolean mDisplay2gOptions;
private boolean mDisplay3gOptions;
private boolean mLteEnabled;
private int mSelectedEntry;
private int mSubId;
private String mSummary;
Expand All @@ -224,23 +228,32 @@ public void updateConfig() {
mSupported5gRadioAccessFamily = checkSupportedRadioBitmask(
mTelephonyManager.getSupportedRadioAccessFamily(),
TelephonyManager.NETWORK_TYPE_BITMASK_NR);
mIsGlobalCdma = mTelephonyManager.isLteCdmaEvdoGsmWcdmaEnabled()
&& carrierConfig != null
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL);
mShow4gForLTE = carrierConfig != null && carrierConfig.getBoolean(
CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL);
if (carrierConfig != null) {
mIsGlobalCdma = mTelephonyManager.isLteCdmaEvdoGsmWcdmaEnabled()
&& carrierConfig.getBoolean(
CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL);
mShow4gForLTE = carrierConfig.getBoolean(
CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL);
mDisplay2gOptions = carrierConfig.getBoolean(
CarrierConfigManager.KEY_PREFER_2G_BOOL);
// TODO: Using the carrier config.
mDisplay3gOptions = getResourcesForSubId().getBoolean(
R.bool.config_display_network_mode_3g_option);
mLteEnabled = carrierConfig.getBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL);
}
Log.d(LOG_TAG, "PreferenceEntriesBuilder: subId" + mSubId
+ ",Supported5gRadioAccessFamily :" + mSupported5gRadioAccessFamily
+ ",mAllowed5gNetworkType :" + mAllowed5gNetworkType
+ ",IsGlobalCdma :" + mIsGlobalCdma
+ ",Show4gForLTE :" + mShow4gForLTE);
+ " ,Supported5gRadioAccessFamily :" + mSupported5gRadioAccessFamily
+ " ,mAllowed5gNetworkType :" + mAllowed5gNetworkType
+ " ,IsGlobalCdma :" + mIsGlobalCdma
+ " ,Display2gOptions:" + mDisplay2gOptions
+ " ,Display3gOptions:" + mDisplay3gOptions
+ " ,Display4gOptions" + mLteEnabled
+ " ,Show4gForLTE :" + mShow4gForLTE);
}

void setPreferenceEntries() {
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);
final boolean display2gOptions = carrierConfig
.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL);

clearAllEntries();
UiOptions.Builder uiOptions = UiOptions.newBuilder();
uiOptions.setType(getEnabledNetworkType());
Expand Down Expand Up @@ -316,6 +329,16 @@ void setPreferenceEntries() {
.addFormat(UiOptions.PresentFormat.addWorldModeCdmaEntry)
.addFormat(UiOptions.PresentFormat.addWorldModeGsmEntry);
break;
case ENABLED_NETWORKS_4G_CHOICES_EXCEPT_GSM_3G:
uiOptions = uiOptions
.setChoices(R.array.enabled_networks_except_gsm_3g_values)
.addFormat(UiOptions.PresentFormat.add5gAnd4gEntry);
break;
case ENABLED_NETWORKS_CHOICES_EXCEPT_GSM_3G:
uiOptions = uiOptions
.setChoices(R.array.enabled_networks_values)
.addFormat(UiOptions.PresentFormat.add5gAndLteEntry);
break;
default:
throw new IllegalArgumentException("Not supported enabled network types.");
}
Expand All @@ -331,53 +354,55 @@ void setPreferenceEntries() {
// Compose options based on given values and formats.
IntStream.range(0, formatList.size()).forEach(entryIndex -> {
switch (formatList.get(entryIndex)) {
case add1xEntry:
if (display2gOptions) {
add1xEntry(entryValuesInt[entryIndex]);
}
break;
case add2gEntry:
if (display2gOptions) {
add2gEntry(entryValuesInt[entryIndex]);
}
break;
case add3gEntry:
add3gEntry(entryValuesInt[entryIndex]);
break;
case addGlobalEntry:
addGlobalEntry(entryValuesInt[entryIndex]);
break;
case addWorldModeCdmaEntry:
addCustomEntry(
getResourcesForSubId().getString(
R.string.network_world_mode_cdma_lte),
entryValuesInt[entryIndex]);
break;
case addWorldModeGsmEntry:
addCustomEntry(
getResourcesForSubId().getString(
R.string.network_world_mode_gsm_lte),
entryValuesInt[entryIndex]);
break;
case add4gEntry:
add4gEntry(entryValuesInt[entryIndex]);
break;
case addLteEntry:
addLteEntry(entryValuesInt[entryIndex]);
break;
case add5gEntry:
add5gEntry(addNrToLteNetworkType(entryValuesInt[entryIndex]));
break;
case add5gAnd4gEntry:
add5gEntry(addNrToLteNetworkType(entryValuesInt[entryIndex]));
add4gEntry(entryValuesInt[entryIndex]);
break;
case add5gAndLteEntry:
add5gEntry(addNrToLteNetworkType(entryValuesInt[entryIndex]));
addLteEntry(entryValuesInt[entryIndex]);
break;
default:
throw new IllegalArgumentException("Not supported ui options format.");
case add1xEntry:
if (mDisplay2gOptions) {
add1xEntry(entryValuesInt[entryIndex]);
}
break;
case add2gEntry:
if (mDisplay2gOptions) {
add2gEntry(entryValuesInt[entryIndex]);
}
break;
case add3gEntry:
if (mDisplay3gOptions) {
add3gEntry(entryValuesInt[entryIndex]);
}
break;
case addGlobalEntry:
addGlobalEntry(entryValuesInt[entryIndex]);
break;
case addWorldModeCdmaEntry:
addCustomEntry(
getResourcesForSubId().getString(
R.string.network_world_mode_cdma_lte),
entryValuesInt[entryIndex]);
break;
case addWorldModeGsmEntry:
addCustomEntry(
getResourcesForSubId().getString(
R.string.network_world_mode_gsm_lte),
entryValuesInt[entryIndex]);
break;
case add4gEntry:
add4gEntry(entryValuesInt[entryIndex]);
break;
case addLteEntry:
addLteEntry(entryValuesInt[entryIndex]);
break;
case add5gEntry:
add5gEntry(addNrToLteNetworkType(entryValuesInt[entryIndex]));
break;
case add5gAnd4gEntry:
add5gEntry(addNrToLteNetworkType(entryValuesInt[entryIndex]));
add4gEntry(entryValuesInt[entryIndex]);
break;
case add5gAndLteEntry:
add5gEntry(addNrToLteNetworkType(entryValuesInt[entryIndex]));
addLteEntry(entryValuesInt[entryIndex]);
break;
default:
throw new IllegalArgumentException("Not supported ui options format.");
}
});
}
Expand All @@ -397,7 +422,6 @@ private int getPreferredNetworkMode() {
private EnabledNetworks getEnabledNetworkType() {
EnabledNetworks enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_UNKNOWN;
final int phoneType = mTelephonyManager.getPhoneType();
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);

if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
final int lteForced = android.provider.Settings.Global.getInt(
Expand Down Expand Up @@ -432,17 +456,17 @@ private EnabledNetworks getEnabledNetworkType() {
} else if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
if (MobileNetworkUtils.isTdscdmaSupported(mContext, mSubId)) {
enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_TDSCDMA_CHOICES;
} else if (carrierConfig != null
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL)) {
} else if (!mDisplay2gOptions && !mDisplay3gOptions) {
enabledNetworkType = mShow4gForLTE
? EnabledNetworks.ENABLED_NETWORKS_4G_CHOICES_EXCEPT_GSM_3G
: EnabledNetworks.ENABLED_NETWORKS_CHOICES_EXCEPT_GSM_3G;
} else if (!mDisplay2gOptions && !mLteEnabled) {
enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_EXCEPT_GSM_LTE_CHOICES;
} else if (carrierConfig != null
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) {
} else if (!mDisplay2gOptions) {
enabledNetworkType = mShow4gForLTE
? EnabledNetworks.ENABLED_NETWORKS_EXCEPT_GSM_4G_CHOICES
: EnabledNetworks.ENABLED_NETWORKS_EXCEPT_GSM_CHOICES;
} else if (carrierConfig != null
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL)) {
} else if (!mLteEnabled) {
enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_EXCEPT_LTE_CHOICES;
} else if (mIsGlobalCdma) {
enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_CDMA_CHOICES;
Expand All @@ -457,6 +481,13 @@ private EnabledNetworks getEnabledNetworkType() {
enabledNetworkType = EnabledNetworks.PREFERRED_NETWORK_MODE_CHOICES_WORLD_MODE;
}

if (phoneType == TelephonyManager.PHONE_TYPE_NONE) {
Log.d(LOG_TAG, "phoneType: PHONE_TYPE_NONE");
enabledNetworkType = mShow4gForLTE
? EnabledNetworks.ENABLED_NETWORKS_4G_CHOICES_EXCEPT_GSM_3G
: EnabledNetworks.ENABLED_NETWORKS_CHOICES_EXCEPT_GSM_3G;
}

Log.d(LOG_TAG, "enabledNetworkType: " + enabledNetworkType);
return enabledNetworkType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ private void mockEnabledNetworkMode(int networkMode) {
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL, true);
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL, true);
}
mController.init(SUB_ID);
}

private void mockAllowedNetworkTypes(long allowedNetworkType) {
Expand Down

0 comments on commit e85bb50

Please sign in to comment.