Fix empty array object obtain.
Test: atest VehicleHalVehicleUtilsTest
Bug: 316432606
Change-Id: I6b2009cf3e96be33cc4abdfaa4c781b46a0f49f8
diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehicleObjectPool.h b/automotive/vehicle/aidl/impl/utils/common/include/VehicleObjectPool.h
index 6e812d1..501ce40 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 @@
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 546421e..523cac5 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 @@
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 2480a73..7e02767 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 @@
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 a62532c..6226e89 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 @@
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.