Merge "support per carrier based iso country code"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 31e5364..125a3ae 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -112,6 +112,13 @@
                   android:singleUser="true"
                   android:multiprocess="false" />
 
+        <provider android:name="RcsProvider"
+                  android:authorities="rcs"
+                  android:multiprocess="false"
+                  android:exported="true"
+                  android:singleUser="true"
+                  android:readPermission="android.permission.READ_SMS" />
+
         <service
             android:name=".TelephonyBackupAgent$DeferredSmsMmsRestoreService"
             android:exported="false" />
diff --git a/OWNERS b/OWNERS
index be3c684..92458db 100644
--- a/OWNERS
+++ b/OWNERS
@@ -9,3 +9,4 @@
 hallliu@google.com
 tgunn@google.com
 breadley@google.com
+nazaninb@google.com
diff --git a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
index 1dc2106..f7a446b 100644
--- a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
+++ b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
@@ -261,6 +261,11 @@
     // cache for INITIAL_CREATE_DONE shared pref so access to it can be avoided when possible
     private static AtomicBoolean sInitialCreateDone = new AtomicBoolean(false);
 
+    // TODO(sahinc): Turn this to true once the schema finalizes, so that people can update their
+    // messaging databases. NOTE: move the switch/case update to the latest version of the database
+    // before turning this flag to true.
+    private static final boolean IS_RCS_TABLE_SCHEMA_CODE_COMPLETE = false;
+
     /**
      * The primary purpose of this DatabaseErrorHandler is to broadcast an intent on corruption and
      * print a Slog.wtf so database corruption can be caught earlier.
@@ -545,6 +550,11 @@
         createMmsTables(db);
         createSmsTables(db);
         createCommonTables(db);
+
+        if (IS_RCS_TABLE_SCHEMA_CODE_COMPLETE) {
+            RcsProviderHelper.createRcsTables(db);
+        }
+
         createCommonTriggers(db);
         createMmsTriggers(db);
         createWordsTables(db);
@@ -1625,6 +1635,12 @@
             } finally {
                 db.endTransaction();
             }
+            // fall through
+        case 67:
+            if (currentVersion <= 67 || !IS_RCS_TABLE_SCHEMA_CODE_COMPLETE) {
+                return;
+            }
+            RcsProviderHelper.createRcsTables(db);
             return;
         }
 
diff --git a/src/com/android/providers/telephony/RcsProvider.java b/src/com/android/providers/telephony/RcsProvider.java
new file mode 100644
index 0000000..83ff130
--- /dev/null
+++ b/src/com/android/providers/telephony/RcsProvider.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2018 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.providers.telephony;
+
+import static com.android.providers.telephony.RcsProviderHelper.ID;
+import static com.android.providers.telephony.RcsProviderHelper.THREAD_TABLE;
+
+import android.app.AppOpsManager;
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.database.sqlite.SQLiteQueryBuilder;
+import android.net.Uri;
+import android.util.Log;
+
+/**
+ * Content provider to handle RCS messages. The functionality here is similar to SmsProvider,
+ * MmsProvider etc. This is not meant to be public.
+ * @hide
+ */
+public class RcsProvider extends ContentProvider {
+    private final static String TAG = "RcsProvider";
+    static final String AUTHORITY = "rcs";
+    private static final UriMatcher URL_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
+
+    private static final int THREAD = 1;
+
+    SQLiteOpenHelper mDbOpenHelper;
+
+    static {
+        URL_MATCHER.addURI(AUTHORITY, "thread", THREAD);
+    }
+
+    @Override
+    public boolean onCreate() {
+        setAppOps(AppOpsManager.OP_READ_SMS, AppOpsManager.OP_WRITE_SMS);
+        // Use the credential encrypted mmssms.db for RCS messages.
+        mDbOpenHelper = MmsSmsDatabaseHelper.getInstanceForCe(getContext());
+        return true;
+    }
+
+    @Override
+    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+            String sortOrder) {
+        int match = URL_MATCHER.match(uri);
+        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+        SQLiteDatabase readableDatabase = mDbOpenHelper.getReadableDatabase();
+
+        switch (match) {
+            case THREAD:
+                RcsProviderHelper.buildThreadQuery(qb);
+                break;
+            default:
+                Log.e(TAG, "Invalid query: " + uri);
+        }
+
+        return qb.query(
+                readableDatabase, projection, selection, selectionArgs, null, null, sortOrder);
+    }
+
+    @Override
+    public String getType(Uri uri) {
+        return null;
+    }
+
+    @Override
+    public Uri insert(Uri uri, ContentValues values) {
+        int match = URL_MATCHER.match(uri);
+        SQLiteDatabase writableDatabase = mDbOpenHelper.getWritableDatabase();
+
+        switch (match) {
+            case THREAD:
+                writableDatabase.insert(THREAD_TABLE, ID, values);
+                break;
+            default:
+                Log.e(TAG, "Invalid insert: " + uri);
+        }
+
+        return null;
+    }
+
+    @Override
+    public int delete(Uri uri, String selection, String[] selectionArgs) {
+        int match = URL_MATCHER.match(uri);
+        int deletedCount = 0;
+        SQLiteDatabase writableDatabase = mDbOpenHelper.getWritableDatabase();
+
+        switch (match) {
+            case THREAD:
+                deletedCount = writableDatabase.delete(THREAD_TABLE, selection, selectionArgs);
+                break;
+            default:
+                Log.e(TAG, "Invalid delete: " + uri);
+        }
+
+        return deletedCount;
+    }
+
+    @Override
+    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+        int match = URL_MATCHER.match(uri);
+        int updatedCount = 0;
+        SQLiteDatabase writableDatabase = mDbOpenHelper.getWritableDatabase();
+
+        switch (match) {
+            case THREAD:
+                updatedCount = writableDatabase.update(
+                        THREAD_TABLE, values, selection, selectionArgs);
+                break;
+            default:
+                Log.e(TAG, "Invalid update: " + uri);
+        }
+
+        return updatedCount;
+    }
+}
diff --git a/src/com/android/providers/telephony/RcsProviderHelper.java b/src/com/android/providers/telephony/RcsProviderHelper.java
new file mode 100644
index 0000000..3966f53
--- /dev/null
+++ b/src/com/android/providers/telephony/RcsProviderHelper.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2018 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.providers.telephony;
+
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteQueryBuilder;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+/**
+ * Constants and helpers for RcsProvider to keep the code clean.
+ * @hide
+ */
+class RcsProviderHelper {
+    static final String ID = "_id";
+    static final String THREAD_TABLE = "rcs_thread";
+    static final String OWNER_PARTICIPANT = "owner_participant";
+
+    @VisibleForTesting
+    public static void createRcsTables(SQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + THREAD_TABLE + " (" +
+                ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
+                OWNER_PARTICIPANT + " INTEGER " +
+                ");");
+    }
+
+    static void buildThreadQuery(SQLiteQueryBuilder qb) {
+        qb.setTables(THREAD_TABLE);
+    }
+}
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 7058660..1c6db11 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -2604,6 +2604,7 @@
         List<String> constraints = new ArrayList<String>();
 
         int match = s_urlMatcher.match(url);
+        checkQueryPermission(match, projectionIn);
         switch (match) {
             case URL_TELEPHONY_USING_SUBID: {
                 subIdString = url.getLastPathSegment();
@@ -2700,18 +2701,19 @@
             }
 
             case URL_FILTERED_ID: {
-                constraints.add("_id = " + url.getLastPathSegment());
+                qb.appendWhere("_id = " + url.getLastPathSegment());
             }
             //intentional fall through from above case
             case URL_FILTERED: {
                 if (isManagedApnEnforced()) {
                     // If enforced, return DPC records only.
-                    constraints.add(IS_OWNED_BY_DPC);
+                    qb.appendWhereStandalone(IS_OWNED_BY_DPC);
                 } else {
                     // Otherwise return non-DPC records only.
-                    constraints.add(IS_NOT_OWNED_BY_DPC);
+                    qb.appendWhereStandalone(IS_NOT_OWNED_BY_DPC);
                 }
-                break;
+                return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs,
+                        sort, subId);
             }
 
             case URL_ENFORCE_MANAGED: {
@@ -2737,7 +2739,9 @@
             }
             //intentional fall through from above case
             case URL_SIM_APN_LIST: {
-                return getSubscriptionMatchingAPNList(qb, projectionIn, sort, subId);
+                qb.appendWhere(IS_NOT_OWNED_BY_DPC);
+                return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs,
+                        sort, subId);
             }
 
             default: {
@@ -2750,28 +2754,6 @@
             qb.appendWhere(TextUtils.join(" AND ", constraints));
         }
 
-        if (match != URL_SIMINFO) {
-            if (projectionIn != null) {
-                for (String column : projectionIn) {
-                    if (TYPE.equals(column) ||
-                            MMSC.equals(column) ||
-                            MMSPROXY.equals(column) ||
-                            MMSPORT.equals(column) ||
-                            MVNO_TYPE.equals(column) ||
-                            MVNO_MATCH_DATA.equals(column) ||
-                            APN.equals(column)) {
-                        // noop
-                    } else {
-                        checkPermission();
-                        break;
-                    }
-                }
-            } else {
-                // null returns all columns, so need permission check
-                checkPermission();
-            }
-        }
-
         SQLiteDatabase db = getReadableDatabase();
         Cursor ret = null;
         try {
@@ -2797,45 +2779,63 @@
         return ret;
     }
 
+    private void checkQueryPermission(int match, String[] projectionIn) {
+        if (match != URL_SIMINFO) {
+            if (projectionIn != null) {
+                for (String column : projectionIn) {
+                    if (TYPE.equals(column) ||
+                            MMSC.equals(column) ||
+                            MMSPROXY.equals(column) ||
+                            MMSPORT.equals(column) ||
+                            MVNO_TYPE.equals(column) ||
+                            MVNO_MATCH_DATA.equals(column) ||
+                            APN.equals(column)) {
+                        // noop
+                    } else {
+                        checkPermission();
+                        break;
+                    }
+                }
+            } else {
+                // null returns all columns, so need permission check
+                checkPermission();
+            }
+        }
+    }
+
     /**
-     * To find the current sim APN.
+     * To find the current sim APN. Query APN based on {MCC, MNC, MVNO} to support backward
+     * compatibility but will move to carrier id in the future.
      *
      * There has three steps:
-     * 1. Query the APN based on carrier ID and fall back to query { MCC, MNC, MVNO }.
-     * 2. If can't find the current APN, then query the parent APN. Query based on
-     *    MNO carrier id and { MCC, MNC }.
+     * 1. Query the APN based on { MCC, MNC, MVNO }.
+     * 2. If can't find the current APN, then query the parent APN. Query based on { MCC, MNC }.
      * 3. else return empty cursor
      *
      */
     private Cursor getSubscriptionMatchingAPNList(SQLiteQueryBuilder qb, String[] projectionIn,
-            String sort, int subId) {
+            String selection, String[] selectionArgs, String sort, int subId) {
 
         Cursor ret;
         final TelephonyManager tm = ((TelephonyManager)
                 getContext().getSystemService(Context.TELEPHONY_SERVICE))
                 .createForSubscriptionId(subId);
         SQLiteDatabase db = getReadableDatabase();
+        String mccmnc = tm.getSimOperator();
 
         // For query db one time, append step 1 and step 2 condition in one selection and
         // separate results after the query is completed. Because IMSI has special match rule,
         // so just query the MCC / MNC and filter the MVNO by ourselves
-        String carrierIDSelection = CARRIER_ID + " =? OR " + NUMERIC + " =? OR "
-                + CARRIER_ID + " =? ";
+        qb.appendWhereStandalone(NUMERIC + " = '" + mccmnc + "' ");
 
-
-        String mccmnc = tm.getSimOperator();
-        String carrierId = String.valueOf(tm.getSimCarrierId());
-        String mnoCarrierId = String.valueOf(tm.getSimMNOCarrierId());
-
-        ret = qb.query(db, null, carrierIDSelection,
-                new String[]{carrierId, mccmnc, mnoCarrierId}, null, null, sort);
+        ret = qb.query(db, null, selection, selectionArgs, null, null, sort);
 
         if (DBG) log("match current APN size:  " + ret.getCount());
 
-        MatrixCursor currentCursor = new MatrixCursor(projectionIn);
-        MatrixCursor parentCursor = new MatrixCursor(projectionIn);
+        String[] coulmnNames = projectionIn != null ? projectionIn : ret.getColumnNames();
+        MatrixCursor currentCursor = new MatrixCursor(coulmnNames);
+        MatrixCursor parentCursor = new MatrixCursor(coulmnNames);
 
-        int carrierIdIndex = ret.getColumnIndex(CARRIER_ID);
         int numericIndex = ret.getColumnIndex(NUMERIC);
         int mvnoIndex = ret.getColumnIndex(MVNO_TYPE);
         int mvnoDataIndex = ret.getColumnIndex(MVNO_MATCH_DATA);
@@ -2845,28 +2845,19 @@
         //Separate the result into MatrixCursor
         while (ret.moveToNext()) {
             List<String> data = new ArrayList<>();
-            for (String column : projectionIn) {
+            for (String column : coulmnNames) {
                 data.add(ret.getString(ret.getColumnIndex(column)));
             }
 
-            if (ret.getString(carrierIdIndex).equals(carrierId)) {
-                // 1. APN query result based on SIM carrier id
-                currentCursor.addRow(data);
-            } else if (!TextUtils.isEmpty(ret.getString(numericIndex)) &&
+            if (!TextUtils.isEmpty(ret.getString(numericIndex)) &&
                     ApnSettingUtils.mvnoMatches(iccRecords,
                             ApnSetting.getMvnoTypeIntFromString(ret.getString(mvnoIndex)),
                             ret.getString(mvnoDataIndex))) {
-                // 1. APN query result based on legacy SIM MCC/MCC and MVNO in case APN carrier id
-                // migration is not 100%. some APNSettings can not find match id.
-                // TODO: remove legacy {mcc,mnc, mvno} support in the future.
+                // 1. APN query result based on legacy SIM MCC/MCC and MVNO
                 currentCursor.addRow(data);
-            } else if (ret.getString(carrierIdIndex).equals(mnoCarrierId)) {
-                // 2. APN query result based on SIM MNO carrier id in case no APN found from
-                // exact carrier id fallback to query the MNO carrier id
-                parentCursor.addRow(data);
-            } else if (!TextUtils.isEmpty(ret.getString(numericIndex))) {
+            } else if (!TextUtils.isEmpty(ret.getString(numericIndex)) &&
+                    TextUtils.isEmpty(ret.getString(mvnoIndex))) {
                 // 2. APN query result based on SIM MCC/MNC
-                // TODO: remove legacy {mcc, mnc} support in the future.
                 parentCursor.addRow(data);
             }
         }
@@ -2879,7 +2870,7 @@
             return parentCursor;
         } else {
             if (DBG) log("APN no match");
-            return new MatrixCursor(projectionIn);
+            return new MatrixCursor(coulmnNames);
         }
     }
 
diff --git a/tests/src/com/android/providers/telephony/RcsProviderTest.java b/tests/src/com/android/providers/telephony/RcsProviderTest.java
new file mode 100644
index 0000000..708078f
--- /dev/null
+++ b/tests/src/com/android/providers/telephony/RcsProviderTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2018 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.providers.telephony;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import android.app.AppOpsManager;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.pm.ProviderInfo;
+import android.net.Uri;
+import android.telephony.TelephonyManager;
+import android.test.mock.MockContentResolver;
+import android.test.mock.MockContext;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class RcsProviderTest {
+    private MockContentResolver mContentResolver;
+
+    @Before
+    public void setUp() {
+        RcsProvider rcsProvider = new RcsProviderTestable();
+        MockContextWithProvider context = new MockContextWithProvider(rcsProvider);
+        mContentResolver = context.getContentResolver();
+    }
+
+    // TODO(sahinc): This test isn't that useful for now as it only checks the return value. Revisit
+    // once we have more of the implementation in place.
+    @Test
+    public void testInsertThread() {
+        ContentValues contentValues = new ContentValues();
+        contentValues.put(RcsProviderHelper.OWNER_PARTICIPANT, 5);
+
+        Uri uri = mContentResolver.insert(Uri.parse("content://rcs/thread"), contentValues);
+        assertNull(uri);
+    }
+
+    @Test
+    public void testUpdateThread() {
+        ContentValues contentValues = new ContentValues();
+        contentValues.put(RcsProviderHelper.OWNER_PARTICIPANT, 5);
+        mContentResolver.insert(Uri.parse("content://rcs/thread"), contentValues);
+
+        contentValues.put(RcsProviderHelper.OWNER_PARTICIPANT, 12);
+        int updateCount = mContentResolver.update(Uri.parse("content://rcs/thread"),
+                contentValues, "owner_participant=5", null);
+
+        assertEquals(1, updateCount);
+    }
+
+    class MockContextWithProvider extends MockContext {
+        private final MockContentResolver mResolver;
+
+        MockContextWithProvider(RcsProvider rcsProvider) {
+            mResolver = new MockContentResolver();
+
+            // Add authority="rcs" to given smsProvider
+            ProviderInfo providerInfo = new ProviderInfo();
+            providerInfo.authority = RcsProvider.AUTHORITY;
+            rcsProvider.attachInfoForTesting(this, providerInfo);
+            mResolver.addProvider(RcsProvider.AUTHORITY, rcsProvider);
+        }
+
+        @Override
+        public MockContentResolver getContentResolver() {
+            return mResolver;
+        }
+
+        @Override
+        public Object getSystemService(String name) {
+            switch (name) {
+                case Context.APP_OPS_SERVICE:
+                    return Mockito.mock(AppOpsManager.class);
+                case Context.TELEPHONY_SERVICE:
+                    return Mockito.mock(TelephonyManager.class);
+                default:
+                    return null;
+            }
+        }
+    }
+
+}
diff --git a/tests/src/com/android/providers/telephony/RcsProviderTestable.java b/tests/src/com/android/providers/telephony/RcsProviderTestable.java
new file mode 100644
index 0000000..1e4da11
--- /dev/null
+++ b/tests/src/com/android/providers/telephony/RcsProviderTestable.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2018 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.providers.telephony;
+
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+/**
+ * A subclass of RcsProvider used for testing on an in-memory database
+ */
+public class RcsProviderTestable extends RcsProvider {
+
+    @Override
+    public boolean onCreate() {
+        mDbOpenHelper = new InMemoryRcsDatabase();
+        return true;
+    }
+
+    static class InMemoryRcsDatabase extends SQLiteOpenHelper {
+        InMemoryRcsDatabase() {
+            super(null,      // no context is needed for in-memory db
+                    null,      // db file name is null for in-memory db
+                    null,      // CursorFactory is null by default
+                    1);        // db version is no-op for tests
+        }
+
+        @Override
+        public void onCreate(SQLiteDatabase db) {
+            RcsProviderHelper.createRcsTables(db);
+        }
+
+        @Override
+        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+            // no-op
+        }
+    }
+}
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index cf4409a..f9acd48 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -136,6 +136,9 @@
             // return test subId 0 for all operators
             doReturn(TEST_OPERATOR).when(mTelephonyManager).getSimOperator(anyInt());
 
+            doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
+            doReturn(TEST_OPERATOR).when(mTelephonyManager).getSimOperator();
+
             // Add authority="telephony" to given telephonyProvider
             ProviderInfo providerInfo = new ProviderInfo();
             providerInfo.authority = "telephony";
@@ -599,7 +602,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";
@@ -1444,7 +1447,7 @@
 
     @Test
     @SmallTest
-    public void testGetCurrentAPNList_APNMatchTheCarrierID() {
+    public void testSIMAPNLIST_APNMatchTheMCCMNCAndMVNO() {
         // Test on getCurrentAPNList() step 1
         TelephonyManager telephonyManager =
                 ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
@@ -1452,52 +1455,14 @@
 
         final String apnName = "apnName";
         final String carrierName = "name";
-        final int carrierID = 100;
-        final String numeric = TEST_OPERATOR;
-        doReturn(carrierID).when(telephonyManager).getSimCarrierId();
-        doReturn(numeric).when(telephonyManager).getSimOperator();
-
-        // Insert the APN
-        ContentValues contentValues = new ContentValues();
-        contentValues.put(Carriers.APN, apnName);
-        contentValues.put(Carriers.NAME, carrierName);
-        contentValues.put(Carriers.CARRIER_ID, carrierID);
-        mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
-
-        final String[] testProjection =
-            {
-                Carriers.APN,
-                Carriers.NAME,
-                Carriers.CARRIER_ID,
-            };
-        Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
-            testProjection, null, null, null);
-
-        cursor.moveToFirst();
-        assertEquals(apnName, cursor.getString(0));
-        assertEquals(carrierName, cursor.getString(1));
-        assertEquals(String.valueOf(carrierID), cursor.getString(2));
-    }
-
-    @Test
-    @SmallTest
-    public void testGetCurrentAPNList_APNMatchTheMCCMNCAndMVNO() {
-        // 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 mvnoType = "spn";
         final String mvnoData = TelephonyProviderTestable.TEST_SPN;
         final int carrierId = 100;
         doReturn(carrierId).when(telephonyManager).getSimCarrierId();
         doReturn(numeric).when(telephonyManager).getSimOperator();
-        //TelephonyProviderTestable had mock iccreord
 
-        // The DB only have the MCC/MNC and MVNO APN
+        // Insert the APN and DB only have the MCC/MNC and MVNO APN
         ContentValues contentValues = new ContentValues();
         contentValues.put(Carriers.APN, apnName);
         contentValues.put(Carriers.NAME, carrierName);
@@ -1506,6 +1471,7 @@
         contentValues.put(Carriers.MVNO_MATCH_DATA, mvnoData);
         mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
 
+        // Query DB
         final String[] testProjection =
             {
                 Carriers.APN,
@@ -1514,8 +1480,7 @@
                 Carriers.MVNO_MATCH_DATA
             };
         Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
-            testProjection, null, null, null);
-
+                testProjection, null, null, null);
 
         cursor.moveToFirst();
         assertEquals(apnName, cursor.getString(0));
@@ -1526,47 +1491,8 @@
 
     @Test
     @SmallTest
-    public void testGetCurrentAPNList_APNMatchTheMNOCarrierID() {
-        // Test on getCurrentAPNList() step 3
-        TelephonyManager telephonyManager =
-                ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
-        doReturn(telephonyManager).when(telephonyManager).createForSubscriptionId(anyInt());
-
-        final String apnName = "apnName";
-        final String carrierName = "name";
-        final int carrierId = 100;
-        final int mnoCarrierId = 101;
-        final String numeric = TEST_OPERATOR;
-        doReturn(carrierId).when(telephonyManager).getSimCarrierId();
-        doReturn(mnoCarrierId).when(telephonyManager).getSimMNOCarrierId();
-        doReturn(numeric).when(telephonyManager).getSimOperator();
-
-        // The DB only have the MNO carrier id APN
-        ContentValues contentValues = new ContentValues();
-        contentValues.put(Carriers.APN, apnName);
-        contentValues.put(Carriers.NAME, carrierName);
-        contentValues.put(Carriers.CARRIER_ID, mnoCarrierId);
-        mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
-
-        final String[] testProjection =
-            {
-                Carriers.APN,
-                Carriers.NAME,
-                Carriers.CARRIER_ID,
-            };
-        Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
-            testProjection, null, null, null);
-
-        cursor.moveToFirst();
-        assertEquals(apnName, cursor.getString(0));
-        assertEquals(carrierName, cursor.getString(1));
-        assertEquals(String.valueOf(mnoCarrierId), cursor.getString(2));
-    }
-
-    @Test
-    @SmallTest
-    public void testGetCurrentAPNList_APNMatchTheParentMCCMNC() {
-        // Test on getCurrentAPNList() step 4
+    public void testSIMAPNLIST_APNMatchTheParentMCCMNC() {
+        // Test on getCurrentAPNList() step 2
         TelephonyManager telephonyManager =
                 ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
         doReturn(telephonyManager).when(telephonyManager).createForSubscriptionId(anyInt());
@@ -1583,13 +1509,14 @@
         doReturn(mvnoData).when(telephonyManager).getSimOperatorName();
         doReturn(mnoCarrierId).when(telephonyManager).getSimMNOCarrierId();
 
-        // The DB only have the MNO APN
+        // Insert the APN and DB only have the MNO APN
         ContentValues contentValues = new ContentValues();
         contentValues.put(Carriers.APN, apnName);
         contentValues.put(Carriers.NAME, carrierName);
         contentValues.put(Carriers.NUMERIC, numeric);
         mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
 
+        // Query DB
         final String[] testProjection =
             {
                 Carriers.APN,
@@ -1597,7 +1524,7 @@
                 Carriers.NUMERIC,
             };
         Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
-            testProjection, null, null, null);
+                testProjection, null, null, null);
 
         cursor.moveToFirst();
         assertEquals(apnName, cursor.getString(0));