Merge "Send identifier disclosure events to safety center" into main
diff --git a/src/java/com/android/internal/telephony/GsmCdmaPhone.java b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
index 3500a31..19851cd 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaPhone.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
@@ -550,7 +550,7 @@
             mIdentifierDisclosureNotifier =
                     mTelephonyComponentFactory
                             .inject(CellularIdentifierDisclosureNotifier.class.getName())
-                            .makeIdentifierDisclosureNotifier();
+                            .makeIdentifierDisclosureNotifier(mSafetySource);
             mCi.registerForCellularIdentifierDisclosures(
                     this, EVENT_CELL_IDENTIFIER_DISCLOSURE, null);
         }
@@ -3745,7 +3745,7 @@
                 if (mFeatureFlags.enableIdentifierDisclosureTransparencyUnsolEvents()
                         && mIdentifierDisclosureNotifier != null
                         && disclosure != null) {
-                    mIdentifierDisclosureNotifier.addDisclosure(getSubId(), disclosure);
+                    mIdentifierDisclosureNotifier.addDisclosure(mContext, getSubId(), disclosure);
                 }
                 break;
 
@@ -5388,11 +5388,11 @@
         // enable/disable API, so we only toggle the enable state if the unsol events feature
         // flag is enabled.
         if (mFeatureFlags.enableIdentifierDisclosureTransparencyUnsolEvents()) {
-          if (prefEnabled) {
-            mIdentifierDisclosureNotifier.enable();
-          } else {
-            mIdentifierDisclosureNotifier.disable();
-          }
+            if (prefEnabled) {
+                mIdentifierDisclosureNotifier.enable(mContext);
+            } else {
+                mIdentifierDisclosureNotifier.disable(mContext);
+            }
         } else {
             logi("Not toggling enable state for disclosure notifier. Feature flag "
                     + "enable_identifier_disclosure_transparency_unsol_events is disabled");
diff --git a/src/java/com/android/internal/telephony/TelephonyComponentFactory.java b/src/java/com/android/internal/telephony/TelephonyComponentFactory.java
index 5533c18..f5aa074 100644
--- a/src/java/com/android/internal/telephony/TelephonyComponentFactory.java
+++ b/src/java/com/android/internal/telephony/TelephonyComponentFactory.java
@@ -583,8 +583,9 @@
     }
 
     /** Create CellularIdentifierDisclosureNotifier. */
-    public CellularIdentifierDisclosureNotifier makeIdentifierDisclosureNotifier() {
-        return CellularIdentifierDisclosureNotifier.getInstance();
+    public CellularIdentifierDisclosureNotifier makeIdentifierDisclosureNotifier(
+            CellularNetworkSecuritySafetySource safetySource) {
+        return CellularIdentifierDisclosureNotifier.getInstance(safetySource);
     }
 
     /** Create NullCipherNotifier. */
diff --git a/src/java/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifier.java b/src/java/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifier.java
index e7f66a3..4540b8a 100644
--- a/src/java/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifier.java
+++ b/src/java/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifier.java
@@ -16,6 +16,7 @@
 
 package com.android.internal.telephony.security;
 
+import android.content.Context;
 import android.telephony.CellularIdentifierDisclosure;
 
 import com.android.internal.annotations.GuardedBy;
@@ -49,6 +50,7 @@
     private static CellularIdentifierDisclosureNotifier sInstance = null;
     private final long mWindowCloseDuration;
     private final TimeUnit mWindowCloseUnit;
+    private final CellularNetworkSecuritySafetySource mSafetySource;
     private final Object mEnabledLock = new Object();
 
     @GuardedBy("mEnabledLock")
@@ -61,11 +63,12 @@
     // outside of that thread would require additional synchronization.
     private Map<Integer, DisclosureWindow> mWindows;
 
-    public CellularIdentifierDisclosureNotifier() {
+    public CellularIdentifierDisclosureNotifier(CellularNetworkSecuritySafetySource safetySource) {
         this(
                 Executors.newSingleThreadScheduledExecutor(),
                 DEFAULT_WINDOW_CLOSE_DURATION_IN_MINUTES,
-                TimeUnit.MINUTES);
+                TimeUnit.MINUTES,
+                safetySource);
     }
 
     /**
@@ -79,18 +82,20 @@
     public CellularIdentifierDisclosureNotifier(
             ScheduledExecutorService notificationQueue,
             long windowCloseDuration,
-            TimeUnit windowCloseUnit) {
+            TimeUnit windowCloseUnit,
+            CellularNetworkSecuritySafetySource safetySource) {
         mSerializedWorkQueue = notificationQueue;
         mWindowCloseDuration = windowCloseDuration;
         mWindowCloseUnit = windowCloseUnit;
         mWindows = new HashMap<>();
+        mSafetySource = safetySource;
     }
 
     /**
      * Add a CellularIdentifierDisclosure to be tracked by this instance. If appropriate, this will
      * trigger a user notification.
      */
-    public void addDisclosure(int subId, CellularIdentifierDisclosure disclosure) {
+    public void addDisclosure(Context context, int subId, CellularIdentifierDisclosure disclosure) {
         Rlog.d(TAG, "Identifier disclosure reported: " + disclosure);
 
         synchronized (mEnabledLock) {
@@ -111,7 +116,7 @@
             // because we know that any actions taken on disabled will be scheduled after this
             // incrementAndNotify call.
             try {
-                mSerializedWorkQueue.execute(incrementAndNotify(subId));
+                mSerializedWorkQueue.execute(incrementAndNotify(context, subId));
             } catch (RejectedExecutionException e) {
                 Rlog.e(TAG, "Failed to schedule incrementAndNotify: " + e.getMessage());
             }
@@ -122,12 +127,12 @@
      * Re-enable if previously disabled. This means that {@code addDisclsoure} will start tracking
      * disclosures again and potentially emitting notifications.
      */
-    public void enable() {
+    public void enable(Context context) {
         synchronized (mEnabledLock) {
             Rlog.d(TAG, "enabled");
             mEnabled = true;
             try {
-                mSerializedWorkQueue.execute(onEnableNotifier());
+                mSerializedWorkQueue.execute(onEnableNotifier(context));
             } catch (RejectedExecutionException e) {
                 Rlog.e(TAG, "Failed to schedule onEnableNotifier: " + e.getMessage());
             }
@@ -139,12 +144,12 @@
      * This can be used to in response to a user disabling the feature to emit notifications.
      * If {@code addDisclosure} is called while in a disabled state, disclosures will be dropped.
      */
-    public void disable() {
+    public void disable(Context context) {
         Rlog.d(TAG, "disabled");
         synchronized (mEnabledLock) {
             mEnabled = false;
             try {
-                mSerializedWorkQueue.execute(onDisableNotifier());
+                mSerializedWorkQueue.execute(onDisableNotifier(context));
             } catch (RejectedExecutionException e) {
                 Rlog.e(TAG, "Failed to schedule onDisableNotifier: " + e.getMessage());
             }
@@ -158,15 +163,16 @@
     }
 
     /** Get a singleton CellularIdentifierDisclosureNotifier. */
-    public static synchronized CellularIdentifierDisclosureNotifier getInstance() {
+    public static synchronized CellularIdentifierDisclosureNotifier getInstance(
+            CellularNetworkSecuritySafetySource safetySource) {
         if (sInstance == null) {
-            sInstance = new CellularIdentifierDisclosureNotifier();
+            sInstance = new CellularIdentifierDisclosureNotifier(safetySource);
         }
 
         return sInstance;
     }
 
-    private Runnable incrementAndNotify(int subId) {
+    private Runnable incrementAndNotify(Context context, int subId) {
         return () -> {
             DisclosureWindow window = mWindows.get(subId);
             if (window == null) {
@@ -174,7 +180,7 @@
                 mWindows.put(subId, window);
             }
 
-            window.increment(this);
+            window.increment(context, this);
 
             int disclosureCount = window.getDisclosureCount();
 
@@ -185,31 +191,29 @@
                             + ". New disclosure count "
                             + disclosureCount);
 
-            // TODO (b/308985417) emit safety center issue
-            //            mSafetySource.setIdentifierDisclosure(
-            //                    subId,
-            //                    disclosureCount,
-            //                    window.getFirstOpen(),
-            //                    window.getCurrentEnd());
+            mSafetySource.setIdentifierDisclosure(
+                    context,
+                    subId,
+                    disclosureCount,
+                    window.getFirstOpen(),
+                    window.getCurrentEnd());
         };
     }
 
-    private Runnable onDisableNotifier() {
+    private Runnable onDisableNotifier(Context context) {
         return () -> {
             Rlog.d(TAG, "On disable notifier");
             for (DisclosureWindow window : mWindows.values()) {
                 window.close();
             }
-            // TODO (b/308985417) disable safety center issues
-            // mSafetySource.setIdentifierDisclosureIssueEnabled(false);
+            mSafetySource.setIdentifierDisclosureIssueEnabled(context, false);
         };
     }
 
-    private Runnable onEnableNotifier() {
+    private Runnable onEnableNotifier(Context context) {
         return () -> {
             Rlog.i(TAG, "On enable notifier");
-            // TODO (b/308985417) enable safety center issues
-            // mSafetySource.setIdentifierDisclosureIssueEnabled(true);
+            mSafetySource.setIdentifierDisclosureIssueEnabled(context, true);
         };
     }
 
@@ -262,7 +266,7 @@
      * A helper class that maintains all state associated with the disclosure window for a single
      * subId. No methods are thread safe. Callers must implement all synchronization.
      */
-    private static class DisclosureWindow {
+    private class DisclosureWindow {
         private int mDisclosureCount;
         private Instant mWindowFirstOpen;
         private Instant mLastEvent;
@@ -278,7 +282,7 @@
             mWhenWindowCloses = null;
         }
 
-        void increment(CellularIdentifierDisclosureNotifier notifier) {
+        void increment(Context context, CellularIdentifierDisclosureNotifier notifier) {
 
             mDisclosureCount++;
 
@@ -295,7 +299,7 @@
             try {
                 mWhenWindowCloses =
                         notifier.mSerializedWorkQueue.schedule(
-                                closeWindowRunnable(),
+                                closeWindowRunnable(context),
                                 notifier.mWindowCloseDuration,
                                 notifier.mWindowCloseUnit);
             } catch (RejectedExecutionException e) {
@@ -331,7 +335,7 @@
             mWhenWindowCloses = null;
         }
 
-        private Runnable closeWindowRunnable() {
+        private Runnable closeWindowRunnable(Context context) {
             return () -> {
                 Rlog.i(
                         TAG,
@@ -340,9 +344,7 @@
                                 + ". Disclosure count was "
                                 + getDisclosureCount());
                 close();
-
-                // TODO (b/308985417) clear safety center issue
-                // mSafetySource.setIdentifierDisclosure(mSubId, 0, null, null);
+                mSafetySource.clearIdentifierDisclosure(context, mSubId);
             };
         }
 
diff --git a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java
index a903a34..e493a18 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java
@@ -2868,7 +2868,10 @@
 
     @Test
     public void testCellularIdentifierDisclosure_disclosureEventAddedToNotifier() {
+        int phoneId = 0;
+        int subId = 10;
         when(mFeatureFlags.enableIdentifierDisclosureTransparencyUnsolEvents()).thenReturn(true);
+        when(mSubscriptionManagerService.getSubId(phoneId)).thenReturn(subId);
 
         Phone phoneUT =
                 new GsmCdmaPhone(
@@ -2876,7 +2879,7 @@
                         mMockCi,
                         mNotifier,
                         true,
-                        0,
+                        phoneId,
                         PhoneConstants.PHONE_TYPE_GSM,
                         mTelephonyComponentFactory,
                         (c, p) -> mImsManager,
@@ -2895,20 +2898,22 @@
         processAllMessages();
 
         verify(mIdentifierDisclosureNotifier, times(1))
-                .addDisclosure(eq(mPhoneUT.getSubId()), eq(disclosure));
+                .addDisclosure(eq(mContext), eq(subId), eq(disclosure));
     }
 
     @Test
     public void testCellularIdentifierDisclosure_disclosureEventNull() {
+        int phoneId = 4;
+        int subId = 6;
         when(mFeatureFlags.enableIdentifierDisclosureTransparencyUnsolEvents()).thenReturn(true);
-
+        when(mSubscriptionManagerService.getSubId(phoneId)).thenReturn(subId);
         Phone phoneUT =
                 new GsmCdmaPhone(
                         mContext,
                         mMockCi,
                         mNotifier,
                         true,
-                        0,
+                        phoneId,
                         PhoneConstants.PHONE_TYPE_GSM,
                         mTelephonyComponentFactory,
                         (c, p) -> mImsManager,
@@ -2920,7 +2925,7 @@
         processAllMessages();
 
         verify(mIdentifierDisclosureNotifier, never())
-                .addDisclosure(eq(mPhoneUT.getSubId()), any(CellularIdentifierDisclosure.class));
+                .addDisclosure(eq(mContext), eq(subId), any(CellularIdentifierDisclosure.class));
     }
 
     @Test
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
index 37b6416..cc33a9e 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
@@ -683,7 +683,7 @@
                 .makeCellularNetworkSecuritySafetySource(any(Context.class));
         doReturn(mIdentifierDisclosureNotifier)
                 .when(mTelephonyComponentFactory)
-                .makeIdentifierDisclosureNotifier();
+                .makeIdentifierDisclosureNotifier(any(CellularNetworkSecuritySafetySource.class));
         doReturn(mNullCipherNotifier)
                 .when(mTelephonyComponentFactory)
                 .makeNullCipherNotifier();
diff --git a/tests/telephonytests/src/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifierTest.java b/tests/telephonytests/src/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifierTest.java
index 582c658..8841c7a 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifierTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/security/CellularIdentifierDisclosureNotifierTest.java
@@ -20,13 +20,24 @@
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
+import android.content.Context;
 import android.telephony.CellularIdentifierDisclosure;
 
 import com.android.internal.telephony.TestExecutorService;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.InOrder;
 
 import java.util.concurrent.TimeUnit;
 
@@ -38,6 +49,9 @@
     private static final int SUB_ID_1 = 1;
     private static final int SUB_ID_2 = 2;
     private CellularIdentifierDisclosure mDislosure;
+    private CellularNetworkSecuritySafetySource mSafetySource;
+    private Context mContext;
+    private InOrder mInOrder;
 
     @Before
     public void setUp() {
@@ -47,33 +61,41 @@
                         CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMSI,
                         "001001",
                         false);
+        mSafetySource = mock(CellularNetworkSecuritySafetySource.class);
+        mInOrder = inOrder(mSafetySource);
     }
 
     @Test
     public void testInitializeDisabled() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
         assertFalse(notifier.isEnabled());
+        verify(mSafetySource, never()).setIdentifierDisclosureIssueEnabled(any(), anyBoolean());
     }
 
     @Test
     public void testDisableAddDisclosureNop() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
         assertFalse(notifier.isEnabled());
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        verify(mSafetySource, never())
+                .setIdentifierDisclosure(any(), anyInt(), anyInt(), any(), any());
     }
 
     @Test
     public void testAddDisclosureEmergencyNop() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
         CellularIdentifierDisclosure emergencyDisclosure =
                 new CellularIdentifierDisclosure(
                         CellularIdentifierDisclosure.NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST,
@@ -81,116 +103,161 @@
                         "001001",
                         true);
 
-        notifier.enable();
-        notifier.addDisclosure(SUB_ID_1, emergencyDisclosure);
+        notifier.enable(mContext);
+        notifier.addDisclosure(mContext, SUB_ID_1, emergencyDisclosure);
 
         assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        verify(mSafetySource, never())
+                .setIdentifierDisclosure(any(), anyInt(), anyInt(), any(), any());
     }
 
     @Test
     public void testAddDisclosureCountIncrements() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
-        notifier.enable();
+        notifier.enable(mContext);
 
         for (int i = 0; i < 3; i++) {
-            notifier.addDisclosure(SUB_ID_1, mDislosure);
+            notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         }
 
         assertEquals(3, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(3), any(), any());
     }
 
     @Test
     public void testSingleDisclosureStartAndEndTimesAreEqual() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
-        notifier.enable();
+        notifier.enable(mContext);
 
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
 
         assertEquals(1, notifier.getCurrentDisclosureCount(SUB_ID_1));
         assertTrue(notifier.getFirstOpen(SUB_ID_1).equals(notifier.getCurrentEnd(SUB_ID_1)));
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
     }
 
     @Test
     public void testMultipleDisclosuresTimeWindows() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
-        notifier.enable();
+        notifier.enable(mContext);
 
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         try {
             Thread.sleep(50);
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
 
         assertEquals(2, notifier.getCurrentDisclosureCount(SUB_ID_1));
         assertTrue(notifier.getFirstOpen(SUB_ID_1).isBefore(notifier.getCurrentEnd(SUB_ID_1)));
+        verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
     }
 
     @Test
     public void testAddDisclosureThenWindowClose() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
         // One round of disclosures
-        notifier.enable();
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.enable(mContext);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         assertEquals(2, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
 
         // Window close should reset the counter
         executor.advanceTime(WINDOW_CLOSE_ADVANCE_MILLIS);
         assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
 
         // A new disclosure should increment as normal
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         assertEquals(1, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
     }
 
     @Test
     public void testDisableClosesWindow() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
         // One round of disclosures
-        notifier.enable();
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.enable(mContext);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         assertEquals(2, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
 
-        notifier.disable();
+        notifier.disable(mContext);
         assertFalse(notifier.isEnabled());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosureIssueEnabled(any(), eq(false));
 
         // We're disabled now so no disclosures should open the disclosure window
-        notifier.addDisclosure(SUB_ID_1, mDislosure);
+        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
+        mInOrder.verifyNoMoreInteractions();
     }
 
     @Test
     public void testMultipleSubIdsTrackedIndependently() {
         TestExecutorService executor = new TestExecutorService();
         CellularIdentifierDisclosureNotifier notifier =
-                new CellularIdentifierDisclosureNotifier(executor, 15, TimeUnit.MINUTES);
+                new CellularIdentifierDisclosureNotifier(
+                        executor, 15, TimeUnit.MINUTES, mSafetySource);
 
-        notifier.enable();
+        notifier.enable(mContext);
         for (int i = 0; i < 3; i++) {
-            notifier.addDisclosure(SUB_ID_1, mDislosure);
+            notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
         }
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(3), any(), any());
 
         for (int i = 0; i < 4; i++) {
-            notifier.addDisclosure(SUB_ID_2, mDislosure);
+            notifier.addDisclosure(mContext, SUB_ID_2, mDislosure);
         }
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(1), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(2), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(3), any(), any());
+        mInOrder.verify(mSafetySource, times(1))
+                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(4), any(), any());
 
         assertEquals(3, notifier.getCurrentDisclosureCount(SUB_ID_1));
         assertEquals(4, notifier.getCurrentDisclosureCount(SUB_ID_2));