1 /* 2 * Copyright (C) 2022 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 package android.car; 17 18 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 19 20 import android.annotation.NonNull; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 25 import com.android.car.internal.util.AnnotationValidations; 26 import com.android.car.internal.util.DataClass; 27 28 /** 29 * Exception thrown when an App tries to calls an API not supported in the platform version. 30 * 31 * <p>Apps are expected to check the {@code ApiRequirements} for each API. If the API is 32 * not supported for the current platform, the API should not be called. Apps can use 33 * {@link Car#getPlatformVersion()} to get the current platform version. 34 */ 35 @DataClass() 36 public final class PlatformVersionMismatchException extends UnsupportedOperationException 37 implements Parcelable { 38 39 @NonNull 40 private final PlatformVersion mExpectedPlatformApiVersion; 41 42 @Override 43 @NonNull getMessage()44 public String getMessage() { 45 return "Expected version: " 46 + mExpectedPlatformApiVersion + ", Current version: " + Car.getPlatformVersion(); 47 } 48 49 50 // Code below generated by codegen v1.0.23. 51 // 52 // DO NOT MODIFY! 53 // CHECKSTYLE:OFF Generated code 54 // 55 // To regenerate run: 56 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/PlatformVersionMismatchException.java 57 // Added AddedInOrBefore or ApiRequirement Annotation manually 58 // 59 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 60 // Settings > Editor > Code Style > Formatter Control 61 //@formatter:off 62 63 64 @DataClass.Generated.Member PlatformVersionMismatchException( @onNull PlatformVersion expectedPlatformApiVersion)65 public PlatformVersionMismatchException( 66 @NonNull PlatformVersion expectedPlatformApiVersion) { 67 this.mExpectedPlatformApiVersion = expectedPlatformApiVersion; 68 AnnotationValidations.validate( 69 NonNull.class, null, mExpectedPlatformApiVersion); 70 71 // onConstructed(); // You can define this method to get a callback 72 } 73 74 /** 75 * Gets expected platform API version. 76 */ 77 @DataClass.Generated.Member getMinimumPlatformApiVersion()78 public @NonNull PlatformVersion getMinimumPlatformApiVersion() { 79 return mExpectedPlatformApiVersion; 80 } 81 82 @Override 83 @DataClass.Generated.Member writeToParcel(@onNull Parcel dest, int flags)84 public void writeToParcel(@NonNull Parcel dest, int flags) { 85 // You can override field parcelling by defining methods like: 86 // void parcelFieldName(Parcel dest, int flags) { ... } 87 88 dest.writeTypedObject(mExpectedPlatformApiVersion, flags); 89 } 90 91 @Override 92 @DataClass.Generated.Member 93 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()94 public int describeContents() { return 0; } 95 96 /** @hide */ 97 @SuppressWarnings({"unchecked", "RedundantCast"}) 98 @DataClass.Generated.Member PlatformVersionMismatchException(@onNull Parcel in)99 /* package-private */ PlatformVersionMismatchException(@NonNull Parcel in) { 100 // You can override field unparcelling by defining methods like: 101 // static FieldType unparcelFieldName(Parcel in) { ... } 102 103 PlatformVersion expectedPlatformApiVersion = (PlatformVersion) in 104 .readTypedObject(PlatformVersion.CREATOR); 105 106 this.mExpectedPlatformApiVersion = expectedPlatformApiVersion; 107 AnnotationValidations.validate( 108 NonNull.class, null, mExpectedPlatformApiVersion); 109 110 // onConstructed(); // You can define this method to get a callback 111 } 112 113 @DataClass.Generated.Member 114 public static final @NonNull Parcelable.Creator<PlatformVersionMismatchException> CREATOR 115 = new Parcelable.Creator<PlatformVersionMismatchException>() { 116 @Override 117 public PlatformVersionMismatchException[] newArray(int size) { 118 return new PlatformVersionMismatchException[size]; 119 } 120 121 @Override 122 public PlatformVersionMismatchException createFromParcel(@NonNull Parcel in) { 123 return new PlatformVersionMismatchException(in); 124 } 125 }; 126 127 @DataClass.Generated( 128 time = 1658181489415L, 129 codegenVersion = "1.0.23", 130 sourceFile = "packages/services/Car/car-lib/src/android/car/PlatformVersionMismatchException.java", 131 inputSignatures = "private final @android.annotation.NonNull android.car.PlatformApiVersion mExpectedPlatformApiVersion\npublic @java.lang.Override @android.annotation.NonNull @android.car.annotation.AddedIn java.lang.String getMessage()\nclass PlatformVersionMismatchException extends java.lang.UnsupportedOperationException implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass()") 132 @Deprecated __metadata()133 private void __metadata() {} 134 135 136 //@formatter:on 137 // End of generated code 138 139 } 140