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.IntDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.StringDef; 25 import android.annotation.SystemApi; 26 import android.os.Parcelable; 27 28 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 29 import com.android.internal.util.DataClass; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 import java.util.List; 34 import java.util.Map; 35 36 /** 37 * Resource overuse configuration for a component. 38 * 39 * @hide 40 */ 41 @SystemApi 42 @DataClass(genToString = true, genBuilder = true, genHiddenConstDefs = true) 43 public final class ResourceOveruseConfiguration implements Parcelable { 44 /** 45 * System component. 46 */ 47 public static final int COMPONENT_TYPE_SYSTEM = 1; 48 49 /** 50 * Vendor component. 51 */ 52 public static final int COMPONENT_TYPE_VENDOR = 2; 53 54 /** 55 * Third party component. 56 */ 57 public static final int COMPONENT_TYPE_THIRD_PARTY = 3; 58 59 /** 60 * Map applications. 61 */ 62 public static final String APPLICATION_CATEGORY_TYPE_MAPS = 63 "android.car.watchdog.app.category.MAPS"; 64 65 /** 66 * Media applications. 67 */ 68 public static final String APPLICATION_CATEGORY_TYPE_MEDIA = 69 "android.car.watchdog.app.category.MEDIA"; 70 71 /** 72 * Component type of the I/O overuse configuration. 73 */ 74 private @ComponentType int mComponentType; 75 76 /** 77 * List of system or vendor packages that are safe to be killed on resource overuse. 78 * 79 * <p>System component must provide only safe-to-kill system packages in this list. 80 * <p>Vendor component must provide only safe-to-kill vendor packages in this list. 81 */ 82 private @NonNull List<String> mSafeToKillPackages; 83 84 /** 85 * List of vendor package prefixes. 86 * 87 * <p>Any pre-installed package name starting with one of the prefixes or any package from the 88 * vendor partition is identified as a vendor package and vendor provided thresholds are applied 89 * to these packages. This list must be provided only by the vendor component. 90 */ 91 private @NonNull List<String> mVendorPackagePrefixes; 92 93 94 /** 95 * Mappings from package name to application category types. 96 * 97 * <p>This mapping must contain only packages that can be mapped to one of the 98 * {@link ApplicationCategoryType} types. This mapping must be defined only by the system and 99 * vendor components. 100 */ 101 private @NonNull Map<String, String> mPackagesToAppCategoryTypes; 102 103 /** 104 * I/O overuse configuration for the component specified by 105 * {@link ResourceOveruseConfiguration#getComponentType}. 106 */ 107 private @Nullable IoOveruseConfiguration mIoOveruseConfiguration = null; 108 109 110 111 // Code below generated by codegen v1.0.22. 112 // 113 // DO NOT MODIFY! 114 // CHECKSTYLE:OFF Generated code 115 // 116 // To regenerate run: 117 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/watchdog/ResourceOveruseConfiguration.java 118 // 119 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 120 // Settings > Editor > Code Style > Formatter Control 121 //@formatter:off 122 123 124 /** @hide */ 125 @IntDef(prefix = "COMPONENT_TYPE_", value = { 126 COMPONENT_TYPE_SYSTEM, 127 COMPONENT_TYPE_VENDOR, 128 COMPONENT_TYPE_THIRD_PARTY 129 }) 130 @Retention(RetentionPolicy.SOURCE) 131 @DataClass.Generated.Member 132 public @interface ComponentType {} 133 134 /** @hide */ 135 @DataClass.Generated.Member componentTypeToString(@omponentType int value)136 public static String componentTypeToString(@ComponentType int value) { 137 switch (value) { 138 case COMPONENT_TYPE_SYSTEM: 139 return "COMPONENT_TYPE_SYSTEM"; 140 case COMPONENT_TYPE_VENDOR: 141 return "COMPONENT_TYPE_VENDOR"; 142 case COMPONENT_TYPE_THIRD_PARTY: 143 return "COMPONENT_TYPE_THIRD_PARTY"; 144 default: return Integer.toHexString(value); 145 } 146 } 147 148 /** @hide */ 149 @StringDef(prefix = "APPLICATION_CATEGORY_TYPE_", value = { 150 APPLICATION_CATEGORY_TYPE_MAPS, 151 APPLICATION_CATEGORY_TYPE_MEDIA 152 }) 153 @Retention(RetentionPolicy.SOURCE) 154 @DataClass.Generated.Member 155 public @interface ApplicationCategoryType {} 156 157 @DataClass.Generated.Member ResourceOveruseConfiguration( @omponentType int componentType, @NonNull List<String> safeToKillPackages, @NonNull List<String> vendorPackagePrefixes, @NonNull Map<String,String> packagesToAppCategoryTypes, @Nullable IoOveruseConfiguration ioOveruseConfiguration)158 /* package-private */ ResourceOveruseConfiguration( 159 @ComponentType int componentType, 160 @NonNull List<String> safeToKillPackages, 161 @NonNull List<String> vendorPackagePrefixes, 162 @NonNull Map<String,String> packagesToAppCategoryTypes, 163 @Nullable IoOveruseConfiguration ioOveruseConfiguration) { 164 this.mComponentType = componentType; 165 166 if (!(mComponentType == COMPONENT_TYPE_SYSTEM) 167 && !(mComponentType == COMPONENT_TYPE_VENDOR) 168 && !(mComponentType == COMPONENT_TYPE_THIRD_PARTY)) { 169 throw new java.lang.IllegalArgumentException( 170 "componentType was " + mComponentType + " but must be one of: " 171 + "COMPONENT_TYPE_SYSTEM(" + COMPONENT_TYPE_SYSTEM + "), " 172 + "COMPONENT_TYPE_VENDOR(" + COMPONENT_TYPE_VENDOR + "), " 173 + "COMPONENT_TYPE_THIRD_PARTY(" + COMPONENT_TYPE_THIRD_PARTY + ")"); 174 } 175 176 this.mSafeToKillPackages = safeToKillPackages; 177 com.android.internal.util.AnnotationValidations.validate( 178 NonNull.class, null, mSafeToKillPackages); 179 this.mVendorPackagePrefixes = vendorPackagePrefixes; 180 com.android.internal.util.AnnotationValidations.validate( 181 NonNull.class, null, mVendorPackagePrefixes); 182 this.mPackagesToAppCategoryTypes = packagesToAppCategoryTypes; 183 com.android.internal.util.AnnotationValidations.validate( 184 NonNull.class, null, mPackagesToAppCategoryTypes); 185 this.mIoOveruseConfiguration = ioOveruseConfiguration; 186 187 // onConstructed(); // You can define this method to get a callback 188 } 189 190 /** 191 * Component type of the I/O overuse configuration. 192 */ 193 @DataClass.Generated.Member getComponentType()194 public @ComponentType int getComponentType() { 195 return mComponentType; 196 } 197 198 /** 199 * List of system or vendor packages that are safe to be killed on resource overuse. 200 * 201 * <p>System component must provide only safe-to-kill system packages in this list. 202 * <p>Vendor component must provide only safe-to-kill vendor packages in this list. 203 */ 204 @DataClass.Generated.Member getSafeToKillPackages()205 public @NonNull List<String> getSafeToKillPackages() { 206 return mSafeToKillPackages; 207 } 208 209 /** 210 * List of vendor package prefixes. 211 * 212 * <p>Any pre-installed package name starting with one of the prefixes or any package from the 213 * vendor partition is identified as a vendor package and vendor provided thresholds are applied 214 * to these packages. This list must be provided only by the vendor component. 215 */ 216 @DataClass.Generated.Member getVendorPackagePrefixes()217 public @NonNull List<String> getVendorPackagePrefixes() { 218 return mVendorPackagePrefixes; 219 } 220 221 /** 222 * Mappings from package name to application category types. 223 * 224 * <p>This mapping must contain only packages that can be mapped to one of the 225 * {@link ApplicationCategoryType} types. This mapping must be defined only by the system and 226 * vendor components. 227 */ 228 @DataClass.Generated.Member getPackagesToAppCategoryTypes()229 public @NonNull Map<String,String> getPackagesToAppCategoryTypes() { 230 return mPackagesToAppCategoryTypes; 231 } 232 233 /** 234 * I/O overuse configuration for the component specified by 235 * {@link ResourceOveruseConfiguration#getComponentType}. 236 */ 237 @DataClass.Generated.Member getIoOveruseConfiguration()238 public @Nullable IoOveruseConfiguration getIoOveruseConfiguration() { 239 return mIoOveruseConfiguration; 240 } 241 242 @Override 243 @DataClass.Generated.Member toString()244 public String toString() { 245 // You can override field toString logic by defining methods like: 246 // String fieldNameToString() { ... } 247 248 return "ResourceOveruseConfiguration { " + 249 "componentType = " + componentTypeToString(mComponentType) + ", " + 250 "safeToKillPackages = " + mSafeToKillPackages + ", " + 251 "vendorPackagePrefixes = " + mVendorPackagePrefixes + ", " + 252 "packagesToAppCategoryTypes = " + mPackagesToAppCategoryTypes + ", " + 253 "ioOveruseConfiguration = " + mIoOveruseConfiguration + 254 " }"; 255 } 256 257 @Override 258 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)259 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 260 // You can override field parcelling by defining methods like: 261 // void parcelFieldName(Parcel dest, int flags) { ... } 262 263 byte flg = 0; 264 if (mIoOveruseConfiguration != null) flg |= 0x10; 265 dest.writeByte(flg); 266 dest.writeInt(mComponentType); 267 dest.writeStringList(mSafeToKillPackages); 268 dest.writeStringList(mVendorPackagePrefixes); 269 dest.writeMap(mPackagesToAppCategoryTypes); 270 if (mIoOveruseConfiguration != null) dest.writeTypedObject(mIoOveruseConfiguration, flags); 271 } 272 273 @Override 274 @DataClass.Generated.Member describeContents()275 public int describeContents() { return 0; } 276 277 /** @hide */ 278 @SuppressWarnings({"unchecked", "RedundantCast"}) 279 @DataClass.Generated.Member ResourceOveruseConfiguration(@onNull android.os.Parcel in)280 /* package-private */ ResourceOveruseConfiguration(@NonNull android.os.Parcel in) { 281 // You can override field unparcelling by defining methods like: 282 // static FieldType unparcelFieldName(Parcel in) { ... } 283 284 byte flg = in.readByte(); 285 int componentType = in.readInt(); 286 List<String> safeToKillPackages = new java.util.ArrayList<>(); 287 in.readStringList(safeToKillPackages); 288 List<String> vendorPackagePrefixes = new java.util.ArrayList<>(); 289 in.readStringList(vendorPackagePrefixes); 290 Map<String,String> packagesToAppCategoryTypes = new java.util.LinkedHashMap<>(); 291 in.readMap(packagesToAppCategoryTypes, String.class.getClassLoader()); 292 IoOveruseConfiguration ioOveruseConfiguration = (flg & 0x10) == 0 ? null : (IoOveruseConfiguration) in.readTypedObject(IoOveruseConfiguration.CREATOR); 293 294 this.mComponentType = componentType; 295 296 if (!(mComponentType == COMPONENT_TYPE_SYSTEM) 297 && !(mComponentType == COMPONENT_TYPE_VENDOR) 298 && !(mComponentType == COMPONENT_TYPE_THIRD_PARTY)) { 299 throw new java.lang.IllegalArgumentException( 300 "componentType was " + mComponentType + " but must be one of: " 301 + "COMPONENT_TYPE_SYSTEM(" + COMPONENT_TYPE_SYSTEM + "), " 302 + "COMPONENT_TYPE_VENDOR(" + COMPONENT_TYPE_VENDOR + "), " 303 + "COMPONENT_TYPE_THIRD_PARTY(" + COMPONENT_TYPE_THIRD_PARTY + ")"); 304 } 305 306 this.mSafeToKillPackages = safeToKillPackages; 307 com.android.internal.util.AnnotationValidations.validate( 308 NonNull.class, null, mSafeToKillPackages); 309 this.mVendorPackagePrefixes = vendorPackagePrefixes; 310 com.android.internal.util.AnnotationValidations.validate( 311 NonNull.class, null, mVendorPackagePrefixes); 312 this.mPackagesToAppCategoryTypes = packagesToAppCategoryTypes; 313 com.android.internal.util.AnnotationValidations.validate( 314 NonNull.class, null, mPackagesToAppCategoryTypes); 315 this.mIoOveruseConfiguration = ioOveruseConfiguration; 316 317 // onConstructed(); // You can define this method to get a callback 318 } 319 320 @DataClass.Generated.Member 321 public static final @NonNull Parcelable.Creator<ResourceOveruseConfiguration> CREATOR 322 = new Parcelable.Creator<ResourceOveruseConfiguration>() { 323 @Override 324 public ResourceOveruseConfiguration[] newArray(int size) { 325 return new ResourceOveruseConfiguration[size]; 326 } 327 328 @Override 329 public ResourceOveruseConfiguration createFromParcel(@NonNull android.os.Parcel in) { 330 return new ResourceOveruseConfiguration(in); 331 } 332 }; 333 334 /** 335 * A builder for {@link ResourceOveruseConfiguration} 336 */ 337 @SuppressWarnings("WeakerAccess") 338 @DataClass.Generated.Member 339 public static final class Builder { 340 341 private @ComponentType int mComponentType; 342 private @NonNull List<String> mSafeToKillPackages; 343 private @NonNull List<String> mVendorPackagePrefixes; 344 private @NonNull Map<String,String> mPackagesToAppCategoryTypes; 345 private @Nullable IoOveruseConfiguration mIoOveruseConfiguration; 346 347 private long mBuilderFieldsSet = 0L; 348 349 /** 350 * Creates a new Builder. 351 * 352 * @param componentType 353 * Component type of the I/O overuse configuration. 354 * @param safeToKillPackages 355 * List of system or vendor packages that are safe to be killed on resource overuse. 356 * 357 * <p>System component must provide only safe-to-kill system packages in this list. 358 * <p>Vendor component must provide only safe-to-kill vendor packages in this list. 359 * @param vendorPackagePrefixes 360 * List of vendor package prefixes. 361 * 362 * <p>Any pre-installed package name starting with one of the prefixes or any package from the 363 * vendor partition is identified as a vendor package and vendor provided thresholds are applied 364 * to these packages. This list must be provided only by the vendor component. 365 * @param packagesToAppCategoryTypes 366 * Mappings from package name to application category types. 367 * 368 * <p>This mapping must contain only packages that can be mapped to one of the 369 * {@link ApplicationCategoryType} types. This mapping must be defined only by the system and 370 * vendor components. 371 */ Builder( @omponentType int componentType, @NonNull List<String> safeToKillPackages, @NonNull List<String> vendorPackagePrefixes, @NonNull Map<String,String> packagesToAppCategoryTypes)372 public Builder( 373 @ComponentType int componentType, 374 @NonNull List<String> safeToKillPackages, 375 @NonNull List<String> vendorPackagePrefixes, 376 @NonNull Map<String,String> packagesToAppCategoryTypes) { 377 mComponentType = componentType; 378 379 if (!(mComponentType == COMPONENT_TYPE_SYSTEM) 380 && !(mComponentType == COMPONENT_TYPE_VENDOR) 381 && !(mComponentType == COMPONENT_TYPE_THIRD_PARTY)) { 382 throw new java.lang.IllegalArgumentException( 383 "componentType was " + mComponentType + " but must be one of: " 384 + "COMPONENT_TYPE_SYSTEM(" + COMPONENT_TYPE_SYSTEM + "), " 385 + "COMPONENT_TYPE_VENDOR(" + COMPONENT_TYPE_VENDOR + "), " 386 + "COMPONENT_TYPE_THIRD_PARTY(" + COMPONENT_TYPE_THIRD_PARTY + ")"); 387 } 388 389 mSafeToKillPackages = safeToKillPackages; 390 com.android.internal.util.AnnotationValidations.validate( 391 NonNull.class, null, mSafeToKillPackages); 392 mVendorPackagePrefixes = vendorPackagePrefixes; 393 com.android.internal.util.AnnotationValidations.validate( 394 NonNull.class, null, mVendorPackagePrefixes); 395 mPackagesToAppCategoryTypes = packagesToAppCategoryTypes; 396 com.android.internal.util.AnnotationValidations.validate( 397 NonNull.class, null, mPackagesToAppCategoryTypes); 398 } 399 400 /** 401 * Component type of the I/O overuse configuration. 402 */ 403 @DataClass.Generated.Member setComponentType(@omponentType int value)404 public @NonNull Builder setComponentType(@ComponentType int value) { 405 checkNotUsed(); 406 mBuilderFieldsSet |= 0x1; 407 mComponentType = value; 408 return this; 409 } 410 411 /** 412 * List of system or vendor packages that are safe to be killed on resource overuse. 413 * 414 * <p>System component must provide only safe-to-kill system packages in this list. 415 * <p>Vendor component must provide only safe-to-kill vendor packages in this list. 416 */ 417 @DataClass.Generated.Member setSafeToKillPackages(@onNull List<String> value)418 public @NonNull Builder setSafeToKillPackages(@NonNull List<String> value) { 419 checkNotUsed(); 420 mBuilderFieldsSet |= 0x2; 421 mSafeToKillPackages = value; 422 return this; 423 } 424 425 /** @see #setSafeToKillPackages */ 426 @DataClass.Generated.Member addSafeToKillPackages(@onNull String value)427 public @NonNull Builder addSafeToKillPackages(@NonNull String value) { 428 // You can refine this method's name by providing item's singular name, e.g.: 429 // @DataClass.PluralOf("item")) mItems = ... 430 431 if (mSafeToKillPackages == null) setSafeToKillPackages(new java.util.ArrayList<>()); 432 mSafeToKillPackages.add(value); 433 return this; 434 } 435 436 /** 437 * List of vendor package prefixes. 438 * 439 * <p>Any pre-installed package name starting with one of the prefixes or any package from the 440 * vendor partition is identified as a vendor package and vendor provided thresholds are applied 441 * to these packages. This list must be provided only by the vendor component. 442 */ 443 @DataClass.Generated.Member setVendorPackagePrefixes(@onNull List<String> value)444 public @NonNull Builder setVendorPackagePrefixes(@NonNull List<String> value) { 445 checkNotUsed(); 446 mBuilderFieldsSet |= 0x4; 447 mVendorPackagePrefixes = value; 448 return this; 449 } 450 451 /** @see #setVendorPackagePrefixes */ 452 @DataClass.Generated.Member addVendorPackagePrefixes(@onNull String value)453 public @NonNull Builder addVendorPackagePrefixes(@NonNull String value) { 454 // You can refine this method's name by providing item's singular name, e.g.: 455 // @DataClass.PluralOf("item")) mItems = ... 456 457 if (mVendorPackagePrefixes == null) setVendorPackagePrefixes(new java.util.ArrayList<>()); 458 mVendorPackagePrefixes.add(value); 459 return this; 460 } 461 462 /** 463 * Mappings from package name to application category types. 464 * 465 * <p>This mapping must contain only packages that can be mapped to one of the 466 * {@link ApplicationCategoryType} types. This mapping must be defined only by the system and 467 * vendor components. 468 */ 469 @DataClass.Generated.Member setPackagesToAppCategoryTypes(@onNull Map<String,String> value)470 public @NonNull Builder setPackagesToAppCategoryTypes(@NonNull Map<String,String> value) { 471 checkNotUsed(); 472 mBuilderFieldsSet |= 0x8; 473 mPackagesToAppCategoryTypes = value; 474 return this; 475 } 476 477 /** @see #setPackagesToAppCategoryTypes */ 478 @DataClass.Generated.Member addPackagesToAppCategoryTypes(@onNull String key, @NonNull String value)479 public @NonNull Builder addPackagesToAppCategoryTypes(@NonNull String key, @NonNull String value) { 480 // You can refine this method's name by providing item's singular name, e.g.: 481 // @DataClass.PluralOf("item")) mItems = ... 482 483 if (mPackagesToAppCategoryTypes == null) setPackagesToAppCategoryTypes(new java.util.LinkedHashMap()); 484 mPackagesToAppCategoryTypes.put(key, value); 485 return this; 486 } 487 488 /** 489 * I/O overuse configuration for the component specified by 490 * {@link ResourceOveruseConfiguration#getComponentType}. 491 */ 492 @DataClass.Generated.Member setIoOveruseConfiguration(@onNull IoOveruseConfiguration value)493 public @NonNull Builder setIoOveruseConfiguration(@NonNull IoOveruseConfiguration value) { 494 checkNotUsed(); 495 mBuilderFieldsSet |= 0x10; 496 mIoOveruseConfiguration = value; 497 return this; 498 } 499 500 /** Builds the instance. This builder should not be touched after calling this! */ build()501 public @NonNull ResourceOveruseConfiguration build() { 502 checkNotUsed(); 503 mBuilderFieldsSet |= 0x20; // Mark builder used 504 505 if ((mBuilderFieldsSet & 0x10) == 0) { 506 mIoOveruseConfiguration = null; 507 } 508 ResourceOveruseConfiguration o = new ResourceOveruseConfiguration( 509 mComponentType, 510 mSafeToKillPackages, 511 mVendorPackagePrefixes, 512 mPackagesToAppCategoryTypes, 513 mIoOveruseConfiguration); 514 return o; 515 } 516 checkNotUsed()517 private void checkNotUsed() { 518 if ((mBuilderFieldsSet & 0x20) != 0) { 519 throw new IllegalStateException( 520 "This Builder should not be reused. Use a new Builder instance instead"); 521 } 522 } 523 } 524 525 @DataClass.Generated( 526 time = 1615571828842L, 527 codegenVersion = "1.0.22", 528 sourceFile = "packages/services/Car/car-lib/src/android/car/watchdog/ResourceOveruseConfiguration.java", 529 inputSignatures = "public static final int COMPONENT_TYPE_SYSTEM\npublic static final int COMPONENT_TYPE_VENDOR\npublic static final int COMPONENT_TYPE_THIRD_PARTY\npublic static final java.lang.String APPLICATION_CATEGORY_TYPE_MAPS\npublic static final java.lang.String APPLICATION_CATEGORY_TYPE_MEDIA\nprivate @android.car.watchdog.ResourceOveruseConfiguration.ComponentType int mComponentType\nprivate @android.annotation.NonNull java.util.List<java.lang.String> mSafeToKillPackages\nprivate @android.annotation.NonNull java.util.List<java.lang.String> mVendorPackagePrefixes\nprivate @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.String> mPackagesToAppCategoryTypes\nprivate @android.annotation.Nullable android.car.watchdog.IoOveruseConfiguration mIoOveruseConfiguration\nclass ResourceOveruseConfiguration extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genBuilder=true, genHiddenConstDefs=true)") 530 @Deprecated 531 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) __metadata()532 private void __metadata() {} 533 534 535 //@formatter:on 536 // End of generated code 537 538 } 539