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