Merge changes I78968aec,I346a809f into main
* changes:
Fix resource mgmt bug in SubscriptionManager.
Implement get supported values for FakeVehicleHardware.
diff --git a/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/src/JsonConfigLoader.cpp b/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/src/JsonConfigLoader.cpp
index 7a1f0e0..f910beb 100644
--- a/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/src/JsonConfigLoader.cpp
+++ b/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/src/JsonConfigLoader.cpp
@@ -58,6 +58,7 @@
using ::aidl::android::hardware::automotive::vehicle::GsrComplianceRequirementType;
using ::aidl::android::hardware::automotive::vehicle::HandsOnDetectionDriverState;
using ::aidl::android::hardware::automotive::vehicle::HandsOnDetectionWarning;
+using ::aidl::android::hardware::automotive::vehicle::HasSupportedValueInfo;
using ::aidl::android::hardware::automotive::vehicle::ImpactSensorLocation;
using ::aidl::android::hardware::automotive::vehicle::LaneCenteringAssistCommand;
using ::aidl::android::hardware::automotive::vehicle::LaneCenteringAssistState;
@@ -600,6 +601,22 @@
if (!supportedEnumValues.empty()) {
areaConfig.supportedEnumValues = std::move(supportedEnumValues);
}
+
+ if (jsonAreaConfig.isMember("hasSupportedValueInfo")) {
+ HasSupportedValueInfo hasSupportedValueInfo = HasSupportedValueInfo{};
+ const Json::Value& jsonHasSupportedValueInfo = jsonAreaConfig["hasSupportedValueInfo"];
+ tryParseJsonValueToVariable(jsonHasSupportedValueInfo, "hasMinSupportedValue",
+ /*optional=*/true,
+ &hasSupportedValueInfo.hasMinSupportedValue, errors);
+ tryParseJsonValueToVariable(jsonHasSupportedValueInfo, "hasMaxSupportedValue",
+ /*optional=*/true,
+ &hasSupportedValueInfo.hasMaxSupportedValue, errors);
+ tryParseJsonValueToVariable(jsonHasSupportedValueInfo, "hasSupportedValuesList",
+ /*optional=*/true,
+ &hasSupportedValueInfo.hasSupportedValuesList, errors);
+ areaConfig.hasSupportedValueInfo = std::move(hasSupportedValueInfo);
+ }
+
config->config.areaConfigs.push_back(std::move(areaConfig));
RawPropValues areaValue = {};
diff --git a/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/test/JsonConfigLoaderUnitTest.cpp b/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/test/JsonConfigLoaderUnitTest.cpp
index 54afbd4..595c2ed 100644
--- a/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/test/JsonConfigLoaderUnitTest.cpp
+++ b/automotive/vehicle/aidl/impl/current/default_config/JsonConfigLoader/test/JsonConfigLoaderUnitTest.cpp
@@ -26,6 +26,7 @@
namespace automotive {
namespace vehicle {
+using ::aidl::android::hardware::automotive::vehicle::HasSupportedValueInfo;
using ::aidl::android::hardware::automotive::vehicle::RawPropValues;
using ::aidl::android::hardware::automotive::vehicle::VehicleAreaConfig;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig;
@@ -803,6 +804,108 @@
ASSERT_EQ(areaConfig2.areaId, 1);
}
+TEST_F(JsonConfigLoaderUnitTest, testHasSupportedValueInfo_allTrue) {
+ std::istringstream iss(R"(
+ {
+ "properties": [{
+ "property": "VehicleProperty::CABIN_LIGHTS_SWITCH",
+ "areas": [{
+ "access": "VehiclePropertyAccess::WRITE",
+ "areaId": 0,
+ "hasSupportedValueInfo": {
+ "hasMinSupportedValue": true,
+ "hasMaxSupportedValue": true,
+ "hasSupportedValuesList": true
+ }
+ }],
+ "access": "VehiclePropertyAccess::READ",
+ }]
+ }
+ )");
+
+ auto result = mLoader.loadPropConfig(iss);
+ ASSERT_TRUE(result.ok());
+
+ auto configs = result.value();
+ ASSERT_EQ(configs.size(), 1u);
+
+ const VehiclePropConfig& config = configs.begin()->second.config;
+ ASSERT_EQ(config.access, VehiclePropertyAccess::READ);
+ ASSERT_EQ(config.areaConfigs.size(), 1u);
+
+ const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
+ ASSERT_EQ(areaConfig.hasSupportedValueInfo, HasSupportedValueInfo({
+ .hasMinSupportedValue = true,
+ .hasMaxSupportedValue = true,
+ .hasSupportedValuesList = true,
+ }));
+}
+
+TEST_F(JsonConfigLoaderUnitTest, testHasSupportedValueInfo_allFalse) {
+ std::istringstream iss(R"(
+ {
+ "properties": [{
+ "property": "VehicleProperty::CABIN_LIGHTS_SWITCH",
+ "areas": [{
+ "access": "VehiclePropertyAccess::WRITE",
+ "areaId": 0,
+ "hasSupportedValueInfo": {
+ "hasMinSupportedValue": false,
+ "hasMaxSupportedValue": false,
+ "hasSupportedValuesList": false
+ }
+ }],
+ "access": "VehiclePropertyAccess::READ",
+ }]
+ }
+ )");
+
+ auto result = mLoader.loadPropConfig(iss);
+ ASSERT_TRUE(result.ok());
+
+ auto configs = result.value();
+ ASSERT_EQ(configs.size(), 1u);
+
+ const VehiclePropConfig& config = configs.begin()->second.config;
+ ASSERT_EQ(config.access, VehiclePropertyAccess::READ);
+ ASSERT_EQ(config.areaConfigs.size(), 1u);
+
+ const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
+ ASSERT_EQ(areaConfig.hasSupportedValueInfo, HasSupportedValueInfo({
+ .hasMinSupportedValue = false,
+ .hasMaxSupportedValue = false,
+ .hasSupportedValuesList = false,
+ }));
+}
+
+TEST_F(JsonConfigLoaderUnitTest, testHasSupportedValueInfo_unspecified) {
+ std::istringstream iss(R"(
+ {
+ "properties": [{
+ "property": "VehicleProperty::CABIN_LIGHTS_SWITCH",
+ "areas": [{
+ "access": "VehiclePropertyAccess::WRITE",
+ "areaId": 0
+ }],
+ "access": "VehiclePropertyAccess::READ",
+ }]
+ }
+ )");
+
+ auto result = mLoader.loadPropConfig(iss);
+ ASSERT_TRUE(result.ok());
+
+ auto configs = result.value();
+ ASSERT_EQ(configs.size(), 1u);
+
+ const VehiclePropConfig& config = configs.begin()->second.config;
+ ASSERT_EQ(config.access, VehiclePropertyAccess::READ);
+ ASSERT_EQ(config.areaConfigs.size(), 1u);
+
+ const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
+ ASSERT_EQ(areaConfig.hasSupportedValueInfo, std::nullopt);
+}
+
} // namespace vehicle
} // namespace automotive
} // namespace hardware
diff --git a/automotive/vehicle/aidl/impl/current/default_config/config/TestProperties.json b/automotive/vehicle/aidl/impl/current/default_config/config/TestProperties.json
index 73e4d44..83debf7 100644
--- a/automotive/vehicle/aidl/impl/current/default_config/config/TestProperties.json
+++ b/automotive/vehicle/aidl/impl/current/default_config/config/TestProperties.json
@@ -99,12 +99,15 @@
{
"defaultValue": {
"int32Values": [
- 1
+ 2
]
},
"areaId": "VehicleAreaWindow::FRONT_WINDSHIELD",
- "minInt32Value": -100,
- "maxInt32Value": 100
+ "hasSupportedValueInfo": {
+ "hasMinSupportedValue": true,
+ "hasMaxSupportedValue": true,
+ "hasSupportedValuesList": true
+ }
},
{
"defaultValue": {
diff --git a/automotive/vehicle/aidl/impl/current/fake_impl/hardware/include/FakeVehicleHardware.h b/automotive/vehicle/aidl/impl/current/fake_impl/hardware/include/FakeVehicleHardware.h
index 5916307..b7ada62 100644
--- a/automotive/vehicle/aidl/impl/current/fake_impl/hardware/include/FakeVehicleHardware.h
+++ b/automotive/vehicle/aidl/impl/current/fake_impl/hardware/include/FakeVehicleHardware.h
@@ -108,6 +108,12 @@
aidl::android::hardware::automotive::vehicle::StatusCode unsubscribe(int32_t propId,
int32_t areaId) override;
+ std::vector<aidlvhal::MinMaxSupportedValueResult> getMinMaxSupportedValues(
+ const std::vector<PropIdAreaId>& propIdAreaIds) override;
+
+ std::vector<aidlvhal::SupportedValuesListResult> getSupportedValuesLists(
+ const std::vector<PropIdAreaId>& propIdAreaIds) override;
+
protected:
// mValuePool is also used in mServerSidePropStore.
const std::shared_ptr<VehiclePropValuePool> mValuePool;
diff --git a/automotive/vehicle/aidl/impl/current/fake_impl/hardware/src/FakeVehicleHardware.cpp b/automotive/vehicle/aidl/impl/current/fake_impl/hardware/src/FakeVehicleHardware.cpp
index 52daf68..f1aaefc 100644
--- a/automotive/vehicle/aidl/impl/current/fake_impl/hardware/src/FakeVehicleHardware.cpp
+++ b/automotive/vehicle/aidl/impl/current/fake_impl/hardware/src/FakeVehicleHardware.cpp
@@ -62,11 +62,13 @@
using ::aidl::android::hardware::automotive::vehicle::ErrorState;
using ::aidl::android::hardware::automotive::vehicle::GetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::GetValueResult;
+using ::aidl::android::hardware::automotive::vehicle::MinMaxSupportedValueResult;
using ::aidl::android::hardware::automotive::vehicle::RawPropValues;
using ::aidl::android::hardware::automotive::vehicle::SetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::SetValueResult;
using ::aidl::android::hardware::automotive::vehicle::StatusCode;
using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
+using ::aidl::android::hardware::automotive::vehicle::SupportedValuesListResult;
using ::aidl::android::hardware::automotive::vehicle::toString;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq;
@@ -2299,6 +2301,62 @@
return StatusCode::OK;
}
+std::vector<MinMaxSupportedValueResult> FakeVehicleHardware::getMinMaxSupportedValues(
+ const std::vector<PropIdAreaId>& propIdAreaIds) {
+ std::vector<MinMaxSupportedValueResult> results;
+ // We only support VENDOR_EXTENSION_INT_PROPERTY
+ for (const auto& propIdAreaId : propIdAreaIds) {
+ int propId = propIdAreaId.propId;
+ int areaId = propIdAreaId.areaId;
+ if (propId != toInt(TestVendorProperty::VENDOR_EXTENSION_INT_PROPERTY)) {
+ results.push_back(MinMaxSupportedValueResult{
+ .status = StatusCode::INVALID_ARG,
+ });
+ continue;
+ }
+ results.push_back(MinMaxSupportedValueResult{
+ .status = StatusCode::OK,
+ .minSupportedValue =
+ RawPropValues{
+ .int32Values = {0},
+ },
+ .maxSupportedValue =
+ RawPropValues{
+ .int32Values = {10},
+ },
+ });
+ }
+ return results;
+}
+
+std::vector<SupportedValuesListResult> FakeVehicleHardware::getSupportedValuesLists(
+ const std::vector<PropIdAreaId>& propIdAreaIds) {
+ std::vector<SupportedValuesListResult> results;
+ // We only support VENDOR_EXTENSION_INT_PROPERTY
+ for (const auto& propIdAreaId : propIdAreaIds) {
+ int propId = propIdAreaId.propId;
+ int areaId = propIdAreaId.areaId;
+ if (propId != toInt(TestVendorProperty::VENDOR_EXTENSION_INT_PROPERTY)) {
+ results.push_back(SupportedValuesListResult{
+ .status = StatusCode::INVALID_ARG,
+ });
+ continue;
+ }
+ results.push_back(SupportedValuesListResult{
+ .status = StatusCode::OK,
+ .supportedValuesList = std::vector<std::optional<RawPropValues>>({
+ RawPropValues{.int32Values = {0}},
+ RawPropValues{.int32Values = {2}},
+ RawPropValues{.int32Values = {4}},
+ RawPropValues{.int32Values = {6}},
+ RawPropValues{.int32Values = {8}},
+ RawPropValues{.int32Values = {10}},
+ }),
+ });
+ }
+ return results;
+}
+
bool FakeVehicleHardware::isVariableUpdateRateSupported(const VehiclePropConfig& vehiclePropConfig,
int32_t areaId) {
for (size_t i = 0; i < vehiclePropConfig.areaConfigs.size(); i++) {
diff --git a/automotive/vehicle/aidl/impl/current/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp b/automotive/vehicle/aidl/impl/current/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp
index f6098ca..29a690b 100644
--- a/automotive/vehicle/aidl/impl/current/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp
+++ b/automotive/vehicle/aidl/impl/current/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp
@@ -3884,6 +3884,44 @@
}
}
+TEST_F(FakeVehicleHardwareTest, testGetMinMaxSupportedValues) {
+ auto results = getHardware()->getMinMaxSupportedValues({
+ PropIdAreaId{.propId = toInt(TestVendorProperty::VENDOR_EXTENSION_INT_PROPERTY),
+ .areaId = 0},
+ PropIdAreaId{.propId = toInt(VehicleProperty::HVAC_TEMPERATURE_SET), .areaId = 0},
+ });
+
+ ASSERT_EQ(results.size(), 2u);
+ EXPECT_EQ(results[0].status, StatusCode::OK);
+ EXPECT_NE(results[0].minSupportedValue, std::nullopt);
+ EXPECT_EQ(results[0].minSupportedValue.value(), RawPropValues{.int32Values = {0}});
+ EXPECT_NE(results[0].maxSupportedValue, std::nullopt);
+ EXPECT_EQ(results[0].maxSupportedValue.value(), RawPropValues{.int32Values = {10}});
+ EXPECT_EQ(results[1].status, StatusCode::INVALID_ARG);
+}
+
+TEST_F(FakeVehicleHardwareTest, testGetSupportedValuesLists) {
+ auto results = getHardware()->getSupportedValuesLists({
+ PropIdAreaId{.propId = toInt(TestVendorProperty::VENDOR_EXTENSION_INT_PROPERTY),
+ .areaId = 0},
+ PropIdAreaId{.propId = toInt(VehicleProperty::HVAC_TEMPERATURE_SET), .areaId = 0},
+ });
+
+ ASSERT_EQ(results.size(), 2u);
+ EXPECT_EQ(results[0].status, StatusCode::OK);
+ EXPECT_NE(results[0].supportedValuesList, std::nullopt);
+ EXPECT_NE((results[0].supportedValuesList)->size(), 0u);
+ EXPECT_EQ(results[0].supportedValuesList.value(), std::vector<std::optional<RawPropValues>>({
+ RawPropValues{.int32Values = {0}},
+ RawPropValues{.int32Values = {2}},
+ RawPropValues{.int32Values = {4}},
+ RawPropValues{.int32Values = {6}},
+ RawPropValues{.int32Values = {8}},
+ RawPropValues{.int32Values = {10}},
+ }));
+ EXPECT_EQ(results[1].status, StatusCode::INVALID_ARG);
+}
+
} // namespace fake
} // namespace vehicle
} // namespace automotive
diff --git a/automotive/vehicle/aidl/impl/current/vhal/include/DefaultVehicleHal.h b/automotive/vehicle/aidl/impl/current/vhal/include/DefaultVehicleHal.h
index 42902fe..d360be0 100644
--- a/automotive/vehicle/aidl/impl/current/vhal/include/DefaultVehicleHal.h
+++ b/automotive/vehicle/aidl/impl/current/vhal/include/DefaultVehicleHal.h
@@ -219,7 +219,7 @@
// mBinderEvents.
void onBinderDiedUnlinkedHandler();
- size_t countSubscribeClients();
+ size_t countClients();
// Handles the property change events in batch.
void handleBatchedPropertyEvents(std::vector<aidlvhal::VehiclePropValue>&& batchedEvents);
diff --git a/automotive/vehicle/aidl/impl/current/vhal/include/SubscriptionManager.h b/automotive/vehicle/aidl/impl/current/vhal/include/SubscriptionManager.h
index fa438ec..f4e6ced 100644
--- a/automotive/vehicle/aidl/impl/current/vhal/include/SubscriptionManager.h
+++ b/automotive/vehicle/aidl/impl/current/vhal/include/SubscriptionManager.h
@@ -146,6 +146,7 @@
private:
// Friend class for testing.
friend class DefaultVehicleHalTest;
+ friend class SubscriptionManagerTest;
IVehicleHardware* mVehicleHardware;
diff --git a/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp b/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp
index 050f88d..ea0c215 100644
--- a/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp
+++ b/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp
@@ -1336,15 +1336,19 @@
dprintf(fd, "Containing %zu property configs\n", configsByPropIdCopy.size());
dprintf(fd, "Currently have %zu getValues clients\n", mGetValuesClients.size());
dprintf(fd, "Currently have %zu setValues clients\n", mSetValuesClients.size());
- dprintf(fd, "Currently have %zu subscribe clients\n", countSubscribeClients());
+ dprintf(fd, "Currently have %zu subscribe clients\n",
+ mSubscriptionManager->countPropertyChangeClients());
dprintf(fd, "Currently have %zu supported values change subscribe clients\n",
mSubscriptionManager->countSupportedValueChangeClients());
}
return STATUS_OK;
}
-size_t DefaultVehicleHal::countSubscribeClients() {
- return mSubscriptionManager->countPropertyChangeClients();
+size_t DefaultVehicleHal::countClients() {
+ std::scoped_lock<std::mutex> lockGuard(mLock);
+ return mGetValuesClients.size() + mSetValuesClients.size() +
+ mSubscriptionManager->countPropertyChangeClients() +
+ mSubscriptionManager->countSupportedValueChangeClients();
}
} // namespace vehicle
diff --git a/automotive/vehicle/aidl/impl/current/vhal/src/SubscriptionManager.cpp b/automotive/vehicle/aidl/impl/current/vhal/src/SubscriptionManager.cpp
index 946c217..64c46c9 100644
--- a/automotive/vehicle/aidl/impl/current/vhal/src/SubscriptionManager.cpp
+++ b/automotive/vehicle/aidl/impl/current/vhal/src/SubscriptionManager.cpp
@@ -414,7 +414,6 @@
std::scoped_lock<std::mutex> lockGuard(mLock);
ClientIdType clientId = callback->asBinder().get();
- ALOGE("ClientId: %p", clientId);
// It is possible that some of the [propId, areaId]s are already subscribed, IVehicleHardware
// will ignore them.
@@ -479,7 +478,7 @@
mSupportedValueChangeClientsByPropIdAreaId.end()) {
mSupportedValueChangeClientsByPropIdAreaId[propIdAreaId].erase(clientId);
}
- if (mSupportedValueChangeClientsByPropIdAreaId.empty()) {
+ if (mSupportedValueChangeClientsByPropIdAreaId[propIdAreaId].empty()) {
mSupportedValueChangeClientsByPropIdAreaId.erase(propIdAreaId);
}
mSupportedValueChangePropIdAreaIdsByClient[clientId].erase(propIdAreaId);
diff --git a/automotive/vehicle/aidl/impl/current/vhal/test/DefaultVehicleHalTest.cpp b/automotive/vehicle/aidl/impl/current/vhal/test/DefaultVehicleHalTest.cpp
index 90b34c4..ab5f667 100644
--- a/automotive/vehicle/aidl/impl/current/vhal/test/DefaultVehicleHalTest.cpp
+++ b/automotive/vehicle/aidl/impl/current/vhal/test/DefaultVehicleHalTest.cpp
@@ -445,11 +445,7 @@
size_t countPendingRequests() { return mVhal->mPendingRequestPool->countPendingRequests(); }
- size_t countClients() {
- std::scoped_lock<std::mutex> lockGuard(mVhal->mLock);
- return mVhal->mGetValuesClients.size() + mVhal->mSetValuesClients.size() +
- mVhal->countSubscribeClients();
- }
+ size_t countClients() { return mVhal->countClients(); }
std::shared_ptr<PendingRequestPool> getPool() { return mVhal->mPendingRequestPool; }
@@ -2575,8 +2571,10 @@
ASSERT_TRUE(status.isOk()) << "Get non-okay status from unregisterSupportedValueChangeCallback"
<< status.getMessage();
- ASSERT_TRUE(getHardware()->getSubscribedSupportedValueChangePropIdAreaIds().empty())
+ EXPECT_TRUE(getHardware()->getSubscribedSupportedValueChangePropIdAreaIds().empty())
<< "All registered [propId, areaId]s must be unregistered";
+ EXPECT_EQ(countClients(), static_cast<size_t>(0)) << "subscribe clients must be cleared";
+ EXPECT_TRUE(hasNoSubscriptions()) << "subscribe clients must be cleared";
}
TEST_F(DefaultVehicleHalTest, testUnregisterSupportedValueChangeCallback_errorFromHardware) {
diff --git a/automotive/vehicle/aidl/impl/current/vhal/test/SubscriptionManagerTest.cpp b/automotive/vehicle/aidl/impl/current/vhal/test/SubscriptionManagerTest.cpp
index 6d0844a..d624cce 100644
--- a/automotive/vehicle/aidl/impl/current/vhal/test/SubscriptionManagerTest.cpp
+++ b/automotive/vehicle/aidl/impl/current/vhal/test/SubscriptionManagerTest.cpp
@@ -124,6 +124,8 @@
std::shared_ptr<MockVehicleHardware> getHardware() { return mHardware; }
+ bool isEmpty() { return mManager->isEmpty(); }
+
private:
std::unique_ptr<SubscriptionManager> mManager;
std::shared_ptr<PropertyCallback> mCallback;
@@ -946,6 +948,19 @@
<< "Incorrect supported value change events for client1";
ASSERT_THAT(clients[client2], UnorderedElementsAre(propIdAreaId2))
<< "Incorrect supported value change events for client2";
+
+ result = getManager()->unsubscribeSupportedValueChange(binder2.get(), {propIdAreaId2});
+
+ ASSERT_TRUE(result.ok()) << "failed to call unsubscribeSupportedValueChange"
+ << result.error().message();
+
+ result = getManager()->unsubscribeSupportedValueChange(binder1.get(), {propIdAreaId1});
+
+ ASSERT_TRUE(result.ok()) << "failed to call unsubscribeSupportedValueChange"
+ << result.error().message();
+
+ EXPECT_EQ(getManager()->countSupportedValueChangeClients(), 0u) << "All clients cleared";
+ EXPECT_TRUE(isEmpty()) << "All clients cleared";
}
} // namespace vehicle