Merge "Get IccRecords with APP_FAM_3GPP"
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 15cec7f..0025943 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -2887,7 +2887,12 @@
         int mvnoIndex = ret.getColumnIndex(MVNO_TYPE);
         int mvnoDataIndex = ret.getColumnIndex(MVNO_MATCH_DATA);
 
-        IccRecords iccRecords = getIccRecords(subId);
+        IccRecords iccRecords = UiccController.getInstance().getIccRecords(
+                SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
+        if (iccRecords == null) {
+            loge("iccRecords is null");
+            return null;
+        }
 
         //Separate the result into MatrixCursor
         while (ret.moveToNext()) {
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index c34e48a..2ca823a 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -42,15 +42,21 @@
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.Log;
 
+import com.android.internal.telephony.uicc.IccRecords;
+import com.android.internal.telephony.uicc.UiccController;
+
 import junit.framework.TestCase;
 
 import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 
+import java.lang.reflect.Field;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.IntStream;
 
-
 /**
  * Tests for testing CRUD operations of TelephonyProvider.
  * Uses a MockContentResolver to get permission WRITE_APN_SETTINGS in order to test insert/delete
@@ -70,6 +76,12 @@
     private MockContentResolver mContentResolver;
     private TelephonyProviderTestable mTelephonyProviderTestable;
 
+    @Mock
+    private UiccController mUiccController;
+
+    @Mock
+    private IccRecords mIcRecords;
+
     private int notifyChangeCount;
     private int notifyChangeRestoreCount;
     private int notifyWfcCount;
@@ -79,6 +91,7 @@
     private static final String TEST_OPERATOR = "123456";
     private static final String TEST_MCC = "123";
     private static final String TEST_MNC = "456";
+    private static final String TEST_SPN = TelephonyProviderTestable.TEST_SPN;
 
     // Used to test the path for URL_TELEPHONY_USING_SUBID with subid 1
     private static final Uri CONTENT_URI_WITH_SUBID = Uri.parse(
@@ -138,6 +151,9 @@
 
             doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
             doReturn(TEST_OPERATOR).when(mTelephonyManager).getSimOperator();
+            doReturn(mIcRecords).when(mUiccController).getIccRecords(anyInt(),
+                    ArgumentMatchers.eq(UiccController.APP_FAM_3GPP));
+            doReturn(TEST_SPN).when(mIcRecords).getServiceProviderName();
 
             // Add authority="telephony" to given telephonyProvider
             ProviderInfo providerInfo = new ProviderInfo();
@@ -199,9 +215,11 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+        MockitoAnnotations.initMocks(this);
         mTelephonyProviderTestable = new TelephonyProviderTestable();
         mContext = new MockContextWithProvider(mTelephonyProviderTestable);
         mContentResolver = (MockContentResolver) mContext.getContentResolver();
+        replaceInstance(UiccController.class, "mInstance", null, mUiccController);
         notifyChangeCount = 0;
         notifyChangeRestoreCount = 0;
     }
@@ -724,7 +742,7 @@
         mTelephonyProviderTestable.fakeCallingUid(Process.SYSTEM_UID);
 
         final int current = 1;
-        final String numeric = "123456789";
+        final String numeric = TEST_OPERATOR;
         final String selection = Carriers.NUMERIC + "=?";
         final String[] selectionArgs = { numeric };
 
@@ -802,7 +820,7 @@
             mTelephonyProviderTestable.fakeCallingUid(Process.SYSTEM_UID);
 
             final int current = 1;
-            final String numeric = "123456789";
+            final String numeric = TEST_OPERATOR;
 
             // Insert DPC record.
             final String dpcRecordApn = "exampleApnNameDPC";
@@ -893,7 +911,7 @@
             mTelephonyProviderTestable.fakeCallingUid(Process.SYSTEM_UID);
 
             final int current = 1;
-            final String numeric = "123456789";
+            final String numeric = TEST_OPERATOR;
 
             // Insert DPC record 1.
             final String dpcRecordApn1 = "exampleApnNameDPC";
@@ -1445,22 +1463,23 @@
         assertEquals(0, notifyWfcCountWithTestSubId);
     }
 
+    protected void replaceInstance(final Class c, final String instanceName,
+            final Object obj, final Object newValue)
+            throws Exception {
+        Field field = c.getDeclaredField(instanceName);
+        field.setAccessible(true);
+        field.set(obj, newValue);
+    }
+
     @Test
     @SmallTest
     public void testSIMAPNLIST_APNMatchTheMCCMNCAndMVNO() {
         // Test on getCurrentAPNList() step 1
-        TelephonyManager telephonyManager =
-                ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
-        doReturn(telephonyManager).when(telephonyManager).createForSubscriptionId(anyInt());
-
         final String apnName = "apnName";
         final String carrierName = "name";
         final String numeric = TEST_OPERATOR;
         final String mvnoType = "spn";
-        final String mvnoData = TelephonyProviderTestable.TEST_SPN;
-        final int carrierId = 100;
-        doReturn(carrierId).when(telephonyManager).getSimCarrierId();
-        doReturn(numeric).when(telephonyManager).getSimOperator();
+        final String mvnoData = TEST_SPN;
 
         // Insert the APN and DB only have the MCC/MNC and MVNO APN
         ContentValues contentValues = new ContentValues();
@@ -1473,12 +1492,12 @@
 
         // Query DB
         final String[] testProjection =
-            {
-                Carriers.APN,
-                Carriers.NAME,
-                Carriers.NUMERIC,
-                Carriers.MVNO_MATCH_DATA
-            };
+                {
+                        Carriers.APN,
+                        Carriers.NAME,
+                        Carriers.NUMERIC,
+                        Carriers.MVNO_MATCH_DATA
+                };
         Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
                 testProjection, null, null, null);
 
@@ -1493,19 +1512,9 @@
     @SmallTest
     public void testSIMAPNLIST_APNMatchTheParentMCCMNC() {
         // Test on getCurrentAPNList() step 2
-        TelephonyManager telephonyManager =
-                ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
-        doReturn(telephonyManager).when(telephonyManager).createForSubscriptionId(anyInt());
-
         final String apnName = "apnName";
         final String carrierName = "name";
         final String numeric = TEST_OPERATOR;
-        final String mvnoData = TelephonyProviderTestable.TEST_SPN;
-        final int carrierId = 100;
-
-        doReturn(carrierId).when(telephonyManager).getSimCarrierId();
-        doReturn(numeric).when(telephonyManager).getSimOperator();
-        doReturn(mvnoData).when(telephonyManager).getSimOperatorName();
 
         // Insert the APN and DB only have the MNO APN
         ContentValues contentValues = new ContentValues();
@@ -1516,11 +1525,11 @@
 
         // Query DB
         final String[] testProjection =
-            {
-                Carriers.APN,
-                Carriers.NAME,
-                Carriers.NUMERIC,
-            };
+                {
+                        Carriers.APN,
+                        Carriers.NAME,
+                        Carriers.NUMERIC,
+                };
         Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
                 testProjection, null, null, null);