• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.NonNull;
20 
21 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
22 import com.android.ondevicepersonalization.internal.util.DataClass;
23 
24 import java.time.Duration;
25 
26 /** Training interval settings required for federated computation jobs. */
27 @DataClass(genBuilder = true, genHiddenConstDefs = true, genEqualsHashCode = true)
28 public final class TrainingInterval {
29     /** The scheduling mode for a one-off task. */
30     public static final int SCHEDULING_MODE_ONE_TIME = 1;
31 
32     /** The scheduling mode for a task that will be rescheduled after each run. */
33     public static final int SCHEDULING_MODE_RECURRENT = 2;
34 
35     /**
36      * The scheduling mode for this task, either {@link #SCHEDULING_MODE_ONE_TIME} or {@link
37      * #SCHEDULING_MODE_RECURRENT}. The default scheduling mode is {@link #SCHEDULING_MODE_ONE_TIME}
38      * if unspecified.
39      */
40     @SchedulingMode private int mSchedulingMode = SCHEDULING_MODE_ONE_TIME;
41 
42     /**
43      * Sets the minimum time interval between two training runs.
44      *
45      * <p>This field will only be used when the scheduling mode is {@link
46      * #SCHEDULING_MODE_RECURRENT}. The value has be greater than zero.
47      *
48      * <p>Please also note this value is advisory, which does not guarantee the job will be run
49      * immediately after the interval expired. Federated compute will still enforce a minimum
50      * required interval and training constraints to ensure system health. The current training
51      * constraints are device on unmetered network, idle and battery not low.
52      */
53     @NonNull private Duration mMinimumInterval = Duration.ZERO;
54 
55     // Code below generated by codegen v1.0.23.
56     //
57     // DO NOT MODIFY!
58     // CHECKSTYLE:OFF Generated code
59     //
60     // To regenerate run:
61     // $ codegen
62     // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/TrainingInterval.java
63     //
64     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
65     //   Settings > Editor > Code Style > Formatter Control
66     // @formatter:off
67 
68     /** @hide */
69     @android.annotation.IntDef(
70             prefix = "SCHEDULING_MODE_",
71             value = {SCHEDULING_MODE_ONE_TIME, SCHEDULING_MODE_RECURRENT})
72     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
73     @DataClass.Generated.Member
74     public @interface SchedulingMode {}
75 
76     /** @hide */
77     @DataClass.Generated.Member
schedulingModeToString(@chedulingMode int value)78     public static String schedulingModeToString(@SchedulingMode int value) {
79         switch (value) {
80             case SCHEDULING_MODE_ONE_TIME:
81                 return "SCHEDULING_MODE_ONE_TIME";
82             case SCHEDULING_MODE_RECURRENT:
83                 return "SCHEDULING_MODE_RECURRENT";
84             default:
85                 return Integer.toHexString(value);
86         }
87     }
88 
89     @DataClass.Generated.Member
TrainingInterval( @chedulingMode int schedulingMode, @NonNull Duration minimumInterval)90     /* package-private */ TrainingInterval(
91             @SchedulingMode int schedulingMode, @NonNull Duration minimumInterval) {
92         this.mSchedulingMode = schedulingMode;
93 
94         if (!(mSchedulingMode == SCHEDULING_MODE_ONE_TIME)
95                 && !(mSchedulingMode == SCHEDULING_MODE_RECURRENT)) {
96             throw new java.lang.IllegalArgumentException(
97                     "schedulingMode was "
98                             + mSchedulingMode
99                             + " but must be one of: "
100                             + "SCHEDULING_MODE_ONE_TIME("
101                             + SCHEDULING_MODE_ONE_TIME
102                             + "), "
103                             + "SCHEDULING_MODE_RECURRENT("
104                             + SCHEDULING_MODE_RECURRENT
105                             + ")");
106         }
107 
108         this.mMinimumInterval = minimumInterval;
109         AnnotationValidations.validate(NonNull.class, null, mMinimumInterval);
110 
111         // onConstructed(); // You can define this method to get a callback
112     }
113 
114     /**
115      * The scheduling mode for this task, either {@link #SCHEDULING_MODE_ONE_TIME} or {@link
116      * #SCHEDULING_MODE_RECURRENT}. The default scheduling mode is {@link #SCHEDULING_MODE_ONE_TIME}
117      * if unspecified.
118      */
119     @DataClass.Generated.Member
getSchedulingMode()120     public @SchedulingMode int getSchedulingMode() {
121         return mSchedulingMode;
122     }
123 
124     /**
125      * Sets the minimum time interval between two training runs.
126      *
127      * <p>This field will only be used when the scheduling mode is {@link
128      * #SCHEDULING_MODE_RECURRENT}. Only positive values are accepted, zero or negative values will
129      * result in IllegalArgumentException.
130      *
131      * <p>Please also note this value is advisory, which does not guarantee the job will be run
132      * immediately after the interval expired. Federated compute will still enforce a minimum
133      * required interval and training constraints to ensure system health. The current training
134      * constraints are device on unmetered network, idle and battery not low.
135      */
136     @DataClass.Generated.Member
getMinimumInterval()137     public @NonNull Duration getMinimumInterval() {
138         return mMinimumInterval;
139     }
140 
141     @Override
142     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)143     public boolean equals(@android.annotation.Nullable Object o) {
144         // You can override field equality logic by defining either of the methods like:
145         // boolean fieldNameEquals(TrainingInterval other) { ... }
146         // boolean fieldNameEquals(FieldType otherValue) { ... }
147 
148         if (this == o) return true;
149         if (o == null || getClass() != o.getClass()) return false;
150         @SuppressWarnings("unchecked")
151         TrainingInterval that = (TrainingInterval) o;
152         //noinspection PointlessBooleanExpression
153         return true
154                 && mSchedulingMode == that.mSchedulingMode
155                 && java.util.Objects.equals(mMinimumInterval, that.mMinimumInterval);
156     }
157 
158     @Override
159     @DataClass.Generated.Member
hashCode()160     public int hashCode() {
161         // You can override field hashCode logic by defining methods like:
162         // int fieldNameHashCode() { ... }
163 
164         int _hash = 1;
165         _hash = 31 * _hash + mSchedulingMode;
166         _hash = 31 * _hash + java.util.Objects.hashCode(mMinimumInterval);
167         return _hash;
168     }
169 
170     /** A builder for {@link TrainingInterval} */
171     @SuppressWarnings("WeakerAccess")
172     @DataClass.Generated.Member
173     public static final class Builder {
174 
175         private @SchedulingMode int mSchedulingMode;
176         private @NonNull Duration mMinimumInterval;
177 
178         private long mBuilderFieldsSet = 0L;
179 
Builder()180         public Builder() {}
181 
182         /**
183          * The scheduling mode for this task, either {@link #SCHEDULING_MODE_ONE_TIME} or {@link
184          * #SCHEDULING_MODE_RECURRENT}. The default scheduling mode is {@link
185          * #SCHEDULING_MODE_ONE_TIME} if unspecified.
186          */
187         @DataClass.Generated.Member
setSchedulingMode(@chedulingMode int value)188         public @NonNull Builder setSchedulingMode(@SchedulingMode int value) {
189             checkNotUsed();
190             mBuilderFieldsSet |= 0x1;
191             mSchedulingMode = value;
192             return this;
193         }
194 
195         /**
196          * Sets the minimum time interval between two training runs.
197          *
198          * <p>This field will only be used when the scheduling mode is {@link
199          * #SCHEDULING_MODE_RECURRENT}. Only positive values are accepted, zero or negative values
200          * will result in IllegalArgumentException.
201          *
202          * <p>Please also note this value is advisory, which does not guarantee the job will be run
203          * immediately after the interval expired. Federated compute will still enforce a minimum
204          * required interval and training constraints to ensure system health. The current training
205          * constraints are device on unmetered network, idle and battery not low.
206          */
207         @DataClass.Generated.Member
setMinimumInterval(@onNull Duration value)208         public @NonNull Builder setMinimumInterval(@NonNull Duration value) {
209             checkNotUsed();
210             mBuilderFieldsSet |= 0x2;
211             mMinimumInterval = value;
212             return this;
213         }
214 
215         /** Builds the instance. This builder should not be touched after calling this! */
build()216         public @NonNull TrainingInterval build() {
217             checkNotUsed();
218             mBuilderFieldsSet |= 0x4; // Mark builder used
219 
220             if ((mBuilderFieldsSet & 0x1) == 0) {
221                 mSchedulingMode = SCHEDULING_MODE_ONE_TIME;
222             }
223             if ((mBuilderFieldsSet & 0x2) == 0) {
224                 mMinimumInterval = Duration.ZERO;
225             }
226             TrainingInterval o = new TrainingInterval(mSchedulingMode, mMinimumInterval);
227             return o;
228         }
229 
checkNotUsed()230         private void checkNotUsed() {
231             if ((mBuilderFieldsSet & 0x4) != 0) {
232                 throw new IllegalStateException(
233                         "This Builder should not be reused. Use a new Builder instance instead");
234             }
235         }
236     }
237 
238     @DataClass.Generated(
239             time = 1697653739724L,
240             codegenVersion = "1.0.23",
241             sourceFile =
242                     "packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/TrainingInterval.java",
243             inputSignatures =
244                     "public static final  int SCHEDULING_MODE_ONE_TIME\npublic static final  int SCHEDULING_MODE_RECURRENT\nprivate @android.adservices.ondevicepersonalization.TrainingInterval.SchedulingMode int mSchedulingMode\nprivate @android.annotation.NonNull java.time.Duration mMinimumInterval\nclass TrainingInterval extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genHiddenConstDefs=true, genEqualsHashCode=true)")
245     @Deprecated
__metadata()246     private void __metadata() {}
247 
248     // @formatter:on
249     // End of generated code
250 
251 }
252