• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.adservices.data.measurement;
18 
19 import android.adservices.measurement.DeletionRequest;
20 import android.net.Uri;
21 import android.util.Pair;
22 
23 import androidx.annotation.NonNull;
24 import androidx.annotation.Nullable;
25 
26 import com.android.adservices.service.measurement.Attribution;
27 import com.android.adservices.service.measurement.EventReport;
28 import com.android.adservices.service.measurement.EventSurfaceType;
29 import com.android.adservices.service.measurement.KeyValueData;
30 import com.android.adservices.service.measurement.KeyValueData.DataType;
31 import com.android.adservices.service.measurement.Source;
32 import com.android.adservices.service.measurement.Trigger;
33 import com.android.adservices.service.measurement.aggregation.AggregateEncryptionKey;
34 import com.android.adservices.service.measurement.aggregation.AggregateReport;
35 import com.android.adservices.service.measurement.registration.AsyncRegistration;
36 import com.android.adservices.service.measurement.reporting.DebugReport;
37 
38 import java.time.Instant;
39 import java.util.Collection;
40 import java.util.List;
41 import java.util.Optional;
42 import java.util.Set;
43 
44 /** Interface for Measurement related data access operations. */
45 public interface IMeasurementDao {
46     /** Set the transaction. */
setTransaction(ITransaction transaction)47     void setTransaction(ITransaction transaction);
48 
49     /** Add an entry to the Trigger datastore. */
insertTrigger(Trigger trigger)50     void insertTrigger(Trigger trigger) throws DatastoreException;
51 
52     /** Returns list of ids for all pending {@link Trigger}. */
getPendingTriggerIds()53     List<String> getPendingTriggerIds() throws DatastoreException;
54 
55     /**
56      * Queries and returns the {@link Source}.
57      *
58      * @param sourceId ID of the requested Source
59      * @return the requested Source
60      */
getSource(@onNull String sourceId)61     Source getSource(@NonNull String sourceId) throws DatastoreException;
62 
63     /**
64      * Queries and returns the {@link Source}'s destinations.
65      *
66      * @param sourceId ID of the requested Source
67      * @return a Pair of lists of app destination and web destination Uris
68      */
getSourceDestinations(@onNull String sourceId)69     Pair<List<Uri>, List<Uri>> getSourceDestinations(@NonNull String sourceId)
70             throws DatastoreException;
71 
72     /**
73      * Queries and returns the {@link Trigger}.
74      *
75      * @param triggerId Id of the request Trigger
76      * @return the requested Trigger
77      */
getTrigger(String triggerId)78     Trigger getTrigger(String triggerId) throws DatastoreException;
79 
80     /**
81      * Fetches the count of aggregate reports for the provided destination.
82      *
83      * @param attributionDestination Uri for the destination
84      * @param destinationType DestinationType App/Web
85      * @return number of aggregate reports in the database attributed to the provided destination
86      */
getNumAggregateReportsPerDestination( @onNull Uri attributionDestination, @EventSurfaceType int destinationType)87     int getNumAggregateReportsPerDestination(
88             @NonNull Uri attributionDestination, @EventSurfaceType int destinationType)
89             throws DatastoreException;
90 
91     /**
92      * Fetches the count of event reports for the provided destination.
93      *
94      * @param attributionDestination Uri for the destination
95      * @param destinationType DestinationType App/Web
96      * @return number of event reports in the database attributed to the provided destination
97      */
getNumEventReportsPerDestination( @onNull Uri attributionDestination, @EventSurfaceType int destinationType)98     int getNumEventReportsPerDestination(
99             @NonNull Uri attributionDestination, @EventSurfaceType int destinationType)
100             throws DatastoreException;
101 
102     /**
103      * Gets the number of sources associated to a publisher.
104      *
105      * @param publisherUri Uri for the publisher
106      * @param publisherType PublisherType App/Web
107      * @return Number of sources registered for the given publisher
108      */
getNumSourcesPerPublisher(Uri publisherUri, @EventSurfaceType int publisherType)109     long getNumSourcesPerPublisher(Uri publisherUri, @EventSurfaceType int publisherType)
110             throws DatastoreException;
111 
112     /** Gets the number of triggers associated to a destination. */
getNumTriggersPerDestination(Uri destination, @EventSurfaceType int destinationType)113     long getNumTriggersPerDestination(Uri destination, @EventSurfaceType int destinationType)
114             throws DatastoreException;
115 
116     /**
117      * Gets the count of distinct IDs of enrollments in the Attribution table in a time window with
118      * matching publisher and destination, excluding a given enrollment ID.
119      */
countDistinctEnrollmentsPerPublisherXDestinationInAttribution( Uri sourceSite, Uri destination, String excludedEnrollmentId, long windowStartTime, long windowEndTime)120     Integer countDistinctEnrollmentsPerPublisherXDestinationInAttribution(
121             Uri sourceSite,
122             Uri destination,
123             String excludedEnrollmentId,
124             long windowStartTime,
125             long windowEndTime)
126             throws DatastoreException;
127 
128     /**
129      * Gets the count of distinct Uri's of destinations in the Source table in a time window with
130      * matching publisher, enrollment, and ACTIVE status, excluding a given destination.
131      */
countDistinctDestinationsPerPublisherXEnrollmentInActiveSource( Uri publisher, @EventSurfaceType int publisherType, String enrollmentId, List<Uri> excludedDestinations, @EventSurfaceType int destinationType, long windowStartTime, long windowEndTime)132     Integer countDistinctDestinationsPerPublisherXEnrollmentInActiveSource(
133             Uri publisher,
134             @EventSurfaceType int publisherType,
135             String enrollmentId,
136             List<Uri> excludedDestinations,
137             @EventSurfaceType int destinationType,
138             long windowStartTime,
139             long windowEndTime)
140             throws DatastoreException;
141 
142     /**
143      * Gets the count of sources in the source table in a time period before event time with
144      * matching publisher, enrollment, excluding the given registration origin.
145      */
countSourcesPerPublisherXEnrollmentExcludingRegOrigin( Uri registrationOrigin, Uri publisher, @EventSurfaceType int publisherType, String enrollmentId, long eventTime, long timePeriodInMs)146     Integer countSourcesPerPublisherXEnrollmentExcludingRegOrigin(
147             Uri registrationOrigin,
148             Uri publisher,
149             @EventSurfaceType int publisherType,
150             String enrollmentId,
151             long eventTime,
152             long timePeriodInMs)
153             throws DatastoreException;
154 
155     /**
156      * Gets the count of distinct IDs of enrollments in the Source table in a time window with
157      * matching publisher and destination, excluding a given enrollment ID.
158      */
countDistinctEnrollmentsPerPublisherXDestinationInSource( Uri publisher, @EventSurfaceType int publisherType, List<Uri> destinations, String excludedEnrollmentId, long windowStartTime, long windowEndTime)159     Integer countDistinctEnrollmentsPerPublisherXDestinationInSource(
160             Uri publisher,
161             @EventSurfaceType int publisherType,
162             List<Uri> destinations,
163             String excludedEnrollmentId,
164             long windowStartTime,
165             long windowEndTime)
166             throws DatastoreException;
167 
168     /**
169      * Updates the {@link Trigger.Status} value for the provided {@link Trigger}.
170      *
171      * @param triggerIds trigger to update
172      * @param status status to apply
173      * @throws DatastoreException database transaction related issues
174      */
updateTriggerStatus(@onNull List<String> triggerIds, @Trigger.Status int status)175     void updateTriggerStatus(@NonNull List<String> triggerIds, @Trigger.Status int status)
176             throws DatastoreException;
177 
178     /**
179      * Add an entry to the Source datastore.
180      *
181      * @param source Source data to be inserted.
182      */
insertSource(Source source)183     void insertSource(Source source) throws DatastoreException;
184 
185     /**
186      * Queries and returns the list of matching {@link Source} for the provided {@link Trigger}.
187      *
188      * @return list of active matching sources; Null in case of SQL failure
189      */
getMatchingActiveSources(Trigger trigger)190     List<Source> getMatchingActiveSources(Trigger trigger) throws DatastoreException;
191 
192     /**
193      * Queries and returns the most recent matching delayed {@link Source} (Optional) for the
194      * provided {@link Trigger}.
195      */
getNearestDelayedMatchingActiveSource(@onNull Trigger trigger)196     Optional<Source> getNearestDelayedMatchingActiveSource(@NonNull Trigger trigger)
197             throws DatastoreException;
198 
199     /**
200      * Updates the {@link Source.Status} value for the provided list of {@link Source}
201      *
202      * @param sourceIds list of sources.
203      * @param status value to be set
204      */
updateSourceStatus(@onNull List<String> sourceIds, @Source.Status int status)205     void updateSourceStatus(@NonNull List<String> sourceIds, @Source.Status int status)
206             throws DatastoreException;
207 
208     /**
209      * Update the value of {@link Source.Status} for the corresponding {@link Source}
210      *
211      * @param source the {@link Source} object.
212      */
updateSourceEventReportDedupKeys(@onNull Source source)213     void updateSourceEventReportDedupKeys(@NonNull Source source) throws DatastoreException;
214 
215     /**
216      * Update the set of Aggregate dedup keys contained in the provided {@link Source}
217      *
218      * @param source the {@link Source} object.
219      */
updateSourceAggregateReportDedupKeys(@onNull Source source)220     void updateSourceAggregateReportDedupKeys(@NonNull Source source) throws DatastoreException;
221 
222     /**
223      * Updates the value of aggregate contributions for the corresponding {@link Source}
224      *
225      * @param source the {@link Source} object.
226      */
updateSourceAggregateContributions(@onNull Source source)227     void updateSourceAggregateContributions(@NonNull Source source) throws DatastoreException;
228 
229     /**
230      * Returns list of all the reports associated with the {@link Source}.
231      *
232      * @param source for querying reports
233      * @return list of relevant eventReports
234      */
getSourceEventReports(Source source)235     List<EventReport> getSourceEventReports(Source source) throws DatastoreException;
236 
237     /**
238      * Queries and returns the {@link EventReport}.
239      *
240      * @param eventReportId Id of the request Event Report
241      * @return the requested Event Report; Null in case of SQL failure
242      */
243     @Nullable
getEventReport(String eventReportId)244     EventReport getEventReport(String eventReportId) throws DatastoreException;
245 
246     /**
247      * Queries and returns the {@link AggregateReport}
248      *
249      * @param aggregateReportId Id of the request Aggregate Report
250      * @return the request Aggregate Report; Null in case of SQL failure
251      */
252     @Nullable
getAggregateReport(String aggregateReportId)253     AggregateReport getAggregateReport(String aggregateReportId) throws DatastoreException;
254 
255     /**
256      * Queries and returns the {@link DebugReport}
257      *
258      * @param debugReportId of the request Debug Report
259      * @return the request Debug Report; Null in case of SQL failure
260      */
261     @Nullable
getDebugReport(String debugReportId)262     DebugReport getDebugReport(String debugReportId) throws DatastoreException;
263 
264     /**
265      * Change the status of an event report to DELIVERED
266      *
267      * @param eventReportId the id of the event report to be updated
268      * @param status status of the event report
269      */
markEventReportStatus(String eventReportId, @EventReport.Status int status)270     void markEventReportStatus(String eventReportId, @EventReport.Status int status)
271             throws DatastoreException;
272 
273     /**
274      * Change the status of an event debug report to DELIVERED
275      *
276      * @param eventReportId the id of the event report to be updated
277      */
markEventDebugReportDelivered(String eventReportId)278     void markEventDebugReportDelivered(String eventReportId) throws DatastoreException;
279 
280     /**
281      * Change the status of an aggregate report to DELIVERED
282      *
283      * @param aggregateReportId the id of the event report to be updated
284      * @param status new status to set
285      */
markAggregateReportStatus(String aggregateReportId, @AggregateReport.Status int status)286     void markAggregateReportStatus(String aggregateReportId, @AggregateReport.Status int status)
287             throws DatastoreException;
288 
289     /**
290      * Change the status of an aggregate debug report to DELIVERED
291      *
292      * @param aggregateReportId the id of the event report to be updated
293      */
markAggregateDebugReportDelivered(String aggregateReportId)294     void markAggregateDebugReportDelivered(String aggregateReportId) throws DatastoreException;
295 
296     /** Saves the {@link EventReport} to datastore. */
insertEventReport(EventReport eventReport)297     void insertEventReport(EventReport eventReport) throws DatastoreException;
298 
299     /** Deletes the {@link EventReport} from datastore. */
deleteEventReport(EventReport eventReport)300     void deleteEventReport(EventReport eventReport) throws DatastoreException;
301 
302     /** Deletes the {@link DebugReport} from datastore. */
deleteDebugReport(String debugReportId)303     void deleteDebugReport(String debugReportId) throws DatastoreException;
304 
305     /**
306      * Returns list of all event reports that have a scheduled reporting time in the given window.
307      */
getPendingEventReportIdsInWindow(long windowStartTime, long windowEndTime)308     List<String> getPendingEventReportIdsInWindow(long windowStartTime, long windowEndTime)
309             throws DatastoreException;
310 
311     /** Returns list of all debug event reports. */
getPendingDebugEventReportIds()312     List<String> getPendingDebugEventReportIds() throws DatastoreException;
313 
314     /** Returns list of all pending event reports for a given app right away. */
getPendingEventReportIdsForGivenApp(Uri appName)315     List<String> getPendingEventReportIdsForGivenApp(Uri appName) throws DatastoreException;
316 
317     /**
318      * Find the number of entries for a rate limit window using the {@link Source} and {@link
319      * Trigger}. Rate-Limit Window: (Source Site, Destination Site, Window) from triggerTime.
320      *
321      * @return the number of entries for the window.
322      */
getAttributionsPerRateLimitWindow(@onNull Source source, @NonNull Trigger trigger)323     long getAttributionsPerRateLimitWindow(@NonNull Source source, @NonNull Trigger trigger)
324             throws DatastoreException;
325 
326     /** Add an entry in Attribution datastore. */
insertAttribution(@onNull Attribution attribution)327     void insertAttribution(@NonNull Attribution attribution) throws DatastoreException;
328 
329     /**
330      * Deletes all records in measurement tables that correspond with the provided Uri.
331      *
332      * @param uri the Uri to match on
333      * @return if any entry was deleted.
334      */
deleteAppRecords(Uri uri)335     boolean deleteAppRecords(Uri uri) throws DatastoreException;
336 
337     /** Deletes all expired records in measurement tables. */
deleteExpiredRecords(long earliestValidInsertion)338     void deleteExpiredRecords(long earliestValidInsertion) throws DatastoreException;
339 
340     /**
341      * Mark relevant source as install attributed.
342      *
343      * @param uri package identifier
344      * @param eventTimestamp timestamp of installation event
345      */
doInstallAttribution(Uri uri, long eventTimestamp)346     void doInstallAttribution(Uri uri, long eventTimestamp) throws DatastoreException;
347 
348     /**
349      * Undo any install attributed source events.
350      *
351      * @param uri package identifier
352      */
undoInstallAttribution(Uri uri)353     void undoInstallAttribution(Uri uri) throws DatastoreException;
354 
355     /** Save aggregate encryption key to datastore. */
insertAggregateEncryptionKey(AggregateEncryptionKey aggregateEncryptionKey)356     void insertAggregateEncryptionKey(AggregateEncryptionKey aggregateEncryptionKey)
357             throws DatastoreException;
358 
359     /**
360      * Retrieve all aggregate encryption keys from the datastore whose expiry time is greater than
361      * or equal to {@code expiry}.
362      */
getNonExpiredAggregateEncryptionKeys(long expiry)363     List<AggregateEncryptionKey> getNonExpiredAggregateEncryptionKeys(long expiry)
364             throws DatastoreException;
365 
366     /** Remove aggregate encryption keys from the datastore older than {@code expiry}. */
deleteExpiredAggregateEncryptionKeys(long expiry)367     void deleteExpiredAggregateEncryptionKeys(long expiry) throws DatastoreException;
368 
369     /** Save unencrypted aggregate payload to datastore. */
insertAggregateReport(AggregateReport payload)370     void insertAggregateReport(AggregateReport payload) throws DatastoreException;
371 
372     /** Save debug report payload to datastore. */
insertDebugReport(DebugReport payload)373     void insertDebugReport(DebugReport payload) throws DatastoreException;
374 
375     /**
376      * Returns list of all aggregate reports that have a scheduled reporting time in the given
377      * window.
378      */
getPendingAggregateReportIdsInWindow(long windowStartTime, long windowEndTime)379     List<String> getPendingAggregateReportIdsInWindow(long windowStartTime, long windowEndTime)
380             throws DatastoreException;
381 
382     /** Returns list of all aggregate debug reports. */
getPendingAggregateDebugReportIds()383     List<String> getPendingAggregateDebugReportIds() throws DatastoreException;
384 
385     /** Returns list of all debug reports. */
getDebugReportIds()386     List<String> getDebugReportIds() throws DatastoreException;
387 
388     /** Returns list of all pending aggregate reports for a given app right away. */
getPendingAggregateReportIdsForGivenApp(Uri appName)389     List<String> getPendingAggregateReportIdsForGivenApp(Uri appName) throws DatastoreException;
390 
391     /**
392      * Delete all data generated by Measurement API, except for tables in the exclusion list.
393      *
394      * @param tablesToExclude a {@link List} of tables that won't be deleted. An empty list will
395      *     delete every table.
396      */
deleteAllMeasurementData(List<String> tablesToExclude)397     void deleteAllMeasurementData(List<String> tablesToExclude) throws DatastoreException;
398 
399     /**
400      * Delete records from source table that match provided source IDs.
401      *
402      * @param sourceIds source IDs to match
403      * @throws DatastoreException database transaction issues
404      */
deleteSources(@onNull List<String> sourceIds)405     void deleteSources(@NonNull List<String> sourceIds) throws DatastoreException;
406 
407     /**
408      * Delete records from Async Registration table whose registrant or app destination match with
409      * provided app URI.
410      *
411      * @param uri AsyncRegistrations registrant or OS Destination to match
412      * @throws DatastoreException database transaction issues
413      */
deleteAsyncRegistrationsProvidedRegistrant(@onNull String uri)414     void deleteAsyncRegistrationsProvidedRegistrant(@NonNull String uri) throws DatastoreException;
415 
416     /**
417      * Delete records from source table that match provided trigger IDs.
418      *
419      * @param triggerIds trigger IDs to match
420      * @throws DatastoreException database transaction issues
421      */
deleteTriggers(@onNull List<String> triggerIds)422     void deleteTriggers(@NonNull List<String> triggerIds) throws DatastoreException;
423 
424     /**
425      * Insert a record into the Async Registration Table.
426      *
427      * @param asyncRegistration a {@link AsyncRegistration} to insert into the Async Registration
428      *     table
429      */
insertAsyncRegistration(@onNull AsyncRegistration asyncRegistration)430     void insertAsyncRegistration(@NonNull AsyncRegistration asyncRegistration)
431             throws DatastoreException;
432 
433     /**
434      * Delete a record from the AsyncRegistration table.
435      *
436      * @param id a {@link String} id of the record to delete from the AsyncRegistration table.
437      */
deleteAsyncRegistration(@onNull String id)438     void deleteAsyncRegistration(@NonNull String id) throws DatastoreException;
439 
440     /**
441      * Get the record with the earliest request time and a valid retry count.
442      *
443      * @param retryLimit a long that is used for determining the next valid record to be serviced
444      * @param failedOrigins set of origins that have failed during the current run
445      */
fetchNextQueuedAsyncRegistration(int retryLimit, Set<Uri> failedOrigins)446     AsyncRegistration fetchNextQueuedAsyncRegistration(int retryLimit, Set<Uri> failedOrigins)
447             throws DatastoreException;
448 
449     /**
450      * Insert/Update the supplied {@link KeyValueData} object
451      *
452      * @param keyValueData a {@link KeyValueData} to be stored/update
453      * @throws DatastoreException when insertion fails
454      */
insertOrUpdateKeyValueData(@onNull KeyValueData keyValueData)455     void insertOrUpdateKeyValueData(@NonNull KeyValueData keyValueData) throws DatastoreException;
456 
457     /**
458      * Returns the {@link KeyValueData} for {key, dataType} pair
459      *
460      * @param key of the stored data
461      * @param dataType of the stored datta
462      * @return {@link KeyValueData} object
463      */
getKeyValueData(@onNull String key, @NonNull DataType dataType)464     KeyValueData getKeyValueData(@NonNull String key, @NonNull DataType dataType)
465             throws DatastoreException;
466 
467     /**
468      * Update the retry count for a record in the Async Registration table.
469      *
470      * @param asyncRegistration a {@link AsyncRegistration} for which the retryCount will be updated
471      */
updateRetryCount(@onNull AsyncRegistration asyncRegistration)472     void updateRetryCount(@NonNull AsyncRegistration asyncRegistration) throws DatastoreException;
473 
474     /**
475      * Deletes all records in measurement tables that correspond with a Uri not in the provided
476      * list.
477      *
478      * @param uriList a {@link List} of Uris whos related records won't be deleted.
479      * @throws DatastoreException
480      * @return If any entry was deleted.
481      */
deleteAppRecordsNotPresent(List<Uri> uriList)482     boolean deleteAppRecordsNotPresent(List<Uri> uriList) throws DatastoreException;
483 
484     /**
485      * Fetches aggregate reports that match either given source or trigger IDs. If A1 is set of
486      * aggregate reports that match any of sourceIds and A2 is set of aggregate reports that match
487      * any of triggerIds, then we delete (A1 U A2).
488      *
489      * @param sourceIds sources to be matched with aggregate reports
490      * @param triggerIds triggers to be matched with aggregate reports
491      */
fetchMatchingAggregateReports( @onNull List<String> sourceIds, @NonNull List<String> triggerIds)492     List<AggregateReport> fetchMatchingAggregateReports(
493             @NonNull List<String> sourceIds, @NonNull List<String> triggerIds)
494             throws DatastoreException;
495 
496     /**
497      * Fetches event reports that match either given source or trigger IDs. If A1 is set of event
498      * reports that match any of sourceIds and A2 is set of event reports that match any of
499      * triggerIds, then we delete (A1 U A2).
500      *
501      * @param sourceIds sources to be matched with event reports
502      * @param triggerIds triggers to be matched with event reports
503      */
fetchMatchingEventReports( @onNull List<String> sourceIds, @NonNull List<String> triggerIds)504     List<EventReport> fetchMatchingEventReports(
505             @NonNull List<String> sourceIds, @NonNull List<String> triggerIds)
506             throws DatastoreException;
507 
508     /**
509      * Returns list of sources matching registrant, publishers and also in the provided time frame.
510      * It matches registrant and time range (start & end) irrespective of the {@code matchBehavior}.
511      * In the resulting set, if matchBehavior is {@link
512      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_DELETE}, then it
513      * matches origins and domains. In case of {@link
514      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_PRESERVE}, it
515      * returns the records that don't match origins or domain.
516      *
517      * @param registrant registrant to match
518      * @param start event time should be after this instant (inclusive)
519      * @param end event time should be after this instant (inclusive)
520      * @param origins publisher site match
521      * @param domains publisher top level domain matches
522      * @param matchBehavior indicates whether to return matching or inversely matching (everything
523      *     except matching) data
524      * @return list of source IDs
525      * @throws DatastoreException database transaction level issues
526      */
fetchMatchingSources( @onNull Uri registrant, @NonNull Instant start, @NonNull Instant end, @NonNull List<Uri> origins, @NonNull List<Uri> domains, @DeletionRequest.MatchBehavior int matchBehavior)527     List<String> fetchMatchingSources(
528             @NonNull Uri registrant,
529             @NonNull Instant start,
530             @NonNull Instant end,
531             @NonNull List<Uri> origins,
532             @NonNull List<Uri> domains,
533             @DeletionRequest.MatchBehavior int matchBehavior)
534             throws DatastoreException;
535 
536     /**
537      * Returns list of triggers matching registrant, publishers and also in the provided time frame.
538      * It matches registrant and time range (start & end) irrespective of the {@code matchBehavior}.
539      * In the resulting set, if matchBehavior is {@link
540      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_DELETE}, then it
541      * matches origins and domains. In case of {@link
542      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_PRESERVE}, it
543      * returns the records that don't match origins or domain.
544      *
545      * @param registrant registrant to match
546      * @param start trigger time should be after this instant (inclusive)
547      * @param end trigger time should be after this instant (inclusive)
548      * @param origins destination site match
549      * @param domains destination top level domain matches
550      * @param matchBehavior indicates whether to return matching or inversely matching (everything
551      *     except matching) data
552      * @return list of trigger IDs
553      * @throws DatastoreException database transaction level issues
554      */
fetchMatchingTriggers( @onNull Uri registrant, @NonNull Instant start, @NonNull Instant end, @NonNull List<Uri> origins, @NonNull List<Uri> domains, @DeletionRequest.MatchBehavior int matchBehavior)555     List<String> fetchMatchingTriggers(
556             @NonNull Uri registrant,
557             @NonNull Instant start,
558             @NonNull Instant end,
559             @NonNull List<Uri> origins,
560             @NonNull List<Uri> domains,
561             @DeletionRequest.MatchBehavior int matchBehavior)
562             throws DatastoreException;
563 
564     /**
565      * Fetches the XNA relevant sources. It includes sources associated to the trigger's enrollment
566      * ID as well as the sources associated to the provided SAN enrollment IDs.
567      *
568      * @param trigger trigger to match
569      * @param xnaEnrollmentIds SAN enrollment IDs to match
570      * @return XNA relevant sources
571      * @throws DatastoreException when SQLite issue occurs
572      */
fetchTriggerMatchingSourcesForXna( @onNull Trigger trigger, @NonNull Collection<String> xnaEnrollmentIds)573     List<Source> fetchTriggerMatchingSourcesForXna(
574             @NonNull Trigger trigger, @NonNull Collection<String> xnaEnrollmentIds)
575             throws DatastoreException;
576 
577     /**
578      * Insert an entry of source ID with enrollment ID into the {@link
579      * MeasurementTables.XnaIgnoredSourcesContract#TABLE}. It means that the provided source should
580      * be ignored to be picked up for doing XNA based attribution on the provided enrollment.
581      *
582      * @param sourceId source ID
583      * @param enrollmentId enrollment ID
584      */
insertIgnoredSourceForEnrollment(@onNull String sourceId, @NonNull String enrollmentId)585     void insertIgnoredSourceForEnrollment(@NonNull String sourceId, @NonNull String enrollmentId)
586             throws DatastoreException;
587 
588     /**
589      * Returns the number of unique AdIds provided by an Ad Tech in web contexts to match with the
590      * platform AdID from app contexts for debug key population in reports. It counts distinct AdIDs
591      * provided by the AdTech across sources and triggers in the DB.
592      *
593      * @param enrollmentId enrollmentId of previous source/trigger registrations to check AdId
594      *     provided on registration.
595      * @return number of unique AdIds the AdTech has provided.
596      * @throws DatastoreException when SQLite issue occurs
597      */
countDistinctDebugAdIdsUsedByEnrollment(@onNull String enrollmentId)598     long countDistinctDebugAdIdsUsedByEnrollment(@NonNull String enrollmentId)
599             throws DatastoreException;
600 }
601