1 /*
2  * Copyright (C) 2021 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.car.watchdog;
18 
19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
20 
21 import android.annotation.NonNull;
22 import android.annotation.SystemApi;
23 import android.os.Parcelable;
24 
25 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
26 import com.android.car.internal.util.AnnotationValidations;
27 import com.android.car.internal.util.DataClass;
28 
29 import java.util.List;
30 import java.util.Map;
31 
32 /**
33  * Disk I/O overuse configuration for a component.
34  *
35  * @hide
36  */
37 @SystemApi
38 @DataClass(genToString = true, genBuilder = true, genHiddenConstDefs = true)
39 public final class IoOveruseConfiguration implements Parcelable {
40     /**
41      * Component level thresholds.
42      *
43      * <p>These are applied to packages that are not covered by the package specific thresholds or
44      * application category specific thresholds. For third-party component, only component level
45      * thresholds must be provided and other thresholds are not applicable.
46      */
47     private @NonNull PerStateBytes mComponentLevelThresholds;
48 
49     /**
50      * Package specific thresholds only for system and vendor packages.
51      *
52      * NOTE: For packages that share a UID, the package name should be the shared package name
53      * because the I/O usage is aggregated for all packages under the shared UID. The shared
54      * package names should have the prefix 'shared:'.
55      *
56      * <p>System component must provide package specific thresholds only for system packages.
57      * <p>Vendor component must provide package specific thresholds only for vendor packages.
58      */
59     private @NonNull Map<String, PerStateBytes> mPackageSpecificThresholds;
60 
61     /**
62      * Application category specific thresholds.
63      *
64      * <p>The key must be one of the {@link ResourceOveruseConfiguration#ApplicationCategoryType}
65      * constants.
66      *
67      * <p>These are applied when package specific thresholds are not provided for a package and a
68      * package is covered by one of the
69      * {@link ResourceOveruseConfiguration#ApplicationCategoryType}. These thresholds must be
70      * provided only by the vendor component.
71      */
72     private @NonNull Map<String, PerStateBytes> mAppCategorySpecificThresholds;
73 
74     /**
75      * List of system-wide thresholds used to detect overall disk I/O overuse.
76      *
77      * <p>These thresholds must be provided only by the system component.
78      */
79     private @NonNull List<IoOveruseAlertThreshold> mSystemWideThresholds;
80 
81 
82 
83     // Code below generated by codegen v1.0.23.
84     //
85     // DO NOT MODIFY!
86     // CHECKSTYLE:OFF Generated code
87     //
88     // To regenerate run:
89     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/watchdog/IoOveruseConfiguration.java
90     // Added AddedInOrBefore or ApiRequirement Annotation manually
91     //
92     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
93     //   Settings > Editor > Code Style > Formatter Control
94     //@formatter:off
95 
96 
97     @DataClass.Generated.Member
IoOveruseConfiguration( @onNull PerStateBytes componentLevelThresholds, @NonNull Map<String,PerStateBytes> packageSpecificThresholds, @NonNull Map<String,PerStateBytes> appCategorySpecificThresholds, @NonNull List<IoOveruseAlertThreshold> systemWideThresholds)98     /* package-private */ IoOveruseConfiguration(
99             @NonNull PerStateBytes componentLevelThresholds,
100             @NonNull Map<String,PerStateBytes> packageSpecificThresholds,
101             @NonNull Map<String,PerStateBytes> appCategorySpecificThresholds,
102             @NonNull List<IoOveruseAlertThreshold> systemWideThresholds) {
103         this.mComponentLevelThresholds = componentLevelThresholds;
104         AnnotationValidations.validate(
105                 NonNull.class, null, mComponentLevelThresholds);
106         this.mPackageSpecificThresholds = packageSpecificThresholds;
107         AnnotationValidations.validate(
108                 NonNull.class, null, mPackageSpecificThresholds);
109         this.mAppCategorySpecificThresholds = appCategorySpecificThresholds;
110         AnnotationValidations.validate(
111                 NonNull.class, null, mAppCategorySpecificThresholds);
112         this.mSystemWideThresholds = systemWideThresholds;
113         AnnotationValidations.validate(
114                 NonNull.class, null, mSystemWideThresholds);
115 
116         // onConstructed(); // You can define this method to get a callback
117     }
118 
119     /**
120      * Component level thresholds.
121      *
122      * <p>These are applied to packages that are not covered by the package specific thresholds or
123      * application category specific thresholds. For third-party component, only component level
124      * thresholds must be provided and other thresholds are not applicable.
125      */
126     @DataClass.Generated.Member
getComponentLevelThresholds()127     public @NonNull PerStateBytes getComponentLevelThresholds() {
128         return mComponentLevelThresholds;
129     }
130 
131     /**
132      * Package specific thresholds only for system and vendor packages.
133      *
134      * NOTE: For packages that share a UID, the package name should be the shared package name
135      * because the I/O usage is aggregated for all packages under the shared UID. The shared
136      * package names should have the prefix 'shared:'.
137      *
138      * <p>System component must provide package specific thresholds only for system packages.
139      * <p>Vendor component must provide package specific thresholds only for vendor packages.
140      */
141     @DataClass.Generated.Member
getPackageSpecificThresholds()142     public @NonNull Map<String,PerStateBytes> getPackageSpecificThresholds() {
143         return mPackageSpecificThresholds;
144     }
145 
146     /**
147      * Application category specific thresholds.
148      *
149      * <p>The key must be one of the {@link ResourceOveruseConfiguration#ApplicationCategoryType}
150      * constants.
151      *
152      * <p>These are applied when package specific thresholds are not provided for a package and a
153      * package is covered by one of the
154      * {@link ResourceOveruseConfiguration#ApplicationCategoryType}. These thresholds must be
155      * provided only by the vendor component.
156      */
157     @DataClass.Generated.Member
getAppCategorySpecificThresholds()158     public @NonNull Map<String,PerStateBytes> getAppCategorySpecificThresholds() {
159         return mAppCategorySpecificThresholds;
160     }
161 
162     /**
163      * List of system-wide thresholds used to detect overall disk I/O overuse.
164      *
165      * <p>These thresholds must be provided only by the system component.
166      */
167     @DataClass.Generated.Member
getSystemWideThresholds()168     public @NonNull List<IoOveruseAlertThreshold> getSystemWideThresholds() {
169         return mSystemWideThresholds;
170     }
171 
172     @Override
173     @DataClass.Generated.Member
toString()174     public String toString() {
175         // You can override field toString logic by defining methods like:
176         // String fieldNameToString() { ... }
177 
178         return "IoOveruseConfiguration { " +
179                 "componentLevelThresholds = " + mComponentLevelThresholds + ", " +
180                 "packageSpecificThresholds = " + mPackageSpecificThresholds + ", " +
181                 "appCategorySpecificThresholds = " + mAppCategorySpecificThresholds + ", " +
182                 "systemWideThresholds = " + mSystemWideThresholds +
183         " }";
184     }
185 
186     @Override
187     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)188     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
189         // You can override field parcelling by defining methods like:
190         // void parcelFieldName(Parcel dest, int flags) { ... }
191 
192         dest.writeTypedObject(mComponentLevelThresholds, flags);
193         dest.writeMap(mPackageSpecificThresholds);
194         dest.writeMap(mAppCategorySpecificThresholds);
195         dest.writeParcelableList(mSystemWideThresholds, flags);
196     }
197 
198     @Override
199     @DataClass.Generated.Member
200     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
describeContents()201     public int describeContents() { return 0; }
202 
203     /** @hide */
204     @SuppressWarnings({"unchecked", "RedundantCast"})
205     @DataClass.Generated.Member
IoOveruseConfiguration(@onNull android.os.Parcel in)206     /* package-private */ IoOveruseConfiguration(@NonNull android.os.Parcel in) {
207         // You can override field unparcelling by defining methods like:
208         // static FieldType unparcelFieldName(Parcel in) { ... }
209 
210         PerStateBytes componentLevelThresholds = (PerStateBytes) in.readTypedObject(PerStateBytes.CREATOR);
211         Map<String,PerStateBytes> packageSpecificThresholds = new java.util.LinkedHashMap<>();
212         in.readMap(packageSpecificThresholds, PerStateBytes.class.getClassLoader());
213         Map<String,PerStateBytes> appCategorySpecificThresholds = new java.util.LinkedHashMap<>();
214         in.readMap(appCategorySpecificThresholds, PerStateBytes.class.getClassLoader());
215         List<IoOveruseAlertThreshold> systemWideThresholds = new java.util.ArrayList<>();
216         in.readParcelableList(systemWideThresholds, IoOveruseAlertThreshold.class.getClassLoader());
217 
218         this.mComponentLevelThresholds = componentLevelThresholds;
219         AnnotationValidations.validate(
220                 NonNull.class, null, mComponentLevelThresholds);
221         this.mPackageSpecificThresholds = packageSpecificThresholds;
222         AnnotationValidations.validate(
223                 NonNull.class, null, mPackageSpecificThresholds);
224         this.mAppCategorySpecificThresholds = appCategorySpecificThresholds;
225         AnnotationValidations.validate(
226                 NonNull.class, null, mAppCategorySpecificThresholds);
227         this.mSystemWideThresholds = systemWideThresholds;
228         AnnotationValidations.validate(
229                 NonNull.class, null, mSystemWideThresholds);
230 
231         // onConstructed(); // You can define this method to get a callback
232     }
233 
234     @DataClass.Generated.Member
235     public static final @NonNull Parcelable.Creator<IoOveruseConfiguration> CREATOR
236             = new Parcelable.Creator<IoOveruseConfiguration>() {
237         @Override
238         public IoOveruseConfiguration[] newArray(int size) {
239             return new IoOveruseConfiguration[size];
240         }
241 
242         @Override
243         public IoOveruseConfiguration createFromParcel(@NonNull android.os.Parcel in) {
244             return new IoOveruseConfiguration(in);
245         }
246     };
247 
248     /**
249      * A builder for {@link IoOveruseConfiguration}
250      */
251     @SuppressWarnings("WeakerAccess")
252     @DataClass.Generated.Member
253     public static final class Builder {
254 
255         private @NonNull PerStateBytes mComponentLevelThresholds;
256         private @NonNull Map<String,PerStateBytes> mPackageSpecificThresholds;
257         private @NonNull Map<String,PerStateBytes> mAppCategorySpecificThresholds;
258         private @NonNull List<IoOveruseAlertThreshold> mSystemWideThresholds;
259 
260         private long mBuilderFieldsSet = 0L;
261 
262         /**
263          * Creates a new Builder.
264          *
265          * @param componentLevelThresholds
266          *   Component level thresholds.
267          *
268          *   <p>These are applied to packages that are not covered by the package specific thresholds or
269          *   application category specific thresholds. For third-party component, only component level
270          *   thresholds must be provided and other thresholds are not applicable.
271          * @param packageSpecificThresholds
272          *   Package specific thresholds only for system and vendor packages.
273          *
274          *   NOTE: For packages that share a UID, the package name should be the shared package name
275          *   because the I/O usage is aggregated for all packages under the shared UID. The shared
276          *   package names should have the prefix 'shared:'.
277          *
278          *   <p>System component must provide package specific thresholds only for system packages.
279          *   <p>Vendor component must provide package specific thresholds only for vendor packages.
280          * @param appCategorySpecificThresholds
281          *   Application category specific thresholds.
282          *
283          *   <p>The key must be one of the {@link ResourceOveruseConfiguration#ApplicationCategoryType}
284          *   constants.
285          *
286          *   <p>These are applied when package specific thresholds are not provided for a package and a
287          *   package is covered by one of the
288          *   {@link ResourceOveruseConfiguration#ApplicationCategoryType}. These thresholds must be
289          *   provided only by the vendor component.
290          * @param systemWideThresholds
291          *   List of system-wide thresholds used to detect overall disk I/O overuse.
292          *
293          *   <p>These thresholds must be provided only by the system component.
294          */
Builder( @onNull PerStateBytes componentLevelThresholds, @NonNull Map<String,PerStateBytes> packageSpecificThresholds, @NonNull Map<String,PerStateBytes> appCategorySpecificThresholds, @NonNull List<IoOveruseAlertThreshold> systemWideThresholds)295         public Builder(
296                 @NonNull PerStateBytes componentLevelThresholds,
297                 @NonNull Map<String,PerStateBytes> packageSpecificThresholds,
298                 @NonNull Map<String,PerStateBytes> appCategorySpecificThresholds,
299                 @NonNull List<IoOveruseAlertThreshold> systemWideThresholds) {
300             mComponentLevelThresholds = componentLevelThresholds;
301             AnnotationValidations.validate(
302                     NonNull.class, null, mComponentLevelThresholds);
303             mPackageSpecificThresholds = packageSpecificThresholds;
304             AnnotationValidations.validate(
305                     NonNull.class, null, mPackageSpecificThresholds);
306             mAppCategorySpecificThresholds = appCategorySpecificThresholds;
307             AnnotationValidations.validate(
308                     NonNull.class, null, mAppCategorySpecificThresholds);
309             mSystemWideThresholds = systemWideThresholds;
310             AnnotationValidations.validate(
311                     NonNull.class, null, mSystemWideThresholds);
312         }
313 
314         /**
315          * Component level thresholds.
316          *
317          * <p>These are applied to packages that are not covered by the package specific thresholds or
318          * application category specific thresholds. For third-party component, only component level
319          * thresholds must be provided and other thresholds are not applicable.
320          */
321         @DataClass.Generated.Member
setComponentLevelThresholds(@onNull PerStateBytes value)322         public @NonNull Builder setComponentLevelThresholds(@NonNull PerStateBytes value) {
323             checkNotUsed();
324             mBuilderFieldsSet |= 0x1;
325             mComponentLevelThresholds = value;
326             return this;
327         }
328 
329         /**
330          * Package specific thresholds only for system and vendor packages.
331          *
332          * NOTE: For packages that share a UID, the package name should be the shared package name
333          * because the I/O usage is aggregated for all packages under the shared UID. The shared
334          * package names should have the prefix 'shared:'.
335          *
336          * <p>System component must provide package specific thresholds only for system packages.
337          * <p>Vendor component must provide package specific thresholds only for vendor packages.
338          */
339         @DataClass.Generated.Member
setPackageSpecificThresholds(@onNull Map<String,PerStateBytes> value)340         public @NonNull Builder setPackageSpecificThresholds(@NonNull Map<String,PerStateBytes> value) {
341             checkNotUsed();
342             mBuilderFieldsSet |= 0x2;
343             mPackageSpecificThresholds = value;
344             return this;
345         }
346 
347         /** @see #setPackageSpecificThresholds */
348         @DataClass.Generated.Member
addPackageSpecificThresholds(@onNull String key, @NonNull PerStateBytes value)349         public @NonNull Builder addPackageSpecificThresholds(@NonNull String key, @NonNull PerStateBytes value) {
350             // You can refine this method's name by providing item's singular name, e.g.:
351             // @DataClass.PluralOf("item")) mItems = ...
352 
353             if (mPackageSpecificThresholds == null) setPackageSpecificThresholds(new java.util.LinkedHashMap());
354             mPackageSpecificThresholds.put(key, value);
355             return this;
356         }
357 
358         /**
359          * Application category specific thresholds.
360          *
361          * <p>The key must be one of the {@link ResourceOveruseConfiguration#ApplicationCategoryType}
362          * constants.
363          *
364          * <p>These are applied when package specific thresholds are not provided for a package and a
365          * package is covered by one of the
366          * {@link ResourceOveruseConfiguration#ApplicationCategoryType}. These thresholds must be
367          * provided only by the vendor component.
368          */
369         @DataClass.Generated.Member
setAppCategorySpecificThresholds(@onNull Map<String,PerStateBytes> value)370         public @NonNull Builder setAppCategorySpecificThresholds(@NonNull Map<String,PerStateBytes> value) {
371             checkNotUsed();
372             mBuilderFieldsSet |= 0x4;
373             mAppCategorySpecificThresholds = value;
374             return this;
375         }
376 
377         /** @see #setAppCategorySpecificThresholds */
378         @DataClass.Generated.Member
addAppCategorySpecificThresholds(@onNull String key, @NonNull PerStateBytes value)379         public @NonNull Builder addAppCategorySpecificThresholds(@NonNull String key, @NonNull PerStateBytes value) {
380             // You can refine this method's name by providing item's singular name, e.g.:
381             // @DataClass.PluralOf("item")) mItems = ...
382 
383             if (mAppCategorySpecificThresholds == null) setAppCategorySpecificThresholds(new java.util.LinkedHashMap());
384             mAppCategorySpecificThresholds.put(key, value);
385             return this;
386         }
387 
388         /**
389          * List of system-wide thresholds used to detect overall disk I/O overuse.
390          *
391          * <p>These thresholds must be provided only by the system component.
392          */
393         @DataClass.Generated.Member
setSystemWideThresholds(@onNull List<IoOveruseAlertThreshold> value)394         public @NonNull Builder setSystemWideThresholds(@NonNull List<IoOveruseAlertThreshold> value) {
395             checkNotUsed();
396             mBuilderFieldsSet |= 0x8;
397             mSystemWideThresholds = value;
398             return this;
399         }
400 
401         /** @see #setSystemWideThresholds */
402         @DataClass.Generated.Member
addSystemWideThresholds(@onNull IoOveruseAlertThreshold value)403         public @NonNull Builder addSystemWideThresholds(@NonNull IoOveruseAlertThreshold value) {
404             // You can refine this method's name by providing item's singular name, e.g.:
405             // @DataClass.PluralOf("item")) mItems = ...
406 
407             if (mSystemWideThresholds == null) setSystemWideThresholds(new java.util.ArrayList<>());
408             mSystemWideThresholds.add(value);
409             return this;
410         }
411 
412         /** Builds the instance. This builder should not be touched after calling this! */
build()413         public @NonNull IoOveruseConfiguration build() {
414             checkNotUsed();
415             mBuilderFieldsSet |= 0x10; // Mark builder used
416 
417             IoOveruseConfiguration o = new IoOveruseConfiguration(
418                     mComponentLevelThresholds,
419                     mPackageSpecificThresholds,
420                     mAppCategorySpecificThresholds,
421                     mSystemWideThresholds);
422             return o;
423         }
424 
checkNotUsed()425         private void checkNotUsed() {
426             if ((mBuilderFieldsSet & 0x10) != 0) {
427                 throw new IllegalStateException(
428                         "This Builder should not be reused. Use a new Builder instance instead");
429             }
430         }
431     }
432 
433     @DataClass.Generated(
434             time = 1628099281770L,
435             codegenVersion = "1.0.23",
436             sourceFile = "packages/services/Car/car-lib/src/android/car/watchdog/IoOveruseConfiguration.java",
437             inputSignatures = "private @android.annotation.NonNull android.car.watchdog.PerStateBytes mComponentLevelThresholds\nprivate @android.annotation.NonNull java.util.Map<java.lang.String,android.car.watchdog.PerStateBytes> mPackageSpecificThresholds\nprivate @android.annotation.NonNull java.util.Map<java.lang.String,android.car.watchdog.PerStateBytes> mAppCategorySpecificThresholds\nprivate @android.annotation.NonNull java.util.List<android.car.watchdog.IoOveruseAlertThreshold> mSystemWideThresholds\nclass IoOveruseConfiguration extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genToString=true, genBuilder=true, genHiddenConstDefs=true)")
438     @Deprecated
439     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
__metadata()440     private void __metadata() {}
441 
442 
443     //@formatter:on
444     // End of generated code
445 
446 }
447