Merge "Show/hide 5G preferred network type also consider allowed_network_type"
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index c8e09b9..2b5b10e 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -122,6 +122,8 @@
         super.updateState(preference);
         final ListPreference listPreference = (ListPreference) preference;
         final int networkMode = getPreferredNetworkMode();
+        Log.d(LOG_TAG, "updateState networkMode: " + networkMode);
+
         updatePreferenceEntries(listPreference);
         updatePreferenceValueAndSummary(listPreference, networkMode);
     }
@@ -132,9 +134,6 @@
 
         if (mTelephonyManager.setPreferredNetworkTypeBitmask(
                 MobileNetworkUtils.getRafFromNetworkType(newPreferredNetworkMode))) {
-            Settings.Global.putInt(mContext.getContentResolver(),
-                    Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
-                    newPreferredNetworkMode);
             updatePreferenceValueAndSummary((ListPreference) preference, newPreferredNetworkMode);
             return true;
         }
@@ -156,16 +155,21 @@
                 : false;
 
         final long supportedRadioBitmask = mTelephonyManager.getSupportedRadioAccessFamily();
+        final boolean is5gEnabledByCarrier = (mTelephonyManager.getAllowedNetworkTypes()
+                & TelephonyManager.NETWORK_TYPE_BITMASK_NR) > 0;
         mDisplay5gList = checkSupportedRadioBitmask(
-                supportedRadioBitmask, mTelephonyManager.NETWORK_TYPE_BITMASK_NR);
-
+                supportedRadioBitmask, mTelephonyManager.NETWORK_TYPE_BITMASK_NR)
+                && is5gEnabledByCarrier;
         lifecycle.addObserver(this);
     }
 
     private int getPreferredNetworkMode() {
-        return Settings.Global.getInt(mContext.getContentResolver(),
+        long preferredNetworkBitMask = MobileNetworkUtils.getRafFromNetworkType(
+                Settings.Global.getInt(mContext.getContentResolver(),
                 Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
-                TelephonyManager.DEFAULT_PREFERRED_NETWORK_MODE);
+                TelephonyManager.DEFAULT_PREFERRED_NETWORK_MODE));
+        return  MobileNetworkUtils.getNetworkTypeFromRaf((int)
+                (preferredNetworkBitMask & mTelephonyManager.getAllowedNetworkTypes()));
     }
 
     private void updatePreferenceEntries(ListPreference preference) {
@@ -176,10 +180,7 @@
                     mContext.getContentResolver(),
                     android.provider.Settings.Global.LTE_SERVICE_FORCED + mSubId,
                     0);
-            final int settingsNetworkMode = android.provider.Settings.Global.getInt(
-                    mContext.getContentResolver(),
-                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
-                    TelephonyManager.DEFAULT_PREFERRED_NETWORK_MODE);
+            final int settingsNetworkMode = getPreferredNetworkMode();
             if (mTelephonyManager.isLteCdmaEvdoGsmWcdmaEnabled()) {
                 if (lteForced == 0) {
                     preference.setEntries(
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index d3784ae..ce8a116 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -80,6 +80,15 @@
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.LTE;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.NR;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_UNKNOWN;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
+
 public class MobileNetworkUtils {
 
     private static final String TAG = "MobileNetworkUtils";
@@ -767,144 +776,166 @@
     public static long getRafFromNetworkType(int type) {
         switch (type) {
             case TelephonyManagerConstants.NETWORK_MODE_WCDMA_PREF:
-                return TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY:
-                return TelephonyManagerConstants.GSM;
+                return GSM;
             case TelephonyManagerConstants.NETWORK_MODE_WCDMA_ONLY:
-                return TelephonyManagerConstants.WCDMA;
+                return WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_GSM_UMTS:
-                return TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_CDMA_EVDO:
-                return TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO;
+                return CDMA | EVDO;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO;
+                return LTE | CDMA | EVDO;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return LTE | GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return LTE | CDMA | EVDO | GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
-                return TelephonyManagerConstants.LTE;
+                return LTE;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.WCDMA;
+                return LTE | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_CDMA_NO_EVDO:
-                return TelephonyManagerConstants.CDMA;
+                return CDMA;
             case TelephonyManagerConstants.NETWORK_MODE_EVDO_NO_CDMA:
-                return TelephonyManagerConstants.EVDO;
+                return EVDO;
             case TelephonyManagerConstants.NETWORK_MODE_GLOBAL:
-                return TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO;
+                return GSM | WCDMA | CDMA | EVDO;
             case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_ONLY:
-                return TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA;
+                return RAF_TD_SCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_WCDMA:
-                return TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.WCDMA;
+                return RAF_TD_SCDMA | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA;
+                return LTE | RAF_TD_SCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM:
-                return TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.GSM;
+                return RAF_TD_SCDMA | GSM;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.GSM;
+                return LTE | RAF_TD_SCDMA | GSM;
             case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
-                return TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return RAF_TD_SCDMA | GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.WCDMA;
+                return LTE | RAF_TD_SCDMA | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return LTE | RAF_TD_SCDMA | GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                return TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
             case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                return TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_ONLY):
-                return TelephonyManagerConstants.NR;
+                return NR;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE;
+                return NR | LTE;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO;
+                return NR | LTE | CDMA | EVDO;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return NR | LTE | GSM | WCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return NR | LTE | CDMA | EVDO | GSM | WCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_WCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManagerConstants.WCDMA;
+                return NR | LTE | WCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA;
+                return NR | LTE | RAF_TD_SCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.GSM;
+                return NR | LTE | RAF_TD_SCDMA | GSM;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.WCDMA;
+                return NR | LTE | RAF_TD_SCDMA | WCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
+                return NR | LTE | RAF_TD_SCDMA | GSM | WCDMA;
             case (TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA):
-                return TelephonyManagerConstants.NR
-                        | TelephonyManagerConstants.LTE
-                        | TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA
-                        | TelephonyManagerConstants.CDMA
-                        | TelephonyManagerConstants.EVDO
-                        | TelephonyManagerConstants.GSM
-                        | TelephonyManagerConstants.WCDMA;
-
+                return NR | LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
             default:
-                return TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN;
+                return RAF_UNKNOWN;
         }
     }
+
+    /**
+     *  Imported from {@link android.telephony.RadioAccessFamily}
+     */
+    public static int getNetworkTypeFromRaf(int raf) {
+        raf = getAdjustedRaf(raf);
+
+        switch (raf) {
+            case (GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_WCDMA_PREF;
+            case GSM:
+                return TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY;
+            case WCDMA:
+                return TelephonyManagerConstants.NETWORK_MODE_WCDMA_ONLY;
+            case (CDMA | EVDO):
+                return TelephonyManagerConstants.NETWORK_MODE_CDMA_EVDO;
+            case (LTE | CDMA | EVDO):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO;
+            case (LTE | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA;
+            case (LTE | CDMA | EVDO | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA;
+            case LTE:
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY;
+            case (LTE | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA;
+            case CDMA:
+                return TelephonyManagerConstants.NETWORK_MODE_CDMA_NO_EVDO;
+            case EVDO:
+                return TelephonyManagerConstants.NETWORK_MODE_EVDO_NO_CDMA;
+            case (GSM | WCDMA | CDMA | EVDO):
+                return TelephonyManagerConstants.NETWORK_MODE_GLOBAL;
+            case RAF_TD_SCDMA:
+                return TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_ONLY;
+            case (RAF_TD_SCDMA | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_WCDMA;
+            case (LTE | RAF_TD_SCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA;
+            case (RAF_TD_SCDMA | GSM):
+                return TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM;
+            case (LTE | RAF_TD_SCDMA | GSM):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM;
+            case (RAF_TD_SCDMA | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA;
+            case (LTE | RAF_TD_SCDMA | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA;
+            case (LTE | RAF_TD_SCDMA | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA;
+            case (RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
+            case (LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
+            case (NR):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_ONLY;
+            case (NR | LTE):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE;
+            case (NR | LTE | CDMA | EVDO):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO;
+            case (NR | LTE | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA;
+            case (NR | LTE | CDMA | EVDO | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA;
+            case (NR | LTE | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_WCDMA;
+            case (NR | LTE | RAF_TD_SCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA;
+            case (NR | LTE | RAF_TD_SCDMA | GSM):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM;
+            case (NR | LTE | RAF_TD_SCDMA | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA;
+            case (NR | LTE | RAF_TD_SCDMA | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA;
+            case (NR | LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA):
+                return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
+            default:
+                return TelephonyManagerConstants.NETWORK_MODE_UNKNOWN;
+        }
+    }
+
+    /**
+     *  Imported from {@link android.telephony.RadioAccessFamily}
+     */
+    private static int getAdjustedRaf(int raf) {
+        raf = ((GSM & raf) > 0) ? (GSM | raf) : raf;
+        raf = ((WCDMA & raf) > 0) ? (WCDMA | raf) : raf;
+        raf = ((CDMA & raf) > 0) ? (CDMA | raf) : raf;
+        raf = ((EVDO & raf) > 0) ? (EVDO | raf) : raf;
+        raf = ((LTE & raf) > 0) ? (LTE | raf) : raf;
+        raf = ((NR & raf) > 0) ? (NR | raf) : raf;
+        return raf;
+    }
 }
diff --git a/src/com/android/settings/network/telephony/TelephonyConstants.java b/src/com/android/settings/network/telephony/TelephonyConstants.java
index 8751cc2..30cd568 100644
--- a/src/com/android/settings/network/telephony/TelephonyConstants.java
+++ b/src/com/android/settings/network/telephony/TelephonyConstants.java
@@ -205,47 +205,12 @@
          * NR 5G, LTE, TD-SCDMA, CDMA, EVDO, GSM and WCDMA
          */
         public static final int NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 33;
-
-
-        // Grouping of RAFs
-        // imported from {@link android.telephony.RadioAccessFamily}
-        // 2G
-        public static final long GSM = TelephonyManager.NETWORK_TYPE_BITMASK_GSM
-                | TelephonyManager.NETWORK_TYPE_BITMASK_GPRS
-                | TelephonyManager.NETWORK_TYPE_BITMASK_EDGE;
-        public static final long CDMA = TelephonyManager.NETWORK_TYPE_BITMASK_CDMA
-                | TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT;
-
-        // 3G
-        public static final long EVDO = TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0
-                | TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A
-                | TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B
-                | TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD;
-        public static final long HS = TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA
-                | TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA
-                | TelephonyManager.NETWORK_TYPE_BITMASK_HSPA
-                | TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP;
-        public static final long WCDMA = HS | TelephonyManager.NETWORK_TYPE_BITMASK_UMTS;
-
-        // 4G
-        public static final long LTE = TelephonyManager.NETWORK_TYPE_BITMASK_LTE
-                | TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA;
-
-        // 5G
-        public static final long NR = TelephonyManager.NETWORK_TYPE_BITMASK_NR;
-
     }
 
     /**
      * Copied from {@link android.telephony.RadioAccessFamily}
      */
     public static class RadioAccessFamily {
-        /**
-         * TODO: get rid of RAF definition in RadioAccessFamily and
-         * use {@link TelephonyManager.NetworkTypeBitMask}
-         * TODO: public definition {@link TelephonyManager.NetworkTypeBitMask} is long.
-         * TODO: Convert from int * to long everywhere including HAL definitions.
-         */
         // 2G
         public static final int RAF_UNKNOWN = (int) TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN;
         public static final int RAF_GSM = (int) TelephonyManager.NETWORK_TYPE_BITMASK_GSM;
@@ -281,7 +246,9 @@
         public static final int WCDMA = HS | RAF_UMTS;
         // 4G
         public static final int LTE = RAF_LTE | RAF_LTE_CA;
+
         // 5G
         public static final int NR = RAF_NR;
+
     }
 }
diff --git a/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java
index d12d543..2f3aecc 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java
@@ -153,8 +153,9 @@
     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 @@
 
     @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 @@
 
     @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 @@
         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 @@
         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,