Overwrite enableVUR to false if not supported.
If VUR is not supported for a specific [propId, areaId], even if
the client enables it, it should be disabled in VHAL.
Test: atest DefaultVehicleHalTest
Bug: 306748801
Change-Id: I52fa9bd3fa6e1230402c23ef1174713816d878fc
diff --git a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
index ee2de6d..d85cc09 100644
--- a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
@@ -695,9 +695,39 @@
if (config.changeMode == VehiclePropertyChangeMode::CONTINUOUS) {
optionCopy.sampleRate = getDefaultSampleRateHz(
optionCopy.sampleRate, config.minSampleRate, config.maxSampleRate);
- // TODO: set this to false if VUR is not supported for the [propId, areaId].
- optionCopy.enableVariableUpdateRate = false;
- continuousSubscriptions.push_back(std::move(optionCopy));
+ if (!optionCopy.enableVariableUpdateRate) {
+ continuousSubscriptions.push_back(std::move(optionCopy));
+ } else {
+ // If clients enables to VUR, we need to check whether VUR is supported for the
+ // specific [propId, areaId] and overwrite the option to disable if not supported.
+ std::vector<int32_t> areasVurEnabled;
+ std::vector<int32_t> areasVurDisabled;
+ for (int32_t areaId : optionCopy.areaIds) {
+ const VehicleAreaConfig* areaConfig = getAreaConfig(propId, areaId, config);
+ if (areaConfig == nullptr) {
+ areasVurDisabled.push_back(areaId);
+ continue;
+ }
+ if (!areaConfig->supportVariableUpdateRate) {
+ areasVurDisabled.push_back(areaId);
+ continue;
+ }
+ areasVurEnabled.push_back(areaId);
+ }
+ if (!areasVurEnabled.empty()) {
+ SubscribeOptions optionVurEnabled = optionCopy;
+ optionVurEnabled.areaIds = areasVurEnabled;
+ optionVurEnabled.enableVariableUpdateRate = true;
+ continuousSubscriptions.push_back(std::move(optionVurEnabled));
+ }
+
+ if (!areasVurDisabled.empty()) {
+ // We use optionCopy for areas with VUR disabled.
+ optionCopy.areaIds = areasVurDisabled;
+ optionCopy.enableVariableUpdateRate = false;
+ continuousSubscriptions.push_back(std::move(optionCopy));
+ }
+ }
} else {
onChangeSubscriptions.push_back(std::move(optionCopy));
}
diff --git a/automotive/vehicle/aidl/impl/vhal/test/DefaultVehicleHalTest.cpp b/automotive/vehicle/aidl/impl/vhal/test/DefaultVehicleHalTest.cpp
index e775612..7195d97 100644
--- a/automotive/vehicle/aidl/impl/vhal/test/DefaultVehicleHalTest.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/test/DefaultVehicleHalTest.cpp
@@ -98,12 +98,22 @@
constexpr int32_t READ_ONLY_PROP = 10006 + 0x10000000 + 0x01000000 + 0x00400000;
// VehiclePropertyGroup:SYSTEM,VehicleArea:GLOBAL,VehiclePropertyType:INT32
constexpr int32_t WRITE_ONLY_PROP = 10007 + 0x10000000 + 0x01000000 + 0x00400000;
+// VehiclePropertyGroup:SYSTEM,VehicleArea:GLOBAL,VehiclePropertyType:INT32
+constexpr int32_t GLOBAL_CONTINUOUS_PROP_NO_VUR = 10008 + 0x10000000 + 0x01000000 + 0x00400000;
int32_t testInt32VecProp(size_t i) {
// VehiclePropertyGroup:SYSTEM,VehicleArea:GLOBAL,VehiclePropertyType:INT32_VEC
return static_cast<int32_t>(i) + 0x10000000 + 0x01000000 + 0x00410000;
}
+std::string toString(const std::vector<SubscribeOptions>& options) {
+ std::string optionsStr;
+ for (const auto& option : options) {
+ optionsStr += option.toString() + "\n";
+ }
+ return optionsStr;
+}
+
struct PropConfigCmp {
bool operator()(const VehiclePropConfig& a, const VehiclePropConfig& b) const {
return (a.prop < b.prop);
@@ -245,8 +255,18 @@
.changeMode = VehiclePropertyChangeMode::ON_CHANGE,
});
// A global continuous property.
+ testConfigs.push_back(VehiclePropConfig{.prop = GLOBAL_CONTINUOUS_PROP,
+ .access = VehiclePropertyAccess::READ_WRITE,
+ .changeMode = VehiclePropertyChangeMode::CONTINUOUS,
+ .minSampleRate = 0.0,
+ .maxSampleRate = 100.0,
+ .areaConfigs = {{
+ .areaId = 0,
+ .supportVariableUpdateRate = true,
+ }}});
+ // A global continuous property that does not support VUR.
testConfigs.push_back(VehiclePropConfig{
- .prop = GLOBAL_CONTINUOUS_PROP,
+ .prop = GLOBAL_CONTINUOUS_PROP_NO_VUR,
.access = VehiclePropertyAccess::READ_WRITE,
.changeMode = VehiclePropertyChangeMode::CONTINUOUS,
.minSampleRate = 0.0,
@@ -286,11 +306,13 @@
.areaId = toInt(VehicleAreaWindow::ROW_1_LEFT),
.minInt32Value = 0,
.maxInt32Value = 100,
+ .supportVariableUpdateRate = true,
},
{
.areaId = toInt(VehicleAreaWindow::ROW_1_RIGHT),
.minInt32Value = 0,
.maxInt32Value = 100,
+ .supportVariableUpdateRate = false,
},
},
});
@@ -1352,6 +1374,62 @@
EXPECT_EQ(countClients(), static_cast<size_t>(1));
}
+TEST_F(DefaultVehicleHalTest, testSubscribeContinuous_propNotSupportVur) {
+ std::vector<SubscribeOptions> options = {
+ {
+ .propId = GLOBAL_CONTINUOUS_PROP,
+ .sampleRate = 20.0,
+ .enableVariableUpdateRate = true,
+ },
+ {
+ .propId = GLOBAL_CONTINUOUS_PROP_NO_VUR,
+ .sampleRate = 30.0,
+ .enableVariableUpdateRate = true,
+ },
+ };
+
+ auto status = getClient()->subscribe(getCallbackClient(), options, 0);
+
+ ASSERT_TRUE(status.isOk()) << "subscribe failed: " << status.getMessage();
+ auto receivedSubscribeOptions = getHardware()->getSubscribeOptions();
+ ASSERT_THAT(receivedSubscribeOptions, UnorderedElementsAre(
+ SubscribeOptions{
+ .propId = GLOBAL_CONTINUOUS_PROP,
+ .areaIds = {0},
+ .enableVariableUpdateRate = true,
+ .sampleRate = 20.0,
+ },
+ SubscribeOptions{
+ .propId = GLOBAL_CONTINUOUS_PROP_NO_VUR,
+ .areaIds = {0},
+ .enableVariableUpdateRate = false,
+ .sampleRate = 30.0,
+ }))
+ << "received unexpected subscribe options: " << toString(receivedSubscribeOptions);
+}
+
+TEST_F(DefaultVehicleHalTest, testSubscribeContinuous_propSupportVurNotEnabled) {
+ std::vector<SubscribeOptions> options = {
+ {
+ .propId = GLOBAL_CONTINUOUS_PROP,
+ .sampleRate = 20.0,
+ .enableVariableUpdateRate = false,
+ },
+ };
+
+ auto status = getClient()->subscribe(getCallbackClient(), options, 0);
+
+ ASSERT_TRUE(status.isOk()) << "subscribe failed: " << status.getMessage();
+ auto receivedSubscribeOptions = getHardware()->getSubscribeOptions();
+ ASSERT_THAT(receivedSubscribeOptions, UnorderedElementsAre(SubscribeOptions{
+ .propId = GLOBAL_CONTINUOUS_PROP,
+ .areaIds = {0},
+ .enableVariableUpdateRate = false,
+ .sampleRate = 20.0,
+ }))
+ << "received unexpected subscribe options: " << toString(receivedSubscribeOptions);
+}
+
TEST_F(DefaultVehicleHalTest, testSubscribeAreaContinuous) {
std::vector<SubscribeOptions> options = {
{
@@ -1404,6 +1482,44 @@
ASSERT_GE(rightCount, static_cast<size_t>(5));
}
+TEST_F(DefaultVehicleHalTest, testAreaContinuous_areaNotSupportVur) {
+ std::vector<SubscribeOptions> options = {
+ {
+ .propId = AREA_CONTINUOUS_PROP,
+ .sampleRate = 20.0,
+ .areaIds = {toInt(VehicleAreaWindow::ROW_1_LEFT)},
+ .enableVariableUpdateRate = true,
+ },
+ {
+ .propId = AREA_CONTINUOUS_PROP,
+ .sampleRate = 10.0,
+ .areaIds = {toInt(VehicleAreaWindow::ROW_1_RIGHT)},
+ .enableVariableUpdateRate = true,
+ },
+ };
+
+ auto status = getClient()->subscribe(getCallbackClient(), options, 0);
+
+ ASSERT_TRUE(status.isOk()) << "subscribe failed: " << status.getMessage();
+ auto receivedSubscribeOptions = getHardware()->getSubscribeOptions();
+ ASSERT_THAT(receivedSubscribeOptions,
+ UnorderedElementsAre(
+ SubscribeOptions{
+ .propId = AREA_CONTINUOUS_PROP,
+ .sampleRate = 20.0,
+ .areaIds = {toInt(VehicleAreaWindow::ROW_1_LEFT)},
+ .enableVariableUpdateRate = true,
+ },
+ SubscribeOptions{
+ .propId = AREA_CONTINUOUS_PROP,
+ .sampleRate = 10.0,
+ .areaIds = {toInt(VehicleAreaWindow::ROW_1_RIGHT)},
+ // Area2 actually does not support VUR.
+ .enableVariableUpdateRate = false,
+ }))
+ << "received unexpected subscribe options: " << toString(receivedSubscribeOptions);
+}
+
TEST_F(DefaultVehicleHalTest, testUnsubscribeOnChange) {
std::vector<SubscribeOptions> options = {
{