From bd65531e3b2f7900437af902f07d032f0e617d97 Mon Sep 17 00:00:00 2001 From: Yu Shan Date: Thu, 14 Dec 2023 17:28:35 -0800 Subject: [PATCH] Fix empty array object obtain. Test: atest VehicleHalVehicleUtilsTest Bug: 316432606 Change-Id: I6b2009cf3e96be33cc4abdfaa4c781b46a0f49f8 --- .../impl/utils/common/include/VehicleObjectPool.h | 2 +- .../aidl/impl/utils/common/include/VehicleUtils.h | 1 - .../impl/utils/common/src/VehicleObjectPool.cpp | 7 ------- .../utils/common/test/VehicleObjectPoolTest.cpp | 14 ++++++++++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehicleObjectPool.h b/automotive/vehicle/aidl/impl/utils/common/include/VehicleObjectPool.h index 6e812d1d40..501ce40b38 100644 --- a/automotive/vehicle/aidl/impl/utils/common/include/VehicleObjectPool.h +++ b/automotive/vehicle/aidl/impl/utils/common/include/VehicleObjectPool.h @@ -235,7 +235,7 @@ class VehiclePropValuePool { bool isDisposable(aidl::android::hardware::automotive::vehicle::VehiclePropertyType type, size_t vectorSize) const { - return vectorSize > mMaxRecyclableVectorSize || isComplexType(type); + return vectorSize == 0 || vectorSize > mMaxRecyclableVectorSize || isComplexType(type); } RecyclableType obtainDisposable( diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h b/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h index 546421e109..523cac527e 100644 --- a/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h +++ b/automotive/vehicle/aidl/impl/utils/common/include/VehicleUtils.h @@ -124,7 +124,6 @@ createVehiclePropValueVec(aidl::android::hardware::automotive::vehicle::VehicleP break; // Valid, but nothing to do. default: ALOGE("createVehiclePropValue: unknown type: %d", toInt(type)); - val.reset(nullptr); } return val; } diff --git a/automotive/vehicle/aidl/impl/utils/common/src/VehicleObjectPool.cpp b/automotive/vehicle/aidl/impl/utils/common/src/VehicleObjectPool.cpp index 2480a7362e..7e0276739e 100644 --- a/automotive/vehicle/aidl/impl/utils/common/src/VehicleObjectPool.cpp +++ b/automotive/vehicle/aidl/impl/utils/common/src/VehicleObjectPool.cpp @@ -55,13 +55,6 @@ VehiclePropValuePool::RecyclableType VehiclePropValuePool::obtain(const VehicleP int propId = src.prop; VehiclePropertyType type = getPropType(propId); size_t vectorSize = getVehicleRawValueVectorSize(src.value, type); - if (vectorSize == 0 && !isComplexType(type)) { - ALOGW("empty vehicle prop value, contains no content"); - ALOGW("empty vehicle prop value, contains no content, prop: %d", propId); - // Return any empty VehiclePropValue. - return RecyclableType{new VehiclePropValue{}, mDisposableDeleter}; - } - auto dest = obtain(type, vectorSize); dest->prop = propId; diff --git a/automotive/vehicle/aidl/impl/utils/common/test/VehicleObjectPoolTest.cpp b/automotive/vehicle/aidl/impl/utils/common/test/VehicleObjectPoolTest.cpp index a62532c911..6226e8943c 100644 --- a/automotive/vehicle/aidl/impl/utils/common/test/VehicleObjectPoolTest.cpp +++ b/automotive/vehicle/aidl/impl/utils/common/test/VehicleObjectPoolTest.cpp @@ -267,6 +267,20 @@ TEST_F(VehicleObjectPoolTest, testObtainCopyInt32Values) { ASSERT_EQ(*gotValue, prop); } +TEST_F(VehicleObjectPoolTest, testObtainCopyInt32ValuesEmptyArray) { + VehiclePropValue prop{ + // INT32_VEC property. + .prop = toInt(VehicleProperty::INFO_FUEL_TYPE), + .areaId = 2, + .timestamp = 3, + .value = {.int32Values = {}}, + }; + auto gotValue = mValuePool->obtain(prop); + + ASSERT_NE(gotValue, nullptr); + ASSERT_EQ(*gotValue, prop); +} + TEST_F(VehicleObjectPoolTest, testObtainCopyInt64Values) { VehiclePropValue prop{ // INT64_VEC property.