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