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