• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.car.hardware.property;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.car.annotation.ApiRequirements;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.util.Collections;
27 import java.util.List;
28 
29 /**
30  * Represents area ID specific configuration information for a vehicle property.
31  *
32  * @param <T> matches the type for the {@link android.car.hardware.CarPropertyConfig}.
33  */
34 public final class AreaIdConfig<T> implements Parcelable {
35     @ApiRequirements(
36             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
37             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
38     @NonNull
39     public static final Parcelable.Creator<AreaIdConfig<Object>> CREATOR = getCreator();
40 
41     private final int mAreaId;
42     @Nullable private final T mMinValue;
43     @Nullable private final T mMaxValue;
44     private final List<T> mSupportedEnumValues;
45 
AreaIdConfig( int areaId, @Nullable T minValue, @Nullable T maxValue, List<T> supportedEnumValues)46     private AreaIdConfig(
47             int areaId, @Nullable T minValue, @Nullable T maxValue, List<T> supportedEnumValues) {
48         mAreaId = areaId;
49         mMinValue = minValue;
50         mMaxValue = maxValue;
51         mSupportedEnumValues = supportedEnumValues;
52     }
53 
54     @SuppressWarnings("unchecked")
AreaIdConfig(Parcel in)55     private AreaIdConfig(Parcel in) {
56         mAreaId = in.readInt();
57         mMinValue = (T) in.readValue(getClass().getClassLoader());
58         mMaxValue = (T) in.readValue(getClass().getClassLoader());
59         mSupportedEnumValues = in.readArrayList(getClass().getClassLoader());
60     }
61 
getCreator()62     private static <E> Parcelable.Creator<AreaIdConfig<E>> getCreator() {
63         return new Creator<AreaIdConfig<E>>() {
64             @Override
65             public AreaIdConfig<E> createFromParcel(Parcel source) {
66                 return new AreaIdConfig<>(source);
67             }
68 
69             @Override
70             @SuppressWarnings("unchecked")
71             public AreaIdConfig<E>[] newArray(int size) {
72                 AreaIdConfig<E>[] areaIdConfigs = new AreaIdConfig[size];
73                 for (int i = 0; i < size; i++) {
74                     areaIdConfigs[i] = null;
75                 }
76                 return areaIdConfigs;
77             }
78         };
79     }
80 
81     /**
82      * @return area ID for this configuration.
83      */
84     @ApiRequirements(
85             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
86             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
87     public int getAreaId() {
88         return mAreaId;
89     }
90 
91     /**
92      * @return minimum value supported for the {@link #getAreaId()}. Will return {@code null} if no
93      *     minimum value supported.
94      */
95     @Nullable
96     @ApiRequirements(
97             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
98             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
99     public T getMinValue() {
100         return mMinValue;
101     }
102 
103     /**
104      * @return maximum value supported for the {@link #getAreaId()}. Will return {@code null} if no
105      *     maximum value supported.
106      */
107     @Nullable
108     @ApiRequirements(
109             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
110             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
111     public T getMaxValue() {
112         return mMaxValue;
113     }
114 
115     /**
116      * Returns the supported enum values for the {@link #getAreaId()}. If list is empty, the
117      * property does not support an enum.
118      */
119     @NonNull
120     @ApiRequirements(
121             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
122             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
123     public List<T> getSupportedEnumValues() {
124         return Collections.unmodifiableList(mSupportedEnumValues);
125     }
126 
127     @Override
128     @ApiRequirements(
129             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
130             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
131     public int describeContents() {
132         return 0;
133     }
134 
135     @Override
136     @ApiRequirements(
137             minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
138             minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
139     public void writeToParcel(@NonNull Parcel dest, int flags) {
140         dest.writeInt(mAreaId);
141         dest.writeValue(mMinValue);
142         dest.writeValue(mMaxValue);
143         dest.writeList(mSupportedEnumValues);
144     }
145 
146     @Override
147     public String toString() {
148         StringBuilder sb = new StringBuilder();
149         sb.append("AreaIdConfig{").append("mAreaId=").append(mAreaId);
150         if (mMinValue != null) {
151             sb.append(", mMinValue=").append(mMinValue);
152         }
153         if (mMaxValue != null) {
154             sb.append(", mMaxValue=").append(mMaxValue);
155         }
156         if (!mSupportedEnumValues.isEmpty()) {
157             sb.append(", mSupportedEnumValues=").append(mSupportedEnumValues);
158         }
159         return sb.append("}").toString();
160     }
161 
162     /**
163      * @param <T> matches the type for the {@link android.car.hardware.CarPropertyConfig}.
164      * @hide
165      */
166     @SystemApi
167     public static final class Builder<T> {
168         private final int mAreaId;
169         private T mMinValue = null;
170         private T mMaxValue = null;
171         private List<T> mSupportedEnumValues = Collections.EMPTY_LIST;
172 
173         public Builder(int areaId) {
174             mAreaId = areaId;
175         }
176 
177         /** Set the min value for the {@link AreaIdConfig}. */
178         @NonNull
179         @ApiRequirements(
180                 minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
181                 minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
182         public Builder<T> setMinValue(T minValue) {
183             mMinValue = minValue;
184             return this;
185         }
186 
187         /** Set the max value for the {@link AreaIdConfig}. */
188         @NonNull
189         @ApiRequirements(
190                 minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
191                 minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
192         public Builder<T> setMaxValue(T maxValue) {
193             mMaxValue = maxValue;
194             return this;
195         }
196 
197         /** Set the supported enum values for the {@link AreaIdConfig}. */
198         @NonNull
199         @ApiRequirements(
200                 minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
201                 minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
202         public Builder<T> setSupportedEnumValues(@NonNull List<T> supportedEnumValues) {
203             mSupportedEnumValues = supportedEnumValues;
204             return this;
205         }
206 
207         /** Builds a new {@link android.car.hardware.property.AreaIdConfig}. */
208         @NonNull
209         @ApiRequirements(
210                 minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0,
211                 minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_0)
212         public AreaIdConfig<T> build() {
213             return new AreaIdConfig<>(mAreaId, mMinValue, mMaxValue, mSupportedEnumValues);
214         }
215     }
216 }
217