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.os.PersistableBundle;
23 
24 import com.android.adservices.ondevicepersonalization.flags.Flags;
25 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
26 import com.android.ondevicepersonalization.internal.util.DataClass;
27 
28 /**
29  * The result returned by
30  * {@link IsolatedWorker#onRender(RenderInput, android.os.OutcomeReceiver)}.
31  *
32  */
33 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
34 @DataClass(genBuilder = true, genEqualsHashCode = true)
35 public final class RenderOutput {
36     /**
37      * The HTML content to be rendered in a webview. If this is null, the ODP service
38      * generates HTML from the data in {@link #getTemplateId()} and {@link #getTemplateParams()}
39      * as described below.
40      */
41     @DataClass.MaySetToNull
42     @Nullable private String mContent = null;
43 
44     /**
45      * A key in the REMOTE_DATA {@link IsolatedService#getRemoteData(RequestToken)} table that
46      * points to an <a href="velocity.apache.org">Apache Velocity</a> template. This is ignored if
47      * {@link #getContent()} is not null.
48      */
49     @DataClass.MaySetToNull
50     @Nullable private String mTemplateId = null;
51 
52     /**
53      * The parameters to be populated in the template from {@link #getTemplateId()}. This is
54      * ignored if {@link #getContent()} is not null.
55      */
56     @NonNull private PersistableBundle mTemplateParams = PersistableBundle.EMPTY;
57 
58 
59 
60 
61 
62     // Code below generated by codegen v1.0.23.
63     //
64     // DO NOT MODIFY!
65     // CHECKSTYLE:OFF Generated code
66     //
67     // To regenerate run:
68     // $ codegen $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/RenderOutput.java
69     //
70     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
71     //   Settings > Editor > Code Style > Formatter Control
72     //@formatter:off
73 
74 
75     @DataClass.Generated.Member
RenderOutput( @ullable String content, @Nullable String templateId, @NonNull PersistableBundle templateParams)76     /* package-private */ RenderOutput(
77             @Nullable String content,
78             @Nullable String templateId,
79             @NonNull PersistableBundle templateParams) {
80         this.mContent = content;
81         this.mTemplateId = templateId;
82         this.mTemplateParams = templateParams;
83         AnnotationValidations.validate(
84                 NonNull.class, null, mTemplateParams);
85 
86         // onConstructed(); // You can define this method to get a callback
87     }
88 
89     /**
90      * The HTML content to be rendered in a webview. If this is null, the ODP service
91      * generates HTML from the data in {@link #getTemplateId()} and {@link #getTemplateParams()}
92      * as described below.
93      */
94     @DataClass.Generated.Member
getContent()95     public @Nullable String getContent() {
96         return mContent;
97     }
98 
99     /**
100      * A key in the REMOTE_DATA {@link IsolatedService#getRemoteData(RequestToken)} table that
101      * points to an <a href="velocity.apache.org">Apache Velocity</a> template. This is ignored if
102      * {@link #getContent()} is not null.
103      */
104     @DataClass.Generated.Member
getTemplateId()105     public @Nullable String getTemplateId() {
106         return mTemplateId;
107     }
108 
109     /**
110      * The parameters to be populated in the template from {@link #getTemplateId()}. This is
111      * ignored if {@link #getContent()} is not null.
112      */
113     @DataClass.Generated.Member
getTemplateParams()114     public @NonNull PersistableBundle getTemplateParams() {
115         return mTemplateParams;
116     }
117 
118     @Override
119     @DataClass.Generated.Member
equals(@ullable Object o)120     public boolean equals(@Nullable Object o) {
121         // You can override field equality logic by defining either of the methods like:
122         // boolean fieldNameEquals(RenderOutput other) { ... }
123         // boolean fieldNameEquals(FieldType otherValue) { ... }
124 
125         if (this == o) return true;
126         if (o == null || getClass() != o.getClass()) return false;
127         @SuppressWarnings("unchecked")
128         RenderOutput that = (RenderOutput) o;
129         //noinspection PointlessBooleanExpression
130         return true
131                 && java.util.Objects.equals(mContent, that.mContent)
132                 && java.util.Objects.equals(mTemplateId, that.mTemplateId)
133                 && java.util.Objects.equals(mTemplateParams, that.mTemplateParams);
134     }
135 
136     @Override
137     @DataClass.Generated.Member
hashCode()138     public int hashCode() {
139         // You can override field hashCode logic by defining methods like:
140         // int fieldNameHashCode() { ... }
141 
142         int _hash = 1;
143         _hash = 31 * _hash + java.util.Objects.hashCode(mContent);
144         _hash = 31 * _hash + java.util.Objects.hashCode(mTemplateId);
145         _hash = 31 * _hash + java.util.Objects.hashCode(mTemplateParams);
146         return _hash;
147     }
148 
149     /**
150      * A builder for {@link RenderOutput}
151      */
152     @SuppressWarnings("WeakerAccess")
153     @DataClass.Generated.Member
154     public static final class Builder {
155 
156         private @Nullable String mContent;
157         private @Nullable String mTemplateId;
158         private @NonNull PersistableBundle mTemplateParams;
159 
160         private long mBuilderFieldsSet = 0L;
161 
Builder()162         public Builder() {
163         }
164 
165         /**
166          * The HTML content to be rendered in a webview. If this is null, the ODP service
167          * generates HTML from the data in {@link #getTemplateId()} and {@link #getTemplateParams()}
168          * as described below.
169          */
170         @DataClass.Generated.Member
setContent(@ullable String value)171         public @NonNull Builder setContent(@Nullable String value) {
172             checkNotUsed();
173             mBuilderFieldsSet |= 0x1;
174             mContent = value;
175             return this;
176         }
177 
178         /**
179          * A key in the REMOTE_DATA {@link IsolatedService#getRemoteData(RequestToken)} table that
180          * points to an <a href="velocity.apache.org">Apache Velocity</a> template. This is ignored if
181          * {@link #getContent()} is not null.
182          */
183         @DataClass.Generated.Member
setTemplateId(@ullable String value)184         public @NonNull Builder setTemplateId(@Nullable String value) {
185             checkNotUsed();
186             mBuilderFieldsSet |= 0x2;
187             mTemplateId = value;
188             return this;
189         }
190 
191         /**
192          * The parameters to be populated in the template from {@link #getTemplateId()}. This is
193          * ignored if {@link #getContent()} is not null.
194          */
195         @DataClass.Generated.Member
setTemplateParams(@onNull PersistableBundle value)196         public @NonNull Builder setTemplateParams(@NonNull PersistableBundle value) {
197             checkNotUsed();
198             mBuilderFieldsSet |= 0x4;
199             mTemplateParams = value;
200             return this;
201         }
202 
203         /** Builds the instance. This builder should not be touched after calling this! */
build()204         public @NonNull RenderOutput build() {
205             checkNotUsed();
206             mBuilderFieldsSet |= 0x8; // Mark builder used
207 
208             if ((mBuilderFieldsSet & 0x1) == 0) {
209                 mContent = null;
210             }
211             if ((mBuilderFieldsSet & 0x2) == 0) {
212                 mTemplateId = null;
213             }
214             if ((mBuilderFieldsSet & 0x4) == 0) {
215                 mTemplateParams = PersistableBundle.EMPTY;
216             }
217             RenderOutput o = new RenderOutput(
218                     mContent,
219                     mTemplateId,
220                     mTemplateParams);
221             return o;
222         }
223 
checkNotUsed()224         private void checkNotUsed() {
225             if ((mBuilderFieldsSet & 0x8) != 0) {
226                 throw new IllegalStateException(
227                         "This Builder should not be reused. Use a new Builder instance instead");
228             }
229         }
230     }
231 
232     @DataClass.Generated(
233             time = 1707253768205L,
234             codegenVersion = "1.0.23",
235             sourceFile = "packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/RenderOutput.java",
236             inputSignatures = "private @com.android.ondevicepersonalization.internal.util.DataClass.MaySetToNull @android.annotation.Nullable java.lang.String mContent\nprivate @com.android.ondevicepersonalization.internal.util.DataClass.MaySetToNull @android.annotation.Nullable java.lang.String mTemplateId\nprivate @android.annotation.NonNull android.os.PersistableBundle mTemplateParams\nclass RenderOutput extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)")
237     @Deprecated
__metadata()238     private void __metadata() {}
239 
240 
241     //@formatter:on
242     // End of generated code
243 
244 }
245