1 /* 2 * Copyright (C) 2023 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.federatedcompute.common; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.ComponentName; 22 import android.os.Parcelable; 23 24 import com.android.internal.util.Preconditions; 25 import com.android.ondevicepersonalization.internal.util.AnnotationValidations; 26 import com.android.ondevicepersonalization.internal.util.DataClass; 27 28 /** 29 * Training options when schedule federated computation job. 30 * 31 * @hide 32 */ 33 @DataClass(genBuilder = true, genEqualsHashCode = true) 34 public final class TrainingOptions implements Parcelable { 35 /** 36 * The task name to be provided to the federated compute server during checkin. The field is 37 * required and should not be empty. 38 */ 39 @NonNull private String mPopulationName = ""; 40 41 /** 42 * The remote federated compute server address that federated compute client need to checkin. 43 * The field is required and should not be empty. 44 */ 45 @NonNull private String mServerAddress = ""; 46 47 /** 48 * Indicated the component of the application requesting federated learning. The field is 49 * required and should not be empty. 50 */ 51 @Nullable private ComponentName mOwnerComponentName = null; 52 53 @Nullable private TrainingInterval mTrainingInterval = null; 54 55 /** 56 * The context data that federatedcompute will pass back to client when bind to 57 * ExampleStoreService and ResultHandlingService. 58 */ 59 @Nullable private final byte[] mContextData; 60 61 // Code below generated by codegen v1.0.23. 62 // 63 // DO NOT MODIFY! 64 // CHECKSTYLE:OFF Generated code 65 // 66 // To regenerate run: 67 // $ codegen 68 // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/federatedcompute/common/TrainingOptions.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 @DataClass.Generated.Member TrainingOptions( @onNull String populationName, @NonNull String serverAddress, @Nullable ComponentName ownerComponentName, @Nullable TrainingInterval trainingInterval, @Nullable byte[] contextData)75 /* package-private */ TrainingOptions( 76 @NonNull String populationName, 77 @NonNull String serverAddress, 78 @Nullable ComponentName ownerComponentName, 79 @Nullable TrainingInterval trainingInterval, 80 @Nullable byte[] contextData) { 81 this.mPopulationName = populationName; 82 AnnotationValidations.validate(NonNull.class, null, mPopulationName); 83 this.mServerAddress = serverAddress; 84 AnnotationValidations.validate(NonNull.class, null, mServerAddress); 85 this.mOwnerComponentName = ownerComponentName; 86 this.mTrainingInterval = trainingInterval; 87 this.mContextData = contextData; 88 89 // onConstructed(); // You can define this method to get a callback 90 } 91 92 /** 93 * The task name to be provided to the federated compute server during checkin. The field is 94 * required and should not be empty. 95 */ 96 @DataClass.Generated.Member getPopulationName()97 public @NonNull String getPopulationName() { 98 return mPopulationName; 99 } 100 101 /** 102 * The remote federated compute server address that federated compute client need to checkin. 103 * The field is required and should not be empty. 104 */ 105 @DataClass.Generated.Member getServerAddress()106 public @NonNull String getServerAddress() { 107 return mServerAddress; 108 } 109 110 /** 111 * Indicated the component of the application requesting federated learning. The field is 112 * required and should not be empty. 113 */ 114 @DataClass.Generated.Member getOwnerComponentName()115 public @Nullable ComponentName getOwnerComponentName() { 116 return mOwnerComponentName; 117 } 118 119 @DataClass.Generated.Member getTrainingInterval()120 public @Nullable TrainingInterval getTrainingInterval() { 121 return mTrainingInterval; 122 } 123 124 /** 125 * The context data that federatedcompute will pass back to client when bind to 126 * ExampleStoreService and ResultHandlingService. 127 */ 128 @DataClass.Generated.Member getContextData()129 public @Nullable byte[] getContextData() { 130 return mContextData; 131 } 132 133 @Override 134 @DataClass.Generated.Member equals(@ullable Object o)135 public boolean equals(@Nullable Object o) { 136 // You can override field equality logic by defining either of the methods like: 137 // boolean fieldNameEquals(TrainingOptions 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 TrainingOptions that = (TrainingOptions) o; 144 //noinspection PointlessBooleanExpression 145 return true 146 && java.util.Objects.equals(mPopulationName, that.mPopulationName) 147 && java.util.Objects.equals(mServerAddress, that.mServerAddress) 148 && java.util.Objects.equals(mOwnerComponentName, that.mOwnerComponentName) 149 && java.util.Objects.equals(mTrainingInterval, that.mTrainingInterval) 150 && java.util.Arrays.equals(mContextData, that.mContextData); 151 } 152 153 @Override 154 @DataClass.Generated.Member hashCode()155 public int hashCode() { 156 // You can override field hashCode logic by defining methods like: 157 // int fieldNameHashCode() { ... } 158 159 int _hash = 1; 160 _hash = 31 * _hash + java.util.Objects.hashCode(mPopulationName); 161 _hash = 31 * _hash + java.util.Objects.hashCode(mServerAddress); 162 _hash = 31 * _hash + java.util.Objects.hashCode(mOwnerComponentName); 163 _hash = 31 * _hash + java.util.Objects.hashCode(mTrainingInterval); 164 _hash = 31 * _hash + java.util.Arrays.hashCode(mContextData); 165 return _hash; 166 } 167 168 @Override 169 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)170 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 171 // You can override field parcelling by defining methods like: 172 // void parcelFieldName(Parcel dest, int flags) { ... } 173 174 byte flg = 0; 175 if (mOwnerComponentName != null) flg |= 0x4; 176 if (mTrainingInterval != null) flg |= 0x8; 177 dest.writeByte(flg); 178 dest.writeString(mPopulationName); 179 dest.writeString(mServerAddress); 180 if (mOwnerComponentName != null) dest.writeTypedObject(mOwnerComponentName, flags); 181 if (mTrainingInterval != null) dest.writeTypedObject(mTrainingInterval, flags); 182 dest.writeByteArray(mContextData); 183 } 184 185 @Override 186 @DataClass.Generated.Member describeContents()187 public int describeContents() { 188 return 0; 189 } 190 191 /** @hide */ 192 @SuppressWarnings({"unchecked", "RedundantCast"}) 193 @DataClass.Generated.Member TrainingOptions(@onNull android.os.Parcel in)194 /* package-private */ TrainingOptions(@NonNull android.os.Parcel in) { 195 // You can override field unparcelling by defining methods like: 196 // static FieldType unparcelFieldName(Parcel in) { ... } 197 198 byte flg = in.readByte(); 199 String populationName = in.readString(); 200 String serverAddress = in.readString(); 201 ComponentName ownerComponentName = 202 (flg & 0x4) == 0 ? null : (ComponentName) in.readTypedObject(ComponentName.CREATOR); 203 TrainingInterval trainingInterval = 204 (flg & 0x8) == 0 205 ? null 206 : (TrainingInterval) in.readTypedObject(TrainingInterval.CREATOR); 207 byte[] contextData = in.createByteArray(); 208 209 this.mPopulationName = populationName; 210 AnnotationValidations.validate(NonNull.class, null, mPopulationName); 211 this.mServerAddress = serverAddress; 212 AnnotationValidations.validate(NonNull.class, null, mServerAddress); 213 this.mOwnerComponentName = ownerComponentName; 214 this.mTrainingInterval = trainingInterval; 215 this.mContextData = contextData; 216 217 // onConstructed(); // You can define this method to get a callback 218 } 219 220 @DataClass.Generated.Member 221 public static final @NonNull Parcelable.Creator<TrainingOptions> CREATOR = 222 new Parcelable.Creator<TrainingOptions>() { 223 @Override 224 public TrainingOptions[] newArray(int size) { 225 return new TrainingOptions[size]; 226 } 227 228 @Override 229 public TrainingOptions createFromParcel(@NonNull android.os.Parcel in) { 230 return new TrainingOptions(in); 231 } 232 }; 233 234 /** A builder for {@link TrainingOptions} */ 235 @SuppressWarnings("WeakerAccess") 236 @DataClass.Generated.Member 237 public static final class Builder { 238 239 private @NonNull String mPopulationName; 240 private @NonNull String mServerAddress; 241 private @Nullable ComponentName mOwnerComponentName; 242 private @Nullable TrainingInterval mTrainingInterval; 243 private @Nullable byte[] mContextData; 244 245 private long mBuilderFieldsSet = 0L; 246 Builder()247 public Builder() {} 248 249 /** 250 * The task name to be provided to the federated compute server during checkin. The field is 251 * required and should not be empty. 252 */ 253 @DataClass.Generated.Member setPopulationName(@onNull String value)254 public @NonNull Builder setPopulationName(@NonNull String value) { 255 checkNotUsed(); 256 Preconditions.checkStringNotEmpty(value); 257 mBuilderFieldsSet |= 0x1; 258 mPopulationName = value; 259 return this; 260 } 261 262 /** 263 * The remote federated compute server address that federated compute client need to 264 * checkin. The field is required and should not be empty. 265 */ 266 @DataClass.Generated.Member setServerAddress(@onNull String value)267 public @NonNull Builder setServerAddress(@NonNull String value) { 268 checkNotUsed(); 269 Preconditions.checkStringNotEmpty(value); 270 mBuilderFieldsSet |= 0x2; 271 mServerAddress = value; 272 return this; 273 } 274 275 /** 276 * Indicated the component of the application requesting federated learning. The field is 277 * required and should not be empty. 278 */ 279 @DataClass.Generated.Member setOwnerComponentName(@onNull ComponentName value)280 public @NonNull Builder setOwnerComponentName(@NonNull ComponentName value) { 281 checkNotUsed(); 282 mBuilderFieldsSet |= 0x4; 283 mOwnerComponentName = value; 284 return this; 285 } 286 287 @DataClass.Generated.Member setTrainingInterval(@onNull TrainingInterval value)288 public @NonNull Builder setTrainingInterval(@NonNull TrainingInterval value) { 289 checkNotUsed(); 290 mBuilderFieldsSet |= 0x8; 291 mTrainingInterval = value; 292 return this; 293 } 294 295 /** 296 * The context data that federatedcompute will pass back to client when bind to 297 * ExampleStoreService and ResultHandlingService. 298 */ 299 @DataClass.Generated.Member setContextData(@onNull byte... value)300 public @NonNull Builder setContextData(@NonNull byte... value) { 301 checkNotUsed(); 302 mBuilderFieldsSet |= 0x10; 303 mContextData = value; 304 return this; 305 } 306 307 /** Builds the instance. This builder should not be touched after calling this! */ build()308 public @NonNull TrainingOptions build() { 309 checkNotUsed(); 310 mBuilderFieldsSet |= 0x20; // Mark builder used 311 312 if ((mBuilderFieldsSet & 0x1) == 0) { 313 mPopulationName = ""; 314 } 315 if ((mBuilderFieldsSet & 0x2) == 0) { 316 mServerAddress = ""; 317 } 318 if ((mBuilderFieldsSet & 0x4) == 0) { 319 mOwnerComponentName = null; 320 } 321 if ((mBuilderFieldsSet & 0x8) == 0) { 322 mTrainingInterval = null; 323 } 324 TrainingOptions o = 325 new TrainingOptions( 326 mPopulationName, 327 mServerAddress, 328 mOwnerComponentName, 329 mTrainingInterval, 330 mContextData); 331 return o; 332 } 333 checkNotUsed()334 private void checkNotUsed() { 335 if ((mBuilderFieldsSet & 0x20) != 0) { 336 throw new IllegalStateException( 337 "This Builder should not be reused. Use a new Builder instance instead"); 338 } 339 } 340 } 341 342 @DataClass.Generated( 343 time = 1706145720044L, 344 codegenVersion = "1.0.23", 345 sourceFile = 346 "packages/modules/OnDevicePersonalization/framework/java/android/federatedcompute/common/TrainingOptions.java", 347 inputSignatures = 348 "private @android.annotation.NonNull java.lang.String mPopulationName\nprivate @android.annotation.NonNull java.lang.String mServerAddress\nprivate @android.annotation.Nullable android.content.ComponentName mOwnerComponentName\nprivate @android.annotation.Nullable android.federatedcompute.common.TrainingInterval mTrainingInterval\nprivate final @android.annotation.Nullable byte[] mContextData\nclass TrainingOptions extends java.lang.Object implements [android.os.Parcelable]\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)") 349 @Deprecated __metadata()350 private void __metadata() {} 351 352 // @formatter:on 353 // End of generated code 354 355 } 356