Snap for 8681172 from 529cd5265bd8b0c468f3fcb8f46b9756b5d3350e to tm-release

Change-Id: I0ea34fc54cc0cf20a2e53d6e8e64b7584f127325
diff --git a/src/com/android/providers/contacts/CallLogProvider.java b/src/com/android/providers/contacts/CallLogProvider.java
index b267483..da2d0b8 100644
--- a/src/com/android/providers/contacts/CallLogProvider.java
+++ b/src/com/android/providers/contacts/CallLogProvider.java
@@ -54,6 +54,7 @@
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
+import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
@@ -1349,8 +1350,11 @@
             PhoneAccountHandle phoneAccountHandle = (PhoneAccountHandle) arg;
             String iccId = null;
             try {
-                iccId = mSubscriptionManager.getActiveSubscriptionInfo(
-                    Integer.parseInt(phoneAccountHandle.getId())).getIccId();
+                SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(
+                        Integer.parseInt(phoneAccountHandle.getId()));
+                if (info != null) {
+                    iccId = info.getIccId();
+                }
             } catch (NumberFormatException nfe) {
                 // Ignore the exception, iccId will remain null and be handled below.
             }
diff --git a/tests/src/com/android/providers/contacts/CallLogProviderTest.java b/tests/src/com/android/providers/contacts/CallLogProviderTest.java
index c755582..a0a8483 100644
--- a/tests/src/com/android/providers/contacts/CallLogProviderTest.java
+++ b/tests/src/com/android/providers/contacts/CallLogProviderTest.java
@@ -18,6 +18,8 @@
 
 import static android.provider.CallLog.Calls.MISSED_REASON_NOT_MISSED;
 
+import static com.android.providers.contacts.ContactsProvider2.BACKGROUND_TASK_MIGRATE_PHONE_ACCOUNT_HANDLES;
+
 import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.when;
 
@@ -736,6 +738,16 @@
         assertEquals(10, mCallLogProvider.getLastSyncTime(/* forShadow =*/ false));
     }
 
+    public void testNullSubscriptionInfo() {
+        PhoneAccountHandle handle = new PhoneAccountHandle(new ComponentName(
+                TELEPHONY_PACKAGE, TELEPHONY_CLASS), TEST_PHONE_ACCOUNT_HANDLE_SUB_ID);
+        when(mSubscriptionManager.getActiveSubscriptionInfo(eq(
+                Integer.parseInt(TEST_PHONE_ACCOUNT_HANDLE_SUB_ID)))).thenReturn(null);
+
+        mCallLogProvider.performBackgroundTask(
+                BACKGROUND_TASK_MIGRATE_PHONE_ACCOUNT_HANDLES, handle);
+    }
+
     private ContentValues getDefaultValues(int callType) {
         ContentValues values = new ContentValues();
         values.put(Calls.TYPE, callType);