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.content.ContentValues;
22 import android.os.Parcelable;
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 import java.time.Instant;
29 import java.util.Collections;
30 import java.util.List;
31 
32 // TODO(b/289102463): Add a link to the public doc for the REQUESTS table when available.
33 /**
34  * Contains data that will be written to the REQUESTS table at the end of a call to
35  * {@link IsolatedWorker#onExecute(ExecuteInput, android.os.OutcomeReceiver)}.
36  * A single {@link RequestLogRecord} is appended to the
37  * REQUESTS table if it is present in the output of one of the methods in {@link IsolatedWorker}.
38  * The contents of the REQUESTS table can be consumed by Federated Learning facilitated model
39  * training, or Federated Analytics facilitated cross-device statistical analysis.
40  */
41 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
42 @DataClass(genBuilder = true, genEqualsHashCode = true)
43 public final class RequestLogRecord implements Parcelable {
44     /**
45      * A List of rows, each containing a {@link ContentValues}.
46      **/
47     @DataClass.PluralOf("row")
48     @NonNull List<ContentValues> mRows = Collections.emptyList();
49 
50     /**
51      * Internal id for the RequestLogRecord.
52      * @hide
53      */
54     private long mRequestId = 0;
55 
56     /**
57      * Time of the request in milliseconds
58      * @hide
59      */
60     private long mTimeMillis = 0;
61 
62     /**
63      * Returns the timestamp of this record.
64      */
getTime()65     @NonNull public Instant getTime() {
66         return Instant.ofEpochMilli(getTimeMillis());
67     }
68 
69     abstract static class BaseBuilder {
70         /**
71          * @hide
72          */
setTimeMillis(long value)73         public abstract Builder setTimeMillis(long value);
74     }
75 
76 
77 
78     // Code below generated by codegen v1.0.23.
79     //
80     // DO NOT MODIFY!
81     // CHECKSTYLE:OFF Generated code
82     //
83     // To regenerate run:
84     // $ codegen $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/RequestLogRecord.java
85     //
86     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
87     //   Settings > Editor > Code Style > Formatter Control
88     //@formatter:off
89 
90 
91     @DataClass.Generated.Member
RequestLogRecord( @onNull List<ContentValues> rows, long requestId, long timeMillis)92     /* package-private */ RequestLogRecord(
93             @NonNull List<ContentValues> rows,
94             long requestId,
95             long timeMillis) {
96         this.mRows = rows;
97         AnnotationValidations.validate(
98                 NonNull.class, null, mRows);
99         this.mRequestId = requestId;
100         this.mTimeMillis = timeMillis;
101 
102         // onConstructed(); // You can define this method to get a callback
103     }
104 
105     /**
106      * A List of rows, each containing a {@link ContentValues}.
107      */
108     @DataClass.Generated.Member
getRows()109     public @NonNull List<ContentValues> getRows() {
110         return mRows;
111     }
112 
113     /**
114      * Internal id for the RequestLogRecord.
115      *
116      * @hide
117      */
118     @DataClass.Generated.Member
getRequestId()119     public long getRequestId() {
120         return mRequestId;
121     }
122 
123     /**
124      * Time of the request in milliseconds
125      *
126      * @hide
127      */
128     @DataClass.Generated.Member
getTimeMillis()129     public long getTimeMillis() {
130         return mTimeMillis;
131     }
132 
133     @Override
134     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)135     public boolean equals(@android.annotation.Nullable Object o) {
136         // You can override field equality logic by defining either of the methods like:
137         // boolean fieldNameEquals(RequestLogRecord other) { ... }
138         // boolean fieldNameEquals(FieldType otherValue) { ... }
139 
140         if (this == o) return true;
141         if (o == null || getClass() != o.getClass()) return false;
142         @SuppressWarnings("unchecked")
143         RequestLogRecord that = (RequestLogRecord) o;
144         //noinspection PointlessBooleanExpression
145         return true
146                 && java.util.Objects.equals(mRows, that.mRows)
147                 && mRequestId == that.mRequestId
148                 && mTimeMillis == that.mTimeMillis;
149     }
150 
151     @Override
152     @DataClass.Generated.Member
hashCode()153     public int hashCode() {
154         // You can override field hashCode logic by defining methods like:
155         // int fieldNameHashCode() { ... }
156 
157         int _hash = 1;
158         _hash = 31 * _hash + java.util.Objects.hashCode(mRows);
159         _hash = 31 * _hash + Long.hashCode(mRequestId);
160         _hash = 31 * _hash + Long.hashCode(mTimeMillis);
161         return _hash;
162     }
163 
164     @Override
165     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)166     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
167         // You can override field parcelling by defining methods like:
168         // void parcelFieldName(Parcel dest, int flags) { ... }
169 
170         dest.writeParcelableList(mRows, flags);
171         dest.writeLong(mRequestId);
172         dest.writeLong(mTimeMillis);
173     }
174 
175     @Override
176     @DataClass.Generated.Member
describeContents()177     public int describeContents() { return 0; }
178 
179     /** @hide */
180     @SuppressWarnings({"unchecked", "RedundantCast"})
181     @DataClass.Generated.Member
RequestLogRecord(@onNull android.os.Parcel in)182     /* package-private */ RequestLogRecord(@NonNull android.os.Parcel in) {
183         // You can override field unparcelling by defining methods like:
184         // static FieldType unparcelFieldName(Parcel in) { ... }
185 
186         List<ContentValues> rows = new java.util.ArrayList<>();
187         in.readParcelableList(rows, ContentValues.class.getClassLoader());
188         long requestId = in.readLong();
189         long timeMillis = in.readLong();
190 
191         this.mRows = rows;
192         AnnotationValidations.validate(
193                 NonNull.class, null, mRows);
194         this.mRequestId = requestId;
195         this.mTimeMillis = timeMillis;
196 
197         // onConstructed(); // You can define this method to get a callback
198     }
199 
200     @DataClass.Generated.Member
201     public static final @NonNull Parcelable.Creator<RequestLogRecord> CREATOR
202             = new Parcelable.Creator<RequestLogRecord>() {
203         @Override
204         public RequestLogRecord[] newArray(int size) {
205             return new RequestLogRecord[size];
206         }
207 
208         @Override
209         public RequestLogRecord createFromParcel(@NonNull android.os.Parcel in) {
210             return new RequestLogRecord(in);
211         }
212     };
213 
214     /**
215      * A builder for {@link RequestLogRecord}
216      */
217     @SuppressWarnings("WeakerAccess")
218     @DataClass.Generated.Member
219     public static final class Builder extends BaseBuilder {
220 
221         private @NonNull List<ContentValues> mRows;
222         private long mRequestId;
223         private long mTimeMillis;
224 
225         private long mBuilderFieldsSet = 0L;
226 
Builder()227         public Builder() {
228         }
229 
230         /**
231          * A List of rows, each containing a {@link ContentValues}.
232          */
233         @DataClass.Generated.Member
setRows(@onNull List<ContentValues> value)234         public @NonNull Builder setRows(@NonNull List<ContentValues> value) {
235             checkNotUsed();
236             mBuilderFieldsSet |= 0x1;
237             mRows = value;
238             return this;
239         }
240 
241         /** @see #setRows */
242         @DataClass.Generated.Member
addRow(@onNull ContentValues value)243         public @NonNull Builder addRow(@NonNull ContentValues value) {
244             if (mRows == null) setRows(new java.util.ArrayList<>());
245             mRows.add(value);
246             return this;
247         }
248 
249         /**
250          * Internal id for the RequestLogRecord.
251          *
252          * @hide
253          */
254         @DataClass.Generated.Member
setRequestId(long value)255         public @NonNull Builder setRequestId(long value) {
256             checkNotUsed();
257             mBuilderFieldsSet |= 0x2;
258             mRequestId = value;
259             return this;
260         }
261 
262         /**
263          * Time of the request in milliseconds
264          *
265          * @hide
266          */
267         @DataClass.Generated.Member
268         @Override
setTimeMillis(long value)269         public @NonNull Builder setTimeMillis(long value) {
270             checkNotUsed();
271             mBuilderFieldsSet |= 0x4;
272             mTimeMillis = value;
273             return this;
274         }
275 
276         /** Builds the instance. This builder should not be touched after calling this! */
build()277         public @NonNull RequestLogRecord build() {
278             checkNotUsed();
279             mBuilderFieldsSet |= 0x8; // Mark builder used
280 
281             if ((mBuilderFieldsSet & 0x1) == 0) {
282                 mRows = Collections.emptyList();
283             }
284             if ((mBuilderFieldsSet & 0x2) == 0) {
285                 mRequestId = 0;
286             }
287             if ((mBuilderFieldsSet & 0x4) == 0) {
288                 mTimeMillis = 0;
289             }
290             RequestLogRecord o = new RequestLogRecord(
291                     mRows,
292                     mRequestId,
293                     mTimeMillis);
294             return o;
295         }
296 
checkNotUsed()297         private void checkNotUsed() {
298             if ((mBuilderFieldsSet & 0x8) != 0) {
299                 throw new IllegalStateException(
300                         "This Builder should not be reused. Use a new Builder instance instead");
301             }
302         }
303     }
304 
305     @DataClass.Generated(
306             time = 1698962042612L,
307             codegenVersion = "1.0.23",
308             sourceFile = "packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/RequestLogRecord.java",
309             inputSignatures = " @com.android.ondevicepersonalization.internal.util.DataClass.PluralOf(\"row\") @android.annotation.NonNull java.util.List<android.content.ContentValues> mRows\nprivate  long mRequestId\nprivate  long mTimeMillis\npublic @android.annotation.NonNull java.time.Instant getTime()\nclass RequestLogRecord extends java.lang.Object implements [android.os.Parcelable]\npublic abstract  android.adservices.ondevicepersonalization.RequestLogRecord.Builder setTimeMillis(long)\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)\npublic abstract  android.adservices.ondevicepersonalization.RequestLogRecord.Builder setTimeMillis(long)\nclass BaseBuilder extends java.lang.Object implements []")
310     @Deprecated
__metadata()311     private void __metadata() {}
312 
313 
314     //@formatter:on
315     // End of generated code
316 
317 }
318