Snap for 7929046 from cc9f5e4317a528f016d461871962deeda70ccbc5 to mainline-adbd-release

Change-Id: I7f3d97a76abdda42a9aa9295bcab5d978a559ef1
diff --git a/Android.bp b/Android.bp
index 3b65737..cd24b24 100644
--- a/Android.bp
+++ b/Android.bp
@@ -32,3 +32,11 @@
     name: "telephonyprovider-assets-carrierlist",
     srcs: ["assets/latest_carrier_id/carrier_list.*"],
 }
+
+// used to share src with unit test app
+filegroup {
+    name: "telephonyprovider-shared-srcs",
+    srcs: [
+        "src/**/*.java",
+    ],
+}
diff --git a/OWNERS b/OWNERS
index 3059d4d..003cc3c 100644
--- a/OWNERS
+++ b/OWNERS
@@ -2,14 +2,15 @@
 breadley@google.com
 fionaxu@google.com
 jackyu@google.com
-hallliu@google.com
 rgreenwalt@google.com
 tgunn@google.com
 jminjie@google.com
 shuoq@google.com
-refuhoo@google.com
 nazaninb@google.com
 sarahchin@google.com
-dbright@google.com
 xiaotonj@google.com
+huiwang@google.com
+jayachandranc@google.com
+chinmayd@google.com
+amruthr@google.com
 
diff --git a/assets/latest_carrier_id/carrier_list.pb b/assets/latest_carrier_id/carrier_list.pb
index ebdaf74..d038016 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 c9b97c5..62398c0 100644
--- a/assets/latest_carrier_id/carrier_list.textpb
+++ b/assets/latest_carrier_id/carrier_list.textpb
Binary files differ
diff --git a/res/values-as/strings.xml b/res/values-as/strings.xml
index 6994d18..20ad0b0 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/CarrierIdProvider.java b/src/com/android/providers/telephony/CarrierIdProvider.java
index 3e751aa..9b6c2c0 100644
--- a/src/com/android/providers/telephony/CarrierIdProvider.java
+++ b/src/com/android/providers/telephony/CarrierIdProvider.java
@@ -189,14 +189,17 @@
                 + CarrierId.All.MCCMNC + ");";
     }
 
+    static {
+        s_urlMatcher.addURI(AUTHORITY, "all", URL_ALL);
+        s_urlMatcher.addURI(AUTHORITY, "all/update_db", URL_ALL_UPDATE_FROM_PB);
+        s_urlMatcher.addURI(AUTHORITY, "all/get_version", URL_ALL_GET_VERSION);
+    }
+
     @Override
     public boolean onCreate() {
         Log.d(TAG, "onCreate");
         mDbHelper = new CarrierIdDatabaseHelper(getContext());
         mDbHelper.getReadableDatabase();
-        s_urlMatcher.addURI(AUTHORITY, "all", URL_ALL);
-        s_urlMatcher.addURI(AUTHORITY, "all/update_db", URL_ALL_UPDATE_FROM_PB);
-        s_urlMatcher.addURI(AUTHORITY, "all/get_version", URL_ALL_GET_VERSION);
         updateDatabaseFromPb(mDbHelper.getWritableDatabase());
         return true;
     }
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 4303823..0ff9fc6 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -3891,6 +3891,31 @@
     }
 
     /**
+     * This method syncs PREF_FILE_FULL_APN with the db based on the current preferred apn ids.
+     */
+    private void updatePreferredApns() {
+        SharedPreferences spApn = getContext().getSharedPreferences(PREF_FILE_APN,
+                Context.MODE_PRIVATE);
+
+        Map<String, ?> allPrefApnId = spApn.getAll();
+        for (String key : allPrefApnId.keySet()) {
+            if (key.startsWith(COLUMN_APN_ID)) {
+                int subId;
+                try {
+                    subId = Integer.parseInt(key.substring(COLUMN_APN_ID.length()));
+                } catch (NumberFormatException e) {
+                    loge("updatePreferredApns: NumberFormatException for key=" + key);
+                    continue;
+                }
+                long preferredApnId = getPreferredApnId(subId, false);
+                if (preferredApnId != INVALID_APN_ID) {
+                    setPreferredApn(preferredApnId, subId);
+                }
+            }
+        }
+    }
+
+    /**
      * To find the current sim APN. Query APN based on {MCC, MNC, MVNO} and {Carrier_ID}.
      *
      * There has three steps:
@@ -4638,6 +4663,19 @@
             }
         }
 
+        // if APNs (CARRIERS_TABLE) have been updated, some of them may be preferred APN for
+        // different subs. So update the APN field values saved in SharedPref for all subIds.
+        switch (match) {
+            case URL_TELEPHONY_USING_SUBID:
+            case URL_TELEPHONY:
+            case URL_CURRENT_USING_SUBID:
+            case URL_CURRENT:
+            case URL_ID:
+            case URL_DPC_ID:
+                updatePreferredApns();
+                break;
+        }
+
         if (count > 0) {
             boolean usingSubId = false;
             switch (uriType) {
diff --git a/tests/Android.bp b/tests/Android.bp
index dafd7cd..8ecc370 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -23,7 +23,7 @@
         "android.test.base",
         "android.test.mock",
     ],
-    srcs: ["src/**/*.java"],
+    srcs: ["src/**/*.java", ":telephonyprovider-shared-srcs"],
     platform_apis: true,
     test_suites: ["device-tests"],
     certificate: "platform",
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 59fd8bd..e4e9e69 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -17,12 +17,17 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.providers.telephony.tests">
 
+    <!-- Permissions required for reading and logging compat changes -->
+    <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE"/>
+    <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG"/>
+    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
+
     <application>
         <uses-library android:name="android.test.runner" />
     </application>
 
     <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
-        android:targetPackage="com.android.providers.telephony"
+        android:targetPackage="com.android.providers.telephony.tests"
         android:label="Tests for TelephonyProvider">
     </instrumentation>
 </manifest>
diff --git a/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java b/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java
index f8cc8a6..f6a9c7f 100644
--- a/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java
@@ -43,6 +43,8 @@
 import android.util.JsonWriter;
 import android.util.SparseArray;
 
+import com.android.internal.telephony.PhoneFactory;
+
 import libcore.io.IoUtils;
 
 import com.google.android.mms.pdu.CharacterSets;
@@ -620,6 +622,7 @@
      */
     public void testRestoreSms_WithException() throws Exception {
         mTelephonyBackupAgent.initUnknownSender();
+        PhoneFactory.addLocalLog("DeferredSmsMmsRestoreService", 1);
         JsonReader jsonReader = new JsonReader(new StringReader(addRandomDataToJson(mAllSmsJson)));
         FakeSmsProvider smsProvider = new FakeSmsProvider(mSmsRows, false);
         mMockContentResolver.addProvider("sms", smsProvider);
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index 37ba7ec..1a9b46c 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -45,7 +45,6 @@
 import android.telephony.TelephonyManager;
 import android.test.mock.MockContentResolver;
 import android.test.mock.MockContext;
-import android.test.mock.MockResources;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.text.TextUtils;
 import android.util.Log;
@@ -54,11 +53,14 @@
 
 import junit.framework.TestCase;
 
+import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.MockitoAnnotations;
 import org.mockito.Mock;
 import static org.mockito.Mockito.when;
 
+import com.android.internal.telephony.PhoneFactory;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -1647,6 +1649,7 @@
         assertEquals(1, cursor.getCount());
         cursor.moveToFirst();
         assertEquals(otherName, cursor.getString(0));
+        PhoneFactory.addLocalLog("TelephonyProvider", 1);
     }
 
     /**