Don't update SimInfo db if restore match is from newer db schema. am: 1fa92318bf am: 032afc3329

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/providers/TelephonyProvider/+/16263893

Change-Id: Id2de075fb977fa7c74a0a3721afda2a248951df8
diff --git a/assets/latest_carrier_id/carrier_list.pb b/assets/latest_carrier_id/carrier_list.pb
index d038016..c19db3a 100644
--- a/assets/latest_carrier_id/carrier_list.pb
+++ b/assets/latest_carrier_id/carrier_list.pb
Binary files differ
diff --git a/assets/latest_carrier_id/carrier_list.textpb b/assets/latest_carrier_id/carrier_list.textpb
index 62398c0..4c7523a 100644
--- a/assets/latest_carrier_id/carrier_list.textpb
+++ b/assets/latest_carrier_id/carrier_list.textpb
Binary files differ
diff --git a/assets/sdk31_carrier_id/carrier_list.pb b/assets/sdk31_carrier_id/carrier_list.pb
new file mode 100644
index 0000000..d038016
--- /dev/null
+++ b/assets/sdk31_carrier_id/carrier_list.pb
Binary files differ
diff --git a/assets/sdk31_carrier_id/carrier_list.textpb b/assets/sdk31_carrier_id/carrier_list.textpb
new file mode 100644
index 0000000..62398c0
--- /dev/null
+++ b/assets/sdk31_carrier_id/carrier_list.textpb
Binary files differ
diff --git a/res/values-as/strings.xml b/res/values-as/strings.xml
index 20ad0b0..6994d18 100644
--- a/res/values-as/strings.xml
+++ b/res/values-as/strings.xml
@@ -17,5 +17,5 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="app_label" product="tablet" msgid="9194799012395299737">"ম’বাইল নেটৱৰ্ক কনফিগাৰেশ্বন"</string>
-    <string name="app_label" product="default" msgid="8338087656149558019">"ফ’ন আৰু বাৰ্তাৰ ষ্ট’ৰেজ"</string>
+    <string name="app_label" product="default" msgid="8338087656149558019">"ফ\'ন আৰু বাৰ্তাৰ সঞ্চয়াগাৰ"</string>
 </resources>
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index c0faeee..e186f76 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -2320,7 +2320,7 @@
                 mncString = getBestStringMnc(mContext, mccString, Integer.parseInt(mnc));
             }
 
-            String numeric = mccString + mncString;
+            String numeric = (mccString == null | mncString == null) ? null : mccString + mncString;
             map.put(NUMERIC, numeric);
             map.put(MCC, mccString);
             map.put(MNC, mncString);
@@ -3966,7 +3966,7 @@
                 .createForSubscriptionId(subId);
         SQLiteDatabase db = getReadableDatabase();
         String mccmnc = tm.getSimOperator();
-        int carrierId = tm.getSimCarrierId();
+        int carrierId = tm.getSimSpecificCarrierId();
 
         qb.appendWhereStandalone(IS_NOT_USER_DELETED + " and " +
                 IS_NOT_USER_DELETED_BUT_PRESENT_IN_XML + " and " +
@@ -3991,6 +3991,7 @@
         MatrixCursor currentCursor = new MatrixCursor(columnNames);
         MatrixCursor parentCursor = new MatrixCursor(columnNames);
         MatrixCursor carrierIdCursor = new MatrixCursor(columnNames);
+        MatrixCursor carrierIdNonMatchingMNOCursor = new MatrixCursor(columnNames);
 
         int numericIndex = ret.getColumnIndex(NUMERIC);
         int mvnoIndex = ret.getColumnIndex(MVNO_TYPE);
@@ -4004,15 +4005,17 @@
                 data.add(ret.getString(ret.getColumnIndex(column)));
             }
 
-            boolean isCurrentSimOperator;
-            final long identity = Binder.clearCallingIdentity();
-            try {
-                isCurrentSimOperator = tm.matchesCurrentSimOperator(
-                        ret.getString(numericIndex),
-                        getMvnoTypeIntFromString(ret.getString(mvnoIndex)),
-                        ret.getString(mvnoDataIndex));
-            } finally {
-                Binder.restoreCallingIdentity(identity);
+            boolean isCurrentSimOperator = false;
+            if (!TextUtils.isEmpty(ret.getString(numericIndex))) {
+                final long identity = Binder.clearCallingIdentity();
+                try {
+                    isCurrentSimOperator = tm.matchesCurrentSimOperator(
+                            ret.getString(numericIndex),
+                            getMvnoTypeIntFromString(ret.getString(mvnoIndex)),
+                            ret.getString(mvnoDataIndex));
+                } finally {
+                    Binder.restoreCallingIdentity(identity);
+                }
             }
 
             boolean isMVNOAPN = !TextUtils.isEmpty(ret.getString(numericIndex))
@@ -4032,7 +4035,11 @@
                 parentCursor.addRow(data);
             } else if (isCarrierIdAPN) {
                 // The APN that query based on carrier Id (not include the MVNO or MNO APN)
-                carrierIdCursor.addRow(data);
+                if (TextUtils.isEmpty(ret.getString(numericIndex))) {
+                    carrierIdCursor.addRow(data);
+                } else {
+                    carrierIdNonMatchingMNOCursor.addRow(data);
+                }
             }
         }
         ret.close();
@@ -4045,8 +4052,11 @@
             if (DBG) log("match MNO APN: " + parentCursor.getCount());
             result = parentCursor;
         } else {
-            if (DBG) log("can't find the MVNO and MNO APN");
-            result = new MatrixCursor(columnNames);
+            if (DBG) {
+                log("No MVNO, MNO and no MCC/MNC match, but we have match/matches with the " +
+                        "same carrier id, count: " + carrierIdNonMatchingMNOCursor.getCount());
+            }
+            result = carrierIdNonMatchingMNOCursor;
         }
 
         if (DBG) log("match carrier id APN: " + carrierIdCursor.getCount());
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index b1cb97e..3455ffd 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -96,6 +96,7 @@
 
     private static final String TEST_SUBID = "1";
     private static final String TEST_OPERATOR = "123456";
+    private static final String TEST_OPERATOR_SECOND_MCCMNC = "567890";
     private static final String TEST_MCC = "123";
     private static final String TEST_MNC = "456";
     private static final String TEST_SPN = TelephonyProviderTestable.TEST_SPN;
@@ -258,7 +259,7 @@
                     .isActiveSubscriptionId(anyInt());
             doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
             doReturn(TEST_OPERATOR).when(mTelephonyManager).getSimOperator();
-            doReturn(TEST_CARRIERID).when(mTelephonyManager).getSimCarrierId();
+            doReturn(TEST_CARRIERID).when(mTelephonyManager).getSimSpecificCarrierId();
 
             // Add authority="telephony" to given telephonyProvider
             ProviderInfo providerInfo = new ProviderInfo();
@@ -2109,4 +2110,119 @@
 
         assertNull(cursor);
     }
+
+    @Test
+    @SmallTest
+    public void testSIMAPNLIST_MatchTheCarrierIDANDdifferentMNOAPN() {
+        setUpMockContext(true);
+
+        final String apnName = "apnName";
+        final String carrierName = "name";
+        final int carrierId = TEST_CARRIERID;
+
+        // Add an APN that have carrier id and matching MNO
+        ContentValues contentValues = new ContentValues();
+        contentValues.put(Carriers.APN, apnName);
+        contentValues.put(Carriers.NAME, carrierName);
+        contentValues.put(Carriers.CARRIER_ID, carrierId);
+        contentValues.put(Carriers.NUMERIC, TEST_OPERATOR);
+        mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
+
+        // Add MNO APN that have same carrier id, but different MNO
+        contentValues = new ContentValues();
+        contentValues.put(Carriers.APN, apnName);
+        contentValues.put(Carriers.NAME, carrierName);
+        contentValues.put(Carriers.CARRIER_ID, carrierId);
+        contentValues.put(Carriers.NUMERIC, TEST_OPERATOR_SECOND_MCCMNC);
+        mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
+
+        // Query DB
+        final String[] testProjection =
+            {
+                Carriers.APN,
+                Carriers.NAME,
+                Carriers.CARRIER_ID,
+                Carriers.NUMERIC,
+            };
+
+        Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST, testProjection, null, null, null);
+
+        // The query based on SIM_APN_LIST will return the APN which matches both carrier id and MNO
+        assertEquals(1, cursor.getCount());
+        cursor.moveToFirst();
+        assertEquals(TEST_OPERATOR, cursor.getString(cursor.getColumnIndex(Carriers.NUMERIC)));
+    }
+
+    @Test
+    @SmallTest
+    public void testSIMAPNLIST_MatchTheCarrierIDMissingMNO() {
+        setUpMockContext(true);
+
+        final String apnName = "apnName";
+        final String carrierName = "name";
+        final int carrierId = TEST_CARRIERID;
+
+        // Add an APN that have matching carrier id and no mno
+        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);
+
+        // Add MNO APN that have non matching carrier id and no mno
+        contentValues = new ContentValues();
+        contentValues.put(Carriers.APN, apnName);
+        contentValues.put(Carriers.NAME, carrierName);
+        contentValues.put(Carriers.CARRIER_ID, 99999);
+        mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
+
+        // Query DB
+        final String[] testProjection =
+            {
+                Carriers.APN,
+                Carriers.NAME,
+                Carriers.CARRIER_ID,
+            };
+
+        Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST, testProjection, null, null, null);
+
+        // The query based on SIM_APN_LIST will return the APN which matches carrier id
+        assertEquals(1, cursor.getCount());
+        cursor.moveToFirst();
+        assertEquals(TEST_CARRIERID, cursor.getInt(cursor.getColumnIndex(Carriers.CARRIER_ID)));
+    }
+
+    @Test
+    @SmallTest
+    public void testSIMAPNLIST_MatchTheCarrierIDNOTMatchingMNO() {
+        setUpMockContext(true);
+
+        final String apnName = "apnName";
+        final String carrierName = "name";
+        final int carrierId = TEST_CARRIERID;
+
+        // Add an APN that have matching carrier id and not matching mno
+        ContentValues contentValues = new ContentValues();
+        contentValues.put(Carriers.APN, apnName);
+        contentValues.put(Carriers.NAME, carrierName);
+        contentValues.put(Carriers.CARRIER_ID, carrierId);
+        contentValues.put(Carriers.NUMERIC, TEST_OPERATOR_SECOND_MCCMNC);
+        mContentResolver.insert(Carriers.CONTENT_URI, contentValues);
+
+        // Query DB
+        final String[] testProjection =
+            {
+                Carriers.APN,
+                Carriers.NAME,
+                Carriers.CARRIER_ID,
+            };
+
+        Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST, testProjection, null, null, null);
+
+        // The query based on SIM_APN_LIST will return the APN which matches carrier id,
+        // even though the mno does not match
+        assertEquals(1, cursor.getCount());
+        cursor.moveToFirst();
+        assertEquals(TEST_CARRIERID, cursor.getInt(cursor.getColumnIndex(Carriers.CARRIER_ID)));
+    }
 }