Merge changes Ice087a6f,I52fa9bd3,I1a375ab2 into main
* changes:
Fix proto converter and support VUR.
Overwrite enableVUR to false if not supported.
Implement VUR in SubscriptionManager.
diff --git a/automotive/vehicle/TEST_MAPPING b/automotive/vehicle/TEST_MAPPING
index 02ad8bb..e1a90cb 100644
--- a/automotive/vehicle/TEST_MAPPING
+++ b/automotive/vehicle/TEST_MAPPING
@@ -51,6 +51,9 @@
"include-filter": "com.android.car.hal.fakevhal.FakeVehicleStubUnitTest"
}
]
+ },
+ {
+ "name": "VehicleHalProtoMessageConverterTest"
}
]
}
diff --git a/automotive/vehicle/aidl/impl/grpc/utils/proto_message_converter/src/ProtoMessageConverter.cpp b/automotive/vehicle/aidl/impl/grpc/utils/proto_message_converter/src/ProtoMessageConverter.cpp
index 6b789bb..491aa10 100644
--- a/automotive/vehicle/aidl/impl/grpc/utils/proto_message_converter/src/ProtoMessageConverter.cpp
+++ b/automotive/vehicle/aidl/impl/grpc/utils/proto_message_converter/src/ProtoMessageConverter.cpp
@@ -78,6 +78,7 @@
protoACfg->add_supported_enum_values(supportedEnumValue);
}
}
+ protoACfg->set_support_variable_update_rate(areaConfig.supportVariableUpdateRate);
}
}
@@ -100,9 +101,14 @@
.maxInt64Value = protoAcfg.max_int64_value(),
.minFloatValue = protoAcfg.min_float_value(),
.maxFloatValue = protoAcfg.max_float_value(),
+ .supportVariableUpdateRate = protoAcfg.support_variable_update_rate(),
};
- COPY_PROTOBUF_VEC_TO_VHAL_TYPE(protoAcfg, supported_enum_values, (&vehicleAreaConfig),
- supportedEnumValues.value());
+ if (protoAcfg.supported_enum_values().size() != 0) {
+ vehicleAreaConfig.supportedEnumValues = std::vector<int64_t>();
+ COPY_PROTOBUF_VEC_TO_VHAL_TYPE(protoAcfg, supported_enum_values, (&vehicleAreaConfig),
+ supportedEnumValues.value());
+ }
+
return vehicleAreaConfig;
};
CAST_COPY_PROTOBUF_VEC_TO_VHAL_TYPE(in, area_configs, out, areaConfigs, cast_to_acfg);
diff --git a/automotive/vehicle/aidl/impl/hardware/include/IVehicleHardware.h b/automotive/vehicle/aidl/impl/hardware/include/IVehicleHardware.h
index b813b11..f49d91b 100644
--- a/automotive/vehicle/aidl/impl/hardware/include/IVehicleHardware.h
+++ b/automotive/vehicle/aidl/impl/hardware/include/IVehicleHardware.h
@@ -117,18 +117,53 @@
return std::chrono::nanoseconds(0);
}
- // A [propId, areaId] is newly subscribed or the update rate is changed.
+ // A [propId, areaId] is newly subscribed or the subscribe options are changed.
//
- // The 'options' contains the property ID, area ID and sample rate in Hz.
+ // The subscribe options contain sample rate in Hz or enable/disable variable update rate.
//
- // For continuous property, the sample rate is never 0 and indicates the new sample rate (or
- // the initial sample rate if this property was not subscribed before).
+ // For continuous properties:
//
- // For on-change property, the sample rate is always 0 and must be ignored.
+ // The sample rate is never 0 and indicates the desired polling rate for this property. The
+ // sample rate is guaranteed to be within supported {@code minSampleRate} and
+ // {@code maxSampleRate} as specified in {@code VehiclePropConfig}.
+ //
+ // If the specified sample rate is not supported, e.g. vehicle bus only supports 5hz and 10hz
+ // polling rate but the sample rate is 8hz, impl must choose the higher polling rate (10hz).
+ //
+ // Whether variable update rate is enabled is specified by {@code enableVariableUpdateRate} in
+ // {@code SubscribeOptions}. If variable update rate is not supported for the
+ // [propId, areaId], impl must ignore this option and always treat it as disabled.
+ //
+ // If variable update rate is disabled/not supported, impl must report all the property events
+ // for this [propId, areaId] through {@code propertyChangeCallback} according to the sample
+ // rate. E.g. a sample rate of 10hz must generate at least 10 property change events per second.
+ //
+ // If variable update rate is enabled AND supported, impl must only report property events
+ // when the [propId, areaId]'s value or status changes (a.k.a same as on-change property).
+ // The sample rate still guides the polling rate, but duplicate property events must be dropped
+ // and not reported via {@code propertyChangeCallback}.
+ //
+ // Async property set error events are not affected by variable update rate and must always
+ // be reported.
+ //
+ // If the impl is always polling at {@code maxSampleRate} for all continuous [propId, areaId]s,
+ // and do not support variable update rate for any [propId, areaId], then this function can be a
+ // no-op.
+ //
+ // For on-change properties:
+ //
+ // The sample rate is always 0 and must be ignored. If the impl is always subscribing to all
+ // on-change properties, then this function can be no-op.
+ //
+ // For all properties:
+ //
+ // It is recommended to only deliver the subscribed property events to DefaultVehicleHal to
+ // improve performance. However, even if unsubscribed property events are delivered, they
+ // will be filtered out by DefaultVehicleHal.
//
// A subscription from VHAL client might not necessarily trigger this function.
// DefaultVehicleHal will aggregate all the subscriptions from all the clients and notify
- // IVehicleHardware if new subscriptions are required or sample rate is updated.
+ // IVehicleHardware if new subscriptions are required or subscribe options are updated.
//
// For example:
// 1. VHAL initially have no subscriber for speed.
@@ -144,15 +179,6 @@
// 5. The second subscriber is removed, 'unsubscribe' is called.
// The impl can optionally disable the polling for vehicle speed.
//
- // It is recommended to only deliver the subscribed property events to DefaultVehicleHal to
- // improve performance. However, even if unsubscribed property events are delivered, they
- // will be filtered out by DefaultVehicleHal.
- //
- // For continuous property, if the impl is always polling at {@code maxSampleRate} as specified
- // in config, then this function can be a no-op.
- //
- // For on-change property, if the impl is always subscribing to all on-change properties, then
- // this function can be no-op.
virtual aidl::android::hardware::automotive::vehicle::StatusCode subscribe(
[[maybe_unused]] aidl::android::hardware::automotive::vehicle::SubscribeOptions
options) {
diff --git a/automotive/vehicle/aidl/impl/vhal/include/SubscriptionManager.h b/automotive/vehicle/aidl/impl/vhal/include/SubscriptionManager.h
index 057da35..5053c96 100644
--- a/automotive/vehicle/aidl/impl/vhal/include/SubscriptionManager.h
+++ b/automotive/vehicle/aidl/impl/vhal/include/SubscriptionManager.h
@@ -36,20 +36,29 @@
namespace automotive {
namespace vehicle {
+// A structure to represent subscription config for one subscription client.
+struct SubConfig {
+ float sampleRateHz;
+ bool enableVur;
+};
+
// A class to represent all the subscription configs for a continuous [propId, areaId].
class ContSubConfigs final {
public:
using ClientIdType = const AIBinder*;
- void addClient(const ClientIdType& clientId, float sampleRateHz);
+ void addClient(const ClientIdType& clientId, float sampleRateHz, bool enableVur);
void removeClient(const ClientIdType& clientId);
float getMaxSampleRateHz() const;
+ bool isVurEnabled() const;
+ bool isVurEnabledForClient(const ClientIdType& clientId);
private:
float mMaxSampleRateHz = 0.;
- std::unordered_map<ClientIdType, float> mSampleRateHzByClient;
+ bool mEnableVur;
+ std::unordered_map<ClientIdType, SubConfig> mConfigByClient;
- void refreshMaxSampleRateHz();
+ void refreshCombinedConfig();
};
// A thread-safe subscription manager that manages all VHAL subscriptions.
@@ -58,6 +67,7 @@
using ClientIdType = const AIBinder*;
using CallbackType =
std::shared_ptr<aidl::android::hardware::automotive::vehicle::IVehicleCallback>;
+ using VehiclePropValue = aidl::android::hardware::automotive::vehicle::VehiclePropValue;
explicit SubscriptionManager(IVehicleHardware* vehicleHardware);
~SubscriptionManager();
@@ -92,11 +102,8 @@
// For a list of updated properties, returns a map that maps clients subscribing to
// the updated properties to a list of updated values. This would only return on-change property
// clients that should be informed for the given updated values.
- std::unordered_map<CallbackType,
- std::vector<aidl::android::hardware::automotive::vehicle::VehiclePropValue>>
- getSubscribedClients(
- std::vector<aidl::android::hardware::automotive::vehicle::VehiclePropValue>&&
- updatedValues);
+ std::unordered_map<CallbackType, std::vector<VehiclePropValue>> getSubscribedClients(
+ std::vector<VehiclePropValue>&& updatedValues);
// For a list of set property error events, returns a map that maps clients subscribing to the
// properties to a list of errors for each client.
@@ -116,6 +123,21 @@
IVehicleHardware* mVehicleHardware;
+ struct VehiclePropValueHashPropIdAreaId {
+ inline size_t operator()(const VehiclePropValue& vehiclePropValue) const {
+ size_t res = 0;
+ hashCombine(res, vehiclePropValue.prop);
+ hashCombine(res, vehiclePropValue.areaId);
+ return res;
+ }
+ };
+
+ struct VehiclePropValueEqualPropIdAreaId {
+ inline bool operator()(const VehiclePropValue& left, const VehiclePropValue& right) const {
+ return left.prop == right.prop && left.areaId == right.areaId;
+ }
+ };
+
mutable std::mutex mLock;
std::unordered_map<PropIdAreaId, std::unordered_map<ClientIdType, CallbackType>,
PropIdAreaIdHash>
@@ -124,10 +146,15 @@
mSubscribedPropsByClient GUARDED_BY(mLock);
std::unordered_map<PropIdAreaId, ContSubConfigs, PropIdAreaIdHash> mContSubConfigsByPropIdArea
GUARDED_BY(mLock);
+ std::unordered_map<CallbackType,
+ std::unordered_set<VehiclePropValue, VehiclePropValueHashPropIdAreaId,
+ VehiclePropValueEqualPropIdAreaId>>
+ mContSubValuesByCallback GUARDED_BY(mLock);
VhalResult<void> addContinuousSubscriberLocked(const ClientIdType& clientId,
const PropIdAreaId& propIdAreaId,
- float sampleRateHz) REQUIRES(mLock);
+ float sampleRateHz, bool enableVur)
+ REQUIRES(mLock);
VhalResult<void> addOnChangeSubscriberLocked(const PropIdAreaId& propIdAreaId) REQUIRES(mLock);
// Removes the subscription client for the continuous [propId, areaId].
VhalResult<void> removeContinuousSubscriberLocked(const ClientIdType& clientId,
@@ -147,6 +174,9 @@
// Checks whether the manager is empty. For testing purpose.
bool isEmpty();
+ bool isValueUpdatedLocked(const CallbackType& callback, const VehiclePropValue& value)
+ REQUIRES(mLock);
+
// Get the interval in nanoseconds accroding to sample rate.
static android::base::Result<int64_t> getIntervalNanos(float sampleRateHz);
};
diff --git a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
index 111a6ec..d85cc09 100644
--- a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
@@ -695,7 +695,39 @@
if (config.changeMode == VehiclePropertyChangeMode::CONTINUOUS) {
optionCopy.sampleRate = getDefaultSampleRateHz(
optionCopy.sampleRate, config.minSampleRate, config.maxSampleRate);
- 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/src/SubscriptionManager.cpp b/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp
index a7c797b..29d81a7 100644
--- a/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp
@@ -42,11 +42,13 @@
constexpr float ONE_SECOND_IN_NANOS = 1'000'000'000.;
-SubscribeOptions newSubscribeOptions(int32_t propId, int32_t areaId, float sampleRateHz) {
+SubscribeOptions newSubscribeOptions(int32_t propId, int32_t areaId, float sampleRateHz,
+ bool enableVur) {
SubscribeOptions subscribedOptions;
subscribedOptions.propId = propId;
subscribedOptions.areaIds = {areaId};
subscribedOptions.sampleRate = sampleRateHz;
+ subscribedOptions.enableVariableUpdateRate = enableVur;
return subscribedOptions;
}
@@ -79,32 +81,50 @@
return intervalNanos;
}
-void ContSubConfigs::refreshMaxSampleRateHz() {
+void ContSubConfigs::refreshCombinedConfig() {
float maxSampleRateHz = 0.;
+ bool enableVur = true;
// This is not called frequently so a brute-focre is okay. More efficient way exists but this
// is simpler.
- for (const auto& [_, sampleRateHz] : mSampleRateHzByClient) {
- if (sampleRateHz > maxSampleRateHz) {
- maxSampleRateHz = sampleRateHz;
+ for (const auto& [_, subConfig] : mConfigByClient) {
+ if (subConfig.sampleRateHz > maxSampleRateHz) {
+ maxSampleRateHz = subConfig.sampleRateHz;
+ }
+ if (!subConfig.enableVur) {
+ // If one client does not enable variable update rate, we cannot enable variable update
+ // rate in IVehicleHardware.
+ enableVur = false;
}
}
mMaxSampleRateHz = maxSampleRateHz;
+ mEnableVur = enableVur;
}
-void ContSubConfigs::addClient(const ClientIdType& clientId, float sampleRateHz) {
- mSampleRateHzByClient[clientId] = sampleRateHz;
- refreshMaxSampleRateHz();
+void ContSubConfigs::addClient(const ClientIdType& clientId, float sampleRateHz, bool enableVur) {
+ mConfigByClient[clientId] = {
+ .sampleRateHz = sampleRateHz,
+ .enableVur = enableVur,
+ };
+ refreshCombinedConfig();
}
void ContSubConfigs::removeClient(const ClientIdType& clientId) {
- mSampleRateHzByClient.erase(clientId);
- refreshMaxSampleRateHz();
+ mConfigByClient.erase(clientId);
+ refreshCombinedConfig();
}
float ContSubConfigs::getMaxSampleRateHz() const {
return mMaxSampleRateHz;
}
+bool ContSubConfigs::isVurEnabled() const {
+ return mEnableVur;
+}
+
+bool ContSubConfigs::isVurEnabledForClient(const ClientIdType& clientId) {
+ return mConfigByClient[clientId].enableVur;
+}
+
VhalResult<void> SubscriptionManager::addOnChangeSubscriberLocked(
const PropIdAreaId& propIdAreaId) {
if (mClientsByPropIdAreaId.find(propIdAreaId) != mClientsByPropIdAreaId.end()) {
@@ -115,7 +135,7 @@
int32_t propId = propIdAreaId.propId;
int32_t areaId = propIdAreaId.areaId;
if (auto status = mVehicleHardware->subscribe(
- newSubscribeOptions(propId, areaId, /*updateRateHz=*/0));
+ newSubscribeOptions(propId, areaId, /*updateRateHz=*/0, /*enableVur*/ false));
status != StatusCode::OK) {
return StatusError(status)
<< StringPrintf("failed subscribe for prop: %s, areaId: %" PRId32,
@@ -125,10 +145,11 @@
}
VhalResult<void> SubscriptionManager::addContinuousSubscriberLocked(
- const ClientIdType& clientId, const PropIdAreaId& propIdAreaId, float sampleRateHz) {
+ const ClientIdType& clientId, const PropIdAreaId& propIdAreaId, float sampleRateHz,
+ bool enableVur) {
// Make a copy so that we don't modify 'mContSubConfigsByPropIdArea' on failure cases.
ContSubConfigs newConfig = mContSubConfigsByPropIdArea[propIdAreaId];
- newConfig.addClient(clientId, sampleRateHz);
+ newConfig.addClient(clientId, sampleRateHz, enableVur);
return updateContSubConfigsLocked(propIdAreaId, newConfig);
}
@@ -159,24 +180,27 @@
VhalResult<void> SubscriptionManager::updateContSubConfigsLocked(const PropIdAreaId& propIdAreaId,
const ContSubConfigs& newConfig) {
- if (newConfig.getMaxSampleRateHz() ==
- mContSubConfigsByPropIdArea[propIdAreaId].getMaxSampleRateHz()) {
+ const auto& oldConfig = mContSubConfigsByPropIdArea[propIdAreaId];
+ float newRateHz = newConfig.getMaxSampleRateHz();
+ float oldRateHz = oldConfig.getMaxSampleRateHz();
+ if (newRateHz == oldRateHz && newConfig.isVurEnabled() == oldConfig.isVurEnabled()) {
mContSubConfigsByPropIdArea[propIdAreaId] = newConfig;
return {};
}
- float newRateHz = newConfig.getMaxSampleRateHz();
int32_t propId = propIdAreaId.propId;
int32_t areaId = propIdAreaId.areaId;
- if (auto status = mVehicleHardware->updateSampleRate(propId, areaId, newRateHz);
- status != StatusCode::OK) {
- return StatusError(status)
- << StringPrintf("failed to update sample rate for prop: %s, areaId: %" PRId32
- ", sample rate: %f HZ",
- propIdToString(propId).c_str(), areaId, newRateHz);
+ if (newRateHz != oldRateHz) {
+ if (auto status = mVehicleHardware->updateSampleRate(propId, areaId, newRateHz);
+ status != StatusCode::OK) {
+ return StatusError(status)
+ << StringPrintf("failed to update sample rate for prop: %s, areaId: %" PRId32
+ ", sample rate: %f HZ",
+ propIdToString(propId).c_str(), areaId, newRateHz);
+ }
}
if (newRateHz != 0) {
- if (auto status =
- mVehicleHardware->subscribe(newSubscribeOptions(propId, areaId, newRateHz));
+ if (auto status = mVehicleHardware->subscribe(
+ newSubscribeOptions(propId, areaId, newRateHz, newConfig.isVurEnabled()));
status != StatusCode::OK) {
return StatusError(status) << StringPrintf(
"failed subscribe for prop: %s, areaId"
@@ -228,7 +252,8 @@
};
VhalResult<void> result;
if (isContinuousProperty) {
- result = addContinuousSubscriberLocked(clientId, propIdAreaId, option.sampleRate);
+ result = addContinuousSubscriberLocked(clientId, propIdAreaId, option.sampleRate,
+ option.enableVariableUpdateRate);
} else {
result = addOnChangeSubscriberLocked(propIdAreaId);
}
@@ -324,6 +349,34 @@
return {};
}
+bool SubscriptionManager::isValueUpdatedLocked(const std::shared_ptr<IVehicleCallback>& callback,
+ const VehiclePropValue& value) {
+ const auto& it = mContSubValuesByCallback[callback].find(value);
+ if (it == mContSubValuesByCallback[callback].end()) {
+ mContSubValuesByCallback[callback].insert(value);
+ return true;
+ }
+
+ if (it->timestamp > value.timestamp) {
+ ALOGE("The updated property value: %s is outdated, ignored", value.toString().c_str());
+ return false;
+ }
+
+ if (it->value == value.value && it->status == value.status) {
+ // Even though the property value is the same, we need to store the new property event to
+ // update the timestamp.
+ mContSubValuesByCallback[callback].insert(value);
+ ALOGD("The updated property value for propId: %" PRId32 ", areaId: %" PRId32
+ " has the "
+ "same value and status, ignored if VUR is enabled",
+ it->prop, it->areaId);
+ return false;
+ }
+
+ mContSubValuesByCallback[callback].insert(value);
+ return true;
+}
+
std::unordered_map<std::shared_ptr<IVehicleCallback>, std::vector<VehiclePropValue>>
SubscriptionManager::getSubscribedClients(std::vector<VehiclePropValue>&& updatedValues) {
std::scoped_lock<std::mutex> lockGuard(mLock);
@@ -338,8 +391,18 @@
continue;
}
- for (const auto& [_, client] : mClientsByPropIdAreaId[propIdAreaId]) {
- clients[client].push_back(value);
+ for (const auto& [client, callback] : mClientsByPropIdAreaId[propIdAreaId]) {
+ auto& subConfigs = mContSubConfigsByPropIdArea[propIdAreaId];
+ // If client wants VUR (and VUR is supported as checked in DefaultVehicleHal), it is
+ // possible that VUR is not enabled in IVehicleHardware because another client does not
+ // enable VUR. We will implement VUR filtering here for the client that enables it.
+ if (subConfigs.isVurEnabledForClient(client) && !subConfigs.isVurEnabled()) {
+ if (isValueUpdatedLocked(callback, value)) {
+ clients[callback].push_back(value);
+ }
+ } else {
+ clients[callback].push_back(value);
+ }
}
}
return clients;
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 = {
{
diff --git a/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.cpp b/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.cpp
index b64c0d7..db15c89 100644
--- a/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.cpp
@@ -90,6 +90,10 @@
}
StatusCode MockVehicleHardware::subscribe(SubscribeOptions options) {
+ {
+ std::scoped_lock<std::mutex> lockGuard(mLock);
+ mSubscribeOptions.push_back(options);
+ }
for (int32_t areaId : options.areaIds) {
if (auto status = subscribePropIdAreaId(options.propId, areaId, options.sampleRate);
status != StatusCode::OK) {
@@ -99,6 +103,16 @@
return StatusCode::OK;
}
+std::vector<SubscribeOptions> MockVehicleHardware::getSubscribeOptions() {
+ std::scoped_lock<std::mutex> lockGuard(mLock);
+ return mSubscribeOptions;
+}
+
+void MockVehicleHardware::clearSubscribeOptions() {
+ std::scoped_lock<std::mutex> lockGuard(mLock);
+ mSubscribeOptions.clear();
+}
+
StatusCode MockVehicleHardware::subscribePropIdAreaId(int32_t propId, int32_t areaId,
float sampleRateHz) {
if (sampleRateHz == 0) {
diff --git a/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.h b/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.h
index e0d2d66..eeca582 100644
--- a/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.h
+++ b/automotive/vehicle/aidl/impl/vhal/test/MockVehicleHardware.h
@@ -95,6 +95,9 @@
std::set<std::pair<int32_t, int32_t>> getSubscribedOnChangePropIdAreaIds();
std::set<std::pair<int32_t, int32_t>> getSubscribedContinuousPropIdAreaIds();
+ std::vector<aidl::android::hardware::automotive::vehicle::SubscribeOptions>
+ getSubscribeOptions();
+ void clearSubscribeOptions();
private:
mutable std::mutex mLock;
@@ -121,6 +124,8 @@
mGetValueResponder GUARDED_BY(mLock);
std::chrono::nanoseconds mEventBatchingWindow GUARDED_BY(mLock) = std::chrono::nanoseconds(0);
std::set<std::pair<int32_t, int32_t>> mSubOnChangePropIdAreaIds GUARDED_BY(mLock);
+ std::vector<aidl::android::hardware::automotive::vehicle::SubscribeOptions> mSubscribeOptions
+ GUARDED_BY(mLock);
template <class ResultType>
aidl::android::hardware::automotive::vehicle::StatusCode returnResponse(
diff --git a/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp b/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp
index 049ca8b..aa5f003 100644
--- a/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp
@@ -43,10 +43,12 @@
using ::aidl::android::hardware::automotive::vehicle::SetValueResults;
using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropErrors;
+using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropValue;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropValues;
using ::ndk::ScopedAStatus;
using ::ndk::SpAIBinder;
+using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::UnorderedElementsAre;
@@ -518,6 +520,257 @@
ASSERT_FALSE(SubscriptionManager::checkSampleRateHz(0));
}
+TEST_F(SubscriptionManagerTest, testSubscribe_enableVur) {
+ std::vector<SubscribeOptions> options = {{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = true,
+ }};
+
+ auto result = getManager()->subscribe(getCallbackClient(), options, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(), ElementsAre(options[0]));
+}
+
+TEST_F(SubscriptionManagerTest, testSubscribe_VurStateChange) {
+ std::vector<SubscribeOptions> options = {{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = true,
+ }};
+
+ auto result = getManager()->subscribe(getCallbackClient(), options, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(), ElementsAre(options[0]));
+
+ getHardware()->clearSubscribeOptions();
+ result = getManager()->subscribe(getCallbackClient(), options, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_TRUE(getHardware()->getSubscribeOptions().empty());
+
+ std::vector<SubscribeOptions> newOptions = {{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = false,
+ }};
+ result = getManager()->subscribe(getCallbackClient(), newOptions, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(), ElementsAre(newOptions[0]));
+}
+
+TEST_F(SubscriptionManagerTest, testSubscribe_enableVur_filterUnchangedEvents) {
+ SpAIBinder binder1 = ndk::SharedRefBase::make<PropertyCallback>()->asBinder();
+ std::shared_ptr<IVehicleCallback> client1 = IVehicleCallback::fromBinder(binder1);
+ SpAIBinder binder2 = ndk::SharedRefBase::make<PropertyCallback>()->asBinder();
+ std::shared_ptr<IVehicleCallback> client2 = IVehicleCallback::fromBinder(binder2);
+ SubscribeOptions client1Option = {
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = false,
+ };
+ auto result = getManager()->subscribe(client1, {client1Option}, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(), UnorderedElementsAre(client1Option));
+
+ getHardware()->clearSubscribeOptions();
+ SubscribeOptions client2Option = {
+ .propId = 0,
+ .areaIds = {0, 1},
+ .sampleRate = 20.0,
+ .enableVariableUpdateRate = true,
+ };
+
+ result = getManager()->subscribe(client2, {client2Option}, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(),
+ UnorderedElementsAre(
+ SubscribeOptions{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 20.0,
+ // This is enabled for client2, but disabled for client1.
+ .enableVariableUpdateRate = false,
+ },
+ SubscribeOptions{
+ .propId = 0,
+ .areaIds = {1},
+ .sampleRate = 20.0,
+ .enableVariableUpdateRate = true,
+ }));
+
+ std::vector<VehiclePropValue> propertyEvents = {{
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {0}},
+ .timestamp = 1,
+ },
+ {
+ .prop = 0,
+ .areaId = 1,
+ .value = {.int32Values = {1}},
+ .timestamp = 1,
+ }};
+ auto clients =
+ getManager()->getSubscribedClients(std::vector<VehiclePropValue>(propertyEvents));
+
+ ASSERT_THAT(clients[client1], UnorderedElementsAre(propertyEvents[0]));
+ ASSERT_THAT(clients[client2], UnorderedElementsAre(propertyEvents[0], propertyEvents[1]));
+
+ // If the same property events happen again with a new timestamp.
+ // VUR is disabled for client1, enabled for client2.
+ clients = getManager()->getSubscribedClients({{
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {0}},
+ .timestamp = 2,
+ }});
+
+ ASSERT_FALSE(clients.find(client1) == clients.end())
+ << "Must not filter out property events if VUR is not enabled";
+ ASSERT_TRUE(clients.find(client2) == clients.end())
+ << "Must filter out property events if VUR is enabled";
+}
+
+TEST_F(SubscriptionManagerTest, testSubscribe_enableVur_mustNotFilterStatusChange) {
+ SpAIBinder binder1 = ndk::SharedRefBase::make<PropertyCallback>()->asBinder();
+ std::shared_ptr<IVehicleCallback> client1 = IVehicleCallback::fromBinder(binder1);
+ SpAIBinder binder2 = ndk::SharedRefBase::make<PropertyCallback>()->asBinder();
+ std::shared_ptr<IVehicleCallback> client2 = IVehicleCallback::fromBinder(binder2);
+ SubscribeOptions client1Option = {
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = false,
+ };
+ auto result = getManager()->subscribe(client1, {client1Option}, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(), UnorderedElementsAre(client1Option));
+
+ getHardware()->clearSubscribeOptions();
+ SubscribeOptions client2Option = {
+ .propId = 0,
+ .areaIds = {0, 1},
+ .sampleRate = 20.0,
+ .enableVariableUpdateRate = true,
+ };
+
+ result = getManager()->subscribe(client2, {client2Option}, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ ASSERT_THAT(getHardware()->getSubscribeOptions(),
+ UnorderedElementsAre(
+ SubscribeOptions{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 20.0,
+ // This is enabled for client2, but disabled for client1.
+ .enableVariableUpdateRate = false,
+ },
+ SubscribeOptions{
+ .propId = 0,
+ .areaIds = {1},
+ .sampleRate = 20.0,
+ .enableVariableUpdateRate = true,
+ }));
+
+ VehiclePropValue propValue1 = {
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {0}},
+ .timestamp = 1,
+ };
+ auto clients = getManager()->getSubscribedClients(std::vector<VehiclePropValue>({propValue1}));
+
+ ASSERT_THAT(clients[client1], UnorderedElementsAre(propValue1));
+
+ // A new event with the same value, but different status must not be filtered out.
+ VehiclePropValue propValue2 = {
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {0}},
+ .status = VehiclePropertyStatus::UNAVAILABLE,
+ .timestamp = 2,
+ };
+ clients = getManager()->getSubscribedClients({propValue2});
+
+ ASSERT_THAT(clients[client1], UnorderedElementsAre(propValue2))
+ << "Must not filter out property events that has status change";
+}
+
+TEST_F(SubscriptionManagerTest, testSubscribe_enableVur_timestampUpdated_filterOutdatedEvent) {
+ SpAIBinder binder1 = ndk::SharedRefBase::make<PropertyCallback>()->asBinder();
+ std::shared_ptr<IVehicleCallback> client1 = IVehicleCallback::fromBinder(binder1);
+ SpAIBinder binder2 = ndk::SharedRefBase::make<PropertyCallback>()->asBinder();
+ std::shared_ptr<IVehicleCallback> client2 = IVehicleCallback::fromBinder(binder2);
+ std::vector<SubscribeOptions> options = {{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = true,
+ }};
+
+ // client1 subscribe with VUR enabled.
+ auto result = getManager()->subscribe(client1, options, true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ // Let client2 subscribe with VUR disabled so that we enabled VUR in DefaultVehicleHal layer.
+ result = getManager()->subscribe(client2,
+ {{
+ .propId = 0,
+ .areaIds = {0},
+ .sampleRate = 10.0,
+ .enableVariableUpdateRate = false,
+ }},
+ true);
+ ASSERT_TRUE(result.ok()) << "failed to subscribe: " << result.error().message();
+
+ VehiclePropValue value0 = {
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {0}},
+ .timestamp = 1,
+ };
+ auto clients = getManager()->getSubscribedClients({value0});
+
+ ASSERT_THAT(clients[client1], UnorderedElementsAre(value0));
+
+ // A new event with the same value arrived. This must update timestamp to 3.
+ VehiclePropValue value1 = {
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {0}},
+ .timestamp = 3,
+ };
+ clients = getManager()->getSubscribedClients({value1});
+
+ ASSERT_TRUE(clients.find(client1) == clients.end())
+ << "Must filter out duplicate property events if VUR is enabled";
+
+ // The latest timestamp is 3, so even though the value is not the same, this is outdated and
+ // must be ignored.
+ VehiclePropValue value2 = {
+ .prop = 0,
+ .areaId = 0,
+ .value = {.int32Values = {1}},
+ .timestamp = 2,
+ };
+ clients = getManager()->getSubscribedClients({value1});
+
+ ASSERT_TRUE(clients.find(client1) == clients.end())
+ << "Must filter out outdated property events if VUR is enabled";
+}
+
} // namespace vehicle
} // namespace automotive
} // namespace hardware