1 /*
2  * Copyright (C) 2023 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 com.android.car.internal.property;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.car.hardware.CarPropertyValue;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import com.android.car.internal.util.AnnotationValidations;
26 import com.android.car.internal.util.DataClass;
27 
28 /**
29  * A request for {@link com.android.car.CarPropertyService#getPropertiesAsync}
30  *
31  * @hide
32  */
33 @DataClass(genConstructor = false)
34 public final class GetSetValueResult implements Parcelable {
35     private final int mRequestId;
36     // Result for async getProperty, ignored for setProperty.
37     @Nullable
38     private final CarPropertyValue mCarPropertyValue;
39     // Only useful for setProperty, ignored for getProperty.
40     private final long mUpdateTimestampNanos;
41     @NonNull
42     private final CarPropertyErrorCodes mCarPropertyErrorCodes;
43 
GetSetValueResult(int requestId, @Nullable CarPropertyValue carPropertyValue, @NonNull CarPropertyErrorCodes carPropertyErrorCodes, long updateTimestampNanos)44     private GetSetValueResult(int requestId, @Nullable CarPropertyValue carPropertyValue,
45             @NonNull CarPropertyErrorCodes carPropertyErrorCodes, long updateTimestampNanos) {
46         mRequestId = requestId;
47         mCarPropertyValue = carPropertyValue;
48         mUpdateTimestampNanos = updateTimestampNanos;
49         mCarPropertyErrorCodes = carPropertyErrorCodes;
50     }
51 
52     /**
53      * Creates an async get property result.
54      */
newGetValueResult(int requestId, CarPropertyValue carPropertyValue)55     public static GetSetValueResult newGetValueResult(int requestId,
56             CarPropertyValue carPropertyValue) {
57         CarPropertyErrorCodes carPropertyErrorCodes = CarPropertyErrorCodes.STATUS_OK_NO_ERROR;
58         return new GetSetValueResult(requestId, carPropertyValue,
59                 carPropertyErrorCodes, /* updateTimestampNanos= */ 0);
60     }
61 
62     /**
63      * Creates an async error property result.
64      */
newErrorResult(int requestId, @NonNull CarPropertyErrorCodes carPropertyErrorCodes)65     public static GetSetValueResult newErrorResult(int requestId,
66             @NonNull CarPropertyErrorCodes carPropertyErrorCodes) {
67         return new GetSetValueResult(requestId, /* carPropertyValue= */ null,
68                 carPropertyErrorCodes, /* updateTimestampNanos= */ 0);
69     }
70 
71     /**
72      * Creates an async set property result.
73      */
newSetValueResult(int requestId, long updateTimestampNanos)74     public static GetSetValueResult newSetValueResult(int requestId,
75             long updateTimestampNanos) {
76         CarPropertyErrorCodes carPropertyErrorCodes = CarPropertyErrorCodes.STATUS_OK_NO_ERROR;
77         return new GetSetValueResult(requestId, /* carPropertyValue= */ null,
78                 carPropertyErrorCodes, updateTimestampNanos);
79     }
80 
81     /**
82      * Creates an async error set property result.
83      */
newErrorSetValueResult(int requestId, @NonNull CarPropertyErrorCodes carPropertyErrorCodes)84     public static GetSetValueResult newErrorSetValueResult(int requestId,
85             @NonNull CarPropertyErrorCodes carPropertyErrorCodes) {
86         return new GetSetValueResult(requestId, /* carPropertyValue= */ null,
87                 carPropertyErrorCodes, /* updateTimestampNanos= */ 0);
88     }
89 
90 
91 
92     // Code below generated by codegen v1.0.23.
93     //
94     // DO NOT MODIFY!
95     // CHECKSTYLE:OFF Generated code
96     //
97     // To regenerate run:
98     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/com/android/car/internal/property/GetSetValueResult.java
99     //
100     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
101     //   Settings > Editor > Code Style > Formatter Control
102     //@formatter:off
103 
104 
105     @DataClass.Generated.Member
getRequestId()106     public int getRequestId() {
107         return mRequestId;
108     }
109 
110     @DataClass.Generated.Member
getCarPropertyValue()111     public @Nullable CarPropertyValue getCarPropertyValue() {
112         return mCarPropertyValue;
113     }
114 
115     @DataClass.Generated.Member
getUpdateTimestampNanos()116     public long getUpdateTimestampNanos() {
117         return mUpdateTimestampNanos;
118     }
119 
120     @DataClass.Generated.Member
getCarPropertyErrorCodes()121     public @NonNull CarPropertyErrorCodes getCarPropertyErrorCodes() {
122         return mCarPropertyErrorCodes;
123     }
124 
125     @Override
126     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)127     public void writeToParcel(@NonNull Parcel dest, int flags) {
128         // You can override field parcelling by defining methods like:
129         // void parcelFieldName(Parcel dest, int flags) { ... }
130 
131         byte flg = 0;
132         if (mCarPropertyValue != null) flg |= 0x2;
133         dest.writeByte(flg);
134         dest.writeInt(mRequestId);
135         if (mCarPropertyValue != null) dest.writeTypedObject(mCarPropertyValue, flags);
136         dest.writeLong(mUpdateTimestampNanos);
137         dest.writeTypedObject(mCarPropertyErrorCodes, flags);
138     }
139 
140     @Override
141     @DataClass.Generated.Member
describeContents()142     public int describeContents() { return 0; }
143 
144     /** @hide */
145     @SuppressWarnings({"unchecked", "RedundantCast"})
146     @DataClass.Generated.Member
GetSetValueResult(@onNull Parcel in)147     /* package-private */ GetSetValueResult(@NonNull Parcel in) {
148         // You can override field unparcelling by defining methods like:
149         // static FieldType unparcelFieldName(Parcel in) { ... }
150 
151         byte flg = in.readByte();
152         int requestId = in.readInt();
153         CarPropertyValue carPropertyValue = (flg & 0x2) == 0 ? null : (CarPropertyValue) in.readTypedObject(CarPropertyValue.CREATOR);
154         long updateTimestampNanos = in.readLong();
155         CarPropertyErrorCodes carPropertyErrorCodes = (CarPropertyErrorCodes) in.readTypedObject(CarPropertyErrorCodes.CREATOR);
156 
157         this.mRequestId = requestId;
158         this.mCarPropertyValue = carPropertyValue;
159         this.mUpdateTimestampNanos = updateTimestampNanos;
160         this.mCarPropertyErrorCodes = carPropertyErrorCodes;
161         AnnotationValidations.validate(
162                 NonNull.class, null, mCarPropertyErrorCodes);
163 
164         // onConstructed(); // You can define this method to get a callback
165     }
166 
167     @DataClass.Generated.Member
168     public static final @NonNull Parcelable.Creator<GetSetValueResult> CREATOR
169             = new Parcelable.Creator<GetSetValueResult>() {
170         @Override
171         public GetSetValueResult[] newArray(int size) {
172             return new GetSetValueResult[size];
173         }
174 
175         @Override
176         public GetSetValueResult createFromParcel(@NonNull Parcel in) {
177             return new GetSetValueResult(in);
178         }
179     };
180 
181     @DataClass.Generated(
182             time = 1707958964110L,
183             codegenVersion = "1.0.23",
184             sourceFile = "packages/services/Car/car-lib/src/com/android/car/internal/property/GetSetValueResult.java",
185             inputSignatures = "private final  int mRequestId\nprivate final @android.annotation.Nullable android.car.hardware.CarPropertyValue mCarPropertyValue\nprivate final  long mUpdateTimestampNanos\nprivate final @android.annotation.NonNull com.android.car.internal.property.CarPropertyErrorCodes mCarPropertyErrorCodes\npublic static  com.android.car.internal.property.GetSetValueResult newGetValueResult(int,android.car.hardware.CarPropertyValue)\npublic static  com.android.car.internal.property.GetSetValueResult newErrorResult(int,com.android.car.internal.property.CarPropertyErrorCodes)\npublic static  com.android.car.internal.property.GetSetValueResult newSetValueResult(int,long)\npublic static  com.android.car.internal.property.GetSetValueResult newErrorSetValueResult(int,com.android.car.internal.property.CarPropertyErrorCodes)\nclass GetSetValueResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genConstructor=false)")
186     @Deprecated
__metadata()187     private void __metadata() {}
188 
189 
190     //@formatter:on
191     // End of generated code
192 
193 }
194