Fix apn option display issue for world phone mode

When configs world_phone_bool and show_apn_setting_cdma_bool are enabled,
'Access Point Names' is displayed twice under Network Settings, as this
preference is added from both GsmUmtsOptions and CdmaOptions.
Fix is to add preference from CdmaOptions only if phone type is cdma and
show_apn_setting_cdma_bool config is enabled.

Change-Id: Ia89b0b882604e287a996fec86c9c961df704f1e8
Test: builds, and CdmaOptionsTest.java (no manual test)
Bug: 70309465
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index ff37c70..7f7d58c 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -26,9 +26,11 @@
 import android.telephony.CarrierConfigManager;
 import android.text.TextUtils;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
 import com.android.settingslib.RestrictedLockUtils;
 
 /**
@@ -53,6 +55,12 @@
     private PreferenceScreen mPrefScreen;
     private Phone mPhone;
 
+    // Constructor for CdmaOptionsTest, since PreferenceScreen is final and cannot be mocked
+    @VisibleForTesting
+    public CdmaOptions(Phone phone) {
+        mPhone = phone;
+    }
+
     public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
         mPrefFragment = prefFragment;
         mPrefScreen = prefScreen;
@@ -79,8 +87,7 @@
         PersistableBundle carrierConfig =
                 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
         // Some CDMA carriers want the APN settings.
-        boolean addAPNExpand =
-                carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
+        boolean addAPNExpand = shouldAddApnExpandPreference(carrierConfig);
         boolean addCdmaSubscription =
                 deviceSupportsNvAndRuim();
         // Read platform settings for carrier settings
@@ -94,6 +101,7 @@
         // Calling add or remove explicitly to make sure they are updated.
 
         if (addAPNExpand) {
+            log("update: addAPNExpand");
             mButtonAPNExpand.setDisabledByAdmin(
                     MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
                             ? RestrictedLockUtils.getDeviceOwner(mButtonAPNExpand.getContext())
@@ -136,6 +144,19 @@
         }
     }
 
+    /**
+     * Return whether we should add the APN expandable preference based on the phone type and
+     * carrier config
+     */
+    @VisibleForTesting
+    public boolean shouldAddApnExpandPreference(PersistableBundle config) {
+        if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
+                && config.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)) {
+            return true;
+        }
+        return false;
+    }
+
     private boolean deviceSupportsNvAndRuim() {
         // retrieve the list of subscription types supported by device.
         String subscriptionsSupported = SystemProperties.get("ril.subscription.types");