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

Commit f30add84 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor VHAL"

parents 887a59b3 1ae977d6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ hidl_interface {
        "VehiclePropertyChangeMode",
        "VehiclePropertyGroup",
        "VehiclePropertyOperation",
        "VehiclePropertyStatus",
        "VehiclePropertyType",
        "VehicleRadioConstants",
        "VehicleTurnSignal",
+4 −8
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public:
    }

    void addOrUpdateSubscription(const SubscribeOptions &opts);
    bool isSubscribed(int32_t propId, int32_t areaId, SubscribeFlags flags);
    bool isSubscribed(int32_t propId, SubscribeFlags flags);
    std::vector<int32_t> getSubscribedProperties() const;

private:
@@ -87,8 +87,7 @@ public:
    /**
     * Constructs SubscriptionManager
     *
     * @param onPropertyUnsubscribed - this callback function will be called when there are no
     *                                    more client subscribed to particular property.
     * @param onPropertyUnsubscribed - called when no more clients are subscribed to the property.
     */
    SubscriptionManager(const OnPropertyUnsubscribed& onPropertyUnsubscribed)
            : mOnPropertyUnsubscribed(onPropertyUnsubscribed),
@@ -115,9 +114,7 @@ public:
            const std::vector<recyclable_ptr<VehiclePropValue>>& propValues,
            SubscribeFlags flags) const;

    std::list<sp<HalClient>> getSubscribedClients(int32_t propId,
                                                  int32_t area,
                                                  SubscribeFlags flags) const;
    std::list<sp<HalClient>> getSubscribedClients(int32_t propId, SubscribeFlags flags) const;
    /**
     * If there are no clients subscribed to given properties than callback function provided
     * in the constructor will be called.
@@ -125,7 +122,6 @@ public:
    void unsubscribe(ClientId clientId, int32_t propId);
private:
    std::list<sp<HalClient>> getSubscribedClientsLocked(int32_t propId,
                                                        int32_t area,
                                                        SubscribeFlags flags) const;

    bool updateHalEventSubscriptionLocked(const SubscribeOptions& opts, SubscribeOptions* out);
+1 −4
Original line number Diff line number Diff line
@@ -48,17 +48,14 @@ public:

    /**
     * Subscribe to HAL property events. This method might be called multiple
     * times for the same vehicle property to update subscribed areas or sample
     * rate.
     * times for the same vehicle property to update sample rate.
     *
     * @param property to subscribe
     * @param areas a bitwise vehicle areas or 0 for all supported areas
     * @param sampleRate sample rate in Hz for properties that support sample
     *                   rate, e.g. for properties with
     *                   VehiclePropertyChangeMode::CONTINUOUS
     */
    virtual StatusCode subscribe(int32_t property,
                                 int32_t areas,
                                 float sampleRate) = 0;

    /**
+2 −3
Original line number Diff line number Diff line
@@ -191,9 +191,8 @@ public:
    VehiclePropValuePool& operator=(VehiclePropValuePool&) = delete;
private:
    bool isDisposable(VehiclePropertyType type, size_t vecSize) const {
        return vecSize > mMaxRecyclableVectorSize ||
               VehiclePropertyType::STRING == type ||
               VehiclePropertyType::COMPLEX == type;
        return vecSize > mMaxRecyclableVectorSize || VehiclePropertyType::STRING == type ||
               VehiclePropertyType::MIXED == type;
    }

    RecyclableType obtainDisposable(VehiclePropertyType valueType,
+8 −22
Original line number Diff line number Diff line
@@ -34,23 +34,12 @@ namespace V2_0 {
bool mergeSubscribeOptions(const SubscribeOptions &oldOpts,
                           const SubscribeOptions &newOpts,
                           SubscribeOptions *outResult) {

    int32_t updatedAreas = oldOpts.vehicleAreas;
    if (updatedAreas != kAllSupportedAreas) {
        updatedAreas = newOpts.vehicleAreas != kAllSupportedAreas
            ? updatedAreas | newOpts.vehicleAreas
            : kAllSupportedAreas;
    }

    float updatedRate = std::max(oldOpts.sampleRate, newOpts.sampleRate);
    SubscribeFlags updatedFlags = SubscribeFlags(oldOpts.flags | newOpts.flags);

    bool updated = updatedRate > oldOpts.sampleRate
                   || updatedAreas != oldOpts.vehicleAreas
                   || updatedFlags != oldOpts.flags;
    bool updated = (updatedRate > oldOpts.sampleRate) || (updatedFlags != oldOpts.flags);
    if (updated) {
        *outResult = oldOpts;
        outResult->vehicleAreas = updatedAreas;
        outResult->sampleRate = updatedRate;
        outResult->flags = updatedFlags;
    }
@@ -75,15 +64,13 @@ void HalClient::addOrUpdateSubscription(const SubscribeOptions &opts) {
}

bool HalClient::isSubscribed(int32_t propId,
                             int32_t areaId,
                             SubscribeFlags flags) {
    auto it = mSubscriptions.find(propId);
    if (it == mSubscriptions.end()) {
        return false;
    }
    const SubscribeOptions& opts = it->second;
    bool res = (opts.flags & flags)
           && (opts.vehicleAreas == 0 || areaId == 0 || opts.vehicleAreas & areaId);
    bool res = (opts.flags & flags);
    return res;
}

@@ -139,8 +126,7 @@ std::list<HalClientValues> SubscriptionManager::distributeValuesToClients(
        MuxGuard g(mLock);
        for (const auto& propValue: propValues) {
            VehiclePropValue* v = propValue.get();
            auto clients = getSubscribedClientsLocked(
                v->prop, v->areaId, flags);
            auto clients = getSubscribedClientsLocked(v->prop, flags);
            for (const auto& client : clients) {
                clientValuesMap[client].push_back(v);
            }
@@ -158,21 +144,21 @@ std::list<HalClientValues> SubscriptionManager::distributeValuesToClients(
    return clientValues;
}

std::list<sp<HalClient>> SubscriptionManager::getSubscribedClients(
    int32_t propId, int32_t area, SubscribeFlags flags) const {
std::list<sp<HalClient>> SubscriptionManager::getSubscribedClients(int32_t propId,
                                                                   SubscribeFlags flags) const {
    MuxGuard g(mLock);
    return getSubscribedClientsLocked(propId, area, flags);
    return getSubscribedClientsLocked(propId, flags);
}

std::list<sp<HalClient>> SubscriptionManager::getSubscribedClientsLocked(
        int32_t propId, int32_t area, SubscribeFlags flags) const {
    int32_t propId, SubscribeFlags flags) const {
    std::list<sp<HalClient>> subscribedClients;

    sp<HalClientVector> propClients = getClientsForPropertyLocked(propId);
    if (propClients.get() != nullptr) {
        for (size_t i = 0; i < propClients->size(); i++) {
            const auto& client = propClients->itemAt(i);
            if (client->isSubscribed(propId, area, flags)) {
            if (client->isSubscribed(propId, flags)) {
                subscribedClients.push_back(client);
            }
        }
Loading