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 
23 import com.android.adservices.ondevicepersonalization.flags.Flags;
24 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
25 import com.android.ondevicepersonalization.internal.util.DataClass;
26 
27 /** The input data for {@link IsolatedWorker#onTrainingExamples}. */
28 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
29 @DataClass(genBuilder = false, genHiddenConstructor = true, genEqualsHashCode = true)
30 public final class TrainingExamplesInput {
31     /**
32      * The name of the federated compute population. It should match the population name in {@link
33      * FederatedComputeInput#getPopulationName}.
34      */
35     @NonNull private String mPopulationName = "";
36 
37     /**
38      * The name of the task within the population. It should match task plan configured at remote
39      * federated compute server. One population may have multiple tasks. The task name can be used
40      * to uniquely identify the job.
41      */
42     @NonNull private String mTaskName = "";
43 
44     /**
45      * Token used to support the resumption of training. If client app wants to use resumption token
46      * to track what examples are already used in previous federated compute jobs, it need set
47      * {@link TrainingExampleRecord.Builder#setResumptionToken}, OnDevicePersonalization will store
48      * it and pass it here for generating new training examples.
49      */
50     @Nullable private byte[] mResumptionToken = null;
51 
52     /**
53      * The data collection name to use to create training examples.
54      */
55     @Nullable private String mCollectionName;
56 
57     /** @hide */
TrainingExamplesInput(@onNull TrainingExamplesInputParcel parcel)58     public TrainingExamplesInput(@NonNull TrainingExamplesInputParcel parcel) {
59         this(
60                 parcel.getPopulationName(),
61                 parcel.getTaskName(),
62                 parcel.getResumptionToken(),
63                 parcel.getCollectionName());
64     }
65 
66     // Code below generated by codegen v1.0.23.
67     //
68     // DO NOT MODIFY!
69     // CHECKSTYLE:OFF Generated code
70     //
71     // To regenerate run:
72     // $ codegen
73     // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/TrainingExamplesInput.java
74     //
75     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
76     //   Settings > Editor > Code Style > Formatter Control
77     // @formatter:off
78 
79     /**
80      * Creates a new TrainingExamplesInput.
81      *
82      * @param populationName The name of the federated compute population. It should match the
83      *     population name in {@link FederatedComputeInput#getPopulationName}.
84      * @param taskName The name of the task within the population. It should match task plan
85      *     configured at remote federated compute server. One population may have multiple tasks.
86      *     The task name can be used to uniquely identify the job.
87      * @param resumptionToken Token used to support the resumption of training. If client app wants
88      *     to use resumption token to track what examples are already used in previous federated
89      *     compute jobs, it need set {@link TrainingExampleRecord.Builder#setResumptionToken},
90      *     OnDevicePersonalization will store it and pass it here for generating new training
91      *     examples.
92      * @param collectionName The data collection name to use to create training examples.
93      * @hide
94      */
95     @DataClass.Generated.Member
TrainingExamplesInput( @onNull String populationName, @NonNull String taskName, @Nullable byte[] resumptionToken, @Nullable String collectionName)96     public TrainingExamplesInput(
97             @NonNull String populationName,
98             @NonNull String taskName,
99             @Nullable byte[] resumptionToken,
100             @Nullable String collectionName) {
101         this.mPopulationName = populationName;
102         AnnotationValidations.validate(NonNull.class, null, mPopulationName);
103         this.mTaskName = taskName;
104         AnnotationValidations.validate(NonNull.class, null, mTaskName);
105         this.mResumptionToken = resumptionToken;
106         this.mCollectionName = collectionName;
107 
108         // onConstructed(); // You can define this method to get a callback
109     }
110 
111     /**
112      * The name of the federated compute population. It should match the population name in {@link
113      * FederatedComputeInput#getPopulationName}.
114      */
115     @DataClass.Generated.Member
getPopulationName()116     public @NonNull String getPopulationName() {
117         return mPopulationName;
118     }
119 
120     /**
121      * The name of the task within the population. It should match task plan configured at remote
122      * federated compute server. One population may have multiple tasks. The task name can be used
123      * to uniquely identify the job.
124      */
125     @DataClass.Generated.Member
getTaskName()126     public @NonNull String getTaskName() {
127         return mTaskName;
128     }
129 
130     /**
131      * Token used to support the resumption of training. If client app wants to use resumption token
132      * to track what examples are already used in previous federated compute jobs, it need set
133      * {@link TrainingExampleRecord.Builder#setResumptionToken}, OnDevicePersonalization will store
134      * it and pass it here for generating new training examples.
135      */
136     @DataClass.Generated.Member
getResumptionToken()137     public @Nullable byte[] getResumptionToken() {
138         return mResumptionToken;
139     }
140 
141     /** The data collection name to use to create training examples. */
142     @DataClass.Generated.Member
143     @FlaggedApi(Flags.FLAG_FCP_MODEL_VERSION_ENABLED)
getCollectionName()144     public @Nullable String getCollectionName() {
145         return mCollectionName;
146     }
147 
148     @Override
149     @DataClass.Generated.Member
equals(@ullable Object o)150     public boolean equals(@Nullable Object o) {
151         // You can override field equality logic by defining either of the methods like:
152         // boolean fieldNameEquals(TrainingExamplesInput other) { ... }
153         // boolean fieldNameEquals(FieldType otherValue) { ... }
154 
155         if (this == o) return true;
156         if (o == null || getClass() != o.getClass()) return false;
157         @SuppressWarnings("unchecked")
158         TrainingExamplesInput that = (TrainingExamplesInput) o;
159         //noinspection PointlessBooleanExpression
160         return true
161                 && java.util.Objects.equals(mPopulationName, that.mPopulationName)
162                 && java.util.Objects.equals(mTaskName, that.mTaskName)
163                 && java.util.Arrays.equals(mResumptionToken, that.mResumptionToken)
164                 && java.util.Objects.equals(mCollectionName, that.mCollectionName);
165     }
166 
167     @Override
168     @DataClass.Generated.Member
hashCode()169     public int hashCode() {
170         // You can override field hashCode logic by defining methods like:
171         // int fieldNameHashCode() { ... }
172 
173         int _hash = 1;
174         _hash = 31 * _hash + java.util.Objects.hashCode(mPopulationName);
175         _hash = 31 * _hash + java.util.Objects.hashCode(mTaskName);
176         _hash = 31 * _hash + java.util.Arrays.hashCode(mResumptionToken);
177         _hash = 31 * _hash + java.util.Objects.hashCode(mCollectionName);
178         return _hash;
179     }
180 
181     @DataClass.Generated(
182             time = 1717540629847L,
183             codegenVersion = "1.0.23",
184             sourceFile =
185                     "packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/TrainingExamplesInput.java",
186             inputSignatures =
187                     "private @android.annotation.NonNull java.lang.String mPopulationName\nprivate @android.annotation.NonNull java.lang.String mTaskName\nprivate @android.annotation.Nullable byte[] mResumptionToken\nprivate @android.annotation.Nullable java.lang.String mCollectionName\nclass TrainingExamplesInput extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=false, genHiddenConstructor=true, genEqualsHashCode=true)")
188     @Deprecated
__metadata()189     private void __metadata() {}
190 
191     // @formatter:on
192     // End of generated code
193 
194 }
195