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.NonNull;
20 import android.annotation.Nullable;
21 import android.car.user.CarUserManager.UserIdentificationAssociationValue;
22 import android.os.Parcelable;
23 
24 import com.android.internal.util.ArrayUtils;
25 import com.android.internal.util.DataClass;
26 import com.android.internal.util.Preconditions;
27 
28 import java.util.Objects;
29 
30 /**
31  * Results of a {@link CarUserManager#getUserIdentificationAssociation(int[]) request.
32  *
33  * @hide
34  */
35 @DataClass(
36         genToString = true,
37         genHiddenConstructor = false,
38         genHiddenConstDefs = true)
39 public final class UserIdentificationAssociationResponse implements Parcelable {
40 
41     /**
42      * Whether the request was successful.
43      *
44      * <p>A successful option has non-null {@link #getValues()}
45      */
46     private final boolean mSuccess;
47 
48     /**
49      * Gets the error message returned by the HAL.
50      */
51     @Nullable
52     private final String mErrorMessage;
53 
54     /**
55      * Gets the list of values associated with the request.
56      *
57      * <p><b>NOTE: </b>It's only set when the response is {@link #isSuccess() successful}.
58      *
59      * <p>For {@link CarUserManager#getUserIdentificationAssociation(int...)}, the values are
60      * defined on
61      * {@link android.hardware.automotive.vehicle.V2_0.UserIdentificationAssociationValue}.
62      *
63      * <p>For {@link CarUserManager#setUserIdentificationAssociation(int...)}, the values are
64      * defined on
65      * {@link android.hardware.automotive.vehicle.V2_0.UserIdentificationAssociationSetValue}.
66      */
67     @Nullable
68     private final int[] mValues;
69 
UserIdentificationAssociationResponse( boolean success, @Nullable String errorMessage, @UserIdentificationAssociationValue int[] values)70     private UserIdentificationAssociationResponse(
71             boolean success,
72             @Nullable String errorMessage,
73             @UserIdentificationAssociationValue int[] values) {
74         this.mSuccess = success;
75         this.mErrorMessage = errorMessage;
76         this.mValues = values;
77     }
78 
79     /**
80      * Factory method for failed UserIdentificationAssociationResponse requests.
81      */
82     @NonNull
forFailure()83     public static UserIdentificationAssociationResponse forFailure() {
84         return forFailure(/* errorMessage= */ null);
85     }
86 
87     /**
88      * Factory method for failed UserIdentificationAssociationResponse requests.
89      */
90     @NonNull
forFailure(@ullable String errorMessage)91     public static UserIdentificationAssociationResponse forFailure(@Nullable String errorMessage) {
92         return new UserIdentificationAssociationResponse(/* success= */ false,
93                 errorMessage, /* values= */ null);
94     }
95 
96     /**
97      * Factory method for successful UserIdentificationAssociationResponse requests.
98      */
99     @NonNull
forSuccess( @serIdentificationAssociationValue int[] values)100     public static UserIdentificationAssociationResponse forSuccess(
101             @UserIdentificationAssociationValue int[] values) {
102         Preconditions.checkArgument(!ArrayUtils.isEmpty(values), "must have at least one value");
103         return new UserIdentificationAssociationResponse(/* success= */ true,
104                 /* errorMessage= */ null, Objects.requireNonNull(values));
105     }
106 
107     /**
108      * Factory method for successful UserIdentificationAssociationResponse requests.
109      */
110     @NonNull
forSuccess( @serIdentificationAssociationValue int[] values, @Nullable String errorMessage)111     public static UserIdentificationAssociationResponse forSuccess(
112             @UserIdentificationAssociationValue int[] values, @Nullable String errorMessage) {
113         Preconditions.checkArgument(!ArrayUtils.isEmpty(values), "must have at least one value");
114         return new UserIdentificationAssociationResponse(/* success= */ true, errorMessage,
115                 Objects.requireNonNull(values));
116     }
117 
118 
119 
120 
121 
122     // Code below generated by codegen v1.0.20.
123     //
124     // DO NOT MODIFY!
125     // CHECKSTYLE:OFF Generated code
126     //
127     // To regenerate run:
128     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserIdentificationAssociationResponse.java
129     //
130     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
131     //   Settings > Editor > Code Style > Formatter Control
132     //@formatter:off
133 
134 
135     /**
136      * Whether the request was successful.
137      *
138      * <p>A successful option has non-null {@link #getValues()}
139      */
140     @DataClass.Generated.Member
isSuccess()141     public boolean isSuccess() {
142         return mSuccess;
143     }
144 
145     /**
146      * Gets the error message returned by the HAL.
147      */
148     @DataClass.Generated.Member
getErrorMessage()149     public @Nullable String getErrorMessage() {
150         return mErrorMessage;
151     }
152 
153     /**
154      * Gets the list of values associated with the request.
155      *
156      * <p><b>NOTE: </b>It's only set when the response is {@link #isSuccess() successful}.
157      *
158      * <p>For {@link CarUserManager#getUserIdentificationAssociation(int...)}, the values are
159      * defined on
160      * {@link android.hardware.automotive.vehicle.V2_0.UserIdentificationAssociationValue}.
161      *
162      * <p>For {@link CarUserManager#setUserIdentificationAssociation(int...)}, the values are
163      * defined on
164      * {@link android.hardware.automotive.vehicle.V2_0.UserIdentificationAssociationSetValue}.
165      */
166     @DataClass.Generated.Member
getValues()167     public @Nullable int[] getValues() {
168         return mValues;
169     }
170 
171     @Override
172     @DataClass.Generated.Member
toString()173     public String toString() {
174         // You can override field toString logic by defining methods like:
175         // String fieldNameToString() { ... }
176 
177         return "UserIdentificationAssociationResponse { " +
178                 "success = " + mSuccess + ", " +
179                 "errorMessage = " + mErrorMessage + ", " +
180                 "values = " + java.util.Arrays.toString(mValues) +
181         " }";
182     }
183 
184     @Override
185     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)186     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
187         // You can override field parcelling by defining methods like:
188         // void parcelFieldName(Parcel dest, int flags) { ... }
189 
190         byte flg = 0;
191         if (mSuccess) flg |= 0x1;
192         if (mErrorMessage != null) flg |= 0x2;
193         if (mValues != null) flg |= 0x4;
194         dest.writeByte(flg);
195         if (mErrorMessage != null) dest.writeString(mErrorMessage);
196         if (mValues != null) dest.writeIntArray(mValues);
197     }
198 
199     @Override
200     @DataClass.Generated.Member
describeContents()201     public int describeContents() { return 0; }
202 
203     /** @hide */
204     @SuppressWarnings({"unchecked", "RedundantCast"})
205     @DataClass.Generated.Member
UserIdentificationAssociationResponse(@onNull android.os.Parcel in)206     /* package-private */ UserIdentificationAssociationResponse(@NonNull android.os.Parcel in) {
207         // You can override field unparcelling by defining methods like:
208         // static FieldType unparcelFieldName(Parcel in) { ... }
209 
210         byte flg = in.readByte();
211         boolean success = (flg & 0x1) != 0;
212         String errorMessage = (flg & 0x2) == 0 ? null : in.readString();
213         int[] values = (flg & 0x4) == 0 ? null : in.createIntArray();
214 
215         this.mSuccess = success;
216         this.mErrorMessage = errorMessage;
217         this.mValues = values;
218 
219         // onConstructed(); // You can define this method to get a callback
220     }
221 
222     @DataClass.Generated.Member
223     public static final @NonNull Parcelable.Creator<UserIdentificationAssociationResponse> CREATOR
224             = new Parcelable.Creator<UserIdentificationAssociationResponse>() {
225         @Override
226         public UserIdentificationAssociationResponse[] newArray(int size) {
227             return new UserIdentificationAssociationResponse[size];
228         }
229 
230         @Override
231         public UserIdentificationAssociationResponse createFromParcel(@NonNull android.os.Parcel in) {
232             return new UserIdentificationAssociationResponse(in);
233         }
234     };
235 
236     @DataClass.Generated(
237             time = 1604638584791L,
238             codegenVersion = "1.0.20",
239             sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserIdentificationAssociationResponse.java",
240             inputSignatures = "private final  boolean mSuccess\nprivate final @android.annotation.Nullable java.lang.String mErrorMessage\nprivate final @android.annotation.Nullable int[] mValues\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forFailure()\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forFailure(java.lang.String)\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forSuccess(int[])\npublic static @android.annotation.NonNull android.car.user.UserIdentificationAssociationResponse forSuccess(int[],java.lang.String)\nclass UserIdentificationAssociationResponse extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstructor=false, genHiddenConstDefs=true)")
241     @Deprecated
__metadata()242     private void __metadata() {}
243 
244 
245     //@formatter:on
246     // End of generated code
247 
248 }
249