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.os.Parcelable; 22 23 import com.android.internal.util.Preconditions; 24 import com.android.ondevicepersonalization.internal.util.AnnotationValidations; 25 import com.android.ondevicepersonalization.internal.util.DataClass; 26 27 /** 28 * Training options when schedule federated computation job. 29 * 30 * @hide 31 */ 32 @DataClass(genBuilder = true, genEqualsHashCode = true) 33 public final class TrainingOptions implements Parcelable { 34 /** A unique JobScheduler job ID for the task. Must be non-zero. */ 35 private int mJobSchedulerJobId = 0; 36 37 /** The task name to be provided to the federated compute server during checkin. */ 38 @NonNull private String mPopulationName = ""; 39 40 @Nullable private TrainingInterval mTrainingInterval = null; 41 42 // Code below generated by codegen v1.0.23. 43 // 44 // DO NOT MODIFY! 45 // CHECKSTYLE:OFF Generated code 46 // 47 // To regenerate run: 48 // $ codegen 49 // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/ondevicepersonalization/federatedcompute/TrainingOptions.java 50 // 51 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 52 // Settings > Editor > Code Style > Formatter Control 53 // @formatter:off 54 55 @DataClass.Generated.Member TrainingOptions( int jobSchedulerJobId, @NonNull String populationName, @Nullable TrainingInterval trainingInterval)56 /* package-private */ TrainingOptions( 57 int jobSchedulerJobId, 58 @NonNull String populationName, 59 @Nullable TrainingInterval trainingInterval) { 60 this.mJobSchedulerJobId = jobSchedulerJobId; 61 this.mPopulationName = populationName; 62 AnnotationValidations.validate(NonNull.class, null, mPopulationName); 63 this.mTrainingInterval = trainingInterval; 64 65 // onConstructed(); // You can define this method to get a callback 66 } 67 68 /** A unique JobScheduler job ID for the task. Must be non-zero. */ 69 @DataClass.Generated.Member getJobSchedulerJobId()70 public int getJobSchedulerJobId() { 71 return mJobSchedulerJobId; 72 } 73 74 /** The task name to be provided to the federated compute server during checkin. */ 75 @DataClass.Generated.Member getPopulationName()76 public @NonNull String getPopulationName() { 77 return mPopulationName; 78 } 79 80 @DataClass.Generated.Member getTrainingInterval()81 public @Nullable TrainingInterval getTrainingInterval() { 82 return mTrainingInterval; 83 } 84 85 @Override 86 @DataClass.Generated.Member equals(@ullable Object o)87 public boolean equals(@Nullable Object o) { 88 // You can override field equality logic by defining either of the methods like: 89 // boolean fieldNameEquals(TrainingOptions other) { ... } 90 // boolean fieldNameEquals(FieldType otherValue) { ... } 91 92 if (this == o) return true; 93 if (o == null || getClass() != o.getClass()) return false; 94 @SuppressWarnings("unchecked") 95 TrainingOptions that = (TrainingOptions) o; 96 //noinspection PointlessBooleanExpression 97 return true 98 && mJobSchedulerJobId == that.mJobSchedulerJobId 99 && java.util.Objects.equals(mPopulationName, that.mPopulationName) 100 && java.util.Objects.equals(mTrainingInterval, that.mTrainingInterval); 101 } 102 103 @Override 104 @DataClass.Generated.Member hashCode()105 public int hashCode() { 106 // You can override field hashCode logic by defining methods like: 107 // int fieldNameHashCode() { ... } 108 109 int _hash = 1; 110 _hash = 31 * _hash + mJobSchedulerJobId; 111 _hash = 31 * _hash + java.util.Objects.hashCode(mPopulationName); 112 _hash = 31 * _hash + java.util.Objects.hashCode(mTrainingInterval); 113 return _hash; 114 } 115 116 @Override 117 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)118 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 119 // You can override field parcelling by defining methods like: 120 // void parcelFieldName(Parcel dest, int flags) { ... } 121 122 byte flg = 0; 123 if (mTrainingInterval != null) flg |= 0x4; 124 dest.writeByte(flg); 125 dest.writeInt(mJobSchedulerJobId); 126 dest.writeString(mPopulationName); 127 if (mTrainingInterval != null) dest.writeTypedObject(mTrainingInterval, flags); 128 } 129 130 @Override 131 @DataClass.Generated.Member describeContents()132 public int describeContents() { 133 return 0; 134 } 135 136 /** @hide */ 137 @SuppressWarnings({"unchecked", "RedundantCast"}) 138 @DataClass.Generated.Member TrainingOptions(@onNull android.os.Parcel in)139 /* package-private */ TrainingOptions(@NonNull android.os.Parcel in) { 140 // You can override field unparcelling by defining methods like: 141 // static FieldType unparcelFieldName(Parcel in) { ... } 142 143 byte flg = in.readByte(); 144 int jobSchedulerJobId = in.readInt(); 145 String populationName = in.readString(); 146 TrainingInterval trainingInterval = 147 (flg & 0x4) == 0 148 ? null 149 : (TrainingInterval) in.readTypedObject(TrainingInterval.CREATOR); 150 151 this.mJobSchedulerJobId = jobSchedulerJobId; 152 this.mPopulationName = populationName; 153 AnnotationValidations.validate(NonNull.class, null, mPopulationName); 154 this.mTrainingInterval = trainingInterval; 155 156 // onConstructed(); // You can define this method to get a callback 157 } 158 159 @DataClass.Generated.Member 160 public static final @NonNull Parcelable.Creator<TrainingOptions> CREATOR = 161 new Parcelable.Creator<TrainingOptions>() { 162 @Override 163 public TrainingOptions[] newArray(int size) { 164 return new TrainingOptions[size]; 165 } 166 167 @Override 168 public TrainingOptions createFromParcel(@NonNull android.os.Parcel in) { 169 return new TrainingOptions(in); 170 } 171 }; 172 173 /** A builder for {@link TrainingOptions} */ 174 @SuppressWarnings("WeakerAccess") 175 @DataClass.Generated.Member 176 public static final class Builder { 177 178 private int mJobSchedulerJobId; 179 private @NonNull String mPopulationName; 180 private @Nullable TrainingInterval mTrainingInterval; 181 182 private long mBuilderFieldsSet = 0L; 183 Builder()184 public Builder() {} 185 186 /** A unique JobScheduler job ID for the task. Must be non-zero. */ 187 @DataClass.Generated.Member setJobSchedulerJobId(int value)188 public @NonNull Builder setJobSchedulerJobId(int value) { 189 checkNotUsed(); 190 Preconditions.checkArgument(value != 0); 191 mBuilderFieldsSet |= 0x1; 192 mJobSchedulerJobId = value; 193 return this; 194 } 195 196 /** The task name to be provided to the federated compute server during checkin. */ 197 @DataClass.Generated.Member setPopulationName(@onNull String value)198 public @NonNull Builder setPopulationName(@NonNull String value) { 199 checkNotUsed(); 200 Preconditions.checkStringNotEmpty(value); 201 mBuilderFieldsSet |= 0x2; 202 mPopulationName = value; 203 return this; 204 } 205 206 @DataClass.Generated.Member setTrainingInterval(@onNull TrainingInterval value)207 public @NonNull Builder setTrainingInterval(@NonNull TrainingInterval value) { 208 checkNotUsed(); 209 mBuilderFieldsSet |= 0x4; 210 mTrainingInterval = value; 211 return this; 212 } 213 214 /** Builds the instance. This builder should not be touched after calling this! */ build()215 public @NonNull TrainingOptions build() { 216 checkNotUsed(); 217 mBuilderFieldsSet |= 0x8; // Mark builder used 218 219 if ((mBuilderFieldsSet & 0x1) == 0) { 220 mJobSchedulerJobId = 0; 221 } 222 if ((mBuilderFieldsSet & 0x2) == 0) { 223 mPopulationName = ""; 224 } 225 if ((mBuilderFieldsSet & 0x4) == 0) { 226 mTrainingInterval = null; 227 } 228 TrainingOptions o = 229 new TrainingOptions(mJobSchedulerJobId, mPopulationName, mTrainingInterval); 230 return o; 231 } 232 checkNotUsed()233 private void checkNotUsed() { 234 if ((mBuilderFieldsSet & 0x8) != 0) { 235 throw new IllegalStateException( 236 "This Builder should not be reused. Use a new Builder instance instead"); 237 } 238 } 239 } 240 241 // @formatter:on 242 // End of generated code 243 244 } 245