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 android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Parcelable;
22 import android.os.UserHandle;
23 
24 import com.android.car.internal.util.AnnotationValidations;
25 import com.android.car.internal.util.DataClass;
26 
27 /**
28  * Resource overuse stats for a package.
29  */
30 @DataClass(genToString = true, genHiddenBuilder = true)
31 public final class ResourceOveruseStats implements Parcelable {
32     /**
33      * Name of the package, whose stats are recorded in the below fields.
34      *
35      * NOTE: For packages that share a UID, the package name will be the shared package name because
36      *       the stats are aggregated for all packages under the shared UID.
37      */
38     private @NonNull String mPackageName;
39 
40     /**
41      * User handle, whose stats are recorded in the below fields.
42      */
43     private @NonNull UserHandle mUserHandle;
44 
45     /**
46      * I/O overuse stats for the package.
47      *
48      * If the package didn't opt-in to receive I/O overuse stats or the package doesn't have
49      * I/O overuse stats, this value will be null.
50      */
51     private @Nullable IoOveruseStats mIoOveruseStats = null;
52 
53 
54 
55 
56     // Code below generated by codegen v1.0.23.
57     //
58     // DO NOT MODIFY!
59     // CHECKSTYLE:OFF Generated code
60     //
61     // To regenerate run:
62     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/watchdog/ResourceOveruseStats.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 
69     @DataClass.Generated.Member
ResourceOveruseStats( @onNull String packageName, @NonNull UserHandle userHandle, @Nullable IoOveruseStats ioOveruseStats)70     /* package-private */ ResourceOveruseStats(
71             @NonNull String packageName,
72             @NonNull UserHandle userHandle,
73             @Nullable IoOveruseStats ioOveruseStats) {
74         this.mPackageName = packageName;
75         AnnotationValidations.validate(
76                 NonNull.class, null, mPackageName);
77         this.mUserHandle = userHandle;
78         AnnotationValidations.validate(
79                 NonNull.class, null, mUserHandle);
80         this.mIoOveruseStats = ioOveruseStats;
81 
82         // onConstructed(); // You can define this method to get a callback
83     }
84 
85     /**
86      * Name of the package, whose stats are recorded in the below fields.
87      *
88      * NOTE: For packages that share a UID, the package name will be the shared package name because
89      *       the stats are aggregated for all packages under the shared UID.
90      */
91     @DataClass.Generated.Member
getPackageName()92     public @NonNull String getPackageName() {
93         return mPackageName;
94     }
95 
96     /**
97      * User handle, whose stats are recorded in the below fields.
98      */
99     @DataClass.Generated.Member
getUserHandle()100     public @NonNull UserHandle getUserHandle() {
101         return mUserHandle;
102     }
103 
104     /**
105      * I/O overuse stats for the package.
106      *
107      * If the package didn't opt-in to receive I/O overuse stats or the package doesn't have
108      * I/O overuse stats, this value will be null.
109      */
110     @DataClass.Generated.Member
getIoOveruseStats()111     public @Nullable IoOveruseStats getIoOveruseStats() {
112         return mIoOveruseStats;
113     }
114 
115     @Override
116     @DataClass.Generated.Member
toString()117     public String toString() {
118         // You can override field toString logic by defining methods like:
119         // String fieldNameToString() { ... }
120 
121         return "ResourceOveruseStats { " +
122                 "packageName = " + mPackageName + ", " +
123                 "userHandle = " + mUserHandle + ", " +
124                 "ioOveruseStats = " + mIoOveruseStats +
125         " }";
126     }
127 
128     @Override
129     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)130     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
131         // You can override field parcelling by defining methods like:
132         // void parcelFieldName(Parcel dest, int flags) { ... }
133 
134         byte flg = 0;
135         if (mIoOveruseStats != null) flg |= 0x4;
136         dest.writeByte(flg);
137         dest.writeString(mPackageName);
138         dest.writeTypedObject(mUserHandle, flags);
139         if (mIoOveruseStats != null) dest.writeTypedObject(mIoOveruseStats, flags);
140     }
141 
142     @Override
143     @DataClass.Generated.Member
describeContents()144     public int describeContents() { return 0; }
145 
146     /** @hide */
147     @SuppressWarnings({"unchecked", "RedundantCast"})
148     @DataClass.Generated.Member
ResourceOveruseStats(@onNull android.os.Parcel in)149     /* package-private */ ResourceOveruseStats(@NonNull android.os.Parcel in) {
150         // You can override field unparcelling by defining methods like:
151         // static FieldType unparcelFieldName(Parcel in) { ... }
152 
153         byte flg = in.readByte();
154         String packageName = in.readString();
155         UserHandle userHandle = (UserHandle) in.readTypedObject(UserHandle.CREATOR);
156         IoOveruseStats ioOveruseStats = (flg & 0x4) == 0 ? null : (IoOveruseStats) in.readTypedObject(IoOveruseStats.CREATOR);
157 
158         this.mPackageName = packageName;
159         AnnotationValidations.validate(
160                 NonNull.class, null, mPackageName);
161         this.mUserHandle = userHandle;
162         AnnotationValidations.validate(
163                 NonNull.class, null, mUserHandle);
164         this.mIoOveruseStats = ioOveruseStats;
165 
166         // onConstructed(); // You can define this method to get a callback
167     }
168 
169     @DataClass.Generated.Member
170     public static final @NonNull Parcelable.Creator<ResourceOveruseStats> CREATOR
171             = new Parcelable.Creator<ResourceOveruseStats>() {
172         @Override
173         public ResourceOveruseStats[] newArray(int size) {
174             return new ResourceOveruseStats[size];
175         }
176 
177         @Override
178         public ResourceOveruseStats createFromParcel(@NonNull android.os.Parcel in) {
179             return new ResourceOveruseStats(in);
180         }
181     };
182 
183     /**
184      * A builder for {@link ResourceOveruseStats}
185      * @hide
186      */
187     @SuppressWarnings("WeakerAccess")
188     @DataClass.Generated.Member
189     public static final class Builder {
190 
191         private @NonNull String mPackageName;
192         private @NonNull UserHandle mUserHandle;
193         private @Nullable IoOveruseStats mIoOveruseStats;
194 
195         private long mBuilderFieldsSet = 0L;
196 
197         /**
198          * Creates a new Builder.
199          *
200          * @param packageName
201          *   Name of the package, whose stats are recorded in the below fields.
202          *
203          *   NOTE: For packages that share a UID, the package name will be the shared package name because
204          *         the stats are aggregated for all packages under the shared UID.
205          * @param userHandle
206          *   User handle, whose stats are recorded in the below fields.
207          */
Builder( @onNull String packageName, @NonNull UserHandle userHandle)208         public Builder(
209                 @NonNull String packageName,
210                 @NonNull UserHandle userHandle) {
211             mPackageName = packageName;
212             AnnotationValidations.validate(
213                     NonNull.class, null, mPackageName);
214             mUserHandle = userHandle;
215             AnnotationValidations.validate(
216                     NonNull.class, null, mUserHandle);
217         }
218 
219         /**
220          * Name of the package, whose stats are recorded in the below fields.
221          *
222          * NOTE: For packages that share a UID, the package name will be the shared package name because
223          *       the stats are aggregated for all packages under the shared UID.
224          */
225         @DataClass.Generated.Member
setPackageName(@onNull String value)226         public @NonNull Builder setPackageName(@NonNull String value) {
227             checkNotUsed();
228             mBuilderFieldsSet |= 0x1;
229             mPackageName = value;
230             return this;
231         }
232 
233         /**
234          * User handle, whose stats are recorded in the below fields.
235          */
236         @DataClass.Generated.Member
setUserHandle(@onNull UserHandle value)237         public @NonNull Builder setUserHandle(@NonNull UserHandle value) {
238             checkNotUsed();
239             mBuilderFieldsSet |= 0x2;
240             mUserHandle = value;
241             return this;
242         }
243 
244         /**
245          * I/O overuse stats for the package.
246          *
247          * If the package didn't opt-in to receive I/O overuse stats or the package doesn't have
248          * I/O overuse stats, this value will be null.
249          */
250         @DataClass.Generated.Member
setIoOveruseStats(@onNull IoOveruseStats value)251         public @NonNull Builder setIoOveruseStats(@NonNull IoOveruseStats value) {
252             checkNotUsed();
253             mBuilderFieldsSet |= 0x4;
254             mIoOveruseStats = value;
255             return this;
256         }
257 
258         /** Builds the instance. This builder should not be touched after calling this! */
build()259         public @NonNull ResourceOveruseStats build() {
260             checkNotUsed();
261             mBuilderFieldsSet |= 0x8; // Mark builder used
262 
263             if ((mBuilderFieldsSet & 0x4) == 0) {
264                 mIoOveruseStats = null;
265             }
266             ResourceOveruseStats o = new ResourceOveruseStats(
267                     mPackageName,
268                     mUserHandle,
269                     mIoOveruseStats);
270             return o;
271         }
272 
checkNotUsed()273         private void checkNotUsed() {
274             if ((mBuilderFieldsSet & 0x8) != 0) {
275                 throw new IllegalStateException(
276                         "This Builder should not be reused. Use a new Builder instance instead");
277             }
278         }
279     }
280 
281     @DataClass.Generated(
282             time = 1715718593235L,
283             codegenVersion = "1.0.23",
284             sourceFile = "packages/services/Car/car-lib/src/android/car/watchdog/ResourceOveruseStats.java",
285             inputSignatures = "private @android.annotation.NonNull java.lang.String mPackageName\nprivate @android.annotation.NonNull android.os.UserHandle mUserHandle\nprivate @android.annotation.Nullable android.car.watchdog.IoOveruseStats mIoOveruseStats\nclass ResourceOveruseStats extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genToString=true, genHiddenBuilder=true)")
286     @Deprecated
__metadata()287     private void __metadata() {}
288 
289 
290     //@formatter:on
291     // End of generated code
292 
293 }
294