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