• 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 android.adservices.ondevicepersonalization;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.net.Uri;
22 
23 import com.android.adservices.ondevicepersonalization.flags.Flags;
24 
25 import java.util.Objects;
26 
27 /**
28  * The input data for
29  * {@link IsolatedWorker#onWebTrigger(WebTriggerInput, android.os.OutcomeReceiver)}.
30  */
31 public final class WebTriggerInput {
32     /** The destination URL (landing page) where the trigger event occurred. */
33     @NonNull private Uri mDestinationUrl;
34 
35     /** The package name of the app where the trigger event occurred */
36     @NonNull private String mAppPackageName;
37 
38     /**
39      * Additional data returned by the server as part of the web trigger registration
40      * to be sent to the {@link IsolatedService}. This can be {@code null} if the server
41      * does not need to send data to the service for processing web triggers.
42      */
43     @NonNull private byte[] mData;
44 
45     /** @hide */
WebTriggerInput(@onNull WebTriggerInputParcel parcel)46     public WebTriggerInput(@NonNull WebTriggerInputParcel parcel) {
47         this(parcel.getDestinationUrl(), parcel.getAppPackageName(), parcel.getData());
48     }
49 
50     /**
51      * Creates a new WebTriggerInput.
52      *
53      * @param destinationUrl
54      *   The destination URL (landing page) where the trigger event occurred.
55      * @param appPackageName
56      *   The package name of the app where the trigger event occurred
57      * @param data
58      *   Additional data returned by the server as part of the web trigger registration
59      *   to be sent to the {@link IsolatedService}. This can be {@code null} if the server
60      *   does not need to send data to the service for processing web triggers.
61      */
62     @FlaggedApi(Flags.FLAG_DATA_CLASS_MISSING_CTORS_AND_GETTERS_ENABLED)
WebTriggerInput( @onNull Uri destinationUrl, @NonNull String appPackageName, @NonNull byte[] data)63     public WebTriggerInput(
64             @NonNull Uri destinationUrl,
65             @NonNull String appPackageName,
66             @NonNull byte[] data) {
67         this.mDestinationUrl = Objects.requireNonNull(destinationUrl);
68         this.mAppPackageName = Objects.requireNonNull(appPackageName);
69         this.mData = Objects.requireNonNull(data);
70     }
71 
72     /**
73      * The destination URL (landing page) where the trigger event occurred.
74      */
getDestinationUrl()75     public @NonNull Uri getDestinationUrl() {
76         return mDestinationUrl;
77     }
78 
79     /**
80      * The package name of the app where the trigger event occurred
81      */
getAppPackageName()82     public @NonNull String getAppPackageName() {
83         return mAppPackageName;
84     }
85 
86     /**
87      * Additional data returned by the server as part of the web trigger registration
88      * to be sent to the {@link IsolatedService}. This can be {@code null} if the server
89      * does not need to send data to the service for processing web triggers.
90      */
getData()91     public @NonNull byte[] getData() {
92         return mData;
93     }
94 
95     @Override
equals(@ndroid.annotation.Nullable Object o)96     public boolean equals(@android.annotation.Nullable Object o) {
97         if (this == o) return true;
98         if (o == null || getClass() != o.getClass()) return false;
99         @SuppressWarnings("unchecked")
100         WebTriggerInput that = (WebTriggerInput) o;
101         //noinspection PointlessBooleanExpression
102         return true
103                 && java.util.Objects.equals(mDestinationUrl, that.mDestinationUrl)
104                 && java.util.Objects.equals(mAppPackageName, that.mAppPackageName)
105                 && java.util.Arrays.equals(mData, that.mData);
106     }
107 
108     @Override
hashCode()109     public int hashCode() {
110         int _hash = 1;
111         _hash = 31 * _hash + java.util.Objects.hashCode(mDestinationUrl);
112         _hash = 31 * _hash + java.util.Objects.hashCode(mAppPackageName);
113         _hash = 31 * _hash + java.util.Arrays.hashCode(mData);
114         return _hash;
115     }
116 }
117