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