• 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.AggregatableNamedBudgets.BudgetAndContribution;
27 import com.android.adservices.service.measurement.Attribution;
28 import com.android.adservices.service.measurement.CountUniqueMetadata;
29 import com.android.adservices.service.measurement.CountUniqueReport;
30 import com.android.adservices.service.measurement.EventReport;
31 import com.android.adservices.service.measurement.EventSurfaceType;
32 import com.android.adservices.service.measurement.KeyValueData;
33 import com.android.adservices.service.measurement.KeyValueData.DataType;
34 import com.android.adservices.service.measurement.Source;
35 import com.android.adservices.service.measurement.Trigger;
36 import com.android.adservices.service.measurement.aggregation.AggregateDebugReportRecord;
37 import com.android.adservices.service.measurement.aggregation.AggregateEncryptionKey;
38 import com.android.adservices.service.measurement.aggregation.AggregateReport;
39 import com.android.adservices.service.measurement.registration.AsyncRegistration;
40 import com.android.adservices.service.measurement.reporting.DebugReport;
41 
42 import java.time.Instant;
43 import java.util.Collection;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.Optional;
47 import java.util.Set;
48 
49 /** Interface for Measurement related data access operations. */
50 public interface IMeasurementDao {
51     /** Set the transaction. */
setTransaction(ITransaction transaction)52     void setTransaction(ITransaction transaction);
53 
54     /**
55      * Add an entry to the Trigger datastore and return the trigger ID.
56      *
57      * @param trigger Trigger to be inserted.
58      * @return trigger ID, if trigger ID is null, the record was not saved.
59      */
insertTrigger(Trigger trigger)60     String insertTrigger(Trigger trigger) throws DatastoreException;
61 
62     /** Returns list of ids for all pending {@link Trigger}. */
getPendingTriggerIds()63     List<String> getPendingTriggerIds() throws DatastoreException;
64 
65     /**
66      * Queries and returns the {@link Source}.
67      *
68      * @param sourceId ID of the requested Source
69      * @return the requested Source
70      */
getSource(@onNull String sourceId)71     Source getSource(@NonNull String sourceId) throws DatastoreException;
72 
73     /**
74      * Queries and returns the {@link Source}'s destinations.
75      *
76      * @param sourceId ID of the requested Source
77      * @return a Pair of lists of app destination and web destination Uris
78      */
getSourceDestinations(@onNull String sourceId)79     Pair<List<Uri>, List<Uri>> getSourceDestinations(@NonNull String sourceId)
80             throws DatastoreException;
81 
82     /**
83      * Queries and returns the {@link Source}'s attribution scopes.
84      *
85      * @param sourceId ID of the requested Source.
86      * @return a list of attribution scopes.
87      */
getSourceAttributionScopes(@onNull String sourceId)88     List<String> getSourceAttributionScopes(@NonNull String sourceId) throws DatastoreException;
89 
90     /**
91      * Queries and returns the {@link Source}'s aggregatable named budgets.
92      *
93      * @param sourceId ID of the requested Source.
94      * @param matchedBudgetName name of the budget to retrieve.
95      * @return the budget and contribution of Source's matchedBudgetName named budget.
96      */
getSourceAggregatableNamedBudgetAndContribution( @onNull String sourceId, @NonNull String matchedBudgetName)97     BudgetAndContribution getSourceAggregatableNamedBudgetAndContribution(
98             @NonNull String sourceId, @NonNull String matchedBudgetName) throws DatastoreException;
99 
100     /**
101      * Queries and returns the {@link Source}'s attribution scopes for a given source registration
102      * and reporting origin.
103      *
104      * @param registrationId ID of the registration.
105      * @param registrationOrigin source registration origin.
106      * @return an optional list of attribution scopes, empty if no source is found for the provided
107      *     registration ID and reporting origin
108      */
getAttributionScopesForRegistration( @onNull String registrationId, @NonNull String registrationOrigin)109     Optional<Set<String>> getAttributionScopesForRegistration(
110             @NonNull String registrationId, @NonNull String registrationOrigin)
111             throws DatastoreException;
112 
113     /**
114      * Updates existing sources based on the following criteria for attribution scope:
115      *
116      * <ol>
117      *   <li>Deactivates sources with {@link Source#getMaxEventStates()} different from {@code
118      *       pendingSource}.
119      *   <li>Deactivates sources with {@link Source#getAttributionScopeLimit()} smaller than {@code
120      *       pendingSource}.
121      *   <li>Removes attribution scopes for existing sources not selected as the latest k
122      *       attribution scopes, where k = {@code pendingSource#getAttributionScopeLimit()}.
123      * </ol>
124      *
125      * @param pendingSource The pending source to compare against existing sources.
126      * @throws DatastoreException If an error occurs while processing the data in the datastore.
127      */
updateSourcesForAttributionScope(@onNull Source pendingSource)128     void updateSourcesForAttributionScope(@NonNull Source pendingSource) throws DatastoreException;
129 
130     /**
131      * Queries and returns the {@link Source}.
132      *
133      * @param sourceId ID of the requested Source
134      * @return the source registrant from requested Source
135      */
getSourceRegistrant(@onNull String sourceId)136     String getSourceRegistrant(@NonNull String sourceId) throws DatastoreException;
137 
138     /**
139      * Queries and returns the {@link Trigger}.
140      *
141      * @param triggerId Id of the request Trigger
142      * @return the requested Trigger
143      */
getTrigger(String triggerId)144     Trigger getTrigger(String triggerId) throws DatastoreException;
145 
146     /**
147      * Fetches the count of aggregate reports for the provided destination.
148      *
149      * @param attributionDestination Uri for the destination
150      * @param destinationType DestinationType App/Web
151      * @return number of aggregate reports in the database attributed to the provided destination
152      */
getNumAggregateReportsPerDestination( @onNull Uri attributionDestination, @EventSurfaceType int destinationType)153     int getNumAggregateReportsPerDestination(
154             @NonNull Uri attributionDestination, @EventSurfaceType int destinationType)
155             throws DatastoreException;
156 
157     /**
158      * Fetches the count of aggregate reports for the provided source id.
159      *
160      * @param sourceId source id
161      * @param api aggregate report API
162      * @return number of aggregate reports in the database attributed to the provided source id and
163      *     with provided api value.
164      */
countNumAggregateReportsPerSource(String sourceId, String api)165     int countNumAggregateReportsPerSource(String sourceId, String api) throws DatastoreException;
166 
167     /**
168      * Fetches the count of event reports for the provided destination.
169      *
170      * @param attributionDestination Uri for the destination
171      * @param destinationType DestinationType App/Web
172      * @return number of event reports in the database attributed to the provided destination
173      */
getNumEventReportsPerDestination( @onNull Uri attributionDestination, @EventSurfaceType int destinationType)174     int getNumEventReportsPerDestination(
175             @NonNull Uri attributionDestination, @EventSurfaceType int destinationType)
176             throws DatastoreException;
177 
178     /**
179      * Gets the number of sources associated to a publisher.
180      *
181      * @param publisherUri Uri for the publisher
182      * @param publisherType PublisherType App/Web
183      * @return Number of sources registered for the given publisher
184      */
getNumSourcesPerPublisher(Uri publisherUri, @EventSurfaceType int publisherType)185     long getNumSourcesPerPublisher(Uri publisherUri, @EventSurfaceType int publisherType)
186             throws DatastoreException;
187 
188     /** Gets the number of triggers associated to a destination. */
getNumTriggersPerDestination(Uri destination, @EventSurfaceType int destinationType)189     long getNumTriggersPerDestination(Uri destination, @EventSurfaceType int destinationType)
190             throws DatastoreException;
191 
192     /**
193      * Returns a list of app names that have measurement data. These app names are not part of the
194      * installedApps list.
195      *
196      * @param installedApps app names with their android-app:// scheme
197      * @return list of app names with their android-app:// scheme
198      * @throws DatastoreException if transaction is not active
199      */
getUninstalledAppNamesHavingMeasurementData(List<Uri> installedApps)200     List<Uri> getUninstalledAppNamesHavingMeasurementData(List<Uri> installedApps)
201             throws DatastoreException;
202 
203     /**
204      * Gets the count of distinct reporting origins in the Attribution table in a time window with
205      * matching publisher and destination, excluding a given reporting origin.
206      */
countDistinctReportingOriginsPerPublisherXDestInAttribution( Uri sourceSite, Uri destination, Uri excludedReportingOrigin, long windowStartTime, long windowEndTime)207     Integer countDistinctReportingOriginsPerPublisherXDestInAttribution(
208             Uri sourceSite,
209             Uri destination,
210             Uri excludedReportingOrigin,
211             long windowStartTime,
212             long windowEndTime)
213             throws DatastoreException;
214 
215     /**
216      * Gets the count of distinct Uris of destinations in the Source table in a time window with
217      * matching publisher, enrollment, and unexpired; excluding given destinations.
218      */
countDistinctDestPerPubXEnrollmentInUnexpiredSourceInWindow( Uri publisher, @EventSurfaceType int publisherType, String enrollmentId, List<Uri> excludedDestinations, @EventSurfaceType int destinationType, long windowStartTime, long windowEndTime)219     Integer countDistinctDestPerPubXEnrollmentInUnexpiredSourceInWindow(
220             Uri publisher,
221             @EventSurfaceType int publisherType,
222             String enrollmentId,
223             List<Uri> excludedDestinations,
224             @EventSurfaceType int destinationType,
225             long windowStartTime,
226             long windowEndTime)
227             throws DatastoreException;
228 
229     /**
230      * Gets the count of distinct Uris of destinations in the Source table with matching publisher,
231      * enrollment, and unexpired; excluding given destinations.
232      */
countDistinctDestinationsPerPubXEnrollmentInUnexpiredSource( Uri publisher, @EventSurfaceType int publisherType, String enrollmentId, List<Uri> excludedDestinations, @EventSurfaceType int destinationType, long windowEndTime)233     Integer countDistinctDestinationsPerPubXEnrollmentInUnexpiredSource(
234             Uri publisher,
235             @EventSurfaceType int publisherType,
236             String enrollmentId,
237             List<Uri> excludedDestinations,
238             @EventSurfaceType int destinationType,
239             long windowEndTime)
240             throws DatastoreException;
241 
242     /**
243      * Gets the count of distinct Uris of destinations in the Source table in a time window with
244      * matching publisher; excluding given destinations.
245      */
countDistinctDestinationsPerPublisherPerRateLimitWindow( Uri publisher, @EventSurfaceType int publisherType, List<Uri> excludedDestinations, @EventSurfaceType int destinationType, long windowStartTime, long windowEndTime)246     Integer countDistinctDestinationsPerPublisherPerRateLimitWindow(
247             Uri publisher,
248             @EventSurfaceType int publisherType,
249             List<Uri> excludedDestinations,
250             @EventSurfaceType int destinationType,
251             long windowStartTime,
252             long windowEndTime)
253             throws DatastoreException;
254 
255     /**
256      * Gets the count of distinct reporting origins in the source table in a time period before
257      * event time with matching publisher, enrollment; excluding the given registration origin.
258      */
countDistinctRegOriginPerPublisherXEnrollmentExclRegOrigin( Uri registrationOrigin, Uri publisher, @EventSurfaceType int publisherType, String enrollmentId, long eventTime, long timePeriodInMs)259     Integer countDistinctRegOriginPerPublisherXEnrollmentExclRegOrigin(
260             Uri registrationOrigin,
261             Uri publisher,
262             @EventSurfaceType int publisherType,
263             String enrollmentId,
264             long eventTime,
265             long timePeriodInMs)
266             throws DatastoreException;
267 
268     /**
269      * Gets the count of distinct IDs of enrollments in the Source table in a time window with
270      * matching publisher and destination; excluding a given reporting origin.
271      */
countDistinctReportingOriginsPerPublisherXDestinationInSource( Uri publisher, @EventSurfaceType int publisherType, List<Uri> destinations, Uri excludedReportingOrigin, long windowStartTime, long windowEndTime)272     Integer countDistinctReportingOriginsPerPublisherXDestinationInSource(
273             Uri publisher,
274             @EventSurfaceType int publisherType,
275             List<Uri> destinations,
276             Uri excludedReportingOrigin,
277             long windowStartTime,
278             long windowEndTime)
279             throws DatastoreException;
280 
281     /**
282      * Updates the {@link Trigger.Status} value for the provided {@link Trigger}.
283      *
284      * @param triggerIds trigger to update
285      * @param status status to apply
286      * @throws DatastoreException database transaction related issues
287      */
updateTriggerStatus(@onNull Collection<String> triggerIds, @Trigger.Status int status)288     void updateTriggerStatus(@NonNull Collection<String> triggerIds, @Trigger.Status int status)
289             throws DatastoreException;
290 
291     /**
292      * Add an entry to the Source datastore and returns the source ID.
293      *
294      * @param source Source data to be inserted.
295      * @return source ID, if source ID is null, the record was not saved.
296      */
insertSource(Source source)297     String insertSource(Source source) throws DatastoreException;
298 
299     /**
300      * Queries and returns the list of matching {@link Source} for the provided {@link Trigger}.
301      *
302      * @return list of active matching sources; Null in case of SQL failure
303      */
getMatchingActiveSources(Trigger trigger)304     List<Source> getMatchingActiveSources(Trigger trigger) throws DatastoreException;
305 
306     /**
307      * Queries and returns the most recent matching delayed {@link Source} (Optional) for the
308      * provided {@link Trigger}.
309      */
getNearestDelayedMatchingActiveSource(@onNull Trigger trigger)310     Optional<Source> getNearestDelayedMatchingActiveSource(@NonNull Trigger trigger)
311             throws DatastoreException;
312 
313     /**
314      * Updates the {@link Source.Status} value for the provided list of {@link Source}
315      *
316      * @param sourceIds list of sources.
317      * @param status value to be set
318      */
updateSourceStatus(@onNull Collection<String> sourceIds, @Source.Status int status)319     void updateSourceStatus(@NonNull Collection<String> sourceIds, @Source.Status int status)
320             throws DatastoreException;
321 
322     /**
323      * @param sourceId the source ID
324      * @param attributionStatus the source's JSON-encoded attributed triggers
325      * @throws DatastoreException throws DatastoreException
326      */
updateSourceAttributedTriggers(String sourceId, String attributionStatus)327     void updateSourceAttributedTriggers(String sourceId, String attributionStatus)
328             throws DatastoreException;
329 
330     /**
331      * Update the value of {@link Source.Status} for the corresponding {@link Source}
332      *
333      * @param source the {@link Source} object.
334      */
updateSourceEventReportDedupKeys(@onNull Source source)335     void updateSourceEventReportDedupKeys(@NonNull Source source) throws DatastoreException;
336 
337     /**
338      * Update the set of Aggregate dedup keys contained in the provided {@link Source}
339      *
340      * @param source the {@link Source} object.
341      */
updateSourceAggregateReportDedupKeys(@onNull Source source)342     void updateSourceAggregateReportDedupKeys(@NonNull Source source) throws DatastoreException;
343 
344     /**
345      * Updates the value of aggregate contributions for the corresponding {@link Source}.
346      *
347      * @param source the {@link Source} object.
348      */
updateSourceAggregateContributions(@onNull Source source)349     void updateSourceAggregateContributions(@NonNull Source source) throws DatastoreException;
350 
351     /**
352      * Updates the value of aggregate debug contributions for the corresponding {@link Source}.
353      *
354      * @param source the {@link Source} object.
355      */
updateSourceAggregateDebugContributions(@onNull Source source)356     void updateSourceAggregateDebugContributions(@NonNull Source source) throws DatastoreException;
357 
358     /**
359      * Updates the value of aggregatable named budgets for the corresponding {@link Source}.
360      *
361      * @param sourceId the id of the {@link Source} object.
362      * @param budgetName the name of the budget to update
363      * @param budgetAndContribution the object containing the information to update for the named
364      *     budget
365      */
updateSourceAggregatableNamedBudgetAndContribution( @onNull String sourceId, @NonNull String budgetName, @NonNull BudgetAndContribution budgetAndContribution)366     void updateSourceAggregatableNamedBudgetAndContribution(
367             @NonNull String sourceId,
368             @NonNull String budgetName,
369             @NonNull BudgetAndContribution budgetAndContribution)
370             throws DatastoreException;
371 
372     /**
373      * Returns list of all the reports associated with the {@link Source}.
374      *
375      * @param source for querying reports
376      * @return list of relevant eventReports
377      */
getSourceEventReports(Source source)378     List<EventReport> getSourceEventReports(Source source) throws DatastoreException;
379 
380     /**
381      * Queries and returns the {@link EventReport}.
382      *
383      * @param eventReportId Id of the request Event Report
384      * @return the requested Event Report; Null in case of SQL failure
385      */
386     @Nullable
getEventReport(String eventReportId)387     EventReport getEventReport(String eventReportId) throws DatastoreException;
388 
389     /**
390      * Queries and returns the {@link AggregateReport}
391      *
392      * @param aggregateReportId Id of the request Aggregate Report
393      * @return the request Aggregate Report; Null in case of SQL failure
394      */
395     @Nullable
getAggregateReport(String aggregateReportId)396     AggregateReport getAggregateReport(String aggregateReportId) throws DatastoreException;
397 
398     /**
399      * Queries and returns the {@link DebugReport}
400      *
401      * @param debugReportId of the request Debug Report
402      * @return the request Debug Report; Null in case of SQL failure
403      */
404     @Nullable
getDebugReport(String debugReportId)405     DebugReport getDebugReport(String debugReportId) throws DatastoreException;
406 
407     /**
408      * Change the status of an event report to DELIVERED
409      *
410      * @param eventReportId the id of the event report to be updated
411      * @param status status of the event report
412      */
markEventReportStatus(String eventReportId, @EventReport.Status int status)413     void markEventReportStatus(String eventReportId, @EventReport.Status int status)
414             throws DatastoreException;
415 
416     /**
417      * Change the summary bucket of the event report
418      *
419      * @param eventReportId the id of the event report to be updated
420      * @param summaryBucket the new summary bucket of the report
421      * @throws DatastoreException
422      */
updateEventReportSummaryBucket( @onNull String eventReportId, @NonNull String summaryBucket)423     void updateEventReportSummaryBucket(
424             @NonNull String eventReportId, @NonNull String summaryBucket) throws DatastoreException;
425     ;
426 
427     /**
428      * Change the status of an event debug report to DELIVERED
429      *
430      * @param eventReportId the id of the event report to be updated
431      */
markEventDebugReportDelivered(String eventReportId)432     void markEventDebugReportDelivered(String eventReportId) throws DatastoreException;
433 
434     /**
435      * Change the status of an aggregate report to DELIVERED
436      *
437      * @param aggregateReportId the id of the event report to be updated
438      * @param status new status to set
439      */
markAggregateReportStatus(String aggregateReportId, @AggregateReport.Status int status)440     void markAggregateReportStatus(String aggregateReportId, @AggregateReport.Status int status)
441             throws DatastoreException;
442 
443     /**
444      * Change the status of an aggregate debug report to DELIVERED
445      *
446      * @param aggregateReportId the id of the event report to be updated
447      */
markAggregateDebugReportDelivered(String aggregateReportId)448     void markAggregateDebugReportDelivered(String aggregateReportId) throws DatastoreException;
449 
450     /** Saves the {@link EventReport} to the datastore. */
insertEventReport(EventReport eventReport)451     void insertEventReport(EventReport eventReport) throws DatastoreException;
452 
453     /** Deletes the {@link EventReport} and associated {@link Attribution} from the datastore. */
deleteEventReportAndAttribution(EventReport eventReport)454     void deleteEventReportAndAttribution(EventReport eventReport) throws DatastoreException;
455 
456     /** Deletes the {@link DebugReport} from the datastore. */
deleteDebugReport(String debugReportId)457     void deleteDebugReport(String debugReportId) throws DatastoreException;
458 
459     /**
460      * Deletes the {@link DebugReport} from the datastore based on parameters.
461      *
462      * @param registrant
463      * @param start
464      * @param end
465      * @return number of debug records deleted
466      * @throws DatastoreException
467      */
deleteDebugReports(@onNull Uri registrant, @NonNull Instant start, @NonNull Instant end)468     int deleteDebugReports(@NonNull Uri registrant, @NonNull Instant start, @NonNull Instant end)
469             throws DatastoreException;
470 
471     /**
472      * Returns list of all event reports that have a scheduled reporting time in the given window.
473      */
getPendingEventReportIdsInWindow(long windowStartTime, long windowEndTime)474     List<String> getPendingEventReportIdsInWindow(long windowStartTime, long windowEndTime)
475             throws DatastoreException;
476 
477     /** Returns list of all debug event reports. */
getPendingDebugEventReportIds()478     List<String> getPendingDebugEventReportIds() throws DatastoreException;
479 
480     /** Returns list of all pending event reports for a given app right away. */
getPendingEventReportIdsForGivenApp(Uri appName)481     List<String> getPendingEventReportIdsForGivenApp(Uri appName) throws DatastoreException;
482 
483     /**
484      * Find the number of entries for a rate limit window, scoped to event- or aggregate-level using
485      * the {@link Source} and {@link Trigger}. Rate-Limit Window: (Scope, Source Site, Destination
486      * Site, Window) from triggerTime.
487      *
488      * @return the number of entries for the window.
489      */
getAttributionsPerRateLimitWindow(@ttribution.Scope int scope, @NonNull Source source, @NonNull Trigger trigger)490     long getAttributionsPerRateLimitWindow(@Attribution.Scope int scope, @NonNull Source source,
491             @NonNull Trigger trigger) throws DatastoreException;
492 
493     /** Add an entry in Attribution datastore. */
insertAttribution(@onNull Attribution attribution)494     void insertAttribution(@NonNull Attribution attribution) throws DatastoreException;
495 
496     /** Deletes all expired records in measurement tables. */
deleteExpiredRecords( long earliestValidInsertion, int registrationRetryLimit, @Nullable Long earliestValidAppReportInsertion, long earliestValidAggregateDebugReportInsertion)497     void deleteExpiredRecords(
498             long earliestValidInsertion,
499             int registrationRetryLimit,
500             @Nullable Long earliestValidAppReportInsertion,
501             long earliestValidAggregateDebugReportInsertion)
502             throws DatastoreException;
503 
504     /**
505      * Mark relevant source as install attributed.
506      *
507      * @param uri package identifier
508      * @param eventTimestamp timestamp of installation event
509      */
doInstallAttribution(Uri uri, long eventTimestamp)510     void doInstallAttribution(Uri uri, long eventTimestamp) throws DatastoreException;
511 
512     /**
513      * Undo any install attributed source events.
514      *
515      * @param uri package identifier
516      */
undoInstallAttribution(Uri uri)517     void undoInstallAttribution(Uri uri) throws DatastoreException;
518 
519     /** Save aggregate encryption key to the datastore. */
insertAggregateEncryptionKey(AggregateEncryptionKey aggregateEncryptionKey)520     void insertAggregateEncryptionKey(AggregateEncryptionKey aggregateEncryptionKey)
521             throws DatastoreException;
522 
523     /**
524      * Retrieve all aggregate encryption keys from the datastore whose expiry time is greater than
525      * or equal to {@code expiry}.
526      */
getNonExpiredAggregateEncryptionKeys(Uri coordinator, long expiry)527     List<AggregateEncryptionKey> getNonExpiredAggregateEncryptionKeys(Uri coordinator, long expiry)
528             throws DatastoreException;
529 
530     /** Remove aggregate encryption keys from the datastore older than {@code expiry}. */
deleteExpiredAggregateEncryptionKeys(long expiry)531     void deleteExpiredAggregateEncryptionKeys(long expiry) throws DatastoreException;
532 
533     /** Delete Event Report from datastore. */
deleteEventReport(EventReport eventReport)534     void deleteEventReport(EventReport eventReport) throws DatastoreException;
535 
536     /** Delete Aggregate Report from datastore. */
deleteAggregateReport(AggregateReport aggregateReport)537     void deleteAggregateReport(AggregateReport aggregateReport) throws DatastoreException;
538 
539     /** Save unencrypted aggregate payload to the datastore. */
insertAggregateReport(AggregateReport payload)540     void insertAggregateReport(AggregateReport payload) throws DatastoreException;
541 
542     /** Save debug report payload to the datastore. */
insertDebugReport(DebugReport payload)543     void insertDebugReport(DebugReport payload) throws DatastoreException;
544 
545     /**
546      * Returns a map of coordinator to pending aggregate reports that have a scheduled reporting
547      * time in the given window.
548      */
getPendingAggregateReportIdsByCoordinatorInWindow( long windowStartTime, long windowEndTime)549     Map<String, List<String>> getPendingAggregateReportIdsByCoordinatorInWindow(
550             long windowStartTime, long windowEndTime) throws DatastoreException;
551 
552     /** Returns a map of coordinator to pending aggregate debug reports */
getPendingAggregateDebugReportIdsByCoordinator()553     Map<String, List<String>> getPendingAggregateDebugReportIdsByCoordinator()
554             throws DatastoreException;
555 
556     /** Returns list of all debug reports. */
getDebugReportIds()557     List<String> getDebugReportIds() throws DatastoreException;
558 
559     /** Returns list of all pending aggregate reports for a given app right away. */
getPendingAggregateReportIdsForGivenApp(Uri appName)560     List<String> getPendingAggregateReportIdsForGivenApp(Uri appName) throws DatastoreException;
561 
562     /**
563      * Delete all data generated by Measurement API, except for tables in the exclusion list.
564      *
565      * @param tablesToExclude a {@link List} of tables that won't be deleted. An empty list will
566      *     delete every table.
567      */
deleteAllMeasurementData(List<String> tablesToExclude)568     void deleteAllMeasurementData(List<String> tablesToExclude) throws DatastoreException;
569 
570     /**
571      * Delete records from source table that match provided source IDs.
572      *
573      * @param sourceIds source IDs to match
574      * @throws DatastoreException database transaction issues
575      */
deleteSources(@onNull Collection<String> sourceIds)576     void deleteSources(@NonNull Collection<String> sourceIds) throws DatastoreException;
577 
578     /**
579      * Delete records from trigger table that match provided trigger IDs.
580      *
581      * @param triggerIds trigger IDs to match
582      * @throws DatastoreException database transaction issues
583      */
deleteTriggers(@onNull Collection<String> triggerIds)584     void deleteTriggers(@NonNull Collection<String> triggerIds) throws DatastoreException;
585 
586     /**
587      * Delete records from async registration table that match provided async registration IDs.
588      *
589      * @param asyncRegistrationIds async registration IDs to match
590      * @throws DatastoreException database transaction issues
591      */
deleteAsyncRegistrations(@onNull List<String> asyncRegistrationIds)592     void deleteAsyncRegistrations(@NonNull List<String> asyncRegistrationIds)
593             throws DatastoreException;
594 
595     /**
596      * Insert a record into the Async Registration Table.
597      *
598      * @param asyncRegistration a {@link AsyncRegistration} to insert into the Async Registration
599      *     table
600      */
insertAsyncRegistration(@onNull AsyncRegistration asyncRegistration)601     void insertAsyncRegistration(@NonNull AsyncRegistration asyncRegistration)
602             throws DatastoreException;
603 
604     /**
605      * Delete a record from the AsyncRegistration table.
606      *
607      * @param id a {@link String} id of the record to delete from the AsyncRegistration table.
608      */
deleteAsyncRegistration(@onNull String id)609     void deleteAsyncRegistration(@NonNull String id) throws DatastoreException;
610 
611     /**
612      * Get the record with the earliest request time and a valid retry count.
613      *
614      * @param retryLimit a long that is used for determining the next valid record to be serviced
615      * @param failedOrigins set of origins that have failed during the current run
616      */
fetchNextQueuedAsyncRegistration(int retryLimit, Set<Uri> failedOrigins)617     AsyncRegistration fetchNextQueuedAsyncRegistration(int retryLimit, Set<Uri> failedOrigins)
618             throws DatastoreException;
619 
620     /** Get all the records from the SourceContract and SourceDestination tables. */
fetchAllSourceRegistrations()621     List<Source> fetchAllSourceRegistrations() throws DatastoreException;
622 
623     /** Get all the records from the TriggerContract table. */
fetchAllTriggerRegistrations()624     List<Trigger> fetchAllTriggerRegistrations() throws DatastoreException;
625 
626     /** Get all the records from the EventReport table. */
fetchAllEventReports()627     List<EventReport> fetchAllEventReports() throws DatastoreException;
628 
629     /** Get all the records from the AggregateReport table. */
fetchAllAggregatableReports()630     List<AggregateReport> fetchAllAggregatableReports() throws DatastoreException;
631 
632     /** Get all the records from the DebugReport table. */
fetchAllDebugReports()633     List<DebugReport> fetchAllDebugReports() throws DatastoreException;
634 
635     /**
636      * Insert/Update the supplied {@link KeyValueData} object
637      *
638      * @param keyValueData a {@link KeyValueData} to be stored/update
639      * @throws DatastoreException when insertion fails
640      */
insertOrUpdateKeyValueData(@onNull KeyValueData keyValueData)641     void insertOrUpdateKeyValueData(@NonNull KeyValueData keyValueData) throws DatastoreException;
642 
643     /**
644      * Returns the {@link KeyValueData} for {key, dataType} pair
645      *
646      * @param key of the stored data
647      * @param dataType of the stored datta
648      * @return {@link KeyValueData} object
649      */
getKeyValueData(@onNull String key, @NonNull DataType dataType)650     KeyValueData getKeyValueData(@NonNull String key, @NonNull DataType dataType)
651             throws DatastoreException;
652 
653     /**
654      * Update the retry count for a record in the Async Registration table.
655      *
656      * @param asyncRegistration a {@link AsyncRegistration} for which the retryCount will be updated
657      */
updateRetryCount(@onNull AsyncRegistration asyncRegistration)658     void updateRetryCount(@NonNull AsyncRegistration asyncRegistration) throws DatastoreException;
659 
660     /**
661      * Fetches aggregate reports that match either given source or trigger IDs. If A1 is set of
662      * aggregate reports that match any of sourceIds and A2 is set of aggregate reports that match
663      * any of triggerIds, then we delete (A1 U A2).
664      *
665      * @param sourceIds sources to be matched with aggregate reports
666      * @param triggerIds triggers to be matched with aggregate reports
667      */
fetchMatchingAggregateReports( @onNull Collection<String> sourceIds, @NonNull Collection<String> triggerIds)668     List<AggregateReport> fetchMatchingAggregateReports(
669             @NonNull Collection<String> sourceIds, @NonNull Collection<String> triggerIds)
670             throws DatastoreException;
671 
672     /**
673      * Fetches event reports that match either given source or trigger IDs. If A1 is set of event
674      * reports that match any of sourceIds and A2 is set of event reports that match any of
675      * triggerIds, then we delete (A1 U A2).
676      *
677      * @param sourceIds sources to be matched with event reports
678      * @param triggerIds triggers to be matched with event reports
679      */
fetchMatchingEventReports( @onNull Collection<String> sourceIds, @NonNull Collection<String> triggerIds)680     List<EventReport> fetchMatchingEventReports(
681             @NonNull Collection<String> sourceIds, @NonNull Collection<String> triggerIds)
682             throws DatastoreException;
683 
684     /**
685      * Get source IDs based on trigger IDs for flexible event API
686      *
687      * @param triggerIds triggers to be matched with source
688      * @return the list of sourced ids
689      * @throws DatastoreException throw DatastoreException
690      */
fetchFlexSourceIdsFor(@onNull Collection<String> triggerIds)691     Set<String> fetchFlexSourceIdsFor(@NonNull Collection<String> triggerIds)
692             throws DatastoreException;
693 
694     /** Deletes the {@link EventReport}s and associated {@link Attribution}s from the datastore. */
deleteFlexEventReportsAndAttributions(List<EventReport> eventReports)695     void deleteFlexEventReportsAndAttributions(List<EventReport> eventReports)
696             throws DatastoreException;
697 
698     /**
699      * Returns list of sources matching registrant, publishers and also in the provided time frame.
700      * It matches registrant and time range (start & end) irrespective of the {@code matchBehavior}.
701      * In the resulting set, if matchBehavior is {@link
702      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_DELETE}, then it
703      * matches origins and domains. In case of {@link
704      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_PRESERVE}, it
705      * returns the records that don't match origins or domain.
706      *
707      * @param registrant registrant to match
708      * @param start event time should be after this instant (inclusive)
709      * @param end event time should be after this instant (inclusive)
710      * @param origins publisher site match
711      * @param domains publisher top level domain matches
712      * @param matchBehavior indicates whether to return matching or inversely matching (everything
713      *     except matching) data
714      * @return list of source IDs
715      * @throws DatastoreException database transaction level issues
716      */
fetchMatchingSources( @onNull Uri registrant, @NonNull Instant start, @NonNull Instant end, @NonNull List<Uri> origins, @NonNull List<Uri> domains, @DeletionRequest.MatchBehavior int matchBehavior)717     List<String> fetchMatchingSources(
718             @NonNull Uri registrant,
719             @NonNull Instant start,
720             @NonNull Instant end,
721             @NonNull List<Uri> origins,
722             @NonNull List<Uri> domains,
723             @DeletionRequest.MatchBehavior int matchBehavior)
724             throws DatastoreException;
725 
726     /**
727      * Returns list of triggers matching registrant and destinations in the provided time frame.
728      * It matches registrant and time range (start & end) irrespective of the {@code matchBehavior}.
729      * In the resulting set, if matchBehavior is {@link
730      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_DELETE}, then it
731      * matches origins and domains. In case of {@link
732      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_PRESERVE}, it
733      * returns the records that don't match origins or domain.
734      *
735      * @param registrant registrant to match
736      * @param start trigger time should be after this instant (inclusive)
737      * @param end trigger time should be after this instant (inclusive)
738      * @param origins destination site match
739      * @param domains destination top level domain matches
740      * @param matchBehavior indicates whether to return matching or inversely matching (everything
741      *     except matching) data
742      * @return list of trigger IDs
743      * @throws DatastoreException database transaction level issues
744      */
fetchMatchingTriggers( @onNull Uri registrant, @NonNull Instant start, @NonNull Instant end, @NonNull List<Uri> origins, @NonNull List<Uri> domains, @DeletionRequest.MatchBehavior int matchBehavior)745     Set<String> fetchMatchingTriggers(
746             @NonNull Uri registrant,
747             @NonNull Instant start,
748             @NonNull Instant end,
749             @NonNull List<Uri> origins,
750             @NonNull List<Uri> domains,
751             @DeletionRequest.MatchBehavior int matchBehavior)
752             throws DatastoreException;
753 
754     /**
755      * Returns a pair of lists of sources matching registrant, publishers and also in the provided
756      * time frame. If 24 hours plus the most recent trigger time of all reports attributed to the
757      * source is less than the current time then the source is in the first pair. If greater than or
758      * equal to the current time then the source is in the second pair. It matches registrant.
759      *
760      * @param registrant registrant to match except matching) data
761      * @param eventTime time of uninstall event
762      * @return pair of lists of source IDs
763      * @throws DatastoreException database transaction level issues
764      */
fetchMatchingSourcesUninstall( @onNull Uri registrant, long eventTime)765     Pair<List<String>, List<String>> fetchMatchingSourcesUninstall(
766             @NonNull Uri registrant, long eventTime) throws DatastoreException;
767 
768     /**
769      * Returns a pair of lists of triggers matching registrant, publishers and also in the provided
770      * time frame. If 24 hours plus the most recent trigger time of all reports attributed to the
771      * trigger is less than the current time then the trigger is in the first pair. If greater than
772      * or equal to the current time then the trigger is in the second pair. It matches registrant.
773      *
774      * @param registrant registrant to match except matching) data
775      * @param eventTime time of uninstall event
776      * @return pair of lists of trigger IDs
777      * @throws DatastoreException database transaction level issues
778      */
fetchMatchingTriggersUninstall( @onNull Uri registrant, long eventTime)779     Pair<List<String>, List<String>> fetchMatchingTriggersUninstall(
780             @NonNull Uri registrant, long eventTime) throws DatastoreException;
781 
782     /**
783      * Returns list of async registrations matching registrant and top origins in the provided time
784      * frame. It matches registrant and time range (start & end) irrespective of the {@code
785      * matchBehavior}. In the resulting set, if matchBehavior is {@link
786      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_DELETE}, then it
787      * matches origins and domains. In case of {@link
788      * android.adservices.measurement.DeletionRequest.MatchBehavior#MATCH_BEHAVIOR_PRESERVE}, it
789      * returns the records that don't match origins or domain.
790      *
791      * @param registrant registrant to match
792      * @param start request time should be after this instant (inclusive)
793      * @param end request time should be after this instant (inclusive)
794      * @param origins top origin site match
795      * @param domains top origin top level domain matches
796      * @param matchBehavior indicates whether to return matching or inversely matching (everything
797      *     except matching) data
798      * @return list of async registration IDs
799      * @throws DatastoreException database transaction level issues
800      */
fetchMatchingAsyncRegistrations( @onNull Uri registrant, @NonNull Instant start, @NonNull Instant end, @NonNull List<Uri> origins, @NonNull List<Uri> domains, @DeletionRequest.MatchBehavior int matchBehavior)801     List<String> fetchMatchingAsyncRegistrations(
802             @NonNull Uri registrant,
803             @NonNull Instant start,
804             @NonNull Instant end,
805             @NonNull List<Uri> origins,
806             @NonNull List<Uri> domains,
807             @DeletionRequest.MatchBehavior int matchBehavior)
808             throws DatastoreException;
809 
810     /**
811      * Fetches the XNA relevant sources. It includes sources associated to the trigger's enrollment
812      * ID as well as the sources associated to the provided SAN enrollment IDs.
813      *
814      * @param trigger trigger to match
815      * @param xnaEnrollmentIds SAN enrollment IDs to match
816      * @return XNA relevant sources
817      * @throws DatastoreException when SQLite issue occurs
818      */
fetchTriggerMatchingSourcesForXna( @onNull Trigger trigger, @NonNull Collection<String> xnaEnrollmentIds)819     List<Source> fetchTriggerMatchingSourcesForXna(
820             @NonNull Trigger trigger, @NonNull Collection<String> xnaEnrollmentIds)
821             throws DatastoreException;
822 
823     /**
824      * Insert an entry of source ID with enrollment ID into the {@link
825      * MeasurementTables.XnaIgnoredSourcesContract#TABLE}. It means that the provided source should
826      * be ignored to be picked up for doing XNA based attribution on the provided enrollment.
827      *
828      * @param sourceId source ID
829      * @param enrollmentId enrollment ID
830      */
insertIgnoredSourceForEnrollment(@onNull String sourceId, @NonNull String enrollmentId)831     void insertIgnoredSourceForEnrollment(@NonNull String sourceId, @NonNull String enrollmentId)
832             throws DatastoreException;
833 
834     /**
835      * Increments Retry Counter for EventReporting Records and return the updated retry count. This
836      * is used for Retry Limiting.
837      *
838      * @param id Primary key id of Record in Measurement Event Report Table.
839      * @param reportType KeyValueData.DataType corresponding with Record type being incremented.
840      * @return current report count
841      */
incrementAndGetReportingRetryCount(String id, DataType reportType)842     int incrementAndGetReportingRetryCount(String id, DataType reportType)
843             throws DatastoreException;
844 
845     /**
846      * Returns the number of unique AdIds provided by an Ad Tech in web contexts to match with the
847      * platform AdID from app contexts for debug key population in reports. It counts distinct AdIDs
848      * provided by the AdTech across sources and triggers in the DB.
849      *
850      * @param enrollmentId enrollmentId of previous source/trigger registrations to check AdId
851      *     provided on registration.
852      * @return number of unique AdIds the AdTech has provided.
853      * @throws DatastoreException when SQLite issue occurs
854      * @deprecated use {@link #countDistinctDebugAdIdsUsedByEnrollmentInWindow(String, long, long,
855      *     String)} instead
856      */
857     @Deprecated
countDistinctDebugAdIdsUsedByEnrollment(@onNull String enrollmentId)858     long countDistinctDebugAdIdsUsedByEnrollment(@NonNull String enrollmentId)
859             throws DatastoreException;
860 
861     /**
862      * Returns the number of unique AdIds provided by an Ad Tech in web contexts to match with the
863      * platform AdID from app contexts for debug key population in reports. It counts distinct AdIDs
864      * provided by the AdTech across sources and triggers in the DB within a time window.
865      *
866      * @param enrollmentId enrollmentId of previous source/trigger registrations to check AdId
867      *     provided on registration.
868      * @param startTime window start time (inclusive)
869      * @param endTime window start time (exclusive)
870      * @param excludedDebugAdId excluded debug ad ID from the count
871      * @return number of unique AdIds the AdTech has provided.
872      * @throws DatastoreException when SQLite issue occurs
873      */
countDistinctDebugAdIdsUsedByEnrollmentInWindow( String enrollmentId, long startTime, long endTime, String excludedDebugAdId)874     long countDistinctDebugAdIdsUsedByEnrollmentInWindow(
875             String enrollmentId, long startTime, long endTime, String excludedDebugAdId)
876             throws DatastoreException;
877 
878     /**
879      * Inserts an entry of app report history with enrollment ID into the {@link
880      * MeasurementTables.AppReportHistoryContract#TABLE}. It means that event / aggregate reports
881      * for the given app destination have been delivered to the registration origin.
882      *
883      * @param appDestination app destination
884      * @param registrationOrigin source registration origin
885      * @param lastReportDeliveredTimestamp last deliver time for the report
886      * @throws DatastoreException when SQLite issue occurs.
887      */
insertOrUpdateAppReportHistory( @onNull Uri appDestination, @NonNull Uri registrationOrigin, long lastReportDeliveredTimestamp)888     void insertOrUpdateAppReportHistory(
889             @NonNull Uri appDestination,
890             @NonNull Uri registrationOrigin,
891             long lastReportDeliveredTimestamp)
892             throws DatastoreException;
893 
894     /**
895      * Stores a Count Unique report into the Count Unique report table
896      *
897      * @param report report to store
898      * @throws DatastoreException when SQLite issue occurs.
899      */
insertCountUniqueReport(@onNull CountUniqueReport report)900     void insertCountUniqueReport(@NonNull CountUniqueReport report) throws DatastoreException;
901 
902     /**
903      * Stores a Count Unique metadata into the Count Unique metadata table
904      *
905      * @param metadata metadata to store
906      * @param ignoreIfPresent if true, ignore record if already present
907      * @throws DatastoreException when SQLite issue occurs.
908      */
insertCountUniqueMetadata(@onNull CountUniqueMetadata metadata, boolean ignoreIfPresent)909     void insertCountUniqueMetadata(@NonNull CountUniqueMetadata metadata, boolean ignoreIfPresent)
910             throws DatastoreException;
911 
912     /**
913      * Gets CountUniqueMetadata given a key and reportingOrigin
914      *
915      * @param key key for the metadata to be returned
916      * @param reportingOrigin reporting origin associated to the metadata
917      * @throws DatastoreException when SQLite issue occurs.
918      */
getCountUniqueMetadata(@onNull String key, Uri reportingOrigin)919     CountUniqueMetadata getCountUniqueMetadata(@NonNull String key, Uri reportingOrigin)
920             throws DatastoreException;
921 
922     /**
923      * Delete count unique metadata
924      *
925      * @param key delete the specified key
926      * @param reportingOrigin reporting origin associated to the request
927      * @throws DatastoreException when SQLite issue occurs.
928      */
deleteCountUniqueMetadata(String key, Uri reportingOrigin)929     void deleteCountUniqueMetadata(String key, Uri reportingOrigin) throws DatastoreException;
930 
931     /**
932      * Insert an entry of {@link AggregateDebugReportRecord} into the {@link
933      * MeasurementTables.AggregatableDebugReportBudgetTrackerContract#TABLE} which tracks budget
934      * limits for aggregate debug reports.
935      *
936      * @param aggregateDebugReportRecord
937      */
insertAggregateDebugReportRecord(AggregateDebugReportRecord aggregateDebugReportRecord)938     void insertAggregateDebugReportRecord(AggregateDebugReportRecord aggregateDebugReportRecord)
939             throws DatastoreException;
940 
941     /**
942      * Returns the number of unique navigation sources by reporting origin and registration id.
943      *
944      * @param reportingOrigin the reporting origin to match.
945      * @param registrationId the registration id to match.
946      * @return the number of matched navigation sources.
947      * @throws DatastoreException
948      */
countNavigationSourcesPerReportingOrigin( @onNull Uri reportingOrigin, @NonNull String registrationId)949     long countNavigationSourcesPerReportingOrigin(
950             @NonNull Uri reportingOrigin, @NonNull String registrationId) throws DatastoreException;
951 
952     /**
953      * Let matchingSources be unexpired sources that match the provided publisher, publisher type
954      * destination surface type and enrollmentId. Pick and return the sources that have the lowest
955      * destination priority value or secondarily the least recently used destination excluding the
956      * provided list of destinations.
957      *
958      * @param publisher publisher to match
959      * @param publisherType publisher surface type, i.e. app/web to match
960      * @param enrollmentId matching enrollment
961      * @param excludedDestinations destinations to exclude while matching
962      * @param destinationType destination type app/web
963      * @param windowEndTime selected sources' expiry needs to be greater than this time
964      * @return sources with least recently used destination along with the priority value
965      * @throws DatastoreException when accessing the DB fails
966      */
fetchSourceIdsForLowestPriorityDestinationXEnrollmentXPublisher( Uri publisher, int publisherType, String enrollmentId, List<Uri> excludedDestinations, int destinationType, long windowEndTime)967     Pair<Long, List<String>> fetchSourceIdsForLowestPriorityDestinationXEnrollmentXPublisher(
968             Uri publisher,
969             int publisherType,
970             String enrollmentId,
971             List<Uri> excludedDestinations,
972             int destinationType,
973             long windowEndTime)
974             throws DatastoreException;
975 
976     /**
977      * Deletes pending aggregate reports for the provided sources. Also delete the attributions that
978      * are associated to those reports.
979      *
980      * @param sourceIds sources to consider to query the pending reports
981      * @throws DatastoreException when accessing the DB fails
982      */
deletePendingAggregateReportsAndAttributionsForSources(List<String> sourceIds)983     void deletePendingAggregateReportsAndAttributionsForSources(List<String> sourceIds)
984             throws DatastoreException;
985 
986     /**
987      * Deletes pending fake event reports for the provided sources. Attributions are not deleted.
988      *
989      * @param sourceIds sources to consider to query the pending reports
990      * @param currentTimeStamp it's practically the current time stamp, we delete only those reports
991      *     that have trigger time in future indicating that they are fake
992      * @throws DatastoreException when deletion fails
993      */
deleteFutureFakeEventReportsForSources(List<String> sourceIds, long currentTimeStamp)994     void deleteFutureFakeEventReportsForSources(List<String> sourceIds, long currentTimeStamp)
995             throws DatastoreException;
996 
997     /**
998      * Return the timestamp of the latest pending report (Event or Aggregate) in the batching
999      * window. The batching window is calculated as the earliest report's timestamp + batchWindow.
1000      * If there are no reports, return null.
1001      *
1002      * @param batchWindow Size of the batching window, in ms, starting at the next pending report.
1003      * @return Latest report's timestamp, in ms, within the batching window.
1004      * @throws DatastoreException when SQLite issue occurs
1005      */
getLatestReportTimeInBatchWindow(long batchWindow)1006     Long getLatestReportTimeInBatchWindow(long batchWindow) throws DatastoreException;
1007 
1008     /**
1009      * Get total aggregate debug report budget per publisher x after window start time stamp.
1010      *
1011      * @param publisher publisher to match
1012      * @throws DatastoreException when SQLite issue occurs
1013      */
sumAggregateDebugReportBudgetXPublisherXWindow( Uri publisher, @EventSurfaceType int publisherType, long windowStartTime)1014     int sumAggregateDebugReportBudgetXPublisherXWindow(
1015             Uri publisher, @EventSurfaceType int publisherType, long windowStartTime)
1016             throws DatastoreException;
1017 
1018     /**
1019      * Get total aggregate debug report budget per reporting publisher x origin x after window start
1020      * time stamp.
1021      *
1022      * @param publisher publisher to match
1023      * @param origin origin to match
1024      * @throws DatastoreException when SQLite issue occurs
1025      */
sumAggregateDebugReportBudgetXOriginXPublisherXWindow( Uri publisher, @EventSurfaceType int publisherType, Uri origin, long windowStartTime)1026     int sumAggregateDebugReportBudgetXOriginXPublisherXWindow(
1027             Uri publisher, @EventSurfaceType int publisherType, Uri origin, long windowStartTime)
1028             throws DatastoreException;
1029 
1030     /**
1031      * Returns if there exists any sources with the same input destination.
1032      *
1033      * @param attributionDestinations destination to match
1034      * @param eventTime to filter out expired sources
1035      * @throws DatastoreException when SQLite issue occurs
1036      */
existsActiveSourcesWithDestination(Uri attributionDestinations, long eventTime)1037     boolean existsActiveSourcesWithDestination(Uri attributionDestinations, long eventTime)
1038             throws DatastoreException;
1039 
1040     /**
1041      * Get the report Ids of all Count Unique reports with a status of {@link
1042      * CountUniqueReport.ReportDeliveryStatus#PENDING}
1043      *
1044      * @return List of ids of pending reports
1045      * @throws DatastoreException when SQLite issue occurs
1046      */
getPendingCountUniqueReportIds()1047     List<String> getPendingCountUniqueReportIds() throws DatastoreException;
1048 
1049     /**
1050      * Update the status of a specific Count Unique report.
1051      *
1052      * @param countUniqueReportId Id of the report to update.
1053      * @param status Status to update to.
1054      * @throws DatastoreException when SQLite issue occurs
1055      */
markCountUniqueReportStatus( String countUniqueReportId, @CountUniqueReport.ReportDeliveryStatus int status)1056     void markCountUniqueReportStatus(
1057             String countUniqueReportId, @CountUniqueReport.ReportDeliveryStatus int status)
1058             throws DatastoreException;
1059 
1060     /**
1061      * Get the Count Unique report with a specific Id.
1062      *
1063      * @param countUniqueReportId Id of the report to get.
1064      * @return The CountUnique report.
1065      * @throws DatastoreException when SQLite issue occurs
1066      */
getCountUniqueReport(@onNull String countUniqueReportId)1067     CountUniqueReport getCountUniqueReport(@NonNull String countUniqueReportId)
1068             throws DatastoreException;
1069 }
1070