Using carrier config for hiding 3G item at preferred network mode

Bug: 310639009
Bug: 301214162
Change-Id: Id3a85f46954311ff668f7175b672ac954a6e984e
Test: build pass. local test. atest EnabledNetworkModePreferenceControllerTest
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index 2a355ad..5e1d56e 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -39,6 +39,7 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
+import com.android.internal.telephony.flags.Flags;
 import com.android.settings.network.AllowedNetworkTypesListener;
 import com.android.settings.network.CarrierConfigCache;
 import com.android.settings.network.SubscriptionsChangeListener;
@@ -241,6 +242,7 @@
         public void updateConfig() {
             mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
             final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);
+            final boolean flagHidePrefer3gItem = Flags.hidePrefer3gItem();
             mAllowed5gNetworkType = checkSupportedRadioBitmask(
                     mTelephonyManager.getAllowedNetworkTypesForReason(
                             TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER),
@@ -256,22 +258,28 @@
                         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);
 
-                int[] carriersWithout3gMenu = getResourcesForSubId().getIntArray(
-                        R.array.network_mode_3g_deprecated_carrier_id);
-                if ((carriersWithout3gMenu != null) && (carriersWithout3gMenu.length > 0)) {
-                    SubscriptionManager sm = mContext.getSystemService(SubscriptionManager.class);
-                    SubscriptionInfo subInfo = sm.getActiveSubscriptionInfo(mSubId);
-                    if (subInfo != null) {
-                        int carrierId = subInfo.getCarrierId();
+                if (flagHidePrefer3gItem) {
+                    mDisplay3gOptions = carrierConfig.getBoolean(
+                        CarrierConfigManager.KEY_PREFER_3G_VISIBILITY_BOOL);
+                } else {
+                    mDisplay3gOptions = getResourcesForSubId().getBoolean(
+                            R.bool.config_display_network_mode_3g_option);
 
-                        for (int idx = 0; idx < carriersWithout3gMenu.length; idx++) {
-                            if (carrierId == carriersWithout3gMenu[idx]) {
-                                mDisplay3gOptions = false;
-                                break;
+                    int[] carriersWithout3gMenu = getResourcesForSubId().getIntArray(
+                            R.array.network_mode_3g_deprecated_carrier_id);
+                    if ((carriersWithout3gMenu != null) && (carriersWithout3gMenu.length > 0)) {
+                        SubscriptionManager sm = mContext.getSystemService(
+                                SubscriptionManager.class);
+                        SubscriptionInfo subInfo = sm.getActiveSubscriptionInfo(mSubId);
+                        if (subInfo != null) {
+                            int carrierId = subInfo.getCarrierId();
+
+                            for (int idx = 0; idx < carriersWithout3gMenu.length; idx++) {
+                                if (carrierId == carriersWithout3gMenu[idx]) {
+                                    mDisplay3gOptions = false;
+                                    break;
+                                }
                             }
                         }
                     }