Add VehicleHal utilities.
Add some utility functions to AIDL VHAL.
Test: atest VehicleHalVehicleUtilsTest
Bug: 199337732
Change-Id: I9e74161efecf7c66caa2f52177fbdd43cdc9d68b
diff --git a/automotive/vehicle/aidl/impl/Android.bp b/automotive/vehicle/aidl/impl/Android.bp
new file mode 100644
index 0000000..0b98c7e
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/Android.bp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_defaults {
+ name: "VehicleHalDefaults",
+ static_libs: [
+ "android.hardware.automotive.vehicle-V1-ndk_platform",
+ ],
+ shared_libs: [
+ "libbase",
+ "liblog",
+ "libutils",
+ ],
+ cflags: [
+ "-Wall",
+ "-Wextra",
+ "-Werror",
+ ],
+}
diff --git a/automotive/vehicle/aidl/impl/utils/TEST_MAPPING b/automotive/vehicle/aidl/impl/utils/TEST_MAPPING
new file mode 100644
index 0000000..d3d00ab
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+ "presubmit": [
+ {
+ "name": "VehicleHalVehicleUtilsTest"
+ }
+ ]
+}
diff --git a/automotive/vehicle/aidl/impl/utils/common/Android.bp b/automotive/vehicle/aidl/impl/utils/common/Android.bp
new file mode 100644
index 0000000..001280f
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/common/Android.bp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_library {
+ name: "VehicleHalUtils",
+ srcs: [
+ "src/*.cpp",
+ ],
+ vendor: true,
+ local_include_dirs: ["include"],
+ export_include_dirs: ["include"],
+ defaults: ["VehicleHalDefaults"],
+}
+
+cc_library_headers {
+ name: "VehicleHalUtilHeaders",
+ export_include_dirs: ["include"],
+ vendor: true,
+}
diff --git a/automotive/vehicle/aidl/impl/utils/common/include/PropertyUtils.h b/automotive/vehicle/aidl/impl/utils/common/include/PropertyUtils.h
new file mode 100644
index 0000000..441c54b
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/common/include/PropertyUtils.h
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef android_hardware_automotive_vehicle_aidl_impl_utils_common_include_PropertyUtils_H_
+#define android_hardware_automotive_vehicle_aidl_impl_utils_common_include_PropertyUtils_H_
+
+#include <VehicleHalTypes.h>
+#include <VehicleUtils.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+
+namespace propertyutils_impl {
+
+// These names are not part of the API since we only expose ints.
+using ::aidl::android::hardware::automotive::vehicle::PortLocationType;
+using ::aidl::android::hardware::automotive::vehicle::VehicleArea;
+using ::aidl::android::hardware::automotive::vehicle::VehicleAreaDoor;
+using ::aidl::android::hardware::automotive::vehicle::VehicleAreaSeat;
+using ::aidl::android::hardware::automotive::vehicle::VehicleAreaWheel;
+using ::aidl::android::hardware::automotive::vehicle::VehicleAreaWindow;
+using ::aidl::android::hardware::automotive::vehicle::VehicleHvacFanDirection;
+using ::aidl::android::hardware::automotive::vehicle::VehicleLightState;
+using ::aidl::android::hardware::automotive::vehicle::VehicleLightSwitch;
+using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
+
+} // namespace propertyutils_impl
+
+// Some handy constants to avoid conversions from enum to int.
+constexpr int ABS_ACTIVE = toInt(propertyutils_impl::VehicleProperty::ABS_ACTIVE);
+constexpr int AP_POWER_STATE_REQ = toInt(propertyutils_impl::VehicleProperty::AP_POWER_STATE_REQ);
+constexpr int AP_POWER_STATE_REPORT =
+ toInt(propertyutils_impl::VehicleProperty::AP_POWER_STATE_REPORT);
+constexpr int DOOR_1_LEFT = toInt(propertyutils_impl::VehicleAreaDoor::ROW_1_LEFT);
+constexpr int DOOR_1_RIGHT = toInt(propertyutils_impl::VehicleAreaDoor::ROW_1_RIGHT);
+constexpr int DOOR_2_LEFT = toInt(propertyutils_impl::VehicleAreaDoor::ROW_2_LEFT);
+constexpr int DOOR_2_RIGHT = toInt(propertyutils_impl::VehicleAreaDoor::ROW_2_RIGHT);
+constexpr int DOOR_REAR = toInt(propertyutils_impl::VehicleAreaDoor::REAR);
+constexpr int WINDOW_1_LEFT = toInt(propertyutils_impl::VehicleAreaWindow::ROW_1_LEFT);
+constexpr int WINDOW_1_RIGHT = toInt(propertyutils_impl::VehicleAreaWindow::ROW_1_RIGHT);
+constexpr int WINDOW_2_LEFT = toInt(propertyutils_impl::VehicleAreaWindow::ROW_2_LEFT);
+constexpr int WINDOW_2_RIGHT = toInt(propertyutils_impl::VehicleAreaWindow::ROW_2_RIGHT);
+constexpr int WINDOW_ROOF_TOP_1 = toInt(propertyutils_impl::VehicleAreaWindow::ROOF_TOP_1);
+constexpr int FAN_DIRECTION_FACE = toInt(propertyutils_impl::VehicleHvacFanDirection::FACE);
+constexpr int FAN_DIRECTION_FLOOR = toInt(propertyutils_impl::VehicleHvacFanDirection::FLOOR);
+constexpr int FAN_DIRECTION_DEFROST = toInt(propertyutils_impl::VehicleHvacFanDirection::DEFROST);
+constexpr int OBD2_LIVE_FRAME = toInt(propertyutils_impl::VehicleProperty::OBD2_LIVE_FRAME);
+constexpr int OBD2_FREEZE_FRAME = toInt(propertyutils_impl::VehicleProperty::OBD2_FREEZE_FRAME);
+constexpr int OBD2_FREEZE_FRAME_INFO =
+ toInt(propertyutils_impl::VehicleProperty::OBD2_FREEZE_FRAME_INFO);
+constexpr int OBD2_FREEZE_FRAME_CLEAR =
+ toInt(propertyutils_impl::VehicleProperty::OBD2_FREEZE_FRAME_CLEAR);
+constexpr int TRACTION_CONTROL_ACTIVE =
+ toInt(propertyutils_impl::VehicleProperty::TRACTION_CONTROL_ACTIVE);
+constexpr int VEHICLE_MAP_SERVICE = toInt(propertyutils_impl::VehicleProperty::VEHICLE_MAP_SERVICE);
+constexpr int WHEEL_TICK = toInt(propertyutils_impl::VehicleProperty::WHEEL_TICK);
+constexpr int SEAT_1_LEFT = toInt(propertyutils_impl::VehicleAreaSeat::ROW_1_LEFT);
+constexpr int SEAT_1_RIGHT = toInt(propertyutils_impl::VehicleAreaSeat::ROW_1_RIGHT);
+constexpr int SEAT_2_LEFT = toInt(propertyutils_impl::VehicleAreaSeat::ROW_2_LEFT);
+constexpr int SEAT_2_RIGHT = toInt(propertyutils_impl::VehicleAreaSeat::ROW_2_RIGHT);
+constexpr int SEAT_2_CENTER = toInt(propertyutils_impl::VehicleAreaSeat::ROW_2_CENTER);
+constexpr int VENDOR_EXTENSION_BOOLEAN_PROPERTY =
+ 0x101 | toInt(propertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(propertyutils_impl::VehiclePropertyType::BOOLEAN) |
+ toInt(propertyutils_impl::VehicleArea::DOOR);
+constexpr int VENDOR_EXTENSION_FLOAT_PROPERTY =
+ 0x102 | toInt(propertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(propertyutils_impl::VehiclePropertyType::FLOAT) |
+ toInt(propertyutils_impl::VehicleArea::SEAT);
+constexpr int VENDOR_EXTENSION_INT_PROPERTY =
+ 0x103 | toInt(propertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(propertyutils_impl::VehiclePropertyType::INT32) |
+ toInt(propertyutils_impl::VehicleArea::WINDOW);
+constexpr int VENDOR_EXTENSION_STRING_PROPERTY =
+ 0x104 | toInt(propertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(propertyutils_impl::VehiclePropertyType::STRING) |
+ toInt(propertyutils_impl::VehicleArea::GLOBAL);
+constexpr int FUEL_DOOR_REAR_LEFT = toInt(propertyutils_impl::PortLocationType::REAR_LEFT);
+constexpr int CHARGE_PORT_FRONT_LEFT = toInt(propertyutils_impl::PortLocationType::FRONT_LEFT);
+constexpr int CHARGE_PORT_REAR_LEFT = toInt(propertyutils_impl::PortLocationType::REAR_LEFT);
+constexpr int LIGHT_STATE_ON = toInt(propertyutils_impl::VehicleLightState::ON);
+constexpr int LIGHT_SWITCH_AUTO = toInt(propertyutils_impl::VehicleLightSwitch::AUTOMATIC);
+constexpr int WHEEL_FRONT_LEFT = toInt(propertyutils_impl::VehicleAreaWheel::LEFT_FRONT);
+constexpr int WHEEL_FRONT_RIGHT = toInt(propertyutils_impl::VehicleAreaWheel::RIGHT_FRONT);
+constexpr int WHEEL_REAR_LEFT = toInt(propertyutils_impl::VehicleAreaWheel::LEFT_REAR);
+constexpr int WHEEL_REAR_RIGHT = toInt(propertyutils_impl::VehicleAreaWheel::RIGHT_REAR);
+constexpr int ALL_WHEELS =
+ WHEEL_FRONT_LEFT | WHEEL_FRONT_RIGHT | WHEEL_REAR_LEFT | WHEEL_REAR_RIGHT;
+constexpr int HVAC_LEFT = SEAT_1_LEFT | SEAT_2_LEFT | SEAT_2_CENTER;
+constexpr int HVAC_RIGHT = SEAT_1_RIGHT | SEAT_2_RIGHT;
+constexpr int HVAC_ALL = HVAC_LEFT | HVAC_RIGHT;
+
+const int32_t kHvacPowerProperties[] = {
+ toInt(propertyutils_impl::VehicleProperty::HVAC_FAN_SPEED),
+ toInt(propertyutils_impl::VehicleProperty::HVAC_FAN_DIRECTION),
+};
+
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
+
+#endif // android_hardware_automotive_vehicle_aidl_impl_utils_common_include_PropertyUtils_H_
diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h b/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h
new file mode 100644
index 0000000..a8f5ec7
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef android_hardware_automotive_vehicle_aidl_impl_utils_common_include_VehicleHalTypes_H_
+#define android_hardware_automotive_vehicle_aidl_impl_utils_common_include_VehicleHalTypes_H_
+
+#include <aidl/android/hardware/automotive/vehicle/EvConnectorType.h>
+#include <aidl/android/hardware/automotive/vehicle/EvsServiceState.h>
+#include <aidl/android/hardware/automotive/vehicle/EvsServiceType.h>
+#include <aidl/android/hardware/automotive/vehicle/FuelType.h>
+#include <aidl/android/hardware/automotive/vehicle/GetValueResult.h>
+#include <aidl/android/hardware/automotive/vehicle/PortLocationType.h>
+#include <aidl/android/hardware/automotive/vehicle/SetValueResult.h>
+#include <aidl/android/hardware/automotive/vehicle/StatusCode.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateReport.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateReq.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleArea.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleAreaDoor.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleAreaSeat.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleAreaWheel.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleAreaWindow.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleGear.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleHvacFanDirection.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleIgnitionState.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleLightState.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleLightSwitch.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleOilLevel.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropConfig.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropError.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropValue.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyAccess.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyChangeMode.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyGroup.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyStatus.h>
+#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyType.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleSeatOccupancyState.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleTurnSignal.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleUnit.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleVendorPermission.h>
+
+#endif // android_hardware_automotive_vehicle_aidl_impl_utils_common_include_VehicleHalTypes_H_
diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h b/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h
new file mode 100644
index 0000000..c4bf1d3
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef android_hardware_automotive_vehicle_aidl_impl_utils_common_include_VehicleUtils_H_
+#define android_hardware_automotive_vehicle_aidl_impl_utils_common_include_VehicleUtils_H_
+
+#include <VehicleHalTypes.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+
+// Represents all supported areas for a property.
+constexpr int32_t kAllSupportedAreas = 0;
+
+// Returns underlying (integer) value for given enum.
+template <typename ENUM, typename U = typename std::underlying_type<ENUM>::type>
+inline constexpr U toInt(ENUM const value) {
+ return static_cast<U>(value);
+}
+
+inline constexpr ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType getPropType(
+ int32_t prop) {
+ return static_cast<::aidl::android::hardware::automotive::vehicle::VehiclePropertyType>(
+ prop &
+ toInt(::aidl::android::hardware::automotive::vehicle::VehiclePropertyType::MASK));
+}
+
+inline constexpr ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup getPropGroup(
+ int32_t prop) {
+ return static_cast<::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup>(
+ prop &
+ toInt(::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup::MASK));
+}
+
+inline constexpr ::aidl::android::hardware::automotive::vehicle::VehicleArea getPropArea(
+ int32_t prop) {
+ return static_cast<::aidl::android::hardware::automotive::vehicle::VehicleArea>(
+ prop & toInt(::aidl::android::hardware::automotive::vehicle::VehicleArea::MASK));
+}
+
+inline constexpr bool isGlobalProp(int32_t prop) {
+ return getPropArea(prop) == ::aidl::android::hardware::automotive::vehicle::VehicleArea::GLOBAL;
+}
+
+inline constexpr bool isSystemProp(int32_t prop) {
+ return ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup::SYSTEM ==
+ getPropGroup(prop);
+}
+
+inline const ::aidl::android::hardware::automotive::vehicle::VehicleAreaConfig* getAreaConfig(
+ const ::aidl::android::hardware::automotive::vehicle::VehiclePropValue& propValue,
+ const ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig& config) {
+ if (config.areaConfigs.size() == 0) {
+ return nullptr;
+ }
+
+ if (isGlobalProp(propValue.prop)) {
+ return &(config.areaConfigs[0]);
+ }
+
+ for (const auto& c : config.areaConfigs) {
+ if (c.areaId == propValue.areaId) {
+ return &c;
+ }
+ }
+ return nullptr;
+}
+
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
+
+#endif // android_hardware_automotive_vehicle_aidl_impl_utils_common_include_VehicleUtils_H_
diff --git a/automotive/vehicle/aidl/impl/utils/common/test/Android.bp b/automotive/vehicle/aidl/impl/utils/common/test/Android.bp
new file mode 100644
index 0000000..40744ce
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/common/test/Android.bp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_test {
+ name: "VehicleHalVehicleUtilsTest",
+ srcs: ["*.cpp"],
+ vendor: true,
+ static_libs: ["VehicleHalUtils"],
+ defaults: ["VehicleHalDefaults"],
+ test_suites: ["general-tests"],
+}
diff --git a/automotive/vehicle/aidl/impl/utils/common/test/VehicleUtilsTest.cpp b/automotive/vehicle/aidl/impl/utils/common/test/VehicleUtilsTest.cpp
new file mode 100644
index 0000000..c09b06d
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/common/test/VehicleUtilsTest.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <PropertyUtils.h>
+#include <VehicleUtils.h>
+#include <gtest/gtest.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+
+using ::aidl::android::hardware::automotive::vehicle::VehicleArea;
+using ::aidl::android::hardware::automotive::vehicle::VehicleAreaConfig;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig;
+using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropValue;
+
+TEST(VehicleUtilsTest, testToInt) {
+ int areaGlobal = toInt(VehicleArea::GLOBAL);
+
+ ASSERT_EQ(areaGlobal, 0x01000000);
+}
+
+TEST(VehicleUtilsTest, testGetPropType) {
+ VehiclePropertyType type = getPropType(toInt(VehicleProperty::INFO_VIN));
+
+ ASSERT_EQ(type, VehiclePropertyType::STRING);
+}
+
+TEST(VehicleUtilsTest, testGetPropGroup) {
+ VehiclePropertyGroup group = getPropGroup(toInt(VehicleProperty::INFO_VIN));
+
+ ASSERT_EQ(group, VehiclePropertyGroup::SYSTEM);
+}
+
+TEST(VehicleUtilsTest, testGetPropArea) {
+ VehicleArea area = getPropArea(toInt(VehicleProperty::INFO_VIN));
+
+ ASSERT_EQ(area, VehicleArea::GLOBAL);
+}
+
+TEST(VehicleUtilsTest, testIsGlobalPropTrue) {
+ ASSERT_TRUE(isGlobalProp(toInt(VehicleProperty::INFO_VIN)));
+}
+
+TEST(VehicleUtilsTest, testIsGlobalPropFalse) {
+ ASSERT_FALSE(isGlobalProp(toInt(VehicleProperty::TIRE_PRESSURE)));
+}
+
+TEST(VehicleUtilsTest, testIsSystemPropTrue) {
+ ASSERT_TRUE(isSystemProp(toInt(VehicleProperty::INFO_VIN)));
+}
+
+TEST(VehicleUtilsTest, testIsSystemPropFalse) {
+ // VehiclePropertyGroup:VENDOR,VehicleArea:GLOBAL,VehiclePropertyType:STRING
+ int vendorProp = 0x0100 + 0x20000000 + 0x01000000 + 0x00100000;
+
+ ASSERT_FALSE(isSystemProp(vendorProp));
+}
+
+TEST(VehicleUtilsTest, testGetAreaConfigGlobal) {
+ VehiclePropValue testPropValue{.prop = toInt(VehicleProperty::INFO_VIN)};
+ VehicleAreaConfig testAreaConfig{.areaId = 0, .minInt32Value = 1};
+ VehiclePropConfig testConfig{.areaConfigs = {testAreaConfig}};
+
+ const VehicleAreaConfig* gotConfig = getAreaConfig(testPropValue, testConfig);
+
+ ASSERT_EQ(*gotConfig, testAreaConfig);
+}
+
+TEST(VehicleUtilsTest, testGetAreaConfigGlobalNoAreaConfig) {
+ VehiclePropValue testPropValue{.prop = toInt(VehicleProperty::INFO_VIN)};
+ VehiclePropConfig testConfig{};
+
+ const VehicleAreaConfig* gotConfig = getAreaConfig(testPropValue, testConfig);
+
+ ASSERT_EQ(gotConfig, nullptr);
+}
+
+TEST(VehicleUtilsTest, testGetAreaConfigNonGlobal) {
+ VehiclePropValue testPropValue = {
+ .prop = toInt(VehicleProperty::TIRE_PRESSURE),
+ };
+ VehicleAreaConfig leftConfig{.areaId = WHEEL_FRONT_LEFT, .minInt32Value = 1};
+ VehicleAreaConfig rightConfig{.areaId = WHEEL_FRONT_RIGHT, .minInt32Value = 2};
+ VehiclePropConfig testConfig{.areaConfigs = {leftConfig, rightConfig}};
+
+ testPropValue.areaId = WHEEL_FRONT_LEFT;
+ const VehicleAreaConfig* gotConfig = getAreaConfig(testPropValue, testConfig);
+
+ ASSERT_EQ(*gotConfig, leftConfig);
+}
+
+TEST(VehicleUtilsTest, testGetAreaConfigNonGlobalNull) {
+ VehiclePropValue testPropValue = {
+ .prop = toInt(VehicleProperty::TIRE_PRESSURE),
+ };
+ VehicleAreaConfig leftConfig{.areaId = WHEEL_FRONT_LEFT, .minInt32Value = 1};
+ VehicleAreaConfig rightConfig{.areaId = WHEEL_FRONT_RIGHT, .minInt32Value = 2};
+ VehiclePropConfig testConfig{.areaConfigs = {leftConfig, rightConfig}};
+
+ // No config for this area.
+ testPropValue.areaId = 0;
+ const VehicleAreaConfig* gotConfig = getAreaConfig(testPropValue, testConfig);
+
+ ASSERT_EQ(gotConfig, nullptr);
+}
+
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
diff --git a/automotive/vehicle/aidl/impl/utils/test/Android.bp b/automotive/vehicle/aidl/impl/utils/test/Android.bp
new file mode 100644
index 0000000..5859151
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/test/Android.bp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_library_headers {
+ name: "VehicleHalTestUtilHeaders",
+ export_include_dirs: ["include"],
+ vendor: true,
+}
diff --git a/automotive/vehicle/aidl/impl/utils/test/include/TestPropertyUtils.h b/automotive/vehicle/aidl/impl/utils/test/include/TestPropertyUtils.h
new file mode 100644
index 0000000..77cf100
--- /dev/null
+++ b/automotive/vehicle/aidl/impl/utils/test/include/TestPropertyUtils.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef android_hardware_automotive_vehicle_utils_test_include_TestPropertyUtils_H_
+#define android_hardware_automotive_vehicle_utils_test_include_TestPropertyUtils_H_
+
+#include <VehicleHalTypes.h>
+#include <VehicleUtils.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+
+namespace testpropertyutils_impl {
+
+// These names are not part of the API since we only expose ints.
+using ::aidl::android::hardware::automotive::vehicle::VehicleArea;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
+
+} // namespace testpropertyutils_impl
+
+#ifdef ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING
+// Converts the system property to the vendor property.
+// WARNING: This is only for the end-to-end testing, Should NOT include in the user build.
+inline constexpr int32_t toVendor(
+ const ::aidl::android::hardware::automotive::vehicle::VehicleProperty& prop) {
+ return (toInt(prop) & ~toInt(testpropertyutils_impl::VehiclePropertyGroup::MASK)) |
+ toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR);
+}
+
+// These properties are used for the end-to-end testing of ClusterHomeService.
+constexpr int32_t VENDOR_CLUSTER_SWITCH_UI = toVendor(
+ ::aidl::android::hardware::automotive::vehicle::VehicleProperty::CLUSTER_SWITCH_UI);
+constexpr int32_t VENDOR_CLUSTER_DISPLAY_STATE =
+ toVendor(::aidl::hardware::automotive::vehicle::VehicleProperty::CLUSTER_DISPLAY_STATE);
+constexpr int32_t VENDOR_CLUSTER_REPORT_STATE =
+ toVendor(::aidl::hardware::automotive::vehicle::VehicleProperty::CLUSTER_REPORT_STATE);
+constexpr int32_t VENDOR_CLUSTER_REQUEST_DISPLAY =
+ toVendor(::aidl::hardware::automotive::vehicle::VehicleProperty::CLUSTER_REQUEST_DISPLAY);
+constexpr int32_t VENDOR_CLUSTER_NAVIGATION_STATE =
+ toVendor(::aidl::hardware::automotive::vehicle::VehicleProperty::CLUSTER_NAVIGATION_STATE);
+#endif // ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING
+
+// These properties are placeholder properties for developers to test new features without
+// implementing a real property.
+constexpr int32_t PLACEHOLDER_PROPERTY_INT =
+ 0x2a11 | toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
+ toInt(testpropertyutils_impl::VehiclePropertyType::INT32);
+constexpr int32_t PLACEHOLDER_PROPERTY_FLOAT =
+ 0x2a11 | toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
+ toInt(testpropertyutils_impl::VehiclePropertyType::FLOAT);
+constexpr int32_t PLACEHOLDER_PROPERTY_BOOLEAN =
+ 0x2a11 | toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
+ toInt(testpropertyutils_impl::VehiclePropertyType::BOOLEAN);
+constexpr int32_t PLACEHOLDER_PROPERTY_STRING =
+ 0x2a11 | toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
+ toInt(testpropertyutils_impl::VehiclePropertyType::STRING);
+
+// This property is used for test purpose. End to end tests use this property to test set and get
+// method for MIXED type properties.
+constexpr int32_t kMixedTypePropertyForTest =
+ 0x1111 | toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR) |
+ toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
+ toInt(testpropertyutils_impl::VehiclePropertyType::MIXED);
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
+
+#endif // android_hardware_automotive_vehicle_utils_test_include_TestPropertyUtils_H_