summaryrefslogtreecommitdiff
path: root/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java')
-rw-r--r--adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java53
1 files changed, 43 insertions, 10 deletions
diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java
index d833b7873f..653bf7d515 100644
--- a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java
+++ b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java
@@ -46,6 +46,7 @@ public class EventReportingJobHandler {
private final EnrollmentDao mEnrollmentDao;
private final DatastoreManager mDatastoreManager;
+ private boolean mIsDebugReport;
EventReportingJobHandler(EnrollmentDao enrollmentDao, DatastoreManager datastoreManager) {
mEnrollmentDao = enrollmentDao;
@@ -53,8 +54,20 @@ public class EventReportingJobHandler {
}
/**
+ * Set Debug Report
+ *
+ * @param isDebugReport
+ * @return the instance of EventReportingJobHandler
+ */
+ public EventReportingJobHandler setDebugReport(boolean isDebugReport) {
+ mIsDebugReport = isDebugReport;
+ return this;
+ }
+
+ /**
* Finds all reports within the given window that have a status {@link
- * EventReport.Status#PENDING} and attempts to upload them individually.
+ * EventReport.Status#PENDING} or {@link EventReport.DebugReportStatus#PENDING} based on
+ * mIsDebugReport and attempts to upload them individually.
*
* @param windowStartTime Start time of the search window
* @param windowEndTime End time of the search window
@@ -62,9 +75,16 @@ public class EventReportingJobHandler {
*/
synchronized boolean performScheduledPendingReportsInWindow(
long windowStartTime, long windowEndTime) {
- Optional<List<String>> pendingEventReportsInWindowOpt = mDatastoreManager
- .runInTransactionWithResult((dao) ->
- dao.getPendingEventReportIdsInWindow(windowStartTime, windowEndTime));
+ Optional<List<String>> pendingEventReportsInWindowOpt =
+ mDatastoreManager.runInTransactionWithResult(
+ (dao) -> {
+ if (mIsDebugReport) {
+ return dao.getPendingDebugEventReportIds();
+ } else {
+ return dao.getPendingEventReportIdsInWindow(
+ windowStartTime, windowEndTime);
+ }
+ });
if (!pendingEventReportsInWindowOpt.isPresent()) {
// Failure during event report retrieval
return true;
@@ -94,7 +114,12 @@ public class EventReportingJobHandler {
return AdServicesStatusUtils.STATUS_IO_ERROR;
}
EventReport eventReport = eventReportOpt.get();
- if (eventReport.getStatus() != EventReport.Status.PENDING) {
+
+ if (mIsDebugReport
+ && eventReport.getDebugReportStatus() != EventReport.DebugReportStatus.PENDING) {
+ return AdServicesStatusUtils.STATUS_INVALID_ARGUMENT;
+ }
+ if (!mIsDebugReport && eventReport.getStatus() != EventReport.Status.PENDING) {
return AdServicesStatusUtils.STATUS_INVALID_ARGUMENT;
}
try {
@@ -110,8 +135,16 @@ public class EventReportingJobHandler {
if (returnCode >= HttpURLConnection.HTTP_OK
&& returnCode <= 299) {
- boolean success = mDatastoreManager.runInTransaction((dao) ->
- dao.markEventReportDelivered(eventReportId));
+ boolean success =
+ mDatastoreManager.runInTransaction(
+ (dao) -> {
+ if (mIsDebugReport) {
+ dao.markEventDebugReportDelivered(eventReportId);
+ } else {
+ dao.markEventReportStatus(
+ eventReportId, EventReport.Status.DELIVERED);
+ }
+ });
return success
? AdServicesStatusUtils.STATUS_SUCCESS
@@ -133,9 +166,9 @@ public class EventReportingJobHandler {
JSONObject createReportJsonPayload(EventReport eventReport) throws JSONException {
return new EventReportPayload.Builder()
.setReportId(eventReport.getId())
- .setSourceEventId(String.valueOf(eventReport.getSourceId()))
+ .setSourceEventId(eventReport.getSourceEventId())
.setAttributionDestination(eventReport.getAttributionDestination().toString())
- .setTriggerData(String.valueOf(eventReport.getTriggerData()))
+ .setTriggerData(eventReport.getTriggerData())
.setSourceType(eventReport.getSourceType().getValue())
.setRandomizedTriggerRate(eventReport.getRandomizedTriggerRate())
.setSourceDebugKey(eventReport.getSourceDebugKey())
@@ -150,7 +183,7 @@ public class EventReportingJobHandler {
@VisibleForTesting
public int makeHttpPostRequest(Uri adTechDomain, JSONObject eventReportPayload)
throws IOException {
- EventReportSender eventReportSender = new EventReportSender();
+ EventReportSender eventReportSender = new EventReportSender(mIsDebugReport);
return eventReportSender.sendReport(adTechDomain, eventReportPayload);
}