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 android.adservices.ondevicepersonalization;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.content.ComponentName;
24 import android.net.Uri;
25 
26 import com.android.adservices.ondevicepersonalization.flags.Flags;
27 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
28 import com.android.ondevicepersonalization.internal.util.DataClass;
29 
30 // TODO(b/301732670): Add link to documentation describing the format of the ODP-specific
31 // attribution data that the server is expected to return.
32 /**
33  * A class that contains Web Trigger Event data sent from the
34  * <a href="https://developer.android.com/design-for-safety/privacy-sandbox/guides/attribution">
35  * Measurement API</a> to the OnDevicePersonalization service when the browser registers a web
36  * trigger URL with the native OS attribution API as described in
37  * <a href="https://github.com/WICG/attribution-reporting-api/blob/main/app_to_web.md">
38  * Cross App and Web Attribution Measurement</a>. The Measurement API fetches and processes the
39  * attribution response from the browser-provided URL. If the URL response contains additional
40  * data that needs to be processed by an {@link IsolatedService}, the Measurement API passes this
41  * to the OnDevicePersonalization service and the OnDevicePersonalization service will invoke
42  * the {@link IsolatedService} with the provided data.
43  *
44  * @hide
45  */
46 @SystemApi
47 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
48 @DataClass(genBuilder = true, genEqualsHashCode = true)
49 public final class MeasurementWebTriggerEventParams {
50     /**
51      * The URL of the web page where the web trigger event occurred.
52      */
53     @NonNull private Uri mDestinationUrl;
54 
55     /**
56      * The package name of the browser app where the web trigger event occurred.
57      */
58     @NonNull private String mAppPackageName;
59 
60     /**
61      * The package and class name of the {@link IsolatedService} that should process
62      * the web trigger event.
63      */
64     @NonNull private ComponentName mIsolatedService;
65 
66     /**
67      * An optional SHA-256 hash of the signing key of the package that contains
68      * the {@link IsolatedService}, to guard against package name spoofing via sideloading.
69      * If this field is present and does not match the signing key of the installed receiver
70      * service package, the web trigger event is discarded.
71      */
72     @DataClass.MaySetToNull
73     @Nullable private String mCertDigest = null;
74 
75     /**
76      * Additional data that the server may provide to the {@link IsolatedService}. This can be
77      * {@code null} if the server does not need to provide any data other than the required fields.
78      */
79     @DataClass.MaySetToNull
80     @Nullable private byte[] mEventData = null;
81 
82 
83 
84     // Code below generated by codegen v1.0.23.
85     //
86     // DO NOT MODIFY!
87     // CHECKSTYLE:OFF Generated code
88     //
89     // To regenerate run:
90     // $ codegen $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/MeasurementWebTriggerEventParams.java
91     //
92     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
93     //   Settings > Editor > Code Style > Formatter Control
94     //@formatter:off
95 
96 
97     @DataClass.Generated.Member
MeasurementWebTriggerEventParams( @onNull Uri destinationUrl, @NonNull String appPackageName, @NonNull ComponentName isolatedService, @Nullable String certDigest, @Nullable byte[] eventData)98     /* package-private */ MeasurementWebTriggerEventParams(
99             @NonNull Uri destinationUrl,
100             @NonNull String appPackageName,
101             @NonNull ComponentName isolatedService,
102             @Nullable String certDigest,
103             @Nullable byte[] eventData) {
104         this.mDestinationUrl = destinationUrl;
105         AnnotationValidations.validate(
106                 NonNull.class, null, mDestinationUrl);
107         this.mAppPackageName = appPackageName;
108         AnnotationValidations.validate(
109                 NonNull.class, null, mAppPackageName);
110         this.mIsolatedService = isolatedService;
111         AnnotationValidations.validate(
112                 NonNull.class, null, mIsolatedService);
113         this.mCertDigest = certDigest;
114         this.mEventData = eventData;
115 
116         // onConstructed(); // You can define this method to get a callback
117     }
118 
119     /**
120      * The URL of the web page where the web trigger event occurred.
121      */
122     @DataClass.Generated.Member
getDestinationUrl()123     public @NonNull Uri getDestinationUrl() {
124         return mDestinationUrl;
125     }
126 
127     /**
128      * The package name of the browser app where the web trigger event occurred.
129      */
130     @DataClass.Generated.Member
getAppPackageName()131     public @NonNull String getAppPackageName() {
132         return mAppPackageName;
133     }
134 
135     /**
136      * The package and class name of the {@link IsolatedService} that should process
137      * the web trigger event.
138      */
139     @DataClass.Generated.Member
getIsolatedService()140     public @NonNull ComponentName getIsolatedService() {
141         return mIsolatedService;
142     }
143 
144     /**
145      * An optional SHA-256 hash of the signing key of the package that contains
146      * the {@link IsolatedService}, to guard against package name spoofing via sideloading.
147      * If this field is present and does not match the signing key of the installed receiver
148      * service package, the web trigger event is discarded.
149      */
150     @DataClass.Generated.Member
getCertDigest()151     public @Nullable String getCertDigest() {
152         return mCertDigest;
153     }
154 
155     /**
156      * Additional data that the server may provide to the {@link IsolatedService}. This can be
157      * {@code null} if the server does not need to provide any data other than the required fields.
158      */
159     @DataClass.Generated.Member
getEventData()160     public @Nullable byte[] getEventData() {
161         return mEventData;
162     }
163 
164     @Override
165     @DataClass.Generated.Member
equals(@ullable Object o)166     public boolean equals(@Nullable Object o) {
167         // You can override field equality logic by defining either of the methods like:
168         // boolean fieldNameEquals(MeasurementWebTriggerEventParams other) { ... }
169         // boolean fieldNameEquals(FieldType otherValue) { ... }
170 
171         if (this == o) return true;
172         if (o == null || getClass() != o.getClass()) return false;
173         @SuppressWarnings("unchecked")
174         MeasurementWebTriggerEventParams that = (MeasurementWebTriggerEventParams) o;
175         //noinspection PointlessBooleanExpression
176         return true
177                 && java.util.Objects.equals(mDestinationUrl, that.mDestinationUrl)
178                 && java.util.Objects.equals(mAppPackageName, that.mAppPackageName)
179                 && java.util.Objects.equals(mIsolatedService, that.mIsolatedService)
180                 && java.util.Objects.equals(mCertDigest, that.mCertDigest)
181                 && java.util.Arrays.equals(mEventData, that.mEventData);
182     }
183 
184     @Override
185     @DataClass.Generated.Member
hashCode()186     public int hashCode() {
187         // You can override field hashCode logic by defining methods like:
188         // int fieldNameHashCode() { ... }
189 
190         int _hash = 1;
191         _hash = 31 * _hash + java.util.Objects.hashCode(mDestinationUrl);
192         _hash = 31 * _hash + java.util.Objects.hashCode(mAppPackageName);
193         _hash = 31 * _hash + java.util.Objects.hashCode(mIsolatedService);
194         _hash = 31 * _hash + java.util.Objects.hashCode(mCertDigest);
195         _hash = 31 * _hash + java.util.Arrays.hashCode(mEventData);
196         return _hash;
197     }
198 
199     /**
200      * A builder for {@link MeasurementWebTriggerEventParams}
201      */
202     @SuppressWarnings("WeakerAccess")
203     @DataClass.Generated.Member
204     public static final class Builder {
205 
206         private @NonNull Uri mDestinationUrl;
207         private @NonNull String mAppPackageName;
208         private @NonNull ComponentName mIsolatedService;
209         private @Nullable String mCertDigest;
210         private @Nullable byte[] mEventData;
211 
212         private long mBuilderFieldsSet = 0L;
213 
214         /**
215          * Creates a new Builder.
216          *
217          * @param destinationUrl
218          *   The URL of the web page where the web trigger event occurred.
219          * @param appPackageName
220          *   The package name of the browser app where the web trigger event occurred.
221          * @param isolatedService
222          *   The package and class name of the {@link IsolatedService} that should process
223          *   the web trigger event.
224          */
Builder( @onNull Uri destinationUrl, @NonNull String appPackageName, @NonNull ComponentName isolatedService)225         public Builder(
226                 @NonNull Uri destinationUrl,
227                 @NonNull String appPackageName,
228                 @NonNull ComponentName isolatedService) {
229             mDestinationUrl = destinationUrl;
230             AnnotationValidations.validate(
231                     NonNull.class, null, mDestinationUrl);
232             mAppPackageName = appPackageName;
233             AnnotationValidations.validate(
234                     NonNull.class, null, mAppPackageName);
235             mIsolatedService = isolatedService;
236             AnnotationValidations.validate(
237                     NonNull.class, null, mIsolatedService);
238         }
239 
240         /**
241          * The URL of the web page where the web trigger event occurred.
242          */
243         @DataClass.Generated.Member
setDestinationUrl(@onNull Uri value)244         public @NonNull Builder setDestinationUrl(@NonNull Uri value) {
245             checkNotUsed();
246             mBuilderFieldsSet |= 0x1;
247             mDestinationUrl = value;
248             return this;
249         }
250 
251         /**
252          * The package name of the browser app where the web trigger event occurred.
253          */
254         @DataClass.Generated.Member
setAppPackageName(@onNull String value)255         public @NonNull Builder setAppPackageName(@NonNull String value) {
256             checkNotUsed();
257             mBuilderFieldsSet |= 0x2;
258             mAppPackageName = value;
259             return this;
260         }
261 
262         /**
263          * The package and class name of the {@link IsolatedService} that should process
264          * the web trigger event.
265          */
266         @DataClass.Generated.Member
setIsolatedService(@onNull ComponentName value)267         public @NonNull Builder setIsolatedService(@NonNull ComponentName value) {
268             checkNotUsed();
269             mBuilderFieldsSet |= 0x4;
270             mIsolatedService = value;
271             return this;
272         }
273 
274         /**
275          * An optional SHA-256 hash of the signing key of the package that contains
276          * the {@link IsolatedService}, to guard against package name spoofing via sideloading.
277          * If this field is present and does not match the signing key of the installed receiver
278          * service package, the web trigger event is discarded.
279          */
280         @DataClass.Generated.Member
setCertDigest(@ullable String value)281         public @NonNull Builder setCertDigest(@Nullable String value) {
282             checkNotUsed();
283             mBuilderFieldsSet |= 0x8;
284             mCertDigest = value;
285             return this;
286         }
287 
288         /**
289          * Additional data that the server may provide to the {@link IsolatedService}. This can be
290          * {@code null} if the server does not need to provide any data other than the required fields.
291          */
292         @DataClass.Generated.Member
setEventData(@ullable byte... value)293         public @NonNull Builder setEventData(@Nullable byte... value) {
294             checkNotUsed();
295             mBuilderFieldsSet |= 0x10;
296             mEventData = value;
297             return this;
298         }
299 
300         /** Builds the instance. This builder should not be touched after calling this! */
build()301         public @NonNull MeasurementWebTriggerEventParams build() {
302             checkNotUsed();
303             mBuilderFieldsSet |= 0x20; // Mark builder used
304 
305             if ((mBuilderFieldsSet & 0x8) == 0) {
306                 mCertDigest = null;
307             }
308             if ((mBuilderFieldsSet & 0x10) == 0) {
309                 mEventData = null;
310             }
311             MeasurementWebTriggerEventParams o = new MeasurementWebTriggerEventParams(
312                     mDestinationUrl,
313                     mAppPackageName,
314                     mIsolatedService,
315                     mCertDigest,
316                     mEventData);
317             return o;
318         }
319 
checkNotUsed()320         private void checkNotUsed() {
321             if ((mBuilderFieldsSet & 0x20) != 0) {
322                 throw new IllegalStateException(
323                         "This Builder should not be reused. Use a new Builder instance instead");
324             }
325         }
326     }
327 
328     @DataClass.Generated(
329             time = 1707510203588L,
330             codegenVersion = "1.0.23",
331             sourceFile = "packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/MeasurementWebTriggerEventParams.java",
332             inputSignatures = "private @android.annotation.NonNull android.net.Uri mDestinationUrl\nprivate @android.annotation.NonNull java.lang.String mAppPackageName\nprivate @android.annotation.NonNull android.content.ComponentName mIsolatedService\nprivate @com.android.ondevicepersonalization.internal.util.DataClass.MaySetToNull @android.annotation.Nullable java.lang.String mCertDigest\nprivate @com.android.ondevicepersonalization.internal.util.DataClass.MaySetToNull @android.annotation.Nullable byte[] mEventData\nclass MeasurementWebTriggerEventParams extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)")
333     @Deprecated
__metadata()334     private void __metadata() {}
335 
336 
337     //@formatter:on
338     // End of generated code
339 
340 }
341