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.IntDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.SystemApi; 25 import android.annotation.TestApi; 26 import android.os.Parcelable; 27 import android.os.UserHandle; 28 import android.os.UserManager; 29 30 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 31 import com.android.car.internal.util.DataClass; 32 import com.android.car.internal.util.DebugUtils; 33 34 import java.lang.annotation.Retention; 35 import java.lang.annotation.RetentionPolicy; 36 37 /** 38 * User creation results. 39 * 40 * @hide 41 */ 42 @DataClass( 43 genToString = true, 44 genHiddenConstructor = true, 45 genHiddenConstDefs = true) 46 @SystemApi 47 public final class UserCreationResult implements Parcelable, OperationResult { 48 49 /** 50 * {@link Status} called when user creation is successful for both HAL and Android. 51 */ 52 @Status 53 public static final int STATUS_SUCCESSFUL = CommonResults.STATUS_SUCCESSFUL; 54 55 /** 56 * {@link Status} called when user creation failed on Android - HAL is not even called in this 57 * case. 58 */ 59 @Status 60 public static final int STATUS_ANDROID_FAILURE = CommonResults.STATUS_ANDROID_FAILURE; 61 62 /** 63 * {@link Status} called when user was created on Android but HAL returned a failure - the 64 * Android user is automatically removed. 65 */ 66 @Status 67 public static final int STATUS_HAL_FAILURE = CommonResults.STATUS_HAL_FAILURE; 68 69 /** 70 * {@link Status} called when user creation is failed for HAL for some internal error - the 71 * Android user is not automatically removed. 72 */ 73 @Status 74 public static final int STATUS_HAL_INTERNAL_FAILURE = CommonResults.STATUS_HAL_INTERNAL_FAILURE; 75 76 /** 77 * {@link Status} called when given parameters or environment states are invalid for creating 78 * user - HAL or Android user creation is not requested. 79 */ 80 @Status 81 public static final int STATUS_INVALID_REQUEST = CommonResults.STATUS_INVALID_REQUEST; 82 83 /** 84 * Gets the user creation result status. 85 * 86 * @return either {@link UserCreationResult#STATUS_SUCCESSFUL}, 87 * {@link UserCreationResult#STATUS_ANDROID_FAILURE}, 88 * {@link UserCreationResult#STATUS_HAL_FAILURE}, 89 * {@link UserCreationResult#STATUS_HAL_INTERNAL_FAILURE}, or 90 * {@link UserCreationResult#STATUS_INVALID_REQUEST}. 91 */ 92 private final @Status int mStatus; 93 94 // TODO(b/214443810): codegen generates call to writeInteger() / readInteger(), we need to 95 // manually change to writeInt() / readInt() 96 /** 97 * Gets the failure status returned by {@link UserManager} when the {@link #getStatus() status} 98 * is {@link #STATUS_ANDROID_FAILURE}. 99 * 100 * @return {@code USER_OPERATION_ERROR_} constants defined by {@link UserManager}, or 101 * {@code null} when the {@link #getStatus() status} is not {@link #STATUS_ANDROID_FAILURE}. 102 */ 103 @Nullable 104 private final Integer mAndroidFailureStatus; 105 106 /** 107 * Gets the created user. 108 */ 109 @Nullable 110 private final UserHandle mUser; 111 112 /** 113 * Gets the error message sent by HAL, if any. 114 */ 115 @Nullable 116 private final String mErrorMessage; 117 118 /** 119 * Gets the internal error message , if any. 120 */ 121 @Nullable 122 private final String mInternalErrorMessage; 123 124 @Override isSuccess()125 public boolean isSuccess() { 126 return mStatus == STATUS_SUCCESSFUL; 127 } 128 129 /** @hide */ 130 @TestApi UserCreationResult(@tatus int status)131 public UserCreationResult(@Status int status) { 132 this(status, /* user= */ null); 133 } 134 135 /** @hide */ UserCreationResult(@tatus int status, UserHandle user)136 public UserCreationResult(@Status int status, UserHandle user) { 137 this(status, /* androidFailureStatus= */ null, user, /* errorMessage= */ null, 138 /* internalErrorMessage= */ null); 139 } 140 141 // NOTE: codegen generates this method, but without @ExcludeFromCodeCoverageGeneratedReport 142 @Override 143 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()144 public int describeContents() { 145 return 0; 146 } 147 148 149 150 // Code below generated by codegen v1.0.23. 151 // 152 // DO NOT MODIFY! 153 // CHECKSTYLE:OFF Generated code 154 // 155 // To regenerate run: 156 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserCreationResult.java 157 // Added AddedInOrBefore or ApiRequirement Annotation manually 158 // 159 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 160 // Settings > Editor > Code Style > Formatter Control 161 //@formatter:off 162 163 164 /** @hide */ 165 @IntDef(prefix = "STATUS_", value = { 166 STATUS_SUCCESSFUL, 167 STATUS_ANDROID_FAILURE, 168 STATUS_HAL_FAILURE, 169 STATUS_HAL_INTERNAL_FAILURE, 170 STATUS_INVALID_REQUEST 171 }) 172 @Retention(RetentionPolicy.SOURCE) 173 @DataClass.Generated.Member 174 public @interface Status {} 175 176 @DataClass.Generated.Member 177 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 178 @NonNull statusToString(@tatus int value)179 public static String statusToString(@Status int value) { 180 switch (value) { 181 case STATUS_SUCCESSFUL: 182 return "STATUS_SUCCESSFUL"; 183 case STATUS_ANDROID_FAILURE: 184 return "STATUS_ANDROID_FAILURE"; 185 case STATUS_HAL_FAILURE: 186 return "STATUS_HAL_FAILURE"; 187 case STATUS_HAL_INTERNAL_FAILURE: 188 return "STATUS_HAL_INTERNAL_FAILURE"; 189 case STATUS_INVALID_REQUEST: 190 return "STATUS_INVALID_REQUEST"; 191 default: return Integer.toHexString(value); 192 } 193 } 194 195 /** 196 * Creates a new UserCreationResult. 197 * 198 * @param status 199 * Gets the user creation result status. 200 * 201 * @return either {@link UserCreationResult#STATUS_SUCCESSFUL}, 202 * {@link UserCreationResult#STATUS_ANDROID_FAILURE}, 203 * {@link UserCreationResult#STATUS_HAL_FAILURE}, 204 * {@link UserCreationResult#STATUS_HAL_INTERNAL_FAILURE}, or 205 * {@link UserCreationResult#STATUS_INVALID_REQUEST}. 206 * @param androidFailureStatus 207 * Gets the failure status returned by {@link UserManager} when the {@link #getStatus() status} 208 * is {@link #STATUS_ANDROID_FAILURE}. 209 * 210 * @return {@code USER_OPERATION_ERROR_} constants defined by {@link UserManager}, or 211 * {@code null} when the {@link #getStatus() status} is not {@link #STATUS_ANDROID_FAILURE}. 212 * @param user 213 * Gets the created user. 214 * @param errorMessage 215 * Gets the error message sent by HAL, if any. 216 * @param internalErrorMessage 217 * Gets the internal error message , if any. 218 * @hide 219 */ 220 @DataClass.Generated.Member UserCreationResult( @tatus int status, @Nullable Integer androidFailureStatus, @Nullable UserHandle user, @Nullable String errorMessage, @Nullable String internalErrorMessage)221 public UserCreationResult( 222 @Status int status, 223 @Nullable Integer androidFailureStatus, 224 @Nullable UserHandle user, 225 @Nullable String errorMessage, 226 @Nullable String internalErrorMessage) { 227 this.mStatus = status; 228 229 if (!(mStatus == STATUS_SUCCESSFUL) 230 && !(mStatus == STATUS_ANDROID_FAILURE) 231 && !(mStatus == STATUS_HAL_FAILURE) 232 && !(mStatus == STATUS_HAL_INTERNAL_FAILURE) 233 && !(mStatus == STATUS_INVALID_REQUEST)) { 234 throw new java.lang.IllegalArgumentException( 235 "status was " + mStatus + " but must be one of: " 236 + "STATUS_SUCCESSFUL(" + STATUS_SUCCESSFUL + "), " 237 + "STATUS_ANDROID_FAILURE(" + STATUS_ANDROID_FAILURE + "), " 238 + "STATUS_HAL_FAILURE(" + STATUS_HAL_FAILURE + "), " 239 + "STATUS_HAL_INTERNAL_FAILURE(" + STATUS_HAL_INTERNAL_FAILURE + "), " 240 + "STATUS_INVALID_REQUEST(" + STATUS_INVALID_REQUEST + ")"); 241 } 242 243 this.mAndroidFailureStatus = androidFailureStatus; 244 this.mUser = user; 245 this.mErrorMessage = errorMessage; 246 this.mInternalErrorMessage = internalErrorMessage; 247 248 // onConstructed(); // You can define this method to get a callback 249 } 250 251 /** 252 * Gets the user creation result status. 253 * 254 * @return either {@link UserCreationResult#STATUS_SUCCESSFUL}, 255 * {@link UserCreationResult#STATUS_ANDROID_FAILURE}, 256 * {@link UserCreationResult#STATUS_HAL_FAILURE}, 257 * {@link UserCreationResult#STATUS_HAL_INTERNAL_FAILURE}, or 258 * {@link UserCreationResult#STATUS_INVALID_REQUEST}. 259 */ 260 @DataClass.Generated.Member getStatus()261 public @Status int getStatus() { 262 return mStatus; 263 } 264 265 /** 266 * Gets the failure status returned by {@link UserManager} when the {@link #getStatus() status} 267 * is {@link #STATUS_ANDROID_FAILURE}. 268 * 269 * @return {@code USER_OPERATION_ERROR_} constants defined by {@link UserManager}, or 270 * {@code null} when the {@link #getStatus() status} is not {@link #STATUS_ANDROID_FAILURE}. 271 */ 272 @DataClass.Generated.Member getAndroidFailureStatus()273 public @Nullable Integer getAndroidFailureStatus() { 274 return mAndroidFailureStatus; 275 } 276 277 /** 278 * Gets the created user. 279 */ 280 @DataClass.Generated.Member getUser()281 public @Nullable UserHandle getUser() { 282 return mUser; 283 } 284 285 /** 286 * Gets the error message sent by HAL, if any. 287 */ 288 @DataClass.Generated.Member getErrorMessage()289 public @Nullable String getErrorMessage() { 290 return mErrorMessage; 291 } 292 293 /** 294 * Gets the internal error message , if any. 295 */ 296 @DataClass.Generated.Member getInternalErrorMessage()297 public @Nullable String getInternalErrorMessage() { 298 return mInternalErrorMessage; 299 } 300 301 @Override 302 @DataClass.Generated.Member toString()303 public String toString() { 304 // You can override field toString logic by defining methods like: 305 // String fieldNameToString() { ... } 306 307 return "UserCreationResult { " + 308 "status = " + statusToString(mStatus) + ", " + 309 "androidFailureStatus = " + mAndroidFailureStatus + 310 (mAndroidFailureStatus != null ? " (" 311 + DebugUtils.constantToString(UserManager.class, "USER_OPERATION_", 312 mAndroidFailureStatus) + ")" : "") + 313 ", user = " + mUser + ", " + 314 "errorMessage = " + mErrorMessage + ", " + 315 "internalErrorMessage = " + mInternalErrorMessage + 316 " }"; 317 } 318 319 @Override 320 @DataClass.Generated.Member writeToParcel(@ndroid.annotation.NonNull android.os.Parcel dest, int flags)321 public void writeToParcel(@android.annotation.NonNull android.os.Parcel dest, int flags) { 322 // You can override field parcelling by defining methods like: 323 // void parcelFieldName(Parcel dest, int flags) { ... } 324 325 byte flg = 0; 326 if (mAndroidFailureStatus != null) flg |= 0x2; 327 if (mUser != null) flg |= 0x4; 328 if (mErrorMessage != null) flg |= 0x8; 329 if (mInternalErrorMessage != null) flg |= 0x10; 330 dest.writeByte(flg); 331 dest.writeInt(mStatus); 332 if (mAndroidFailureStatus != null) dest.writeInt(mAndroidFailureStatus); 333 if (mUser != null) dest.writeTypedObject(mUser, flags); 334 if (mErrorMessage != null) dest.writeString(mErrorMessage); 335 if (mInternalErrorMessage != null) dest.writeString(mInternalErrorMessage); 336 } 337 338 /** @hide */ 339 @SuppressWarnings({"unchecked", "RedundantCast"}) 340 @DataClass.Generated.Member UserCreationResult(@ndroid.annotation.NonNull android.os.Parcel in)341 /* package-private */ UserCreationResult(@android.annotation.NonNull android.os.Parcel in) { 342 // You can override field unparcelling by defining methods like: 343 // static FieldType unparcelFieldName(Parcel in) { ... } 344 345 byte flg = in.readByte(); 346 int status = in.readInt(); 347 Integer androidFailureStatus = (flg & 0x2) == 0 ? null : (Integer) in.readInt(); 348 UserHandle user = (flg & 0x4) == 0 ? null : (UserHandle) in.readTypedObject(UserHandle.CREATOR); 349 String errorMessage = (flg & 0x8) == 0 ? null : in.readString(); 350 String internalErrorMessage = (flg & 0x10) == 0 ? null : in.readString(); 351 352 this.mStatus = status; 353 354 if (!(mStatus == STATUS_SUCCESSFUL) 355 && !(mStatus == STATUS_ANDROID_FAILURE) 356 && !(mStatus == STATUS_HAL_FAILURE) 357 && !(mStatus == STATUS_HAL_INTERNAL_FAILURE) 358 && !(mStatus == STATUS_INVALID_REQUEST)) { 359 throw new java.lang.IllegalArgumentException( 360 "status was " + mStatus + " but must be one of: " 361 + "STATUS_SUCCESSFUL(" + STATUS_SUCCESSFUL + "), " 362 + "STATUS_ANDROID_FAILURE(" + STATUS_ANDROID_FAILURE + "), " 363 + "STATUS_HAL_FAILURE(" + STATUS_HAL_FAILURE + "), " 364 + "STATUS_HAL_INTERNAL_FAILURE(" + STATUS_HAL_INTERNAL_FAILURE + "), " 365 + "STATUS_INVALID_REQUEST(" + STATUS_INVALID_REQUEST + ")"); 366 } 367 368 this.mAndroidFailureStatus = androidFailureStatus; 369 this.mUser = user; 370 this.mErrorMessage = errorMessage; 371 this.mInternalErrorMessage = internalErrorMessage; 372 373 // onConstructed(); // You can define this method to get a callback 374 } 375 376 @DataClass.Generated.Member 377 public static final @android.annotation.NonNull Parcelable.Creator<UserCreationResult> CREATOR 378 = new Parcelable.Creator<UserCreationResult>() { 379 @Override 380 public UserCreationResult[] newArray(int size) { 381 return new UserCreationResult[size]; 382 } 383 384 @Override 385 public UserCreationResult createFromParcel(@android.annotation.NonNull android.os.Parcel in) { 386 return new UserCreationResult(in); 387 } 388 }; 389 390 @DataClass.Generated( 391 time = 1673057364539L, 392 codegenVersion = "1.0.23", 393 sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserCreationResult.java", 394 inputSignatures = "public static final @android.car.user.UserCreationResult.Status @android.car.annotation.AddedInOrBefore int STATUS_SUCCESSFUL\npublic static final @android.car.user.UserCreationResult.Status @android.car.annotation.AddedInOrBefore int STATUS_ANDROID_FAILURE\npublic static final @android.car.user.UserCreationResult.Status @android.car.annotation.AddedInOrBefore int STATUS_HAL_FAILURE\npublic static final @android.car.user.UserCreationResult.Status @android.car.annotation.AddedInOrBefore int STATUS_HAL_INTERNAL_FAILURE\npublic static final @android.car.user.UserCreationResult.Status @android.car.annotation.AddedInOrBefore int STATUS_INVALID_REQUEST\nprivate final @android.car.user.UserCreationResult.Status int mStatus\nprivate final @android.annotation.Nullable java.lang.Integer mAndroidFailureStatus\nprivate final @android.annotation.Nullable android.os.UserHandle mUser\nprivate final @android.annotation.Nullable java.lang.String mErrorMessage\nprivate final @android.annotation.Nullable java.lang.String mInternalErrorMessage\npublic @java.lang.Override @android.car.annotation.AddedInOrBefore boolean isSuccess()\npublic @java.lang.Override @com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport @android.car.annotation.AddedInOrBefore int describeContents()\nclass UserCreationResult extends java.lang.Object implements [android.os.Parcelable, android.car.user.OperationResult]\n@com.android.car.internal.util.DataClass(genToString=true, genHiddenConstructor=true, genHiddenConstDefs=true)") 395 @Deprecated __metadata()396 private void __metadata() {} 397 398 399 //@formatter:on 400 // End of generated code 401 402 } 403