Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae629f86 authored by Yu Shan's avatar Yu Shan
Browse files

Implement supported value change callback.

Implement supported value change callback in DefaultVehicleHal
and SubscriptionManager.

Flag: EXEMPT HAL change
Test: atest DefaultVehicleHalTest
Bug: 382563296
Change-Id: I2330bb219a68541f641b0b4c9c9453e20f0f3f8d
parent 84b14e04
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -116,6 +116,10 @@ class SubscriptionClient {
            CallbackType callback,
            std::vector<aidl::android::hardware::automotive::vehicle::VehiclePropError>&&
                    vehiclePropErrors);

    // Invokes onSupportedValueChange callback.
    static void sendSupportedValueChangeEvents(CallbackType callback,
                                               std::vector<PropIdAreaId> propIdAreaIds);
};

}  // namespace vehicle
+4 −0
Original line number Diff line number Diff line
@@ -255,6 +255,10 @@ class DefaultVehicleHal final : public aidlvhal::BnVehicle {
            const std::weak_ptr<SubscriptionManager>& subscriptionManager,
            const std::vector<SetValueErrorEvent>& errorEvents);

    static void onSupportedValueChange(
            const std::weak_ptr<SubscriptionManager>& subscriptionManager,
            const std::vector<PropIdAreaId>& updatedPropIdAreaIds);

    static void checkHealth(IVehicleHardware* hardware,
                            std::weak_ptr<SubscriptionManager> subscriptionManager);

+5 −0
Original line number Diff line number Diff line
@@ -118,6 +118,11 @@ class SubscriptionManager final {
                       std::vector<aidl::android::hardware::automotive::vehicle::VehiclePropError>>
    getSubscribedClientsForErrorEvents(const std::vector<SetValueErrorEvent>& errorEvents);

    // For a list of [propId, areaId]s that has updated supported value, returns a map that maps
    // subscribing clients to updated [propId, areaId]s.
    std::unordered_map<CallbackType, std::vector<PropIdAreaId>>
    getSubscribedClientsForSupportedValueChange(const std::vector<PropIdAreaId>& propIdAreaIds);

    // Subscribes to supported values change.
    VhalResult<void> subscribeSupportedValueChange(const CallbackType& callback,
                                                   const std::vector<PropIdAreaId>& propIdAreaIds);
+24 −0
Original line number Diff line number Diff line
@@ -306,6 +306,30 @@ void SubscriptionClient::sendPropertySetErrors(std::shared_ptr<IVehicleCallback>
    }
}

void SubscriptionClient::sendSupportedValueChangeEvents(std::shared_ptr<IVehicleCallback> callback,
                                                        std::vector<PropIdAreaId> propIdAreaIds) {
    if (propIdAreaIds.empty()) {
        return;
    }

    std::vector<aidl::android::hardware::automotive::vehicle::PropIdAreaId> vhalPropIdAreaIds;
    for (const auto& propIdAreaId : propIdAreaIds) {
        vhalPropIdAreaIds.push_back(aidl::android::hardware::automotive::vehicle::PropIdAreaId{
                .propId = propIdAreaId.propId,
                .areaId = propIdAreaId.areaId,
        });
    }

    if (ScopedAStatus callbackStatus = callback->onSupportedValueChange(vhalPropIdAreaIds);
        !callbackStatus.isOk()) {
        ALOGE("subscribe: failed to call onSupportedValueChange callback, client ID: %p, error: "
              "%s, "
              "exception: %d, service specific error: %d",
              callback->asBinder().get(), callbackStatus.getMessage(),
              callbackStatus.getExceptionCode(), callbackStatus.getServiceSpecificError());
    }
}

}  // namespace vehicle
}  // namespace automotive
}  // namespace hardware
+25 −3
Original line number Diff line number Diff line
@@ -160,6 +160,11 @@ DefaultVehicleHal::DefaultVehicleHal(std::unique_ptr<IVehicleHardware> vehicleHa
                    [subscriptionManagerCopy](std::vector<SetValueErrorEvent> errorEvents) {
                        onPropertySetErrorEvent(subscriptionManagerCopy, errorEvents);
                    }));
    mVehicleHardware->registerSupportedValueChangeCallback(
            std::make_unique<IVehicleHardware::SupportedValueChangeCallback>(
                    [subscriptionManagerCopy](std::vector<PropIdAreaId> propIdAreaIds) {
                        onSupportedValueChange(subscriptionManagerCopy, propIdAreaIds);
                    }));

    // Register heartbeat event.
    mRecurrentAction = std::make_shared<std::function<void()>>(
@@ -207,7 +212,8 @@ void DefaultVehicleHal::batchPropertyChangeEvent(
        std::vector<VehiclePropValue>&& updatedValues) {
    auto batchedEventQueueStrong = batchedEventQueue.lock();
    if (batchedEventQueueStrong == nullptr) {
        ALOGW("the batched property events queue is destroyed, DefaultVehicleHal is ending");
        ALOGW("%s: the batched property events queue is destroyed, DefaultVehicleHal is ending",
              __func__);
        return;
    }
    batchedEventQueueStrong->push(std::move(updatedValues));
@@ -223,7 +229,7 @@ void DefaultVehicleHal::onPropertyChangeEvent(
    ATRACE_CALL();
    auto manager = subscriptionManager.lock();
    if (manager == nullptr) {
        ALOGW("the SubscriptionManager is destroyed, DefaultVehicleHal is ending");
        ALOGW("%s: the SubscriptionManager is destroyed, DefaultVehicleHal is ending", __func__);
        return;
    }
    auto updatedValuesByClients = manager->getSubscribedClients(std::move(updatedValues));
@@ -237,7 +243,7 @@ void DefaultVehicleHal::onPropertySetErrorEvent(
        const std::vector<SetValueErrorEvent>& errorEvents) {
    auto manager = subscriptionManager.lock();
    if (manager == nullptr) {
        ALOGW("the SubscriptionManager is destroyed, DefaultVehicleHal is ending");
        ALOGW("%s: the SubscriptionManager is destroyed, DefaultVehicleHal is ending", __func__);
        return;
    }
    auto vehiclePropErrorsByClient = manager->getSubscribedClientsForErrorEvents(errorEvents);
@@ -246,6 +252,22 @@ void DefaultVehicleHal::onPropertySetErrorEvent(
    }
}

void DefaultVehicleHal::onSupportedValueChange(
        const std::weak_ptr<SubscriptionManager>& subscriptionManager,
        const std::vector<PropIdAreaId>& propIdAreaIds) {
    auto manager = subscriptionManager.lock();
    if (manager == nullptr) {
        ALOGW("%s: the SubscriptionManager is destroyed, DefaultVehicleHal is ending", __func__);
        return;
    }
    auto updatedPropIdAreaIdsByClient =
            manager->getSubscribedClientsForSupportedValueChange(propIdAreaIds);
    for (auto& [callback, updatedPropIdAreaIds] : updatedPropIdAreaIdsByClient) {
        SubscriptionClient::sendSupportedValueChangeEvents(callback,
                                                           std::move(updatedPropIdAreaIds));
    }
}

template <class T>
std::shared_ptr<T> DefaultVehicleHal::getOrCreateClient(
        std::unordered_map<const AIBinder*, std::shared_ptr<T>>* clients,
Loading