1 /* 2 * Copyright (C) 2021 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.os.Parcelable; 23 24 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 25 import com.android.car.internal.util.DataClass; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * User stop result. 32 * 33 * @hide 34 */ 35 @DataClass( 36 genToString = true, 37 genHiddenConstructor = true, 38 genHiddenConstDefs = true) 39 public final class UserStopResult implements Parcelable, OperationResult { 40 41 /** 42 * When user stop is successful. 43 */ 44 @Status 45 public static final int STATUS_SUCCESSFUL = CommonResults.STATUS_SUCCESSFUL; 46 47 /** 48 * When user stop fails. 49 */ 50 @Status 51 public static final int STATUS_ANDROID_FAILURE = CommonResults.STATUS_ANDROID_FAILURE; 52 53 /** 54 * When user to stop doesn't exits. 55 */ 56 @Status 57 public static final int STATUS_USER_DOES_NOT_EXIST = CommonResults.LAST_COMMON_STATUS + 1; 58 59 /** 60 * When user to stop is the system user. 61 */ 62 @Status 63 public static final int STATUS_FAILURE_SYSTEM_USER = CommonResults.LAST_COMMON_STATUS + 2; 64 65 /** 66 * When user to stop is the current user. 67 */ 68 @Status 69 public static final int STATUS_FAILURE_CURRENT_USER = CommonResults.LAST_COMMON_STATUS + 3; 70 71 /** 72 * Gets the user switch result status. 73 * 74 * @return either {@link UserStopResult#STATUS_SUCCESSFUL}, 75 * {@link UserStopResult#STATUS_ANDROID_FAILURE}, 76 * {@link UserStopResult#STATUS_USER_DOES_NOT_EXIST}, 77 * {@link UserStopResult#STATUS_FAILURE_SYSTEM_USER}, or 78 * {@link UserStopResult#STATUS_FAILURE_CURRENT_USER}. 79 */ 80 private final @Status int mStatus; 81 82 /** 83 * Checks if the {@code status} represents a success status. 84 * 85 * @param status to check 86 * @return true for a success status 87 */ isSuccess(@tatus int status)88 public static boolean isSuccess(@Status int status) { 89 return status == STATUS_SUCCESSFUL; 90 } 91 92 @Override isSuccess()93 public boolean isSuccess() { 94 return isSuccess(mStatus); 95 } 96 97 98 99 // Code below generated by codegen v1.0.23. 100 // 101 // DO NOT MODIFY! 102 // CHECKSTYLE:OFF Generated code 103 // 104 // To regenerate run: 105 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserStopResult.java 106 // Added AddedInOrBefore or ApiRequirement Annotation manually 107 // 108 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 109 // Settings > Editor > Code Style > Formatter Control 110 //@formatter:off 111 112 113 /** @hide */ 114 @IntDef(prefix = "STATUS_", value = { 115 STATUS_SUCCESSFUL, 116 STATUS_ANDROID_FAILURE, 117 STATUS_USER_DOES_NOT_EXIST, 118 STATUS_FAILURE_SYSTEM_USER, 119 STATUS_FAILURE_CURRENT_USER 120 }) 121 @Retention(RetentionPolicy.SOURCE) 122 @DataClass.Generated.Member 123 public @interface Status {} 124 125 /** @hide */ 126 @DataClass.Generated.Member 127 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) statusToString(@tatus int value)128 public static String statusToString(@Status int value) { 129 switch (value) { 130 case STATUS_SUCCESSFUL: 131 return "STATUS_SUCCESSFUL"; 132 case STATUS_ANDROID_FAILURE: 133 return "STATUS_ANDROID_FAILURE"; 134 case STATUS_USER_DOES_NOT_EXIST: 135 return "STATUS_USER_DOES_NOT_EXIST"; 136 case STATUS_FAILURE_SYSTEM_USER: 137 return "STATUS_FAILURE_SYSTEM_USER"; 138 case STATUS_FAILURE_CURRENT_USER: 139 return "STATUS_FAILURE_CURRENT_USER"; 140 default: return Integer.toHexString(value); 141 } 142 } 143 144 /** 145 * Creates a new UserStopResult. 146 * 147 * @param status 148 * Gets the user switch result status. 149 * 150 * @return either {@link UserStopResult#STATUS_SUCCESSFUL}, 151 * {@link UserStopResult#STATUS_ANDROID_FAILURE}, 152 * {@link UserStopResult#STATUS_USER_DOES_NOT_EXIST}, 153 * {@link UserStopResult#STATUS_FAILURE_SYSTEM_USER}, or 154 * {@link UserStopResult#STATUS_FAILURE_CURRENT_USER}. 155 * @hide 156 */ 157 @DataClass.Generated.Member UserStopResult( @tatus int status)158 public UserStopResult( 159 @Status int status) { 160 this.mStatus = status; 161 162 if (!(mStatus == STATUS_SUCCESSFUL) 163 && !(mStatus == STATUS_ANDROID_FAILURE) 164 && !(mStatus == STATUS_USER_DOES_NOT_EXIST) 165 && !(mStatus == STATUS_FAILURE_SYSTEM_USER) 166 && !(mStatus == STATUS_FAILURE_CURRENT_USER)) { 167 throw new java.lang.IllegalArgumentException( 168 "status was " + mStatus + " but must be one of: " 169 + "STATUS_SUCCESSFUL(" + STATUS_SUCCESSFUL + "), " 170 + "STATUS_ANDROID_FAILURE(" + STATUS_ANDROID_FAILURE + "), " 171 + "STATUS_USER_DOES_NOT_EXIST(" + STATUS_USER_DOES_NOT_EXIST + "), " 172 + "STATUS_FAILURE_SYSTEM_USER(" + STATUS_FAILURE_SYSTEM_USER + "), " 173 + "STATUS_FAILURE_CURRENT_USER(" + STATUS_FAILURE_CURRENT_USER + ")"); 174 } 175 176 177 // onConstructed(); // You can define this method to get a callback 178 } 179 180 /** 181 * Gets the user switch result status. 182 * 183 * @return either {@link UserStopResult#STATUS_SUCCESSFUL}, 184 * {@link UserStopResult#STATUS_ANDROID_FAILURE}, 185 * {@link UserStopResult#STATUS_USER_DOES_NOT_EXIST}, 186 * {@link UserStopResult#STATUS_FAILURE_SYSTEM_USER}, or 187 * {@link UserStopResult#STATUS_FAILURE_CURRENT_USER}. 188 */ 189 @DataClass.Generated.Member getStatus()190 public @Status int getStatus() { 191 return mStatus; 192 } 193 194 @Override 195 @DataClass.Generated.Member toString()196 public String toString() { 197 // You can override field toString logic by defining methods like: 198 // String fieldNameToString() { ... } 199 200 return "UserStopResult { " + 201 "status = " + statusToString(mStatus) + 202 " }"; 203 } 204 205 @Override 206 @DataClass.Generated.Member writeToParcel(@ndroid.annotation.NonNull android.os.Parcel dest, int flags)207 public void writeToParcel(@android.annotation.NonNull android.os.Parcel dest, int flags) { 208 // You can override field parcelling by defining methods like: 209 // void parcelFieldName(Parcel dest, int flags) { ... } 210 211 dest.writeInt(mStatus); 212 } 213 214 @Override 215 @DataClass.Generated.Member 216 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()217 public int describeContents() { return 0; } 218 219 /** @hide */ 220 @SuppressWarnings({"unchecked", "RedundantCast"}) 221 @DataClass.Generated.Member UserStopResult(@ndroid.annotation.NonNull android.os.Parcel in)222 /* package-private */ UserStopResult(@android.annotation.NonNull android.os.Parcel in) { 223 // You can override field unparcelling by defining methods like: 224 // static FieldType unparcelFieldName(Parcel in) { ... } 225 226 int status = in.readInt(); 227 228 this.mStatus = status; 229 230 if (!(mStatus == STATUS_SUCCESSFUL) 231 && !(mStatus == STATUS_ANDROID_FAILURE) 232 && !(mStatus == STATUS_USER_DOES_NOT_EXIST) 233 && !(mStatus == STATUS_FAILURE_SYSTEM_USER) 234 && !(mStatus == STATUS_FAILURE_CURRENT_USER)) { 235 throw new java.lang.IllegalArgumentException( 236 "status was " + mStatus + " but must be one of: " 237 + "STATUS_SUCCESSFUL(" + STATUS_SUCCESSFUL + "), " 238 + "STATUS_ANDROID_FAILURE(" + STATUS_ANDROID_FAILURE + "), " 239 + "STATUS_USER_DOES_NOT_EXIST(" + STATUS_USER_DOES_NOT_EXIST + "), " 240 + "STATUS_FAILURE_SYSTEM_USER(" + STATUS_FAILURE_SYSTEM_USER + "), " 241 + "STATUS_FAILURE_CURRENT_USER(" + STATUS_FAILURE_CURRENT_USER + ")"); 242 } 243 244 245 // onConstructed(); // You can define this method to get a callback 246 } 247 248 @DataClass.Generated.Member 249 public static final @android.annotation.NonNull Parcelable.Creator<UserStopResult> CREATOR 250 = new Parcelable.Creator<UserStopResult>() { 251 @Override 252 public UserStopResult[] newArray(int size) { 253 return new UserStopResult[size]; 254 } 255 256 @Override 257 public UserStopResult createFromParcel(@android.annotation.NonNull android.os.Parcel in) { 258 return new UserStopResult(in); 259 } 260 }; 261 262 @DataClass.Generated( 263 time = 1673057466203L, 264 codegenVersion = "1.0.23", 265 sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserStopResult.java", 266 inputSignatures = "public static final @android.car.user.UserStopResult.Status @android.car.annotation.AddedInOrBefore int STATUS_SUCCESSFUL\npublic static final @android.car.user.UserStopResult.Status @android.car.annotation.AddedInOrBefore int STATUS_ANDROID_FAILURE\npublic static final @android.car.user.UserStopResult.Status @android.car.annotation.AddedInOrBefore int STATUS_USER_DOES_NOT_EXIST\npublic static final @android.car.user.UserStopResult.Status @android.car.annotation.AddedInOrBefore int STATUS_FAILURE_SYSTEM_USER\npublic static final @android.car.user.UserStopResult.Status @android.car.annotation.AddedInOrBefore int STATUS_FAILURE_CURRENT_USER\nprivate final @android.car.user.UserStopResult.Status int mStatus\npublic static @android.car.annotation.AddedInOrBefore boolean isSuccess(int)\npublic @java.lang.Override @android.car.annotation.AddedInOrBefore boolean isSuccess()\nclass UserStopResult 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)") 267 @Deprecated __metadata()268 private void __metadata() {} 269 270 271 //@formatter:on 272 // End of generated code 273 274 } 275