blob: a79abeebe86f0a00c315f08a97f049933c811963 [file] [log] [blame]
felipealdfdf8512020-06-01 09:35:45 -07001/*
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
17package android.car.user;
18
19import android.annotation.IntDef;
20import android.annotation.Nullable;
21import android.content.pm.UserInfo;
22import android.os.Parcelable;
23
24import com.android.internal.util.DataClass;
25
26import java.lang.annotation.Retention;
27import 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)
38public final class UserCreationResult implements Parcelable {
39
40 /**
41 * {@link Status} called when user creation is successful for both HAL and Android.
42 *
43 * @hide
44 */
felipeal59a47742020-06-02 17:39:32 -070045 public static final int STATUS_SUCCESSFUL = CommonResults.STATUS_SUCCESSFUL;
felipealdfdf8512020-06-01 09:35:45 -070046
47 /**
48 * {@link Status} called when user creation failed on Android - HAL is not even called in this
49 * case.
50 *
51 * @hide
52 */
felipeal59a47742020-06-02 17:39:32 -070053 public static final int STATUS_ANDROID_FAILURE = CommonResults.STATUS_ANDROID_FAILURE;
felipealdfdf8512020-06-01 09:35:45 -070054
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 */
felipeal59a47742020-06-02 17:39:32 -070061 public static final int STATUS_HAL_FAILURE = CommonResults.STATUS_HAL_FAILURE;
felipealdfdf8512020-06-01 09:35:45 -070062
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 */
felipeal59a47742020-06-02 17:39:32 -070069 public static final int STATUS_HAL_INTERNAL_FAILURE = CommonResults.STATUS_HAL_INTERNAL_FAILURE;
felipealdfdf8512020-06-01 09:35:45 -070070
71 /**
72 * Gets the user switch result status.
73 *
74 * @return either {@link UserCreationResult#STATUS_SUCCESSFUL},
75 * {@link UserCreationResult#STATUS_ANDROID_FAILURE},
76 * {@link UserCreationResult#STATUS_HAL_FAILURE},
77 * or
78 * {@link UserCreationResult#STATUS_HAL_INTERNAL_FAILURE}
79 */
80 private final int mStatus;
81
82 /**
83 * Gets the created user.
84 */
85 @Nullable
86 private final UserInfo mUser;
87
88 /**
89 * Gets the error message sent by HAL, if any.
90 */
91 @Nullable
92 private final String mErrorMessage;
93
94 /**
95 * Checks if this result is successful.
96 */
97 public boolean isSuccess() {
98 return mStatus == STATUS_SUCCESSFUL;
99 }
100
101
102
103 // Code below generated by codegen v1.0.15.
104 //
105 // DO NOT MODIFY!
106 // CHECKSTYLE:OFF Generated code
107 //
108 // To regenerate run:
109 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserCreationResult.java
110 //
111 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
112 // Settings > Editor > Code Style > Formatter Control
113 //@formatter:off
114
115
116 /** @hide */
117 @IntDef(prefix = "STATUS_", value = {
118 STATUS_SUCCESSFUL,
119 STATUS_ANDROID_FAILURE,
120 STATUS_HAL_FAILURE,
121 STATUS_HAL_INTERNAL_FAILURE
122 })
123 @Retention(RetentionPolicy.SOURCE)
124 @DataClass.Generated.Member
125 public @interface Status {}
126
127 /** @hide */
128 @DataClass.Generated.Member
129 public static String statusToString(@Status int value) {
130 switch (value) {
131 case STATUS_SUCCESSFUL:
132 return "STATUS_SUCCESSFUL";
133 case STATUS_ANDROID_FAILURE:
134 return "STATUS_ANDROID_FAILURE";
135 case STATUS_HAL_FAILURE:
136 return "STATUS_HAL_FAILURE";
137 case STATUS_HAL_INTERNAL_FAILURE:
138 return "STATUS_HAL_INTERNAL_FAILURE";
139 default: return Integer.toHexString(value);
140 }
141 }
142
143 /**
144 * Creates a new UserCreationResult.
145 *
146 * @param status
147 * Gets the user switch result status.
148 *
149 * @return either {@link UserCreationResult#STATUS_SUCCESSFUL},
150 * {@link UserCreationResult#STATUS_ANDROID_FAILURE},
151 * {@link UserCreationResult#STATUS_HAL_FAILURE},
152 * or
153 * {@link UserCreationResult#STATUS_HAL_INTERNAL_FAILURE}
154 * @param user
155 * Gets the created user.
156 * @param errorMessage
157 * Gets the error message sent by HAL, if any.
158 * @hide
159 */
160 @DataClass.Generated.Member
161 public UserCreationResult(
162 int status,
163 @Nullable UserInfo user,
164 @Nullable String errorMessage) {
165 this.mStatus = status;
166 this.mUser = user;
167 this.mErrorMessage = errorMessage;
168
169 // onConstructed(); // You can define this method to get a callback
170 }
171
172 /**
173 * Gets the user switch result status.
174 *
175 * @return either {@link UserCreationResult#STATUS_SUCCESSFUL},
176 * {@link UserCreationResult#STATUS_ANDROID_FAILURE},
177 * {@link UserCreationResult#STATUS_HAL_FAILURE},
178 * or
179 * {@link UserCreationResult#STATUS_HAL_INTERNAL_FAILURE}
180 */
181 @DataClass.Generated.Member
182 public int getStatus() {
183 return mStatus;
184 }
185
186 /**
187 * Gets the created user.
188 */
189 @DataClass.Generated.Member
190 public @Nullable UserInfo getUser() {
191 return mUser;
192 }
193
194 /**
195 * Gets the error message sent by HAL, if any.
196 */
197 @DataClass.Generated.Member
198 public @Nullable String getErrorMessage() {
199 return mErrorMessage;
200 }
201
202 @Override
203 @DataClass.Generated.Member
204 public String toString() {
205 // You can override field toString logic by defining methods like:
206 // String fieldNameToString() { ... }
207
208 return "UserCreationResult { " +
209 "status = " + mStatus + ", " +
210 "user = " + mUser + ", " +
211 "errorMessage = " + mErrorMessage +
212 " }";
213 }
214
215 @Override
216 @DataClass.Generated.Member
217 public void writeToParcel(@android.annotation.NonNull android.os.Parcel dest, int flags) {
218 // You can override field parcelling by defining methods like:
219 // void parcelFieldName(Parcel dest, int flags) { ... }
220
221 byte flg = 0;
222 if (mUser != null) flg |= 0x2;
223 if (mErrorMessage != null) flg |= 0x4;
224 dest.writeByte(flg);
225 dest.writeInt(mStatus);
226 if (mUser != null) dest.writeTypedObject(mUser, flags);
227 if (mErrorMessage != null) dest.writeString(mErrorMessage);
228 }
229
230 @Override
231 @DataClass.Generated.Member
232 public int describeContents() { return 0; }
233
234 /** @hide */
235 @SuppressWarnings({"unchecked", "RedundantCast"})
236 @DataClass.Generated.Member
237 /* package-private */ UserCreationResult(@android.annotation.NonNull android.os.Parcel in) {
238 // You can override field unparcelling by defining methods like:
239 // static FieldType unparcelFieldName(Parcel in) { ... }
240
241 byte flg = in.readByte();
242 int status = in.readInt();
243 UserInfo user = (flg & 0x2) == 0 ? null : (UserInfo) in.readTypedObject(UserInfo.CREATOR);
244 String errorMessage = (flg & 0x4) == 0 ? null : in.readString();
245
246 this.mStatus = status;
247 this.mUser = user;
248 this.mErrorMessage = errorMessage;
249
250 // onConstructed(); // You can define this method to get a callback
251 }
252
253 @DataClass.Generated.Member
254 public static final @android.annotation.NonNull Parcelable.Creator<UserCreationResult> CREATOR
255 = new Parcelable.Creator<UserCreationResult>() {
256 @Override
257 public UserCreationResult[] newArray(int size) {
258 return new UserCreationResult[size];
259 }
260
261 @Override
262 public UserCreationResult createFromParcel(@android.annotation.NonNull android.os.Parcel in) {
263 return new UserCreationResult(in);
264 }
265 };
266
267 @DataClass.Generated(
268 time = 1591121994170L,
269 codegenVersion = "1.0.15",
270 sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserCreationResult.java",
271 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\nprivate final int mStatus\nprivate final @android.annotation.Nullable android.content.pm.UserInfo mUser\nprivate final @android.annotation.Nullable java.lang.String mErrorMessage\npublic boolean isSuccess()\nclass UserCreationResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstructor=true, genHiddenConstDefs=true)")
272 @Deprecated
273 private void __metadata() {}
274
275
276 //@formatter:on
277 // End of generated code
278
279}