• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.net.Uri;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 import java.util.Objects;
27 
28 /** POJO for Count Unique Report. */
29 public class CountUniqueReport {
30 
31     private String mReportId;
32     private String mPayload;
33     private Uri mReportingOrigin;
34 
35     @ReportDeliveryStatus private int mStatus;
36     @ReportDeliveryStatus private int mDebugReportStatus;
37     private Long mScheduledReportTime; // async registration time + random([0min, 10 min])
38 
39     private String mApiVersion;
40 
41     @Nullable private String mDebugKey;
42     @Nullable private String mContextId;
43     private String mEnrollmentId;
44     private Integer mContributionValue;
45     private Long mContributionTime;
46 
47     @IntDef(
48             value = {
49                 ReportDeliveryStatus.NONE,
50                 ReportDeliveryStatus.PENDING,
51                 ReportDeliveryStatus.DELIVERED
52             })
53     @Retention(RetentionPolicy.SOURCE)
54     public @interface ReportDeliveryStatus {
55         int NONE = 0;
56         int PENDING = 1;
57         int DELIVERED = 2;
58     }
59 
CountUniqueReport()60     private CountUniqueReport() {
61         mReportId = null;
62         mPayload = null;
63         mReportingOrigin = null;
64         mStatus = ReportDeliveryStatus.PENDING;
65         mDebugReportStatus = ReportDeliveryStatus.NONE;
66         mScheduledReportTime = null;
67         mApiVersion = null;
68         mDebugKey = null;
69         mContextId = null;
70         mEnrollmentId = null;
71         mContributionValue = null;
72         mContributionTime = null;
73     }
74 
75     @Override
equals(Object obj)76     public boolean equals(Object obj) {
77         if (!(obj instanceof CountUniqueReport countUniqueReport)) {
78             return false;
79         }
80         return Objects.equals(mReportId, countUniqueReport.mReportId)
81                 && Objects.equals(mPayload, countUniqueReport.mPayload)
82                 && Objects.equals(mReportingOrigin, countUniqueReport.mReportingOrigin)
83                 && mStatus == countUniqueReport.mStatus
84                 && mScheduledReportTime.equals(countUniqueReport.mScheduledReportTime)
85                 && Objects.equals(mApiVersion, countUniqueReport.mApiVersion)
86                 && Objects.equals(mDebugKey, countUniqueReport.mDebugKey)
87                 && Objects.equals(mContextId, countUniqueReport.mContextId)
88                 && mDebugReportStatus == countUniqueReport.mDebugReportStatus
89                 && Objects.equals(mEnrollmentId, countUniqueReport.mEnrollmentId)
90                 && Objects.equals(mContributionValue, countUniqueReport.mContributionValue)
91                 && Objects.equals(mContributionTime, countUniqueReport.mContributionTime);
92     }
93 
94     @Override
hashCode()95     public int hashCode() {
96         return Objects.hash(
97                 mReportId,
98                 mPayload,
99                 mReportingOrigin,
100                 mStatus,
101                 mScheduledReportTime,
102                 mApiVersion,
103                 mDebugKey,
104                 mContextId,
105                 mDebugReportStatus,
106                 mEnrollmentId,
107                 mContributionValue,
108                 mContributionTime);
109     }
110 
111     /** Report id for the report */
getReportId()112     public String getReportId() {
113         return mReportId;
114     }
115 
116     /** Clear text payload containing the histogram contribution */
getPayload()117     public String getPayload() {
118         return mPayload;
119     }
120 
121     /** Reporting origin for sending reports */
getReportingOrigin()122     public Uri getReportingOrigin() {
123         return mReportingOrigin;
124     }
125 
126     /** Time when the report is scheduled to be sent */
getScheduledReportTime()127     public Long getScheduledReportTime() {
128         return mScheduledReportTime;
129     }
130 
131     /** Version of the API */
getApiVersion()132     public String getApiVersion() {
133         return mApiVersion;
134     }
135 
136     /** Status of the report */
137     @ReportDeliveryStatus
getStatus()138     public int getStatus() {
139         return mStatus;
140     }
141 
142     /** Debug key for the report */
getDebugKey()143     public String getDebugKey() {
144         return mDebugKey;
145     }
146 
147     /** ContextId for the report */
getContextId()148     public String getContextId() {
149         return mContextId;
150     }
151 
152     /** Debug Report Status of the report */
153     @ReportDeliveryStatus
getDebugReportStatus()154     public int getDebugReportStatus() {
155         return mDebugReportStatus;
156     }
157 
158     /** EnrollmentId for the report */
getEnrollmentId()159     public String getEnrollmentId() {
160         return mEnrollmentId;
161     }
162 
163     /** Contribution value for the histogram in report */
getContributionValue()164     public Integer getContributionValue() {
165         return mContributionValue;
166     }
167 
168     /** Timestamp at which contribution is made */
getContributionTime()169     public Long getContributionTime() {
170         return mContributionTime;
171     }
172 
173     public static class Builder {
174 
175         private final CountUniqueReport mReport;
176 
Builder()177         public Builder() {
178             mReport = new CountUniqueReport();
179         }
180 
181         /** See {@link CountUniqueReport#getReportId()} */
setReportId(@onNull String reportId)182         public Builder setReportId(@NonNull String reportId) {
183             mReport.mReportId = reportId;
184             return this;
185         }
186 
187         /** See {@link CountUniqueReport#getPayload()} */
setPayload(@onNull String payload)188         public Builder setPayload(@NonNull String payload) {
189             mReport.mPayload = payload;
190             return this;
191         }
192 
193         /** See {@link CountUniqueReport#getReportingOrigin()} */
setReportingOrigin(@onNull Uri reportingOrigin)194         public Builder setReportingOrigin(@NonNull Uri reportingOrigin) {
195             mReport.mReportingOrigin = reportingOrigin;
196             return this;
197         }
198 
199         /** See {@link CountUniqueReport#getStatus()} */
setStatus(@eportDeliveryStatus int status)200         public Builder setStatus(@ReportDeliveryStatus int status) {
201             mReport.mStatus = status;
202             return this;
203         }
204 
205         /** See {@link CountUniqueReport#getScheduledReportTime()} */
setScheduledReportTime(@onNull Long scheduledReportTime)206         public Builder setScheduledReportTime(@NonNull Long scheduledReportTime) {
207             mReport.mScheduledReportTime = scheduledReportTime;
208             return this;
209         }
210 
211         /** See {@link CountUniqueReport#getApiVersion()} */
setApiVersion(@onNull String apiVersion)212         public Builder setApiVersion(@NonNull String apiVersion) {
213             mReport.mApiVersion = apiVersion;
214             return this;
215         }
216 
217         /** See {@link CountUniqueReport#getDebugKey()} */
setDebugKey(@ullable String debugKey)218         public Builder setDebugKey(@Nullable String debugKey) {
219             mReport.mDebugKey = debugKey;
220             return this;
221         }
222 
223         /** See {@link CountUniqueReport#getContextId()} */
setContextId(@ullable String contextId)224         public Builder setContextId(@Nullable String contextId) {
225             mReport.mContextId = contextId;
226             return this;
227         }
228 
229         /** See {@link CountUniqueReport#getDebugReportStatus()} */
setDebugReportStatus(@eportDeliveryStatus int debugReportStatus)230         public Builder setDebugReportStatus(@ReportDeliveryStatus int debugReportStatus) {
231             mReport.mDebugReportStatus = debugReportStatus;
232             return this;
233         }
234 
235         /** See {@link CountUniqueReport#getEnrollmentId()} */
setEnrollmentId(@onNull String enrollmentId)236         public Builder setEnrollmentId(@NonNull String enrollmentId) {
237             mReport.mEnrollmentId = enrollmentId;
238             return this;
239         }
240 
241         /** See {@link CountUniqueReport#getContributionValue()} */
setContributionValue(@onNull Integer contributionValue)242         public Builder setContributionValue(@NonNull Integer contributionValue) {
243             mReport.mContributionValue = contributionValue;
244             return this;
245         }
246 
247         /** See {@link CountUniqueReport#getContributionTime()} */
setContributionTime(@onNull Long contributionTime)248         public Builder setContributionTime(@NonNull Long contributionTime) {
249             mReport.mContributionTime = contributionTime;
250             return this;
251         }
252 
253         /** Builds a CountUniqueReport */
build()254         public CountUniqueReport build() {
255             return mReport;
256         }
257     }
258 }
259