• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.hardware.property;
18 
19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
20 
21 import android.annotation.NonNull;
22 import android.car.annotation.AddedInOrBefore;
23 import android.car.hardware.CarPropertyValue;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
28 
29 /** @hide */
30 public class CarPropertyEvent implements Parcelable {
31     @AddedInOrBefore(majorVersion = 33)
32     public static final int PROPERTY_EVENT_PROPERTY_CHANGE = 0;
33     @AddedInOrBefore(majorVersion = 33)
34     public static final int PROPERTY_EVENT_ERROR = 1;
35     /**
36      * EventType of this message
37      */
38     private final int mEventType;
39 
40     /**
41      * ErrorCode of this message.
42      */
43     private final @CarPropertyManager.CarSetPropertyErrorCode int mErrorCode;
44     private final CarPropertyValue<?> mCarPropertyValue;
45 
46     // Use it as default value for error events.
47     private static final int ERROR_EVENT_VALUE = -1;
48 
49     /**
50      * @return EventType field
51      */
52     @AddedInOrBefore(majorVersion = 33)
getEventType()53     public int getEventType() {
54         return mEventType;
55     }
56 
57     /**
58      * Returns {@link CarPropertyValue} associated with this event.
59      */
60     @AddedInOrBefore(majorVersion = 33)
getCarPropertyValue()61     public CarPropertyValue<?> getCarPropertyValue() {
62         return mCarPropertyValue;
63     }
64 
65     @Override
66     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
67     @AddedInOrBefore(majorVersion = 33)
describeContents()68     public int describeContents() {
69         return 0;
70     }
71 
72     @Override
73     @AddedInOrBefore(majorVersion = 33)
writeToParcel(Parcel dest, int flags)74     public void writeToParcel(Parcel dest, int flags) {
75         dest.writeInt(mEventType);
76         dest.writeInt(mErrorCode);
77         dest.writeParcelable(mCarPropertyValue, flags);
78     }
79 
80     @AddedInOrBefore(majorVersion = 33)
81     public static final Parcelable.Creator<CarPropertyEvent> CREATOR =
82             new Parcelable.Creator<CarPropertyEvent>() {
83 
84         @Override
85         public CarPropertyEvent createFromParcel(Parcel in) {
86             return new CarPropertyEvent(in);
87         }
88 
89         @Override
90         public CarPropertyEvent[] newArray(int size) {
91             return new CarPropertyEvent[size];
92         }
93         };
94 
95     /**
96      * Constructor for {@link CarPropertyEvent}.
97      */
CarPropertyEvent(int eventType, @NonNull CarPropertyValue<?> carPropertyValue)98     public CarPropertyEvent(int eventType, @NonNull CarPropertyValue<?> carPropertyValue) {
99         mEventType  = eventType;
100         mErrorCode = CarPropertyManager.CAR_SET_PROPERTY_ERROR_CODE_UNKNOWN;
101         mCarPropertyValue = carPropertyValue;
102     }
103 
104     /**
105      * Constructor for {@link CarPropertyEvent} with an error code.
106      */
CarPropertyEvent(int eventType, @NonNull CarPropertyValue<?> carPropertyValue, @CarPropertyManager.CarSetPropertyErrorCode int errorCode)107     public CarPropertyEvent(int eventType, @NonNull CarPropertyValue<?> carPropertyValue,
108             @CarPropertyManager.CarSetPropertyErrorCode int errorCode) {
109         mEventType  = eventType;
110         mErrorCode = errorCode;
111         mCarPropertyValue = carPropertyValue;
112     }
113 
114 
115     /**
116      * Constructor for {@link CarPropertyEvent} when it is an error event.
117      *
118      * The status of {@link CarPropertyValue} should be {@link CarPropertyValue#STATUS_ERROR}.
119      * In {@link CarPropertyManager}, the value of {@link CarPropertyValue} will be dropped.
120      */
121     @AddedInOrBefore(majorVersion = 33)
createErrorEventWithErrorCode(int propertyId, int areaId, @CarPropertyManager.CarSetPropertyErrorCode int errorCode)122     public static CarPropertyEvent createErrorEventWithErrorCode(int propertyId, int areaId,
123             @CarPropertyManager.CarSetPropertyErrorCode int errorCode) {
124         CarPropertyValue<Integer> valueWithErrorCode = new CarPropertyValue<>(propertyId, areaId,
125                 CarPropertyValue.STATUS_ERROR, 0, ERROR_EVENT_VALUE);
126         CarPropertyEvent event = new CarPropertyEvent(PROPERTY_EVENT_ERROR, valueWithErrorCode,
127                 errorCode);
128         return event;
129     }
130 
131     @AddedInOrBefore(majorVersion = 33)
getErrorCode()132     public @CarPropertyManager.CarSetPropertyErrorCode int getErrorCode() {
133         return mErrorCode;
134     }
135 
CarPropertyEvent(Parcel in)136     private CarPropertyEvent(Parcel in) {
137         mEventType  = in.readInt();
138         mErrorCode = in.readInt();
139         mCarPropertyValue = in.readParcelable(CarPropertyValue.class.getClassLoader());
140     }
141 
142     @Override
143     @AddedInOrBefore(majorVersion = 33)
toString()144     public String toString() {
145         return "CarPropertyEvent{"
146                 + "mEventType=" + mEventType
147                 + ", mErrorCode=" + mErrorCode
148                 + ", mCarPropertyValue=" + mCarPropertyValue
149                 + '}';
150     }
151 }
152