Wipe carrier certificates in SubscriptionInfoUpdater
so that when certificates are wiped, we also wipe them from
accessRules

Test: CtsNetTestCasesLatestSdk:ConnectivityDiagnosticsManagerTest#testRegisterCallbackWithCarrierPrivileges --rerun-until-failure 20
Bug: 162700101
Change-Id: I9d4a69038e85cbdd8928da697b6c7f0dde8bbb58
Merged-In: I9d4a69038e85cbdd8928da697b6c7f0dde8bbb58
diff --git a/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java b/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java
index 5d7ad9a..7065e00 100644
--- a/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java
+++ b/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java
@@ -1050,15 +1050,16 @@
         // this current package is not a CarrierServicePackage
         String[] certs = config.getStringArray(
             CarrierConfigManager.KEY_CARRIER_CERTIFICATE_STRING_ARRAY);
+        UiccAccessRule[] carrierConfigAccessRules = null;
         if (certs != null) {
-            UiccAccessRule[] carrierConfigAccessRules = new UiccAccessRule[certs.length];
+            carrierConfigAccessRules = new UiccAccessRule[certs.length];
             for (int i = 0; i < certs.length; i++) {
                 carrierConfigAccessRules[i] = new UiccAccessRule(IccUtils.hexStringToBytes(
                     certs[i]), null, 0);
             }
-            cv.put(SubscriptionManager.ACCESS_RULES_FROM_CARRIER_CONFIGS,
-                    UiccAccessRule.encodeRules(carrierConfigAccessRules));
         }
+        cv.put(SubscriptionManager.ACCESS_RULES_FROM_CARRIER_CONFIGS,
+                UiccAccessRule.encodeRules(carrierConfigAccessRules));
 
         if (!isCarrierServicePackage(phoneId, configPackageName)) {
             loge("Cannot manage subId=" + currentSubId + ", carrierPackage=" + configPackageName);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/SubscriptionInfoUpdaterTest.java b/tests/telephonytests/src/com/android/internal/telephony/SubscriptionInfoUpdaterTest.java
index ce5be8e..fe60ecb 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/SubscriptionInfoUpdaterTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/SubscriptionInfoUpdaterTest.java
@@ -725,9 +725,10 @@
         mUpdater.updateSubscriptionByCarrierConfig(mPhone.getPhoneId(),
                 carrierPackageName, new PersistableBundle());
 
-        verify(mContentProvider, never()).update(any(), any(), any(), any());
-        verify(mSubscriptionController, never()).refreshCachedActiveSubscriptionInfoList();
-        verify(mSubscriptionController, never()).notifySubscriptionInfoChanged();
+        //at each call to updateSubscriptionByCarrierConfig, only carrier certs are updated
+        verify(mContentProvider, times(1)).update(any(), any(), any(), any());
+        verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
+        verify(mSubscriptionController, times(1)).refreshCachedActiveSubscriptionInfoList();
     }
 
     @Test
@@ -756,7 +757,8 @@
                 cvCaptor.capture(), eq(null), eq(null));
         assertEquals(1, cvCaptor.getValue().getAsInteger(
                 SubscriptionManager.IS_OPPORTUNISTIC).intValue());
-        assertEquals(1, cvCaptor.getValue().size());
+        // 2 updates: isOpportunistic, and carrier certs:
+        assertEquals(2, cvCaptor.getValue().size());
         verify(mSubscriptionController, times(1)).refreshCachedActiveSubscriptionInfoList();
         verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
     }
@@ -792,7 +794,8 @@
                 cvCaptor.getValue().getAsString(SubscriptionManager.GROUP_UUID));
         assertEquals(carrierPackageName,
                 cvCaptor.getValue().getAsString(SubscriptionManager.GROUP_OWNER));
-        assertEquals(3, cvCaptor.getValue().size());
+        // 4 updates: isOpportunistic, groupUuid, groupOwner, and carrier certs:
+        assertEquals(4, cvCaptor.getValue().size());
     }
 
     @Test
@@ -825,7 +828,8 @@
         assertEquals(1, cvCaptor.getValue().getAsInteger(
                 SubscriptionManager.IS_OPPORTUNISTIC).intValue());
         assertNull(cvCaptor.getValue().getAsString(SubscriptionManager.GROUP_UUID));
-        assertEquals(2, cvCaptor.getValue().size());
+        // 3 updates: isOpportunistic, groupUuid, and carrier certs:
+        assertEquals(3, cvCaptor.getValue().size());
     }
 
     @Test