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 package android.car.apitest;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import android.car.VehiclePropertyIds;
21 import android.hardware.automotive.vehicle.VehicleProperty;
22 import android.util.SparseArray;
23 
24 import androidx.test.filters.SmallTest;
25 import androidx.test.runner.AndroidJUnit4;
26 
27 import com.android.compatibility.common.util.ApiTest;
28 import com.android.compatibility.common.util.NonApiTest;
29 
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 
33 import java.lang.reflect.Field;
34 import java.lang.reflect.Modifier;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Objects;
38 import java.util.stream.Collectors;
39 
40 @RunWith(AndroidJUnit4.class)
41 @SmallTest
42 public final class VehiclePropertyIdsTest extends CarLessApiTestBase {
43     // IDs that only exist in CarPropertyManager, not VHAL.
44     private static final List<String> MISSING_VHAL_IDS = List.of();
45 
46     // IDs that only exist in VHAL, not exposed by CarPropertyManager.
47     private static final List<String> MISSING_VEHICLE_PROPERTY_IDS = List.of(
48                     "CAMERA_SERVICE_CURRENT_STATE",
49                     "DISABLED_OPTIONAL_FEATURES",
50                     "EVS_SERVICE_REQUEST",
51                     "EXTERNAL_CAR_TIME",
52                     "HW_KEY_INPUT_V2",
53                     "HW_MOTION_INPUT",
54                     "HW_CUSTOM_INPUT",
55                     "HW_ROTARY_INPUT",
56                     "SUPPORT_CUSTOMIZE_VENDOR_PERMISSION",
57                     "SUPPORTED_PROPERTY_IDS",
58                     "STORAGE_ENCRYPTION_BINDING_SEED",
59                     "SHUTDOWN_REQUEST",
60                     "VEHICLE_IN_USE");
61 
62     @Test
63     @NonApiTest(exemptionReasons = {}, justification = "Large number of constant fields")
testMatchingVehiclePropertyNamesInVehicleHal()64     public void testMatchingVehiclePropertyNamesInVehicleHal() {
65         List<String> carServiceNames = getListOfConstantNames(VehiclePropertyIds.class);
66         List<String> vhalNames = getListOfConstantNames(VehicleProperty.class);
67         assertThat(vhalNames.size() + MISSING_VHAL_IDS.size()).isEqualTo(
68                 carServiceNames.size() + MISSING_VEHICLE_PROPERTY_IDS.size());
69 
70         List<String> expectedCarServiceNames = new ArrayList<>();
71         for (String vhalName : vhalNames) {
72             if (MISSING_VEHICLE_PROPERTY_IDS.contains(vhalName)) {
73                 continue;
74             }
75             if (Objects.equals(vhalName, "ANDROID_EPOCH_TIME")) {
76                 // This is renamed in AIDL VHAL.
77                 expectedCarServiceNames.add("EPOCH_TIME");
78                 continue;
79             }
80             if (Objects.equals(vhalName, "GENERAL_SAFETY_REGULATION_COMPLIANCE_REQUIREMENT")) {
81                 // We renamed this property in Car Service.
82                 expectedCarServiceNames.add("GENERAL_SAFETY_REGULATION_COMPLIANCE");
83                 continue;
84             }
85             expectedCarServiceNames.add(vhalName);
86         }
87 
88         List<String> filteredCarServiceNames = carServiceNames.stream().filter(
89                 name -> !MISSING_VHAL_IDS.contains(name)).collect(Collectors.toList());
90 
91         assertThat(expectedCarServiceNames).containsExactlyElementsIn(filteredCarServiceNames);
92     }
93 
94     @Test
95     @NonApiTest(exemptionReasons = {}, justification = "Large number of constant fields")
testMatchingVehiclePropertyValuesInVehicleHal()96     public void testMatchingVehiclePropertyValuesInVehicleHal() {
97         List<String> carServiceNames = getListOfConstantNames(VehiclePropertyIds.class);
98         List<String> vhalNames = getListOfConstantNames(VehicleProperty.class);
99         assertThat(vhalNames.size() + MISSING_VHAL_IDS.size()).isEqualTo(
100                 carServiceNames.size() + MISSING_VEHICLE_PROPERTY_IDS.size());
101 
102         List<String> mismatchNames = new ArrayList<>();
103 
104         for (String vhalName : vhalNames) {
105             if (MISSING_VEHICLE_PROPERTY_IDS.contains(vhalName)) {
106                 continue;
107             }
108             int vhalPropId = getValue(VehicleProperty.class, vhalName);
109             // TODO(b/151168399): VEHICLE_SPEED_DISPLAY_UNITS mismatch between java and hal.
110             if (vhalPropId == VehicleProperty.VEHICLE_SPEED_DISPLAY_UNITS) {
111                 continue;
112             }
113 
114             String carServiceName = vhalName;
115             if (Objects.equals(carServiceName, "ANDROID_EPOCH_TIME")) {
116                 // This is renamed in AIDL VHAL.
117                 carServiceName = "EPOCH_TIME";
118             }
119             if (Objects.equals(carServiceName,
120                     "GENERAL_SAFETY_REGULATION_COMPLIANCE_REQUIREMENT")) {
121                 // We renamed this property in Car Service.
122                 carServiceName = "GENERAL_SAFETY_REGULATION_COMPLIANCE";
123                 continue;
124             }
125             int carServicePropId = getValue(VehiclePropertyIds.class, carServiceName);
126 
127             if (vhalPropId != carServicePropId) {
128                 mismatchNames.add(vhalName);
129             }
130         }
131 
132         assertThat(mismatchNames).isEmpty();
133     }
134 
135     @Test
136     @ApiTest(apis = {"android.car.VehiclePropertyIds#toString"})
testToString()137     public void testToString() {
138         SparseArray<String> propsToString = new SparseArray<>();
139 
140         propsToString.put(3, "0x3");
141         propsToString.put(VehiclePropertyIds.INVALID, "INVALID");
142         propsToString.put(VehiclePropertyIds.INFO_VIN, "INFO_VIN");
143         propsToString.put(VehiclePropertyIds.INFO_MAKE, "INFO_MAKE");
144         propsToString.put(VehiclePropertyIds.INFO_MODEL, "INFO_MODEL");
145         propsToString.put(VehiclePropertyIds.INFO_MODEL_YEAR, "INFO_MODEL_YEAR");
146         propsToString.put(VehiclePropertyIds.INFO_FUEL_CAPACITY, "INFO_FUEL_CAPACITY");
147         propsToString.put(VehiclePropertyIds.INFO_FUEL_TYPE, "INFO_FUEL_TYPE");
148         propsToString.put(VehiclePropertyIds.INFO_EV_BATTERY_CAPACITY, "INFO_EV_BATTERY_CAPACITY");
149         propsToString.put(VehiclePropertyIds.INFO_MULTI_EV_PORT_LOCATIONS,
150                 "INFO_MULTI_EV_PORT_LOCATIONS");
151         propsToString.put(VehiclePropertyIds.INFO_EV_CONNECTOR_TYPE, "INFO_EV_CONNECTOR_TYPE");
152         propsToString.put(VehiclePropertyIds.INFO_FUEL_DOOR_LOCATION, "INFO_FUEL_DOOR_LOCATION");
153         propsToString.put(VehiclePropertyIds.INFO_EV_PORT_LOCATION, "INFO_EV_PORT_LOCATION");
154         propsToString.put(VehiclePropertyIds.INFO_DRIVER_SEAT, "INFO_DRIVER_SEAT");
155         propsToString.put(VehiclePropertyIds.INFO_EXTERIOR_DIMENSIONS, "INFO_EXTERIOR_DIMENSIONS");
156         propsToString.put(VehiclePropertyIds.PERF_ODOMETER, "PERF_ODOMETER");
157         propsToString.put(VehiclePropertyIds.PERF_VEHICLE_SPEED, "PERF_VEHICLE_SPEED");
158         propsToString.put(VehiclePropertyIds.PERF_VEHICLE_SPEED_DISPLAY,
159                 "PERF_VEHICLE_SPEED_DISPLAY");
160         propsToString.put(VehiclePropertyIds.PERF_STEERING_ANGLE, "PERF_STEERING_ANGLE");
161         propsToString.put(VehiclePropertyIds.PERF_REAR_STEERING_ANGLE, "PERF_REAR_STEERING_ANGLE");
162         propsToString.put(VehiclePropertyIds.ENGINE_COOLANT_TEMP, "ENGINE_COOLANT_TEMP");
163         propsToString.put(VehiclePropertyIds.ENGINE_OIL_LEVEL, "ENGINE_OIL_LEVEL");
164         propsToString.put(VehiclePropertyIds.ENGINE_OIL_TEMP, "ENGINE_OIL_TEMP");
165         propsToString.put(VehiclePropertyIds.ENGINE_RPM, "ENGINE_RPM");
166         propsToString.put(VehiclePropertyIds.WHEEL_TICK, "WHEEL_TICK");
167         propsToString.put(VehiclePropertyIds.FUEL_LEVEL, "FUEL_LEVEL");
168         propsToString.put(VehiclePropertyIds.FUEL_DOOR_OPEN, "FUEL_DOOR_OPEN");
169         propsToString.put(VehiclePropertyIds.EV_BATTERY_LEVEL, "EV_BATTERY_LEVEL");
170         propsToString.put(VehiclePropertyIds.EV_CHARGE_PORT_OPEN, "EV_CHARGE_PORT_OPEN");
171         propsToString.put(VehiclePropertyIds.EV_CHARGE_PORT_CONNECTED, "EV_CHARGE_PORT_CONNECTED");
172         propsToString.put(VehiclePropertyIds.EV_BATTERY_INSTANTANEOUS_CHARGE_RATE,
173                 "EV_BATTERY_INSTANTANEOUS_CHARGE_RATE");
174         propsToString.put(VehiclePropertyIds.RANGE_REMAINING, "RANGE_REMAINING");
175         propsToString.put(VehiclePropertyIds.TIRE_PRESSURE, "TIRE_PRESSURE");
176         propsToString.put(VehiclePropertyIds.CRITICALLY_LOW_TIRE_PRESSURE,
177                 "CRITICALLY_LOW_TIRE_PRESSURE");
178         propsToString.put(VehiclePropertyIds.GEAR_SELECTION, "GEAR_SELECTION");
179         propsToString.put(VehiclePropertyIds.CURRENT_GEAR, "CURRENT_GEAR");
180         propsToString.put(VehiclePropertyIds.PARKING_BRAKE_ON, "PARKING_BRAKE_ON");
181         propsToString.put(VehiclePropertyIds.PARKING_BRAKE_AUTO_APPLY, "PARKING_BRAKE_AUTO_APPLY");
182         propsToString.put(VehiclePropertyIds.FUEL_LEVEL_LOW, "FUEL_LEVEL_LOW");
183         propsToString.put(VehiclePropertyIds.NIGHT_MODE, "NIGHT_MODE");
184         propsToString.put(VehiclePropertyIds.TURN_SIGNAL_STATE, "TURN_SIGNAL_STATE");
185         propsToString.put(VehiclePropertyIds.IGNITION_STATE, "IGNITION_STATE");
186         propsToString.put(VehiclePropertyIds.ABS_ACTIVE, "ABS_ACTIVE");
187         propsToString.put(VehiclePropertyIds.TRACTION_CONTROL_ACTIVE, "TRACTION_CONTROL_ACTIVE");
188         propsToString.put(VehiclePropertyIds.HVAC_FAN_SPEED, "HVAC_FAN_SPEED");
189         propsToString.put(VehiclePropertyIds.HVAC_FAN_DIRECTION, "HVAC_FAN_DIRECTION");
190         propsToString.put(VehiclePropertyIds.HVAC_TEMPERATURE_CURRENT, "HVAC_TEMPERATURE_CURRENT");
191         propsToString.put(VehiclePropertyIds.HVAC_TEMPERATURE_SET, "HVAC_TEMPERATURE_SET");
192         propsToString.put(VehiclePropertyIds.HVAC_TEMPERATURE_VALUE_SUGGESTION,
193                 "HVAC_TEMPERATURE_VALUE_SUGGESTION");
194         propsToString.put(VehiclePropertyIds.HVAC_DEFROSTER, "HVAC_DEFROSTER");
195         propsToString.put(VehiclePropertyIds.HVAC_AC_ON, "HVAC_AC_ON");
196         propsToString.put(VehiclePropertyIds.HVAC_MAX_AC_ON, "HVAC_MAX_AC_ON");
197         propsToString.put(VehiclePropertyIds.HVAC_MAX_DEFROST_ON, "HVAC_MAX_DEFROST_ON");
198         propsToString.put(VehiclePropertyIds.HVAC_RECIRC_ON, "HVAC_RECIRC_ON");
199         propsToString.put(VehiclePropertyIds.HVAC_DUAL_ON, "HVAC_DUAL_ON");
200         propsToString.put(VehiclePropertyIds.HVAC_AUTO_ON, "HVAC_AUTO_ON");
201         propsToString.put(VehiclePropertyIds.HVAC_SEAT_TEMPERATURE, "HVAC_SEAT_TEMPERATURE");
202         propsToString.put(VehiclePropertyIds.HVAC_SIDE_MIRROR_HEAT, "HVAC_SIDE_MIRROR_HEAT");
203         propsToString.put(VehiclePropertyIds.HVAC_STEERING_WHEEL_HEAT, "HVAC_STEERING_WHEEL_HEAT");
204         propsToString.put(VehiclePropertyIds.HVAC_TEMPERATURE_DISPLAY_UNITS,
205                 "HVAC_TEMPERATURE_DISPLAY_UNITS");
206         propsToString.put(VehiclePropertyIds.HVAC_ACTUAL_FAN_SPEED_RPM,
207                 "HVAC_ACTUAL_FAN_SPEED_RPM");
208         propsToString.put(VehiclePropertyIds.HVAC_POWER_ON, "HVAC_POWER_ON");
209         propsToString.put(VehiclePropertyIds.HVAC_FAN_DIRECTION_AVAILABLE,
210                 "HVAC_FAN_DIRECTION_AVAILABLE");
211         propsToString.put(VehiclePropertyIds.HVAC_AUTO_RECIRC_ON, "HVAC_AUTO_RECIRC_ON");
212         propsToString.put(VehiclePropertyIds.HVAC_SEAT_VENTILATION, "HVAC_SEAT_VENTILATION");
213         propsToString.put(VehiclePropertyIds.HVAC_ELECTRIC_DEFROSTER_ON,
214                 "HVAC_ELECTRIC_DEFROSTER_ON");
215         propsToString.put(VehiclePropertyIds.DISTANCE_DISPLAY_UNITS, "DISTANCE_DISPLAY_UNITS");
216         propsToString.put(VehiclePropertyIds.FUEL_VOLUME_DISPLAY_UNITS,
217                 "FUEL_VOLUME_DISPLAY_UNITS");
218         propsToString.put(VehiclePropertyIds.TIRE_PRESSURE_DISPLAY_UNITS,
219                 "TIRE_PRESSURE_DISPLAY_UNITS");
220         propsToString.put(VehiclePropertyIds.EV_BATTERY_DISPLAY_UNITS, "EV_BATTERY_DISPLAY_UNITS");
221         propsToString.put(VehiclePropertyIds.FUEL_CONSUMPTION_UNITS_DISTANCE_OVER_VOLUME,
222                 "FUEL_CONSUMPTION_UNITS_DISTANCE_OVER_VOLUME");
223         propsToString.put(VehiclePropertyIds.ENV_OUTSIDE_TEMPERATURE, "ENV_OUTSIDE_TEMPERATURE");
224         propsToString.put(VehiclePropertyIds.AP_POWER_STATE_REQ, "AP_POWER_STATE_REQ");
225         propsToString.put(VehiclePropertyIds.AP_POWER_STATE_REPORT, "AP_POWER_STATE_REPORT");
226         propsToString.put(VehiclePropertyIds.AP_POWER_BOOTUP_REASON, "AP_POWER_BOOTUP_REASON");
227         propsToString.put(VehiclePropertyIds.DISPLAY_BRIGHTNESS, "DISPLAY_BRIGHTNESS");
228         propsToString.put(VehiclePropertyIds.HW_KEY_INPUT, "HW_KEY_INPUT");
229         propsToString.put(VehiclePropertyIds.DOOR_POS, "DOOR_POS");
230         propsToString.put(VehiclePropertyIds.DOOR_MOVE, "DOOR_MOVE");
231         propsToString.put(VehiclePropertyIds.DOOR_LOCK, "DOOR_LOCK");
232         propsToString.put(VehiclePropertyIds.MIRROR_Z_POS, "MIRROR_Z_POS");
233         propsToString.put(VehiclePropertyIds.MIRROR_Z_MOVE, "MIRROR_Z_MOVE");
234         propsToString.put(VehiclePropertyIds.MIRROR_Y_POS, "MIRROR_Y_POS");
235         propsToString.put(VehiclePropertyIds.MIRROR_Y_MOVE, "MIRROR_Y_MOVE");
236         propsToString.put(VehiclePropertyIds.MIRROR_LOCK, "MIRROR_LOCK");
237         propsToString.put(VehiclePropertyIds.MIRROR_FOLD, "MIRROR_FOLD");
238         propsToString.put(VehiclePropertyIds.SEAT_MEMORY_SELECT, "SEAT_MEMORY_SELECT");
239         propsToString.put(VehiclePropertyIds.SEAT_MEMORY_SET, "SEAT_MEMORY_SET");
240         propsToString.put(VehiclePropertyIds.SEAT_BELT_BUCKLED, "SEAT_BELT_BUCKLED");
241         propsToString.put(VehiclePropertyIds.SEAT_BELT_HEIGHT_POS, "SEAT_BELT_HEIGHT_POS");
242         propsToString.put(VehiclePropertyIds.SEAT_BELT_HEIGHT_MOVE, "SEAT_BELT_HEIGHT_MOVE");
243         propsToString.put(VehiclePropertyIds.SEAT_FORE_AFT_POS, "SEAT_FORE_AFT_POS");
244         propsToString.put(VehiclePropertyIds.SEAT_FORE_AFT_MOVE, "SEAT_FORE_AFT_MOVE");
245         propsToString.put(VehiclePropertyIds.SEAT_BACKREST_ANGLE_1_POS,
246                 "SEAT_BACKREST_ANGLE_1_POS");
247         propsToString.put(VehiclePropertyIds.SEAT_BACKREST_ANGLE_1_MOVE,
248                 "SEAT_BACKREST_ANGLE_1_MOVE");
249         propsToString.put(VehiclePropertyIds.SEAT_BACKREST_ANGLE_2_POS,
250                 "SEAT_BACKREST_ANGLE_2_POS");
251         propsToString.put(VehiclePropertyIds.SEAT_BACKREST_ANGLE_2_MOVE,
252                 "SEAT_BACKREST_ANGLE_2_MOVE");
253         propsToString.put(VehiclePropertyIds.SEAT_HEIGHT_POS, "SEAT_HEIGHT_POS");
254         propsToString.put(VehiclePropertyIds.SEAT_HEIGHT_MOVE, "SEAT_HEIGHT_MOVE");
255         propsToString.put(VehiclePropertyIds.SEAT_DEPTH_POS, "SEAT_DEPTH_POS");
256         propsToString.put(VehiclePropertyIds.SEAT_DEPTH_MOVE, "SEAT_DEPTH_MOVE");
257         propsToString.put(VehiclePropertyIds.SEAT_TILT_POS, "SEAT_TILT_POS");
258         propsToString.put(VehiclePropertyIds.SEAT_TILT_MOVE, "SEAT_TILT_MOVE");
259         propsToString.put(VehiclePropertyIds.SEAT_LUMBAR_FORE_AFT_POS, "SEAT_LUMBAR_FORE_AFT_POS");
260         propsToString.put(VehiclePropertyIds.SEAT_LUMBAR_FORE_AFT_MOVE,
261                 "SEAT_LUMBAR_FORE_AFT_MOVE");
262         propsToString.put(VehiclePropertyIds.SEAT_LUMBAR_SIDE_SUPPORT_POS,
263                 "SEAT_LUMBAR_SIDE_SUPPORT_POS");
264         propsToString.put(VehiclePropertyIds.SEAT_LUMBAR_SIDE_SUPPORT_MOVE,
265                 "SEAT_LUMBAR_SIDE_SUPPORT_MOVE");
266         propsToString.put(VehiclePropertyIds.SEAT_HEADREST_HEIGHT_POS, "SEAT_HEADREST_HEIGHT_POS");
267         propsToString.put(VehiclePropertyIds.SEAT_HEADREST_HEIGHT_MOVE,
268                 "SEAT_HEADREST_HEIGHT_MOVE");
269         propsToString.put(VehiclePropertyIds.SEAT_HEADREST_ANGLE_POS, "SEAT_HEADREST_ANGLE_POS");
270         propsToString.put(VehiclePropertyIds.SEAT_HEADREST_ANGLE_MOVE, "SEAT_HEADREST_ANGLE_MOVE");
271         propsToString.put(VehiclePropertyIds.SEAT_HEADREST_FORE_AFT_POS,
272                 "SEAT_HEADREST_FORE_AFT_POS");
273         propsToString.put(VehiclePropertyIds.SEAT_HEADREST_FORE_AFT_MOVE,
274                 "SEAT_HEADREST_FORE_AFT_MOVE");
275         propsToString.put(VehiclePropertyIds.SEAT_OCCUPANCY, "SEAT_OCCUPANCY");
276         propsToString.put(VehiclePropertyIds.WINDOW_POS, "WINDOW_POS");
277         propsToString.put(VehiclePropertyIds.WINDOW_MOVE, "WINDOW_MOVE");
278         propsToString.put(VehiclePropertyIds.WINDOW_LOCK, "WINDOW_LOCK");
279         propsToString.put(VehiclePropertyIds.VEHICLE_MAP_SERVICE, "VEHICLE_MAP_SERVICE");
280         propsToString.put(VehiclePropertyIds.OBD2_LIVE_FRAME, "OBD2_LIVE_FRAME");
281         propsToString.put(VehiclePropertyIds.OBD2_FREEZE_FRAME, "OBD2_FREEZE_FRAME");
282         propsToString.put(VehiclePropertyIds.OBD2_FREEZE_FRAME_INFO, "OBD2_FREEZE_FRAME_INFO");
283         propsToString.put(VehiclePropertyIds.OBD2_FREEZE_FRAME_CLEAR, "OBD2_FREEZE_FRAME_CLEAR");
284         propsToString.put(VehiclePropertyIds.HEADLIGHTS_STATE, "HEADLIGHTS_STATE");
285         propsToString.put(VehiclePropertyIds.HIGH_BEAM_LIGHTS_STATE, "HIGH_BEAM_LIGHTS_STATE");
286         propsToString.put(VehiclePropertyIds.FOG_LIGHTS_STATE, "FOG_LIGHTS_STATE");
287         propsToString.put(VehiclePropertyIds.HAZARD_LIGHTS_STATE, "HAZARD_LIGHTS_STATE");
288         propsToString.put(VehiclePropertyIds.HEADLIGHTS_SWITCH, "HEADLIGHTS_SWITCH");
289         propsToString.put(VehiclePropertyIds.HIGH_BEAM_LIGHTS_SWITCH, "HIGH_BEAM_LIGHTS_SWITCH");
290         propsToString.put(VehiclePropertyIds.FOG_LIGHTS_SWITCH, "FOG_LIGHTS_SWITCH");
291         propsToString.put(VehiclePropertyIds.HAZARD_LIGHTS_SWITCH, "HAZARD_LIGHTS_SWITCH");
292         propsToString.put(VehiclePropertyIds.CABIN_LIGHTS_STATE, "CABIN_LIGHTS_STATE");
293         propsToString.put(VehiclePropertyIds.CABIN_LIGHTS_SWITCH, "CABIN_LIGHTS_SWITCH");
294         propsToString.put(VehiclePropertyIds.READING_LIGHTS_STATE, "READING_LIGHTS_STATE");
295         propsToString.put(VehiclePropertyIds.READING_LIGHTS_SWITCH, "READING_LIGHTS_SWITCH");
296         propsToString.put(VehiclePropertyIds.VEHICLE_SPEED_DISPLAY_UNITS,
297                 "VEHICLE_SPEED_DISPLAY_UNITS");
298         propsToString.put(VehiclePropertyIds.INITIAL_USER_INFO, "INITIAL_USER_INFO");
299         propsToString.put(VehiclePropertyIds.SWITCH_USER, "SWITCH_USER");
300         propsToString.put(VehiclePropertyIds.CREATE_USER, "CREATE_USER");
301         propsToString.put(VehiclePropertyIds.REMOVE_USER, "REMOVE_USER");
302         propsToString.put(VehiclePropertyIds.USER_IDENTIFICATION_ASSOCIATION,
303                 "USER_IDENTIFICATION_ASSOCIATION");
304         propsToString.put(VehiclePropertyIds.POWER_POLICY_REQ, "POWER_POLICY_REQ");
305         propsToString.put(VehiclePropertyIds.POWER_POLICY_GROUP_REQ, "POWER_POLICY_GROUP_REQ");
306         propsToString.put(VehiclePropertyIds.CURRENT_POWER_POLICY, "CURRENT_POWER_POLICY");
307         propsToString.put(VehiclePropertyIds.WATCHDOG_ALIVE, "WATCHDOG_ALIVE");
308         propsToString.put(VehiclePropertyIds.WATCHDOG_TERMINATED_PROCESS,
309                 "WATCHDOG_TERMINATED_PROCESS");
310         propsToString.put(VehiclePropertyIds.VHAL_HEARTBEAT, "VHAL_HEARTBEAT");
311         propsToString.put(VehiclePropertyIds.CLUSTER_SWITCH_UI, "CLUSTER_SWITCH_UI");
312         propsToString.put(VehiclePropertyIds.CLUSTER_DISPLAY_STATE, "CLUSTER_DISPLAY_STATE");
313         propsToString.put(VehiclePropertyIds.CLUSTER_REPORT_STATE, "CLUSTER_REPORT_STATE");
314         propsToString.put(VehiclePropertyIds.CLUSTER_REQUEST_DISPLAY, "CLUSTER_REQUEST_DISPLAY");
315         propsToString.put(VehiclePropertyIds.CLUSTER_NAVIGATION_STATE, "CLUSTER_NAVIGATION_STATE");
316         propsToString.put(VehiclePropertyIds.EPOCH_TIME, "EPOCH_TIME");
317         propsToString.put(VehiclePropertyIds.ELECTRONIC_TOLL_COLLECTION_CARD_STATUS,
318                 "ELECTRONIC_TOLL_COLLECTION_CARD_STATUS");
319         propsToString.put(VehiclePropertyIds.ELECTRONIC_TOLL_COLLECTION_CARD_TYPE,
320                 "ELECTRONIC_TOLL_COLLECTION_CARD_TYPE");
321         propsToString.put(VehiclePropertyIds.FRONT_FOG_LIGHTS_STATE, "FRONT_FOG_LIGHTS_STATE");
322         propsToString.put(VehiclePropertyIds.FRONT_FOG_LIGHTS_SWITCH, "FRONT_FOG_LIGHTS_SWITCH");
323         propsToString.put(VehiclePropertyIds.REAR_FOG_LIGHTS_STATE, "REAR_FOG_LIGHTS_STATE");
324         propsToString.put(VehiclePropertyIds.REAR_FOG_LIGHTS_SWITCH, "REAR_FOG_LIGHTS_SWITCH");
325         propsToString.put(VehiclePropertyIds.EV_CHARGE_CURRENT_DRAW_LIMIT,
326                 "EV_CHARGE_CURRENT_DRAW_LIMIT");
327         propsToString.put(VehiclePropertyIds.EV_CHARGE_PERCENT_LIMIT, "EV_CHARGE_PERCENT_LIMIT");
328         propsToString.put(VehiclePropertyIds.EV_CHARGE_STATE, "EV_CHARGE_STATE");
329         propsToString.put(VehiclePropertyIds.EV_CHARGE_SWITCH, "EV_CHARGE_SWITCH");
330         propsToString.put(VehiclePropertyIds.EV_CHARGE_TIME_REMAINING, "EV_CHARGE_TIME_REMAINING");
331         propsToString.put(VehiclePropertyIds.EV_REGENERATIVE_BRAKING_STATE,
332                 "EV_REGENERATIVE_BRAKING_STATE");
333         propsToString.put(VehiclePropertyIds.VEHICLE_CURB_WEIGHT, "VEHICLE_CURB_WEIGHT");
334         propsToString.put(VehiclePropertyIds.TRAILER_PRESENT, "TRAILER_PRESENT");
335 
336         for (int i = 0; i < propsToString.size(); i++) {
337             assertThat(VehiclePropertyIds.toString(propsToString.keyAt(i))).isEqualTo(
338                     propsToString.valueAt(i));
339         }
340     }
341 
getListOfConstantNames(Class clazz)342     private static List<String> getListOfConstantNames(Class clazz) {
343         List<String> list = new ArrayList<String>();
344         for (Field field : clazz.getFields()) {
345             int modifiers = field.getModifiers();
346             if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) {
347                 list.add(field.getName());
348             }
349         }
350         return list;
351     }
352 
getValue(Class clazz, String name)353     private static int getValue(Class clazz, String name) {
354         for (Field field : clazz.getFields()) {
355             int modifiers = field.getModifiers();
356             if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)
357                     && field.getName().equals(name)) {
358                 try {
359                     return field.getInt(null);
360                 } catch (IllegalAccessException e) {
361                     // ignore
362                 }
363             }
364         }
365         return 0;
366     }
367 }
368