1 /* 2 * Copyright (C) 2020 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.user; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.car.annotation.AddedInOrBefore; 24 import android.car.user.CarUserManager.UserIdentificationAssociationValue; 25 import android.os.Parcelable; 26 27 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 28 import com.android.car.internal.util.ArrayUtils; 29 import com.android.car.internal.util.DataClass; 30 import com.android.internal.util.Preconditions; 31 32 import java.util.Objects; 33 34 /** 35 * Results of a {@link CarUserManager#getUserIdentificationAssociation(int[]) request. 36 * 37 * @hide 38 */ 39 @DataClass( 40 genToString = true, 41 genHiddenConstructor = false, 42 genHiddenConstDefs = true) 43 public final class UserIdentificationAssociationResponse implements Parcelable { 44 45 /** 46 * Whether the request was successful. 47 * 48 * <p>A successful option has non-null {@link #getValues()} 49 */ 50 private final boolean mSuccess; 51 52 /** 53 * Gets the error message returned by the HAL. 54 */ 55 @Nullable 56 private final String mErrorMessage; 57 58 /** 59 * Gets the list of values associated with the request. 60 * 61 * <p><b>NOTE: </b>It's only set when the response is {@link #isSuccess() successful}. 62 * 63 * <p>For {@link CarUserManager#getUserIdentificationAssociation(int...)}, the values are 64 * defined on 65 * {@link android.hardware.automotive.vehicle.UserIdentificationAssociationValue}. 66 * 67 * <p>For {@link CarUserManager#setUserIdentificationAssociation(int...)}, the values are 68 * defined on 69 * {@link android.hardware.automotive.vehicle.UserIdentificationAssociationSetValue}. 70 */ 71 @Nullable 72 private final int[] mValues; 73 UserIdentificationAssociationResponse( boolean success, @Nullable String errorMessage, @UserIdentificationAssociationValue int[] values)74 private UserIdentificationAssociationResponse( 75 boolean success, 76 @Nullable String errorMessage, 77 @UserIdentificationAssociationValue int[] values) { 78 this.mSuccess = success; 79 this.mErrorMessage = errorMessage; 80 this.mValues = values; 81 } 82 83 /** 84 * Factory method for failed UserIdentificationAssociationResponse requests. 85 */ 86 @NonNull 87 @AddedInOrBefore(majorVersion = 33) forFailure()88 public static UserIdentificationAssociationResponse forFailure() { 89 return forFailure(/* errorMessage= */ null); 90 } 91 92 /** 93 * Factory method for failed UserIdentificationAssociationResponse requests. 94 */ 95 @NonNull 96 @AddedInOrBefore(majorVersion = 33) forFailure(@ullable String errorMessage)97 public static UserIdentificationAssociationResponse forFailure(@Nullable String errorMessage) { 98 return new UserIdentificationAssociationResponse(/* success= */ false, 99 errorMessage, /* values= */ null); 100 } 101 102 /** 103 * Factory method for successful UserIdentificationAssociationResponse requests. 104 */ 105 @NonNull 106 @AddedInOrBefore(majorVersion = 33) forSuccess( @serIdentificationAssociationValue int[] values)107 public static UserIdentificationAssociationResponse forSuccess( 108 @UserIdentificationAssociationValue int[] values) { 109 Preconditions.checkArgument(!ArrayUtils.isEmpty(values), "must have at least one value"); 110 return new UserIdentificationAssociationResponse(/* success= */ true, 111 /* errorMessage= */ null, Objects.requireNonNull(values)); 112 } 113 114 /** 115 * Factory method for successful UserIdentificationAssociationResponse requests. 116 */ 117 @NonNull 118 @AddedInOrBefore(majorVersion = 33) forSuccess( @serIdentificationAssociationValue int[] values, @Nullable String errorMessage)119 public static UserIdentificationAssociationResponse forSuccess( 120 @UserIdentificationAssociationValue int[] values, @Nullable String errorMessage) { 121 Preconditions.checkArgument(!ArrayUtils.isEmpty(values), "must have at least one value"); 122 return new UserIdentificationAssociationResponse(/* success= */ true, errorMessage, 123 Objects.requireNonNull(values)); 124 } 125 126 127 128 129 130 // Code below generated by codegen v1.0.20. 131 // 132 // DO NOT MODIFY! 133 // CHECKSTYLE:OFF Generated code 134 // 135 // To regenerate run: 136 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserIdentificationAssociationResponse.java 137 // 138 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 139 // Settings > Editor > Code Style > Formatter Control 140 //@formatter:off 141 142 143 /** 144 * Whether the request was successful. 145 * 146 * <p>A successful option has non-null {@link #getValues()} 147 */ 148 @DataClass.Generated.Member 149 @AddedInOrBefore(majorVersion = 33) isSuccess()150 public boolean isSuccess() { 151 return mSuccess; 152 } 153 154 /** 155 * Gets the error message returned by the HAL. 156 */ 157 @DataClass.Generated.Member 158 @AddedInOrBefore(majorVersion = 33) getErrorMessage()159 public @Nullable String getErrorMessage() { 160 return mErrorMessage; 161 } 162 163 /** 164 * Gets the list of values associated with the request. 165 * 166 * <p><b>NOTE: </b>It's only set when the response is {@link #isSuccess() successful}. 167 * 168 * <p>For {@link CarUserManager#getUserIdentificationAssociation(int...)}, the values are 169 * defined on 170 * {@link android.hardware.automotive.vehicle.UserIdentificationAssociationValue}. 171 * 172 * <p>For {@link CarUserManager#setUserIdentificationAssociation(int...)}, the values are 173 * defined on 174 * {@link android.hardware.automotive.vehicle.UserIdentificationAssociationSetValue}. 175 */ 176 @DataClass.Generated.Member 177 @AddedInOrBefore(majorVersion = 33) getValues()178 public @Nullable int[] getValues() { 179 return mValues; 180 } 181 182 @Override 183 @DataClass.Generated.Member 184 @AddedInOrBefore(majorVersion = 33) toString()185 public String toString() { 186 // You can override field toString logic by defining methods like: 187 // String fieldNameToString() { ... } 188 189 return "UserIdentificationAssociationResponse { " + 190 "success = " + mSuccess + ", " + 191 "errorMessage = " + mErrorMessage + ", " + 192 "values = " + java.util.Arrays.toString(mValues) + 193 " }"; 194 } 195 196 @Override 197 @DataClass.Generated.Member 198 @AddedInOrBefore(majorVersion = 33) writeToParcel(@onNull android.os.Parcel dest, int flags)199 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 200 // You can override field parcelling by defining methods like: 201 // void parcelFieldName(Parcel dest, int flags) { ... } 202 203 byte flg = 0; 204 if (mSuccess) flg |= 0x1; 205 if (mErrorMessage != null) flg |= 0x2; 206 if (mValues != null) flg |= 0x4; 207 dest.writeByte(flg); 208 if (mErrorMessage != null) dest.writeString(mErrorMessage); 209 if (mValues != null) dest.writeIntArray(mValues); 210 } 211 212 @Override 213 @DataClass.Generated.Member 214 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 215 @AddedInOrBefore(majorVersion = 33) describeContents()216 public int describeContents() { return 0; } 217 218 /** @hide */ 219 @SuppressWarnings({"unchecked", "RedundantCast"}) 220 @DataClass.Generated.Member UserIdentificationAssociationResponse(@onNull android.os.Parcel in)221 /* package-private */ UserIdentificationAssociationResponse(@NonNull android.os.Parcel in) { 222 // You can override field unparcelling by defining methods like: 223 // static FieldType unparcelFieldName(Parcel in) { ... } 224 225 byte flg = in.readByte(); 226 boolean success = (flg & 0x1) != 0; 227 String errorMessage = (flg & 0x2) == 0 ? null : in.readString(); 228 int[] values = (flg & 0x4) == 0 ? null : in.createIntArray(); 229 230 this.mSuccess = success; 231 this.mErrorMessage = errorMessage; 232 this.mValues = values; 233 234 // onConstructed(); // You can define this method to get a callback 235 } 236 237 @DataClass.Generated.Member 238 @AddedInOrBefore(majorVersion = 33) 239 public static final @NonNull Parcelable.Creator<UserIdentificationAssociationResponse> CREATOR 240 = new Parcelable.Creator<UserIdentificationAssociationResponse>() { 241 @Override 242 public UserIdentificationAssociationResponse[] newArray(int size) { 243 return new UserIdentificationAssociationResponse[size]; 244 } 245 246 @Override 247 public UserIdentificationAssociationResponse createFromParcel(@NonNull android.os.Parcel in) { 248 return new UserIdentificationAssociationResponse(in); 249 } 250 }; 251 252 @DataClass.Generated( 253 time = 1604638584791L, 254 codegenVersion = "1.0.20", 255 sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserIdentificationAssociationResponse.java", 256 inputSignatures = "private final boolean mSuccess\nprivate final @android.annotation.Nullable java.lang.String mErrorMessage\nprivate final @android.annotation.Nullable int[] mValues\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forFailure()\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forFailure(java.lang.String)\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forSuccess(int[])\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forSuccess(int[],java.lang.String)\nclass UserIdentificationAssociationResponse extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genToString=true, genHiddenConstructor=false, genHiddenConstDefs=true)") 257 @Deprecated __metadata()258 private void __metadata() {} 259 260 261 //@formatter:on 262 // End of generated code 263 264 } 265