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

Commit 1d0356ca authored by Dan Shi's avatar Dan Shi Committed by Automerger Merge Worker
Browse files

Merge "Revert "libaudiohal@aidl: Make IHalAdapterVendorExtension mandatory""...

Merge "Revert "libaudiohal@aidl: Make IHalAdapterVendorExtension mandatory"" into main am: c30f7ec5

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2944649



Change-Id: Id0710184a3bc32f1b80acebddde434f73dbcf411
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5eccd6f7 c30f7ec5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ status_t parseAndGetVendorParameters(
    using ParameterScope = IHalAdapterVendorExtension::ParameterScope;
    if (parameterKeys.size() == 0) return OK;
    const String8 rawKeys = parameterKeys.keysToString();
    if (vendorExt == nullptr) {
        ALOGW("%s: unknown parameters, ignored: \"%s\"", __func__, rawKeys.c_str());
        return OK;
    }

    std::vector<std::string> parameterIds;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(vendorExt->parseVendorParameterIds(
@@ -81,6 +85,10 @@ status_t parseAndSetVendorParameters(
    using ParameterScope = IHalAdapterVendorExtension::ParameterScope;
    if (parameters.size() == 0) return OK;
    const String8 rawKeysAndValues = parameters.toString();
    if (vendorExt == nullptr) {
        ALOGW("%s: unknown parameters, ignored: \"%s\"", __func__, rawKeysAndValues.c_str());
        return OK;
    }

    std::vector<VendorParameter> syncParameters, asyncParameters;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(vendorExt->parseVendorParameters(
+9 −5
Original line number Diff line number Diff line
@@ -1052,11 +1052,15 @@ status_t DeviceHalAidl::filterAndUpdateBtA2dpParameters(AudioParameter &paramete
    (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>(
                    parameters, String8(AudioParameter::keyReconfigA2dp),
                    [&](const String8& value) -> status_t {
                        if (mVendorExt != nullptr) {
                            std::vector<VendorParameter> result;
                            RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
                                    mVendorExt->parseBluetoothA2dpReconfigureOffload(
                                            std::string(value.c_str()), &result)));
                            reconfigureOffload = std::move(result);
                        } else {
                            reconfigureOffload = std::vector<VendorParameter>();
                        }
                        return OK;
                    }));
    if (mBluetoothA2dp != nullptr && a2dpEnabled.has_value()) {
+16 −80
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
//#define LOG_NDEBUG 0

#include <aidl/android/hardware/audio/core/IModule.h>
#include <aidl/android/media/audio/BnHalAdapterVendorExtension.h>
#include <android/binder_manager.h>
#include <media/AidlConversionNdkCpp.h>
#include <media/AidlConversionUtil.h>
@@ -36,7 +35,6 @@ using aidl::android::aidl_utils::statusTFromBinderStatus;
using aidl::android::hardware::audio::core::IConfig;
using aidl::android::hardware::audio::core::IModule;
using aidl::android::hardware::audio::core::SurroundSoundConfig;
using aidl::android::hardware::audio::core::VendorParameter;
using aidl::android::media::audio::common::AudioHalEngineConfig;
using aidl::android::media::audio::IHalAdapterVendorExtension;
using android::detail::AudioHalVersionInfo;
@@ -64,86 +62,10 @@ ndk2cpp_SurroundSoundConfig(const SurroundSoundConfig& ndk) {
    return cpp;
}

class HalAdapterVendorExtensionWrapper :
            public ::aidl::android::media::audio::BnHalAdapterVendorExtension {
  private:
    ndk::ScopedAStatus parseVendorParameterIds(ParameterScope in_scope,
                                               const std::string& in_rawKeys,
                                               std::vector<std::string>* _aidl_return) override {
        ndk::ScopedAStatus status;
        while (true) {
            status = get()->parseVendorParameterIds(in_scope, in_rawKeys, _aidl_return);
            if (status.getStatus() != STATUS_DEAD_OBJECT) break;
            mVendorExt.reset();
        }
        return status;
    }

    ndk::ScopedAStatus parseVendorParameters(
            ParameterScope in_scope, const std::string& in_rawKeysAndValues,
            std::vector<VendorParameter>* out_syncParameters,
            std::vector<VendorParameter>* out_asyncParameters) override {
        ndk::ScopedAStatus status;
        while (true) {
            status = get()->parseVendorParameters(in_scope, in_rawKeysAndValues,
                    out_syncParameters, out_asyncParameters);
            if (status.getStatus() != STATUS_DEAD_OBJECT) break;
            mVendorExt.reset();
        }
        return status;
    }

    ndk::ScopedAStatus parseBluetoothA2dpReconfigureOffload(
            const std::string& in_rawValue, std::vector<VendorParameter>* _aidl_return) override {
        ndk::ScopedAStatus status;
        while (true) {
            status = get()->parseBluetoothA2dpReconfigureOffload(in_rawValue, _aidl_return);
            if (status.getStatus() != STATUS_DEAD_OBJECT) break;
            mVendorExt.reset();
        }
        return status;
    }

    ndk::ScopedAStatus parseBluetoothLeReconfigureOffload(const std::string& in_rawValue,
            std::vector<VendorParameter>* _aidl_return) override {
        ndk::ScopedAStatus status;
        while (true) {
            status = get()->parseBluetoothLeReconfigureOffload(in_rawValue, _aidl_return);
            if (status.getStatus() != STATUS_DEAD_OBJECT) break;
            mVendorExt.reset();
        }
        return status;
    }

    ndk::ScopedAStatus processVendorParameters(ParameterScope in_scope,
                                               const std::vector<VendorParameter>& in_parameters,
                                               std::string* _aidl_return) override {
        ndk::ScopedAStatus status;
        while (true) {
            status = get()->processVendorParameters(in_scope, in_parameters, _aidl_return);
            if (status.getStatus() != STATUS_DEAD_OBJECT) break;
            mVendorExt.reset();
        }
        return status;
    }

    std::shared_ptr<IHalAdapterVendorExtension> get() {
        if (!mVendorExt) {
            auto serviceName = std::string(IHalAdapterVendorExtension::descriptor) + "/default";
            mVendorExt = IHalAdapterVendorExtension::fromBinder(ndk::SpAIBinder(
                            AServiceManager_waitForService(serviceName.c_str())));
        }
        return mVendorExt;
    }

    std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt;
};

}  // namespace

DevicesFactoryHalAidl::DevicesFactoryHalAidl(std::shared_ptr<IConfig> config)
        : mConfig(std::move(config)),
          mVendorExt(ndk::SharedRefBase::make<HalAdapterVendorExtensionWrapper>()) {
    : mConfig(std::move(config)) {
}

status_t DevicesFactoryHalAidl::getDeviceNames(std::vector<std::string> *names) {
@@ -188,7 +110,7 @@ status_t DevicesFactoryHalAidl::openDevice(const char *name, sp<DeviceHalInterfa
        ALOGE("%s fromBinder %s failed", __func__, serviceName.c_str());
        return NO_INIT;
    }
    *device = sp<DeviceHalAidl>::make(name, service, mVendorExt);
    *device = sp<DeviceHalAidl>::make(name, service, getVendorExtension());
    return OK;
}

@@ -227,6 +149,20 @@ status_t DevicesFactoryHalAidl::getEngineConfig(
    return OK;
}

std::shared_ptr<IHalAdapterVendorExtension> DevicesFactoryHalAidl::getVendorExtension() {
    if (!mVendorExt.has_value()) {
        auto serviceName = std::string(IHalAdapterVendorExtension::descriptor) + "/default";
        if (AServiceManager_isDeclared(serviceName.c_str())) {
            mVendorExt = std::shared_ptr<IHalAdapterVendorExtension>(
                    IHalAdapterVendorExtension::fromBinder(ndk::SpAIBinder(
                                    AServiceManager_waitForService(serviceName.c_str()))));
        } else {
            mVendorExt = nullptr;
        }
    }
    return mVendorExt.value();
}

// Main entry-point to the shared library.
extern "C" __attribute__((visibility("default"))) void* createIDevicesFactoryImpl() {
    auto serviceName = std::string(IConfig::descriptor) + "/default";
+4 −1
Original line number Diff line number Diff line
@@ -45,7 +45,10 @@ class DevicesFactoryHalAidl : public DevicesFactoryHalInterface

  private:
    const std::shared_ptr<::aidl::android::hardware::audio::core::IConfig> mConfig;
    const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt;
    std::optional<std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension>>
            mVendorExt;

    std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> getVendorExtension();

    ~DevicesFactoryHalAidl() = default;
};
+15 −0
Original line number Diff line number Diff line
@@ -443,6 +443,21 @@ TEST_F(DeviceHalAidlTest, ScreenRotation) {
    EXPECT_EQ(ScreenRotation::DEG_0, mModule->getScreenRotation());
}

// Without a vendor extension, any unrecognized parameters must be ignored.
TEST_F(DeviceHalAidlTest, VendorParameterIgnored) {
    EXPECT_EQ(0UL, mModule->getAsyncParameters().size());
    EXPECT_EQ(0UL, mModule->getSyncParameters().size());
    EXPECT_EQ(OK, mDevice->setParameters(createParameterString("random_name", "random_value")));
    EXPECT_EQ(0UL, mModule->getAsyncParameters().size());
    EXPECT_EQ(0UL, mModule->getSyncParameters().size());

    EXPECT_EQ(0UL, mModule->getRetrievedParameterIds().size());
    String8 values;
    EXPECT_EQ(OK, mDevice->getParameters(String8("random_name"), &values));
    EXPECT_EQ(0UL, mModule->getRetrievedParameterIds().size());
    EXPECT_EQ(0UL, values.length());
}

class DeviceHalAidlVendorParametersTest : public testing::Test {
  public:
    void SetUp() override {
Loading