Merge "Remove dependency on apn network attributes"
diff --git a/src/java/com/android/internal/telephony/dataconnection/ApnConfigType.java b/src/java/com/android/internal/telephony/dataconnection/ApnConfigType.java
new file mode 100644
index 0000000..10e6463
--- /dev/null
+++ b/src/java/com/android/internal/telephony/dataconnection/ApnConfigType.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony.dataconnection;
+
+import android.telephony.Annotation;
+
+/**
+ * Container of network configuration settings relevant for telephony module.
+ */
+class ApnConfigType {
+
+    private final int mType;
+    private final int mPriority;
+
+    ApnConfigType(@Annotation.ApnType int type, int priority) {
+        mType = type;
+        mPriority = priority;
+    }
+
+    /**
+     * Returns the apn type of this config type
+     * @return Type of apn.
+     */
+    int getType() {
+        return mType;
+    }
+
+    /**
+     * Returns the priority of this apn config type.
+     * @return The priority of this apn.
+     */
+    int getPriority() {
+        return mPriority;
+    }
+}
diff --git a/src/java/com/android/internal/telephony/dataconnection/ApnConfigTypeRepository.java b/src/java/com/android/internal/telephony/dataconnection/ApnConfigTypeRepository.java
new file mode 100644
index 0000000..5f156cd
--- /dev/null
+++ b/src/java/com/android/internal/telephony/dataconnection/ApnConfigTypeRepository.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony.dataconnection;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.telephony.Annotation;
+import android.telephony.data.ApnSetting;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Hard coded configuration of specific network types that the telephony module needs.
+ * Formerly stored in network attributes within the resources file.
+ */
+public final class ApnConfigTypeRepository {
+
+    private static final ApnConfigTypeRepository sDefault = new ApnConfigTypeRepository();
+
+    private final Map<Integer, ApnConfigType> mConfigTypeMap;
+
+    ApnConfigTypeRepository() {
+        mConfigTypeMap = new HashMap<>();
+        setup();
+    }
+
+    /**
+     * Gets the default instance of the repository.
+     * @return The singleton instance of repository.
+     */
+    @NonNull
+    public static ApnConfigTypeRepository getDefault() {
+        return sDefault;
+    }
+
+    /**
+     * Gets list of apn config types.
+     * @return All apn config types.
+     */
+    public Collection<ApnConfigType> getTypes() {
+        return mConfigTypeMap.values();
+    }
+
+    /**
+     * Gets the apn config type by apn type.
+     * @param type The ApnType to search for.
+     * @return The config type matching the given apn type.
+     */
+    @Nullable
+    public ApnConfigType getByType(@Annotation.ApnType int type) {
+        return mConfigTypeMap.get(type);
+    }
+
+    private void setup() {
+        add(ApnSetting.TYPE_DEFAULT, 0);
+        add(ApnSetting.TYPE_MMS, 2);
+        add(ApnSetting.TYPE_SUPL, 2);
+        add(ApnSetting.TYPE_DUN, 2);
+        add(ApnSetting.TYPE_HIPRI, 3);
+        add(ApnSetting.TYPE_FOTA, 2);
+        add(ApnSetting.TYPE_IMS, 2);
+        add(ApnSetting.TYPE_CBS, 2);
+        add(ApnSetting.TYPE_IA, 2);
+        add(ApnSetting.TYPE_EMERGENCY, 2);
+        add(ApnSetting.TYPE_MCX, 3);
+        add(ApnSetting.TYPE_XCAP, 3);
+    }
+
+    private void add(@Annotation.ApnType int type, int priority) {
+        mConfigTypeMap.put(type, new ApnConfigType(type, priority));
+    }
+}
diff --git a/src/java/com/android/internal/telephony/dataconnection/ApnContext.java b/src/java/com/android/internal/telephony/dataconnection/ApnContext.java
index 9e4dbd7..9644d61 100644
--- a/src/java/com/android/internal/telephony/dataconnection/ApnContext.java
+++ b/src/java/com/android/internal/telephony/dataconnection/ApnContext.java
@@ -18,11 +18,9 @@
 
 import android.net.ConnectivityManager;
 import android.net.NetworkCapabilities;
-import android.net.NetworkConfig;
 import android.net.NetworkRequest;
 import android.os.Message;
 import android.telephony.Annotation.ApnType;
-import com.android.telephony.Rlog;
 import android.telephony.data.ApnSetting;
 import android.text.TextUtils;
 import android.util.LocalLog;
@@ -35,6 +33,7 @@
 import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
 import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
 import com.android.internal.util.IndentingPrintWriter;
+import com.android.telephony.Rlog;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -59,13 +58,13 @@
 
     private DctConstants.State mState;
 
-    public final int priority;
+    private final int mPriority;
 
     private ApnSetting mApnSetting;
 
     private DataConnection mDataConnection;
 
-    String mReason;
+    private String mReason;
 
     /**
      * user/app requested connection on this APN
@@ -73,15 +72,10 @@
     AtomicBoolean mDataEnabled;
 
     private final Object mRefCountLock = new Object();
-    private int mRefCount = 0;
-
-    /**
-     * carrier requirements met
-     */
-    AtomicBoolean mDependencyMet;
 
     private final DcTracker mDcTracker;
 
+
     /**
      * Remember this as a change in this value to a more permissive state
      * should cause us to retry even permanent failures
@@ -100,27 +94,40 @@
     private final RetryManager mRetryManager;
 
     /**
-     * AonContext constructor
+     * ApnContext constructor
+     * @param phone phone object
+     * @param typeId APN type Id
+     * @param logTag Tag for logging
+     * @param tracker Data call tracker
+     * @param priority Priority of APN type
+     */
+    public ApnContext(Phone phone, int typeId, String logTag, DcTracker tracker, int priority) {
+        this(phone, ApnSetting.getApnTypeString(typeId), logTag, tracker, priority);
+    }
+
+    /**
+     * ApnContext constructor
      * @param phone phone object
      * @param apnType APN type (e.g. default, supl, mms, etc...)
      * @param logTag Tag for logging
-     * @param config Network configuration
      * @param tracker Data call tracker
+     * @param priority Priority of APN type
      */
-    public ApnContext(Phone phone, String apnType, String logTag, NetworkConfig config,
-            DcTracker tracker) {
+    public ApnContext(Phone phone, String apnType, String logTag, DcTracker tracker,
+            int priority) {
         mPhone = phone;
         mApnType = apnType;
         mState = DctConstants.State.IDLE;
         setReason(Phone.REASON_DATA_ENABLED);
         mDataEnabled = new AtomicBoolean(false);
-        mDependencyMet = new AtomicBoolean(config.dependencyMet);
-        priority = config.priority;
+        mPriority = priority;
         LOG_TAG = logTag;
         mDcTracker = tracker;
         mRetryManager = new RetryManager(phone, apnType);
     }
 
+
+
     /**
      * Get the APN type
      * @return The APN type
@@ -146,6 +153,23 @@
     }
 
     /**
+     * This priority is taken into account when concurrent data connections are not allowed.  The
+     * APN with the HIGHER priority is given preference.
+     * @return The priority of the APN type
+     */
+    public int getPriority() {
+        return mPriority;
+    }
+
+    /**
+     * Keeping for backwards compatibility and in case it's needed in the future
+     * @return true
+     */
+    public boolean isDependencyMet() {
+        return true;
+    }
+
+    /**
      * Set the associated data connection.
      * @param dc data connection
      */
@@ -312,7 +336,7 @@
      * @return True if ready, otherwise false.
      */
     public boolean isReady() {
-        return mDataEnabled.get() && mDependencyMet.get();
+        return mDataEnabled.get() && isDependencyMet();
     }
 
     /**
@@ -360,10 +384,6 @@
         return mDataEnabled.get();
     }
 
-    public boolean isDependencyMet() {
-       return mDependencyMet.get();
-    }
-
     public boolean isProvisioningApn() {
         String provisioningApn = mPhone.getContext().getResources()
                 .getString(R.string.mobile_provisioning_apn);
@@ -619,8 +639,7 @@
         // We don't print mDataConnection because its recursive.
         return "{mApnType=" + mApnType + " mState=" + getState() + " mWaitingApns={" +
                 mRetryManager.getWaitingApns() + "}" + " mApnSetting={" + mApnSetting +
-                "} mReason=" + mReason + " mDataEnabled=" + mDataEnabled + " mDependencyMet=" +
-                mDependencyMet + "}";
+                "} mReason=" + mReason + " mDataEnabled=" + mDataEnabled + "}";
     }
 
     private void log(String s) {
diff --git a/src/java/com/android/internal/telephony/dataconnection/DcRequest.java b/src/java/com/android/internal/telephony/dataconnection/DcRequest.java
index 099fc5a..76022b1 100644
--- a/src/java/com/android/internal/telephony/dataconnection/DcRequest.java
+++ b/src/java/com/android/internal/telephony/dataconnection/DcRequest.java
@@ -16,12 +16,9 @@
 package com.android.internal.telephony.dataconnection;
 
 import android.content.Context;
-import android.net.NetworkConfig;
 import android.net.NetworkRequest;
 import android.telephony.Annotation.ApnType;
 
-import java.util.HashMap;
-
 public class DcRequest implements Comparable<DcRequest> {
     private static final String LOG_TAG = "DcRequest";
 
@@ -30,10 +27,9 @@
     public final @ApnType int apnType;
 
     public DcRequest(NetworkRequest nr, Context context) {
-        initApnPriorities(context);
         networkRequest = nr;
         apnType = ApnContext.getApnTypeFromNetworkRequest(networkRequest);
-        priority = priorityForApnType(apnType);
+        priority = ApnConfigTypeRepository.getDefault().getByType(apnType).getPriority();
     }
 
     public String toString() {
@@ -54,26 +50,4 @@
     public int compareTo(DcRequest o) {
         return o.priority - priority;
     }
-
-    private static final HashMap<Integer, Integer> sApnPriorityMap =
-            new HashMap<Integer, Integer>();
-
-    private void initApnPriorities(Context context) {
-        synchronized (sApnPriorityMap) {
-            if (sApnPriorityMap.isEmpty()) {
-                String[] networkConfigStrings = context.getResources().getStringArray(
-                        com.android.internal.R.array.networkAttributes);
-                for (String networkConfigString : networkConfigStrings) {
-                    NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
-                    final int apnType = ApnContext.getApnTypeFromNetworkType(networkConfig.type);
-                    sApnPriorityMap.put(apnType, networkConfig.priority);
-                }
-            }
-        }
-    }
-
-    private int priorityForApnType(int apnType) {
-        Integer priority = sApnPriorityMap.get(apnType);
-        return (priority != null ? priority.intValue() : 0);
-    }
 }
diff --git a/src/java/com/android/internal/telephony/dataconnection/DcTracker.java b/src/java/com/android/internal/telephony/dataconnection/DcTracker.java
index deb11f6..b67a675 100644
--- a/src/java/com/android/internal/telephony/dataconnection/DcTracker.java
+++ b/src/java/com/android/internal/telephony/dataconnection/DcTracker.java
@@ -47,7 +47,6 @@
 import android.net.LinkProperties;
 import android.net.NetworkAgent;
 import android.net.NetworkCapabilities;
-import android.net.NetworkConfig;
 import android.net.NetworkPolicyManager;
 import android.net.NetworkRequest;
 import android.net.ProxyInfo;
@@ -123,6 +122,7 @@
 import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
@@ -145,26 +145,6 @@
     private static final boolean VDBG_STALL = false; // STOPSHIP if true
     private static final boolean RADIO_TESTS = false;
 
-    /**
-     * These constants exist here because ConnectivityManager.TYPE_xxx constants are deprecated and
-     * new ones will not be added (for instance NETWORK_TYPE_MCX below).
-     * For backward compatibility, the values here need to be the same as
-     * ConnectivityManager.TYPE_xxx because networkAttributes overlay uses those values.
-     */
-    private static final int NETWORK_TYPE_DEFAULT = ConnectivityManager.TYPE_MOBILE;
-    private static final int NETWORK_TYPE_MMS = ConnectivityManager.TYPE_MOBILE_MMS;
-    private static final int NETWORK_TYPE_SUPL = ConnectivityManager.TYPE_MOBILE_SUPL;
-    private static final int NETWORK_TYPE_DUN = ConnectivityManager.TYPE_MOBILE_DUN;
-    private static final int NETWORK_TYPE_HIPRI = ConnectivityManager.TYPE_MOBILE_HIPRI;
-    private static final int NETWORK_TYPE_FOTA = ConnectivityManager.TYPE_MOBILE_FOTA;
-    private static final int NETWORK_TYPE_IMS = ConnectivityManager.TYPE_MOBILE_IMS;
-    private static final int NETWORK_TYPE_CBS = ConnectivityManager.TYPE_MOBILE_CBS;
-    private static final int NETWORK_TYPE_IA = ConnectivityManager.TYPE_MOBILE_IA;
-    private static final int NETWORK_TYPE_EMERGENCY = ConnectivityManager.TYPE_MOBILE_EMERGENCY;
-    // far away from ConnectivityManager.TYPE_xxx constants as the APNs below aren't defined there.
-    private static final int NETWORK_TYPE_MCX = 1001;
-    private static final int NETWORK_TYPE_XCAP = 1002;
-
     @IntDef(value = {
             REQUEST_TYPE_NORMAL,
             REQUEST_TYPE_HANDOVER,
@@ -287,7 +267,7 @@
             new PriorityQueue<ApnContext>(5,
             new Comparator<ApnContext>() {
                 public int compare(ApnContext c1, ApnContext c2) {
-                    return c2.priority - c1.priority;
+                    return c2.getPriority() - c1.getPriority();
                 }
             } );
 
@@ -1022,70 +1002,32 @@
         if(DBG && mPhone != null) log("finalize");
     }
 
-    private ApnContext addApnContext(String type, NetworkConfig networkConfig) {
-        ApnContext apnContext = new ApnContext(mPhone, type, mLogTag, networkConfig, this);
-        mApnContexts.put(type, apnContext);
-        mApnContextsByType.put(ApnSetting.getApnTypesBitmaskFromString(type), apnContext);
-        mPrioritySortedApnContexts.add(apnContext);
-        return apnContext;
-    }
-
     private void initApnContexts() {
-        log("initApnContexts: E");
-        // Load device network attributes from resources
-        String[] networkConfigStrings = mPhone.getContext().getResources().getStringArray(
-                com.android.internal.R.array.networkAttributes);
-        for (String networkConfigString : networkConfigStrings) {
-            NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
-            ApnContext apnContext;
-
-            switch (networkConfig.type) {
-                case NETWORK_TYPE_DEFAULT:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_DEFAULT, networkConfig);
-                    break;
-                case NETWORK_TYPE_MMS:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_MMS, networkConfig);
-                    break;
-                case NETWORK_TYPE_SUPL:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_SUPL, networkConfig);
-                    break;
-                case NETWORK_TYPE_DUN:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_DUN, networkConfig);
-                    break;
-                case NETWORK_TYPE_HIPRI:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_HIPRI, networkConfig);
-                    break;
-                case NETWORK_TYPE_FOTA:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_FOTA, networkConfig);
-                    break;
-                case NETWORK_TYPE_IMS:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_IMS, networkConfig);
-                    break;
-                case NETWORK_TYPE_CBS:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_CBS, networkConfig);
-                    break;
-                case NETWORK_TYPE_IA:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_IA, networkConfig);
-                    break;
-                case NETWORK_TYPE_EMERGENCY:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_EMERGENCY, networkConfig);
-                    break;
-                case NETWORK_TYPE_MCX:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_MCX, networkConfig);
-                    break;
-                case NETWORK_TYPE_XCAP:
-                    apnContext = addApnContext(PhoneConstants.APN_TYPE_XCAP, networkConfig);
-                    break;
-                default:
-                    log("initApnContexts: skipping unknown type=" + networkConfig.type);
-                    continue;
-            }
-            log("initApnContexts: apnContext=" + apnContext);
+        if (!mTelephonyManager.isDataCapable()) {
+            log("initApnContexts: isDataCapable == false.  No Apn Contexts loaded");
+            return;
         }
 
+        log("initApnContexts: E");
+        // Load device network attributes from resources
+        final Collection<ApnConfigType> types = ApnConfigTypeRepository.getDefault().getTypes();
+        for (ApnConfigType apnConfigType : types) {
+            addApnContext(apnConfigType);
+            log("initApnContexts: apnContext=" + ApnSetting.getApnTypeString(
+                    apnConfigType.getType()));
+        }
         if (VDBG) log("initApnContexts: X mApnContexts=" + mApnContexts);
     }
 
+    private void addApnContext(ApnConfigType apnContextType) {
+        ApnContext apnContext = new ApnContext(mPhone, apnContextType.getType(), mLogTag, this,
+                apnContextType.getPriority());
+        mApnContexts.put(apnContext.getApnType(), apnContext);
+        mApnContextsByType.put(ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType()),
+                apnContext);
+        mPrioritySortedApnContexts.add(apnContext);
+    }
+
     public LinkProperties getLinkProperties(String apnType) {
         ApnContext apnContext = mApnContexts.get(apnType);
         if (apnContext != null) {
@@ -1128,6 +1070,11 @@
         return result.toArray(new String[0]);
     }
 
+    @VisibleForTesting
+    public Collection<ApnContext> getApnContexts() {
+        return mApnContexts.values();
+    }
+
     /** Return active ApnSetting of a specific apnType */
     public ApnSetting getActiveApnSetting(String apnType) {
         if (VDBG) log("get active ApnSetting for type:" + apnType);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/PhoneSwitcherTest.java b/tests/telephonytests/src/com/android/internal/telephony/PhoneSwitcherTest.java
index 443eb4d..362d713 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/PhoneSwitcherTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/PhoneSwitcherTest.java
@@ -76,13 +76,6 @@
 @RunWith(AndroidTestingRunner.class)
 @TestableLooper.RunWithLooper
 public class PhoneSwitcherTest extends TelephonyTest {
-    private static final String[] sNetworkAttributes = new String[] {
-            "mobile,0,0,0,-1,true", "mobile_mms,2,0,2,60000,true",
-            "mobile_supl,3,0,2,60000,true", "mobile_dun,4,0,2,60000,true",
-            "mobile_hipri,5,0,3,60000,true", "mobile_fota,10,0,2,60000,true",
-            "mobile_ims,11,0,2,60000,true", "mobile_cbs,12,0,2,60000,true",
-            "mobile_ia,14,0,2,-1,true", "mobile_emergency,15,0,2,-1,true"};
-
     private static final int ACTIVE_PHONE_SWITCH = 1;
 
     @Mock
@@ -333,7 +326,7 @@
         assertTrue("data not allowed", mDataAllowed[0]);
         assertFalse("data allowed", mDataAllowed[1]);
 
-        // now start a higher priority conneciton on the other sub
+        // now start a higher priority connection on the other sub
         addMmsNetworkRequest(1);
 
         // After gain of network request, mActivePhoneSwitchHandler should be notified 2 times.
@@ -1012,9 +1005,6 @@
     }
 
     private void initialize() throws Exception {
-        mContextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
-                sNetworkAttributes);
-
         setNumPhones(mActiveModemCount, mSupportedModemCount);
 
         initializeSubControllerMock();
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
index a928b58..6452319 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
@@ -547,6 +547,8 @@
                 nullable(Intent[].class), nullable(String[].class), anyInt(),
                 nullable(Bundle.class), anyInt());
         doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
+        doReturn(true).when(mTelephonyManager).isDataCapable();
+
         doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
         doReturn(mServiceState).when(mSST).getServiceState();
         mSST.mSS = mServiceState;
diff --git a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/ApnContextTest.java b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/ApnContextTest.java
index ca9f1ac..525afe2 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/ApnContextTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/ApnContextTest.java
@@ -54,8 +54,7 @@
     public void setUp() throws Exception {
         super.setUp(getClass().getSimpleName());
         mNetworkConfig.dependencyMet = true;
-        mApnContext = new ApnContext(mPhone, PhoneConstants.APN_TYPE_DEFAULT, TAG, mNetworkConfig,
-                mDcTracker);
+        mApnContext = new ApnContext(mPhone, ApnSetting.TYPE_DEFAULT, TAG, mDcTracker, 1);
     }
 
     @After
diff --git a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java
index 7f234a7..ac5e6ea 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java
@@ -110,18 +110,10 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class DcTrackerTest extends TelephonyTest {
-
-    private final static String[] sNetworkAttributes = new String[]{
-            "mobile,0,0,0,-1,true", "mobile_mms,2,0,2,60000,true",
-            "mobile_supl,3,0,2,60000,true", "mobile_dun,4,0,2,60000,true",
-            "mobile_hipri,5,0,3,60000,true", "mobile_fota,10,0,2,60000,true",
-            "mobile_ims,11,0,2,60000,true", "mobile_cbs,12,0,2,60000,true",
-            "mobile_ia,14,0,2,-1,true", "mobile_emergency,15,0,2,-1,true",
-            "mobile_xcap,18,0,2,-1,true"};
-
     public static final String FAKE_APN1 = "FAKE APN 1";
     public static final String FAKE_APN2 = "FAKE APN 2";
     public static final String FAKE_APN3 = "FAKE APN 3";
@@ -480,8 +472,6 @@
         doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState)
                 .getRilDataRadioTechnology();
 
-        mContextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
-                sNetworkAttributes);
         mContextFixture.putStringArrayResource(com.android.internal.R.array.
                 config_mobile_tcp_buffers, new String[]{
                 "umts:131072,262144,1452032,4096,16384,399360",
@@ -826,7 +816,25 @@
                 eq(AccessNetworkType.EUTRAN), dpCaptor.capture(),
                 eq(false), eq(false), eq(DataService.REQUEST_REASON_NORMAL), any(),
                 any(Message.class));
-        verifyDataProfile(dpCaptor.getValue(), FAKE_APN1, 0, 21, 1, NETWORK_TYPE_LTE_BITMASK);
+
+
+        List<DataProfile> dataProfiles = dpCaptor.getAllValues();
+        assertEquals(2, dataProfiles.size());
+
+        //Verify FAKE_APN1
+        Optional<DataProfile> fakeApn1 = dataProfiles.stream()
+                .filter(dp -> dp.getApn().equals(FAKE_APN1))
+                .findFirst();
+        assertTrue(fakeApn1.isPresent());
+        verifyDataProfile(fakeApn1.get(), FAKE_APN1, 0, 21, 1, NETWORK_TYPE_LTE_BITMASK);
+
+        //Verify FAKE_APN6
+        Optional<DataProfile> fakeApn6 = dataProfiles.stream()
+                .filter(dp -> dp.getApn().equals(FAKE_APN6))
+                .findFirst();
+        assertTrue(fakeApn6.isPresent());
+        verifyDataProfile(fakeApn6.get(), FAKE_APN6, 0, 2, 1, NETWORK_TYPE_LTE_BITMASK);
+
 
         logd("Sending DATA_DISABLED_CMD for default data");
         doReturn(false).when(mDataEnabledSettings).isDataEnabled();
@@ -2047,4 +2055,20 @@
 
         return true;
     }
+    @Test
+    public void testNoApnContextsWhenDataIsDisabled() {
+        doReturn(false).when(mTelephonyManager).isDataCapable();
+        mDcTrackerTestHandler = new DcTrackerTestHandler(getClass().getSimpleName());
+        setReady(false);
+        mDcTrackerTestHandler.start();
+        waitUntilReady();
+        assertTrue(mDct.getApnContexts().size() == 0);
+
+        doReturn(true).when(mTelephonyManager).isDataCapable();
+        mDcTrackerTestHandler = new DcTrackerTestHandler(getClass().getSimpleName());
+        setReady(false);
+        mDcTrackerTestHandler.start();
+        waitUntilReady();
+        assertTrue(mDct.getApnContexts().size() > 0);
+    }
 }