• 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.service.measurement;
18 
19 import com.android.adservices.service.measurement.util.Validation;
20 
21 import java.util.Objects;
22 
23 /**
24  * It is used to insert and retrieve an entry in the database that counts towards attribution rate
25  * limits. It is typically built from an {@link EventReport} or {@link Source}-{@link Trigger}
26  * combination.
27  */
28 public class Attribution {
29     private final String mId;
30     private final String mSourceSite;
31     private final String mSourceOrigin;
32     private final String mDestinationSite;
33     private final String mDestinationOrigin;
34     private final String mEnrollmentId;
35     // TODO: b/276638412 rename to source time
36     private final long mTriggerTime;
37     private final String mRegistrant;
38     private final String mSourceId;
39     private final String mTriggerId;
40 
Attribution(Builder builder)41     private Attribution(Builder builder) {
42         this.mId = builder.mId;
43         this.mSourceSite = builder.mSourceSite;
44         this.mSourceOrigin = builder.mSourceOrigin;
45         this.mDestinationSite = builder.mDestinationSite;
46         this.mDestinationOrigin = builder.mDestinationOrigin;
47         this.mEnrollmentId = builder.mEnrollmentId;
48         this.mTriggerTime = builder.mTriggerTime;
49         this.mRegistrant = builder.mRegistrant;
50         this.mSourceId = builder.mSourceId;
51         this.mTriggerId = builder.mTriggerId;
52     }
53 
54     @Override
equals(Object obj)55     public boolean equals(Object obj) {
56         if (!(obj instanceof Attribution)) {
57             return false;
58         }
59         Attribution attr = (Attribution) obj;
60         return mTriggerTime == attr.mTriggerTime
61                 && Objects.equals(mSourceSite, attr.mSourceSite)
62                 && Objects.equals(mSourceOrigin, attr.mSourceOrigin)
63                 && Objects.equals(mDestinationSite, attr.mDestinationSite)
64                 && Objects.equals(mDestinationOrigin, attr.mDestinationOrigin)
65                 && Objects.equals(mEnrollmentId, attr.mEnrollmentId)
66                 && Objects.equals(mRegistrant, attr.mRegistrant)
67                 && Objects.equals(mSourceId, attr.mSourceId)
68                 && Objects.equals(mTriggerId, attr.mTriggerId);
69     }
70 
71     @Override
hashCode()72     public int hashCode() {
73         return Objects.hash(
74                 mSourceSite,
75                 mSourceOrigin,
76                 mDestinationSite,
77                 mDestinationOrigin,
78                 mEnrollmentId,
79                 mTriggerTime,
80                 mRegistrant,
81                 mSourceId,
82                 mTriggerId);
83     }
84 
85     /** @return unique identifier for {@link Attribution} */
getId()86     public String getId() {
87         return mId;
88     }
89 
90     /** @return top private domain of {@link Source} publisher */
getSourceSite()91     public String getSourceSite() {
92         return mSourceSite;
93     }
94 
95     /** @return complete {@link Source} publisher */
getSourceOrigin()96     public String getSourceOrigin() {
97         return mSourceOrigin;
98     }
99 
100     /** @return top private domain of {@link Trigger} destination */
getDestinationSite()101     public String getDestinationSite() {
102         return mDestinationSite;
103     }
104 
105     /** @return complete {@link Trigger} destination */
getDestinationOrigin()106     public String getDestinationOrigin() {
107         return mDestinationOrigin;
108     }
109 
110     /** @return {@link Source} or {@link Trigger} enrollment ID */
getEnrollmentId()111     public String getEnrollmentId() {
112         return mEnrollmentId;
113     }
114 
115     /** @return {@link Trigger} event time */
getTriggerTime()116     public long getTriggerTime() {
117         return mTriggerTime;
118     }
119 
120     /** @return {@link Trigger} registrant */
getRegistrant()121     public String getRegistrant() {
122         return mRegistrant;
123     }
124 
125     /** @return {@link Source} ID */
getSourceId()126     public String getSourceId() {
127         return mSourceId;
128     }
129 
130     /** @return {@link Trigger} ID */
getTriggerId()131     public String getTriggerId() {
132         return mTriggerId;
133     }
134 
135     /** Builder for AttributionRateLimit */
136     public static final class Builder {
137         private String mId;
138         private String mSourceSite;
139         private String mSourceOrigin;
140         private String mDestinationSite;
141         private String mDestinationOrigin;
142         private String mEnrollmentId;
143         private long mTriggerTime;
144         private String mRegistrant;
145         private String mSourceId;
146         private String mTriggerId;
147 
148         /** See {@link Attribution#getId()}. */
setId(String id)149         public Builder setId(String id) {
150             mId = id;
151             return this;
152         }
153 
154         /** See {@link Attribution#getSourceSite()}. */
setSourceSite(String sourceSite)155         public Builder setSourceSite(String sourceSite) {
156             mSourceSite = sourceSite;
157             return this;
158         }
159 
160         /** See {@link Attribution#getSourceOrigin()}. */
setSourceOrigin(String sourceOrigin)161         public Builder setSourceOrigin(String sourceOrigin) {
162             mSourceOrigin = sourceOrigin;
163             return this;
164         }
165 
166         /** See {@link Attribution#getDestinationSite()}. */
setDestinationSite(String destinationSite)167         public Builder setDestinationSite(String destinationSite) {
168             mDestinationSite = destinationSite;
169             return this;
170         }
171 
172         /** See {@link Attribution#getDestinationOrigin()}. */
setDestinationOrigin(String destinationOrigin)173         public Builder setDestinationOrigin(String destinationOrigin) {
174             mDestinationOrigin = destinationOrigin;
175             return this;
176         }
177 
178         /** See {@link Attribution#getEnrollmentId()}. */
setEnrollmentId(String enrollmentId)179         public Builder setEnrollmentId(String enrollmentId) {
180             mEnrollmentId = enrollmentId;
181             return this;
182         }
183 
184         /** See {@link Attribution#getTriggerTime()}. */
setTriggerTime(long triggerTime)185         public Builder setTriggerTime(long triggerTime) {
186             mTriggerTime = triggerTime;
187             return this;
188         }
189 
190         /** See {@link Attribution#getRegistrant()}. */
setRegistrant(String registrant)191         public Builder setRegistrant(String registrant) {
192             mRegistrant = registrant;
193             return this;
194         }
195 
196         /** See {@link Attribution#getSourceId()}. */
setSourceId(String sourceId)197         public Builder setSourceId(String sourceId) {
198             mSourceId = sourceId;
199             return this;
200         }
201 
202         /** See {@link Attribution#getTriggerId()}. */
setTriggerId(String triggerId)203         public Builder setTriggerId(String triggerId) {
204             mTriggerId = triggerId;
205             return this;
206         }
207 
208         /** Validate and build the {@link Attribution}. */
build()209         public Attribution build() {
210             Validation.validateNonNull(
211                     mSourceSite,
212                     mSourceOrigin,
213                     mDestinationSite,
214                     mDestinationOrigin,
215                     mEnrollmentId,
216                     mRegistrant);
217             return new Attribution(this);
218         }
219     }
220 }
221