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