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