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 {
37 
38     /**
39      * When user remove is successful.
40      *
41      * @hide
42      */
43     public static final int STATUS_SUCCESSFUL = CommonResults.STATUS_SUCCESSFUL;
44 
45     /**
46      * When user remove fails for android. Hal user is not removed.
47      *
48      * @hide
49      */
50     public static final int STATUS_ANDROID_FAILURE = CommonResults.STATUS_ANDROID_FAILURE;
51 
52     /**
53      * When remove user fails for unknown error.
54      *
55      * @hide
56      */
57     public static final int STATUS_HAL_INTERNAL_FAILURE = CommonResults.STATUS_HAL_INTERNAL_FAILURE;
58 
59      /**
60      * When user to remove is same as current user.
61      *
62      * @hide
63      */
64     public static final int STATUS_TARGET_USER_IS_CURRENT_USER =
65             CommonResults.LAST_COMMON_STATUS + 1;
66 
67     /**
68      * When user to remove doesn't exits.
69      *
70      * @hide
71      */
72     public static final int STATUS_USER_DOES_NOT_EXIST = CommonResults.LAST_COMMON_STATUS + 2;
73 
74     /**
75      * When user to remove is last admin user.
76      *
77      * @hide
78      */
79     public static final int STATUS_TARGET_USER_IS_LAST_ADMIN_USER =
80             CommonResults.LAST_COMMON_STATUS + 3;
81 
82     /**
83      * Gets the user switch result status.
84      *
85      * @return either {@link UserRemovalResult#STATUS_SUCCESSFUL},
86      *         {@link UserRemovalResult#STATUS_ANDROID_FAILURE},
87      *         {@link UserRemovalResult#STATUS_HAL_INTERNAL_FAILURE},
88      *         {@link UserRemovalResult#STATUS_TARGET_USER_IS_CURRENT_USER},
89      *         {@link UserRemovalResult#STATUS_USER_DOES_NOT_EXIST}, or
90      *         {@link UserRemovalResult#STATUS_TARGET_USER_IS_LAST_ADMIN_USER}.
91      */
92     private final @Status int mStatus;
93 
isSuccess()94     public boolean isSuccess() {
95         return mStatus == STATUS_SUCCESSFUL;
96     }
97 
98     // TODO(b/158195639): if you change any status constant, you need to manually assign its values
99     // (rather than using CommonResults) before running codegen to regenerate the class
100 
101 
102     // Code below generated by codegen v1.0.15.
103     //
104     // DO NOT MODIFY!
105     // CHECKSTYLE:OFF Generated code
106     //
107     // To regenerate run:
108     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserRemovalResult.java
109     //
110     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
111     //   Settings > Editor > Code Style > Formatter Control
112     //@formatter:off
113 
114 
115     /** @hide */
116     @IntDef(prefix = "STATUS_", value = {
117         STATUS_SUCCESSFUL,
118         STATUS_ANDROID_FAILURE,
119         STATUS_HAL_INTERNAL_FAILURE,
120         STATUS_TARGET_USER_IS_CURRENT_USER,
121         STATUS_USER_DOES_NOT_EXIST,
122         STATUS_TARGET_USER_IS_LAST_ADMIN_USER
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_HAL_INTERNAL_FAILURE:
137                     return "STATUS_HAL_INTERNAL_FAILURE";
138             case STATUS_TARGET_USER_IS_CURRENT_USER:
139                     return "STATUS_TARGET_USER_IS_CURRENT_USER";
140             case STATUS_USER_DOES_NOT_EXIST:
141                     return "STATUS_USER_DOES_NOT_EXIST";
142             case STATUS_TARGET_USER_IS_LAST_ADMIN_USER:
143                     return "STATUS_TARGET_USER_IS_LAST_ADMIN_USER";
144             default: return Integer.toHexString(value);
145         }
146     }
147 
148     /**
149      * Creates a new UserRemovalResult.
150      *
151      * @param status
152      *   Gets the user switch result status.
153      *
154      *   @return either {@link UserRemovalResult#STATUS_SUCCESSFUL},
155      *           {@link UserRemovalResult#STATUS_ANDROID_FAILURE},
156      *           {@link UserRemovalResult#STATUS_HAL_INTERNAL_FAILURE},
157      *           {@link UserRemovalResult#STATUS_TARGET_USER_IS_CURRENT_USER},
158      *           {@link UserRemovalResult#STATUS_USER_DOES_NOT_EXIST}, or
159      *           {@link UserRemovalResult#STATUS_TARGET_USER_IS_LAST_ADMIN_USER}.
160      * @hide
161      */
162     @DataClass.Generated.Member
UserRemovalResult( int status)163     public UserRemovalResult(
164             int status) {
165         this.mStatus = status;
166 
167         // onConstructed(); // You can define this method to get a callback
168     }
169 
170     /**
171      * Gets the user switch result status.
172      *
173      * @return either {@link UserRemovalResult#STATUS_SUCCESSFUL},
174      *         {@link UserRemovalResult#STATUS_ANDROID_FAILURE},
175      *         {@link UserRemovalResult#STATUS_HAL_INTERNAL_FAILURE},
176      *         {@link UserRemovalResult#STATUS_TARGET_USER_IS_CURRENT_USER},
177      *         {@link UserRemovalResult#STATUS_USER_DOES_NOT_EXIST}, or
178      *         {@link UserRemovalResult#STATUS_TARGET_USER_IS_LAST_ADMIN_USER}.
179      */
180     @DataClass.Generated.Member
getStatus()181     public int getStatus() {
182         return mStatus;
183     }
184 
185     @Override
186     @DataClass.Generated.Member
toString()187     public String toString() {
188         // You can override field toString logic by defining methods like:
189         // String fieldNameToString() { ... }
190 
191         return "UserRemovalResult { " +
192                 "status = " + mStatus +
193         " }";
194     }
195 
196     @Override
197     @DataClass.Generated.Member
writeToParcel(@ndroid.annotation.NonNull android.os.Parcel dest, int flags)198     public void writeToParcel(@android.annotation.NonNull android.os.Parcel dest, int flags) {
199         // You can override field parcelling by defining methods like:
200         // void parcelFieldName(Parcel dest, int flags) { ... }
201 
202         dest.writeInt(mStatus);
203     }
204 
205     @Override
206     @DataClass.Generated.Member
describeContents()207     public int describeContents() { return 0; }
208 
209     /** @hide */
210     @SuppressWarnings({"unchecked", "RedundantCast"})
211     @DataClass.Generated.Member
UserRemovalResult(@ndroid.annotation.NonNull android.os.Parcel in)212     /* package-private */ UserRemovalResult(@android.annotation.NonNull android.os.Parcel in) {
213         // You can override field unparcelling by defining methods like:
214         // static FieldType unparcelFieldName(Parcel in) { ... }
215 
216         int status = in.readInt();
217 
218         this.mStatus = status;
219 
220         // onConstructed(); // You can define this method to get a callback
221     }
222 
223     @DataClass.Generated.Member
224     public static final @android.annotation.NonNull Parcelable.Creator<UserRemovalResult> CREATOR
225             = new Parcelable.Creator<UserRemovalResult>() {
226         @Override
227         public UserRemovalResult[] newArray(int size) {
228             return new UserRemovalResult[size];
229         }
230 
231         @Override
232         public UserRemovalResult createFromParcel(@android.annotation.NonNull android.os.Parcel in) {
233             return new UserRemovalResult(in);
234         }
235     };
236 
237     @DataClass.Generated(
238             time = 1591259644931L,
239             codegenVersion = "1.0.15",
240             sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserRemovalResult.java",
241             inputSignatures = "public static final  int STATUS_SUCCESSFUL\npublic static final  int STATUS_ANDROID_FAILURE\npublic static final  int STATUS_HAL_INTERNAL_FAILURE\npublic static final  int STATUS_TARGET_USER_IS_CURRENT_USER\npublic static final  int STATUS_USER_DOES_NOT_EXIST\npublic static final  int STATUS_TARGET_USER_IS_LAST_ADMIN_USER\nprivate final  int mStatus\npublic  boolean isSuccess()\nclass UserRemovalResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstructor=true, genHiddenConstDefs=true)")
242     @Deprecated
__metadata()243     private void __metadata() {}
244 
245 
246     //@formatter:on
247     // End of generated code
248 
249 }
250