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

Commit 95bd53d0 authored by Devin Moore's avatar Devin Moore
Browse files

libtunerservice: Use libfmq MQDescriptor conversion function

The unsafeHidlToAidlMQDescriptor was implimented in libtunerservice
before libfmq's version was checked in. Since it is now checked in and
supported, we are using it.

Test: m libtunerservice && m mediatuner
Bug: 176912570
Change-Id: I8758101948b2e95dc68c5889cca79ef3f87619fc
parent bca2cbe2
Loading
Loading
Loading
Loading
+1 −44
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_TAG "TunerService"

#include <android/binder_manager.h>
#include <fmq/ConvertMQDescriptors.h>
#include <utils/Log.h>
#include "TunerService.h"
#include "TunerFrontend.h"
@@ -57,50 +58,6 @@ void TunerService::instantiate() {
    AServiceManager_addService(service->asBinder().get(), getServiceName());
}

template <typename HidlPayload, typename AidlPayload, typename AidlFlavor>
bool TunerService::unsafeHidlToAidlMQDescriptor(
        const hardware::MQDescriptor<HidlPayload, FlavorTypeToValue<AidlFlavor>::value>& hidlDesc,
        MQDescriptor<AidlPayload, AidlFlavor>* aidlDesc) {
    // TODO: use the builtin coversion method when it's merged.
    ALOGD("unsafeHidlToAidlMQDescriptor");
    static_assert(sizeof(HidlPayload) == sizeof(AidlPayload), "Payload types are incompatible");
    static_assert(
            has_typedef_fixed_size<AidlPayload>::value == true ||
            is_fundamental<AidlPayload>::value ||
            is_enum<AidlPayload>::value,
            "Only fundamental types, enums, and AIDL parcelables annotated with @FixedSize "
            "and built for the NDK backend are supported as AIDL payload types.");
    aidlDesc->fileDescriptor = ndk::ScopedFileDescriptor(dup(hidlDesc.handle()->data[0]));
    for (const auto& grantor : hidlDesc.grantors()) {
        if (static_cast<int32_t>(grantor.offset) < 0 || static_cast<int64_t>(grantor.extent) < 0) {
            ALOGD("Unsafe static_cast of grantor fields. offset=%d, extend=%ld",
                    static_cast<int32_t>(grantor.offset), static_cast<long>(grantor.extent));
            logError(
                    "Unsafe static_cast of grantor fields. Either the hardware::MQDescriptor is "
                    "invalid, or the MessageQueue is too large to be described by AIDL.");
            return false;
        }
        aidlDesc->grantors.push_back(
                GrantorDescriptor {
                        .offset = static_cast<int32_t>(grantor.offset),
                        .extent = static_cast<int64_t>(grantor.extent)
                });
    }
    if (static_cast<int32_t>(hidlDesc.getQuantum()) < 0 ||
            static_cast<int32_t>(hidlDesc.getFlags()) < 0) {
        ALOGD("Unsafe static_cast of quantum or flags. Quantum=%d, flags=%d",
                static_cast<int32_t>(hidlDesc.getQuantum()),
                static_cast<int32_t>(hidlDesc.getFlags()));
        logError(
                "Unsafe static_cast of quantum or flags. Either the hardware::MQDescriptor is "
                "invalid, or the MessageQueue is too large to be described by AIDL.");
        return false;
    }
    aidlDesc->quantum = static_cast<int32_t>(hidlDesc.getQuantum());
    aidlDesc->flags = static_cast<int32_t>(hidlDesc.getFlags());
    return true;
}

bool TunerService::getITuner() {
    ALOGD("getITuner");
    if (mTuner != nullptr) {
+0 −5
Original line number Diff line number Diff line
@@ -105,11 +105,6 @@ public:
    Status openDemux(int32_t demuxHandle, std::shared_ptr<ITunerDemux>* _aidl_return) override;

private:
    template <typename HidlPayload, typename AidlPayload, typename AidlFlavor>
    bool unsafeHidlToAidlMQDescriptor(
            const hardware::MQDescriptor<HidlPayload, FlavorTypeToValue<AidlFlavor>::value>& hidl,
            MQDescriptor<AidlPayload, AidlFlavor>* aidl);

    bool getITuner();
    Result configFilter();