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

Commit 8b23b375 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "CSD: add logic for selecting ISoundDose interface"

parents 788c1053 03bd5bca
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -207,6 +207,8 @@ cc_library_shared {
cc_library_shared {
    name: "libaudiohal@7.1",
    defaults: [
        "latest_android_hardware_audio_core_sounddose_ndk_shared",
        "latest_android_hardware_audio_sounddose_ndk_shared",
        "libaudiohal_default",
        "libaudiohal_hidl_default"
    ],
@@ -226,6 +228,9 @@ cc_library_shared {
        "android.hardware.audio@7.1-util",
        "libaudiohal.effect@7.0",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    cflags: [
        "-DMAJOR_VERSION=7",
        "-DMINOR_VERSION=1",
@@ -241,6 +246,7 @@ cc_library_shared {
        "libaudiohal_default",
        "latest_android_hardware_audio_common_ndk_shared",
        "latest_android_hardware_audio_core_ndk_shared",
        "latest_android_hardware_audio_core_sounddose_ndk_shared",
        "latest_android_hardware_audio_effect_ndk_static",
        "latest_android_media_audio_common_types_ndk_shared",
    ],
+22 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#define LOG_TAG "DeviceHalAidl"
// #define LOG_NDEBUG 0

#include <aidl/android/hardware/audio/core/StreamDescriptor.h>
#include <error/expected_utils.h>
@@ -32,6 +33,7 @@ using aidl::android::media::audio::common::Float;
using aidl::android::hardware::audio::core::IModule;
using aidl::android::hardware::audio::core::ITelephony;
using aidl::android::hardware::audio::core::StreamDescriptor;
using aidl::android::hardware::audio::core::sounddose::ISoundDose;

namespace android {

@@ -286,4 +288,24 @@ int32_t DeviceHalAidl::supportsBluetoothVariableLatency(bool* supports __unused)
    return INVALID_OPERATION;
}

status_t DeviceHalAidl::getSoundDoseInterface(const std::string& module,
                                              ::ndk::SpAIBinder* soundDoseBinder)  {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    if (mSoundDose == nullptr) {
        ndk::ScopedAStatus status = mModule->getSoundDose(&mSoundDose);
        if (!status.isOk()) {
            ALOGE("%s failed to return the sound dose interface for module %s: %s",
                  __func__,
                  module.c_str(),
                  status.getDescription().c_str());
            return BAD_VALUE;
        }
    }
    *soundDoseBinder = mSoundDose->asBinder();
    ALOGI("%s using audio AIDL HAL sound dose interface", __func__);

    return OK;
}

} // namespace android
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <aidl/android/hardware/audio/core/sounddose/BpSoundDose.h>
#include <aidl/android/hardware/audio/core/BpModule.h>
#include <media/audiohal/DeviceHalInterface.h>
#include <media/audiohal/EffectHalInterface.h>
@@ -117,10 +118,15 @@ class DeviceHalAidl : public DeviceHalInterface, public ConversionHelperAidl {

    int32_t supportsBluetoothVariableLatency(bool* supports __unused) override;

    status_t getSoundDoseInterface(const std::string& module,
                                   ::ndk::SpAIBinder* soundDoseBinder) override;

  private:
    friend class sp<DeviceHalAidl>;

    const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mModule;
    std::shared_ptr<::aidl::android::hardware::audio::core::sounddose::ISoundDose>
        mSoundDose = nullptr;

    // Can not be constructed directly by clients.
    explicit DeviceHalAidl(
+74 −3
Original line number Diff line number Diff line
@@ -35,6 +35,17 @@
#include "ParameterUtils.h"
#include "StreamHalHidl.h"

#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
#include <aidl/android/hardware/audio/core/sounddose/BpSoundDose.h>
#include <aidl/android/hardware/audio/sounddose/BpSoundDoseFactory.h>
#include <android/binder_manager.h>

constexpr std::string_view kSoundDoseInterfaceModule = "/default";

using aidl::android::hardware::audio::core::sounddose::ISoundDose;
using aidl::android::hardware::audio::sounddose::ISoundDoseFactory;
#endif

using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::common::utils::EnumBitfield;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
@@ -46,8 +57,21 @@ namespace android {
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;

class DeviceHalHidl::SoundDoseWrapper {
public:
    SoundDoseWrapper() = default;
    ~SoundDoseWrapper() = default;

#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
    std::shared_ptr<ISoundDoseFactory> mSoundDoseFactory;
    std::shared_ptr<ISoundDose> mSoundDose;
#endif
};

DeviceHalHidl::DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device)
        : CoreConversionHelperHidl("DeviceHalHidl"), mDevice(device) {
        : CoreConversionHelperHidl("DeviceHalHidl"),
          mDevice(device),
          mSoundDoseWrapper(std::make_unique<DeviceHalHidl::SoundDoseWrapper>()) {
}

DeviceHalHidl::DeviceHalHidl(
@@ -56,7 +80,8 @@ DeviceHalHidl::DeviceHalHidl(
#if MAJOR_VERSION <= 6 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0)
          mDevice(device),
#endif
          mPrimaryDevice(device) {
          mPrimaryDevice(device),
          mSoundDoseWrapper(std::make_unique<DeviceHalHidl::SoundDoseWrapper>()) {
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
    auto getDeviceRet = mPrimaryDevice->getDevice();
    if (getDeviceRet.isOk()) {
@@ -574,4 +599,50 @@ status_t DeviceHalHidl::dump(int fd, const Vector<String16>& args) {
    return processReturn("dump", ret);
}

#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
status_t DeviceHalHidl::getSoundDoseInterface(const std::string& module,
                                              ::ndk::SpAIBinder* soundDoseBinder) {
    if (mSoundDoseWrapper->mSoundDose != nullptr) {
        *soundDoseBinder = mSoundDoseWrapper->mSoundDose->asBinder();
        return OK;
    }

    if (mSoundDoseWrapper->mSoundDoseFactory == nullptr) {
        std::string interface =
            std::string(ISoundDoseFactory::descriptor) + kSoundDoseInterfaceModule.data();
        AIBinder* binder = AServiceManager_checkService(interface.c_str());
        if (binder == nullptr) {
            ALOGW("%s service %s doesn't exist", __func__, interface.c_str());
            return NO_INIT;
        }
        mSoundDoseWrapper->mSoundDoseFactory =
                ISoundDoseFactory::fromBinder(ndk::SpAIBinder(binder));
    }

    auto result = mSoundDoseWrapper->mSoundDoseFactory->getSoundDose(
                        module, &mSoundDoseWrapper->mSoundDose);
    if (!result.isOk()) {
        ALOGW("%s could not get sound dose interface: %s", __func__, result.getMessage());
        return BAD_VALUE;
    }

    if (mSoundDoseWrapper->mSoundDose == nullptr) {
        ALOGW("%s standalone sound dose interface is not implemented", __func__);
        *soundDoseBinder = nullptr;
        return OK;
    }

    *soundDoseBinder = mSoundDoseWrapper->mSoundDose->asBinder();
    ALOGI("%s using standalone sound dose interface", __func__);
    return OK;
}
#else
status_t DeviceHalHidl::getSoundDoseInterface(const std::string& module,
                                              ::ndk::SpAIBinder* soundDoseBinder) {
    (void)module;  // avoid unused param
    (void)soundDoseBinder;  // avoid unused param
    return INVALID_OPERATION;
}
#endif

} // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -130,12 +130,17 @@ class DeviceHalHidl : public DeviceHalInterface, public CoreConversionHelperHidl

    status_t dump(int fd, const Vector<String16>& args) override;

    status_t getSoundDoseInterface(const std::string& module,
                                   ::ndk::SpAIBinder* soundDoseBinder) override;

  private:
    friend class DevicesFactoryHalHidl;
    sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice;
    // Null if it's not a primary device.
    sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice;
    bool supportsSetConnectedState7_1 = true;
    class SoundDoseWrapper;
    const std::unique_ptr<SoundDoseWrapper> mSoundDoseWrapper;

    // Can not be constructed directly by clients.
    explicit DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device);
Loading