1 /*
2  * Copyright (C) 2023 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.service.measurement.reporting;
18 
19 
20 
21 /** POJO for storing aggregate and event reporting status */
22 public class ReportingStatus {
23 
24     /** Enums are tied to the AdservicesMeasurementReportsUploaded atom */
25     public enum ReportType {
26         UNKNOWN(0),
27         EVENT(1),
28         AGGREGATE(2),
29         DEBUG_EVENT(3),
30         DEBUG_AGGREGATE(4),
31         VERBOSE_DEBUG_SOURCE_DESTINATION_LIMIT(5),
32         VERBOSE_DEBUG_SOURCE_NOISED(6),
33         VERBOSE_DEBUG_SOURCE_STORAGE_LIMIT(7),
34         VERBOSE_DEBUG_SOURCE_SUCCESS(8),
35         VERBOSE_DEBUG_SOURCE_UNKNOWN_ERROR(9),
36         VERBOSE_DEBUG_SOURCE_FLEXIBLE_EVENT_REPORT_VALUE_ERROR(10),
37         VERBOSE_DEBUG_TRIGGER_AGGREGATE_DEDUPLICATED(11),
38         VERBOSE_DEBUG_TRIGGER_AGGREGATE_INSUFFICIENT_BUDGET(12),
39         VERBOSE_DEBUG_TRIGGER_AGGREGATE_NO_CONTRIBUTIONS(13),
40         VERBOSE_DEBUG_TRIGGER_AGGREGATE_REPORT_WINDOW_PASSED(14),
41         VERBOSE_DEBUG_TRIGGER_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT(15),
42         VERBOSE_DEBUG_TRIGGER_EVENT_DEDUPLICATED(16),
43         VERBOSE_DEBUG_TRIGGER_EVENT_EXCESSIVE_REPORTS(17),
44         VERBOSE_DEBUG_TRIGGER_EVENT_LOW_PRIORITY(18),
45         VERBOSE_DEBUG_TRIGGER_EVENT_NO_MATCHING_CONFIGURATIONS(19),
46         VERBOSE_DEBUG_TRIGGER_EVENT_NOISE(20),
47         VERBOSE_DEBUG_TRIGGER_EVENT_REPORT_WINDOW_PASSED(21),
48         VERBOSE_DEBUG_TRIGGER_NO_MATCHING_FILTER_DATA(22),
49         VERBOSE_DEBUG_TRIGGER_NO_MATCHING_SOURCE(23),
50         VERBOSE_DEBUG_TRIGGER_REPORTING_ORIGIN_LIMIT(24),
51         VERBOSE_DEBUG_TRIGGER_EVENT_STORAGE_LIMIT(25),
52         VERBOSE_DEBUG_TRIGGER_UNKNOWN_ERROR(26),
53         VERBOSE_DEBUG_TRIGGER_AGGREGATE_STORAGE_LIMIT(27),
54         VERBOSE_DEBUG_TRIGGER_AGGREGATE_EXCESSIVE_REPORTS(28),
55         VERBOSE_DEBUG_TRIGGER_EVENT_REPORT_WINDOW_NOT_STARTED(29),
56         VERBOSE_DEBUG_TRIGGER_EVENT_NO_MATCHING_TRIGGER_DATA(30),
57         VERBOSE_DEBUG_TRIGGER_EVENT_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT(31),
58         VERBOSE_DEBUG_TRIGGER_AGG_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT(32),
59         VERBOSE_DEBUG_UNKNOWN(9999);
60 
61         private final int mValue;
62 
ReportType(int value)63         ReportType(int value) {
64             mValue = value;
65         }
66 
getValue()67         public int getValue() {
68             return mValue;
69         }
70     }
71 
72     public enum UploadStatus {
73         UNKNOWN(0),
74         SUCCESS(1),
75         FAILURE(2);
76 
77         private final int mValue;
78 
UploadStatus(int value)79         UploadStatus(int value) {
80             mValue = value;
81         }
82 
getValue()83         public int getValue() {
84             return mValue;
85         }
86     }
87 
88     public enum FailureStatus {
89         UNKNOWN(0),
90         ENROLLMENT_NOT_FOUND(1),
91         NETWORK(2),
92         DATASTORE(3),
93         REPORT_NOT_PENDING(4),
94         JOB_RETRY_LIMIT_REACHED(5),
95         SERIALIZATION_ERROR(6),
96         ENCRYPTION_ERROR(7),
97         UNSUCCESSFUL_HTTP_RESPONSE_CODE(8),
98         REPORT_NOT_FOUND(9);
99         private final int mValue;
100 
FailureStatus(int value)101         FailureStatus(int value) {
102             mValue = value;
103         }
104 
getValue()105         public int getValue() {
106             return mValue;
107         }
108     }
109 
110     public enum UploadMethod {
111         UNKNOWN(0),
112         REGULAR(1),
113         FALLBACK(2);
114         private final int mValue;
115 
UploadMethod(int value)116         UploadMethod(int value) {
117             mValue = value;
118         }
119 
getValue()120         public int getValue() {
121             return mValue;
122         }
123     }
124 
125     private ReportType mReportType;
126     private UploadStatus mUploadStatus;
127 
128     private FailureStatus mFailureStatus;
129 
130     private UploadMethod mUploadMethod;
131 
132     private long mReportingDelay;
133 
134     private String mSourceRegistrant;
135 
136     private int mRetryCount;
137 
ReportingStatus()138     public ReportingStatus() {
139         mReportType = ReportType.UNKNOWN;
140         mUploadStatus = UploadStatus.UNKNOWN;
141         mFailureStatus = FailureStatus.UNKNOWN;
142         mUploadMethod = UploadMethod.UNKNOWN;
143         mReportingDelay = 0L;
144         mSourceRegistrant = "";
145     }
146 
147     /** Get the type of report that is being uploaded. */
getReportType()148     public ReportType getReportType() {
149         return mReportType;
150     }
151 
152     /** Set the type of report that is being uploaded. */
setReportType(ReportType reportType)153     public void setReportType(ReportType reportType) {
154         mReportType = reportType;
155     }
156 
157     /** set the type of report that is being uploaded from debug report type string. */
setReportType(String reportType)158     public void setReportType(String reportType) {
159         if (reportType.equals(DebugReportApi.Type.SOURCE_DESTINATION_LIMIT)) {
160             mReportType = ReportType.VERBOSE_DEBUG_SOURCE_DESTINATION_LIMIT;
161         } else if (reportType.equals(DebugReportApi.Type.SOURCE_NOISED)) {
162             mReportType = ReportType.VERBOSE_DEBUG_SOURCE_NOISED;
163         } else if (reportType.equals(DebugReportApi.Type.SOURCE_STORAGE_LIMIT)) {
164             mReportType = ReportType.VERBOSE_DEBUG_SOURCE_STORAGE_LIMIT;
165         } else if (reportType.equals(DebugReportApi.Type.SOURCE_SUCCESS)) {
166             mReportType = ReportType.VERBOSE_DEBUG_SOURCE_SUCCESS;
167         } else if (reportType.equals(DebugReportApi.Type.SOURCE_UNKNOWN_ERROR)) {
168             mReportType = ReportType.VERBOSE_DEBUG_SOURCE_UNKNOWN_ERROR;
169         } else if (reportType.equals(
170                 DebugReportApi.Type.SOURCE_FLEXIBLE_EVENT_REPORT_VALUE_ERROR)) {
171             mReportType = ReportType.VERBOSE_DEBUG_SOURCE_FLEXIBLE_EVENT_REPORT_VALUE_ERROR;
172         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_AGGREGATE_DEDUPLICATED)) {
173             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_AGGREGATE_DEDUPLICATED;
174         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_AGGREGATE_INSUFFICIENT_BUDGET)) {
175             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_AGGREGATE_INSUFFICIENT_BUDGET;
176         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_AGGREGATE_NO_CONTRIBUTIONS)) {
177             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_AGGREGATE_NO_CONTRIBUTIONS;
178         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_AGGREGATE_REPORT_WINDOW_PASSED)) {
179             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_AGGREGATE_REPORT_WINDOW_PASSED;
180         } else if (reportType.equals(
181                 DebugReportApi.Type.TRIGGER_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT)) {
182             mReportType =
183                     ReportType.VERBOSE_DEBUG_TRIGGER_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT;
184         } else if (reportType.equals(
185                 DebugReportApi.Type.TRIGGER_EVENT_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT)) {
186             mReportType =
187                     ReportType
188                             .VERBOSE_DEBUG_TRIGGER_EVENT_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT;
189         } else if (reportType.equals(
190                 DebugReportApi.Type.TRIGGER_AGGREGATE_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT)) {
191             mReportType =
192                     ReportType.VERBOSE_DEBUG_TRIGGER_AGG_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT;
193         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_DEDUPLICATED)) {
194             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_DEDUPLICATED;
195         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_EXCESSIVE_REPORTS)) {
196             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_EXCESSIVE_REPORTS;
197         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_LOW_PRIORITY)) {
198             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_LOW_PRIORITY;
199         } else if (reportType.equals(
200                 DebugReportApi.Type.TRIGGER_EVENT_NO_MATCHING_CONFIGURATIONS)) {
201             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_NO_MATCHING_CONFIGURATIONS;
202         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_NOISE)) {
203             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_NOISE;
204         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_REPORT_WINDOW_PASSED)) {
205             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_REPORT_WINDOW_PASSED;
206         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_NO_MATCHING_FILTER_DATA)) {
207             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_NO_MATCHING_FILTER_DATA;
208         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_NO_MATCHING_SOURCE)) {
209             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_NO_MATCHING_SOURCE;
210         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_REPORTING_ORIGIN_LIMIT)) {
211             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_REPORTING_ORIGIN_LIMIT;
212         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_STORAGE_LIMIT)) {
213             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_STORAGE_LIMIT;
214         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_UNKNOWN_ERROR)) {
215             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_UNKNOWN_ERROR;
216         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_AGGREGATE_STORAGE_LIMIT)) {
217             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_AGGREGATE_STORAGE_LIMIT;
218         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_AGGREGATE_EXCESSIVE_REPORTS)) {
219             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_AGGREGATE_EXCESSIVE_REPORTS;
220         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_REPORT_WINDOW_NOT_STARTED)) {
221             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_REPORT_WINDOW_NOT_STARTED;
222         } else if (reportType.equals(DebugReportApi.Type.TRIGGER_EVENT_NO_MATCHING_TRIGGER_DATA)) {
223             mReportType = ReportType.VERBOSE_DEBUG_TRIGGER_EVENT_NO_MATCHING_TRIGGER_DATA;
224         } else {
225             mReportType = ReportType.VERBOSE_DEBUG_UNKNOWN;
226         }
227     }
228 
229     /** Get the upload status of reporting. */
getUploadStatus()230     public UploadStatus getUploadStatus() {
231         return mUploadStatus;
232     }
233 
234     /** Set upload status of reporting. */
setUploadStatus(UploadStatus status)235     public void setUploadStatus(UploadStatus status) {
236         mUploadStatus = status;
237     }
238 
239     /** Get the failure status of reporting. */
getFailureStatus()240     public FailureStatus getFailureStatus() {
241         return mFailureStatus;
242     }
243 
244     /** Set failure status of reporting. */
setFailureStatus(FailureStatus status)245     public void setFailureStatus(FailureStatus status) {
246         mFailureStatus = status;
247     }
248 
249     /** Get the upload method of reporting. */
getUploadMethod()250     public UploadMethod getUploadMethod() {
251         return mUploadMethod;
252     }
253 
254     /** Set upload method of reporting. */
setUploadMethod(UploadMethod method)255     public void setUploadMethod(UploadMethod method) {
256         mUploadMethod = method;
257     }
258 
259     /** Get registration delay. */
getReportingDelay()260     public long getReportingDelay() {
261         return mReportingDelay;
262     }
263 
264     /** Set registration delay. */
setReportingDelay(long reportingDelay)265     public void setReportingDelay(long reportingDelay) {
266         mReportingDelay = reportingDelay;
267     }
268 
269     /** Get source registrant. */
getSourceRegistrant()270     public String getSourceRegistrant() {
271         return mSourceRegistrant;
272     }
273 
274     /** Set source registrant. */
setSourceRegistrant(String sourceRegistrant)275     public void setSourceRegistrant(String sourceRegistrant) {
276         mSourceRegistrant = sourceRegistrant;
277     }
278 
279     /** Get retry count. */
getRetryCount()280     public int getRetryCount() {
281         return mRetryCount;
282     }
283 
284     /** Set retry count. */
setRetryCount(int retryCount)285     public void setRetryCount(int retryCount) {
286         mRetryCount = retryCount;
287     }
288 }
289