Fix empty array object obtain.

Test: atest VehicleHalVehicleUtilsTest
Bug: 316432606
Change-Id: I6b2009cf3e96be33cc4abdfaa4c781b46a0f49f8
This commit is contained in:
Yu Shan
2023-12-14 17:28:35 -08:00
parent bdea4eaf7f
commit bd65531e3b
4 changed files with 15 additions and 9 deletions

View File

@@ -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(

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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.