1 /*
2  * Copyright (C) 2022 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 static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
20 
21 import android.annotation.Nullable;
22 import android.car.hardware.CarPropertyValue;
23 import android.car.hardware.property.CarPropertyManager.GetPropertyRequest;
24 import android.car.hardware.property.CarPropertyManager.SetPropertyRequest;
25 import android.os.Parcelable;
26 
27 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
28 import com.android.car.internal.util.DataClass;
29 
30 /**
31  * A request for {@link CarPropertyService.getPropertiesAsync} or
32  * {@link CarPropertyService.setPropertiesAsync}
33  *
34  * @hide
35  */
36 @DataClass(genConstructor = false)
37 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
38 public final class AsyncPropertyServiceRequest implements Parcelable {
39     private final int mRequestId;
40     private final int mPropertyId;
41     private final int mAreaId;
42     // The property value to set. Ignored for get request.
43     @Nullable
44     private final CarPropertyValue mCarPropertyValue;
45     // The update rate in HZ for listening to new property update event for async set. Ignored for
46     // get request.
47     private float mUpdateRateHz;
48     // Whether to listen for property update event before calling success callback for async set.
49     // Ignored for get request.
50     private boolean mWaitForPropertyUpdate;
51 
52     /**
53      * Creates an async get request.
54      */
newGetAsyncRequest( GetPropertyRequest getPropertyRequest)55     public static AsyncPropertyServiceRequest newGetAsyncRequest(
56             GetPropertyRequest getPropertyRequest) {
57         return new AsyncPropertyServiceRequest(getPropertyRequest.getRequestId(),
58                 getPropertyRequest.getPropertyId(), getPropertyRequest.getAreaId());
59     }
60 
61     /**
62      * Creates an async set request.
63      */
newSetAsyncRequest( SetPropertyRequest setPropertyRequest)64     public static AsyncPropertyServiceRequest newSetAsyncRequest(
65             SetPropertyRequest setPropertyRequest) {
66         int propertyId = setPropertyRequest.getPropertyId();
67         int areaId = setPropertyRequest.getAreaId();
68         AsyncPropertyServiceRequest request = new AsyncPropertyServiceRequest(
69                 setPropertyRequest.getRequestId(), propertyId, areaId,
70                 new CarPropertyValue(propertyId, areaId, setPropertyRequest.getValue()));
71         request.setUpdateRateHz(setPropertyRequest.getUpdateRateHz());
72         request.setWaitForPropertyUpdate(setPropertyRequest.isWaitForPropertyUpdate());
73         return request;
74     }
75 
76     /**
77      * Creates an async get request, for test only.
78      */
AsyncPropertyServiceRequest(int requestId, int propertyId, int areaId)79     public AsyncPropertyServiceRequest(int requestId, int propertyId, int areaId) {
80         this(requestId, propertyId, areaId, /* carPropertyValue= */ null);
81     }
82 
83     /**
84      * Creates an async set request, for test only.
85      */
AsyncPropertyServiceRequest(int requestId, int propertyId, int areaId, @Nullable CarPropertyValue carPropertyValue)86     public AsyncPropertyServiceRequest(int requestId, int propertyId, int areaId,
87             @Nullable CarPropertyValue carPropertyValue) {
88         mRequestId = requestId;
89         mPropertyId = propertyId;
90         mAreaId = areaId;
91         mCarPropertyValue = carPropertyValue;
92         mWaitForPropertyUpdate = true;
93     }
94 
95     /**
96      * Sets the update rate in HZ for listening to new property update event.
97      */
setUpdateRateHz(float updateRateHz)98     public void setUpdateRateHz(float updateRateHz) {
99         mUpdateRateHz = updateRateHz;
100     }
101 
102     /**
103      * Sets whether to wait for property update before calling async set's success callback.
104      */
setWaitForPropertyUpdate(boolean waitForPropertyUpdate)105     public void setWaitForPropertyUpdate(boolean waitForPropertyUpdate) {
106         mWaitForPropertyUpdate = waitForPropertyUpdate;
107     }
108 
109 
110 
111     // Code below generated by codegen v1.0.23.
112     //
113     // DO NOT MODIFY!
114     // CHECKSTYLE:OFF Generated code
115     //
116     // To regenerate run:
117     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/com/android/car/internal/property/AsyncPropertyServiceRequest.java
118     //
119     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
120     //   Settings > Editor > Code Style > Formatter Control
121     //@formatter:off
122 
123     @DataClass.Generated.Member
getRequestId()124     public int getRequestId() {
125         return mRequestId;
126     }
127 
128     @DataClass.Generated.Member
getPropertyId()129     public int getPropertyId() {
130         return mPropertyId;
131     }
132 
133     @DataClass.Generated.Member
getAreaId()134     public int getAreaId() {
135         return mAreaId;
136     }
137 
138     @DataClass.Generated.Member
getCarPropertyValue()139     public @Nullable CarPropertyValue getCarPropertyValue() {
140         return mCarPropertyValue;
141     }
142 
143     @DataClass.Generated.Member
getUpdateRateHz()144     public float getUpdateRateHz() {
145         return mUpdateRateHz;
146     }
147 
148     @DataClass.Generated.Member
isWaitForPropertyUpdate()149     public boolean isWaitForPropertyUpdate() {
150         return mWaitForPropertyUpdate;
151     }
152 
153     @Override
154     @DataClass.Generated.Member
writeToParcel(@ndroid.annotation.NonNull android.os.Parcel dest, int flags)155     public void writeToParcel(@android.annotation.NonNull android.os.Parcel dest, int flags) {
156         // You can override field parcelling by defining methods like:
157         // void parcelFieldName(Parcel dest, int flags) { ... }
158 
159         byte flg = 0;
160         if (mWaitForPropertyUpdate) flg |= 0x20;
161         if (mCarPropertyValue != null) flg |= 0x8;
162         dest.writeByte(flg);
163         dest.writeInt(mRequestId);
164         dest.writeInt(mPropertyId);
165         dest.writeInt(mAreaId);
166         if (mCarPropertyValue != null) dest.writeTypedObject(mCarPropertyValue, flags);
167         dest.writeFloat(mUpdateRateHz);
168     }
169 
170     @Override
171     @DataClass.Generated.Member
describeContents()172     public int describeContents() { return 0; }
173 
174     /** @hide */
175     @SuppressWarnings({"unchecked", "RedundantCast"})
176     @DataClass.Generated.Member
AsyncPropertyServiceRequest(@ndroid.annotation.NonNull android.os.Parcel in)177     /* package-private */ AsyncPropertyServiceRequest(@android.annotation.NonNull android.os.Parcel in) {
178         // You can override field unparcelling by defining methods like:
179         // static FieldType unparcelFieldName(Parcel in) { ... }
180 
181         byte flg = in.readByte();
182         boolean waitForPropertyUpdate = (flg & 0x20) != 0;
183         int requestId = in.readInt();
184         int propertyId = in.readInt();
185         int areaId = in.readInt();
186         CarPropertyValue carPropertyValue = (flg & 0x8) == 0 ? null : (CarPropertyValue) in.readTypedObject(CarPropertyValue.CREATOR);
187         float updateRateHz = in.readFloat();
188 
189         this.mRequestId = requestId;
190         this.mPropertyId = propertyId;
191         this.mAreaId = areaId;
192         this.mCarPropertyValue = carPropertyValue;
193         this.mUpdateRateHz = updateRateHz;
194         this.mWaitForPropertyUpdate = waitForPropertyUpdate;
195 
196         // onConstructed(); // You can define this method to get a callback
197     }
198 
199     @DataClass.Generated.Member
200     public static final @android.annotation.NonNull Parcelable.Creator<AsyncPropertyServiceRequest> CREATOR
201             = new Parcelable.Creator<AsyncPropertyServiceRequest>() {
202         @Override
203         public AsyncPropertyServiceRequest[] newArray(int size) {
204             return new AsyncPropertyServiceRequest[size];
205         }
206 
207         @Override
208         public AsyncPropertyServiceRequest createFromParcel(@android.annotation.NonNull android.os.Parcel in) {
209             return new AsyncPropertyServiceRequest(in);
210         }
211     };
212 
213     @DataClass.Generated(
214             time = 1678739854323L,
215             codegenVersion = "1.0.23",
216             sourceFile = "packages/services/Car/car-lib/src/com/android/car/internal/property/AsyncPropertyServiceRequest.java",
217             inputSignatures = "private final  int mRequestId\nprivate final  int mPropertyId\nprivate final  int mAreaId\nprivate final @android.annotation.Nullable android.car.hardware.CarPropertyValue mCarPropertyValue\nprivate  float mUpdateRateHz\nprivate  boolean mWaitForPropertyUpdate\npublic static  com.android.car.internal.property.AsyncPropertyServiceRequest newGetAsyncRequest(android.car.hardware.Property.GetPropertyRequest)\npublic static  com.android.car.internal.property.AsyncPropertyServiceRequest newSetAsyncRequest(setPropertyRequest)\npublic  void setUpdateRateHz(float)\npublic  void setWaitForPropertyUpdate(boolean)\nclass AsyncPropertyServiceRequest extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genConstructor=false)")
218     @Deprecated
__metadata()219     private void __metadata() {}
220 
221 
222     //@formatter:on
223     // End of generated code
224 
225 }
226