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

Commit fab697c2 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

libaudiohal: Implement some functions called during startup

Based on the logs during CF startup, implemented the following
methods:
  - DeviceFactoryHalAild::getHalPids
  - DeviceHalAidl::dump
  - DeviceHalAidl::get/setMasterMute
  - DeviceHalAidl::get/setMasterVolume
  - DeviceHalAidl::get/setMicMute
  - DeviceHalAidl::setMode
  - DeviceHalAidl::setVoiceVolume

Also implemented retrieving of IStreamCommon.

Bug: 205884982
Test: boot cuttlefish with AIDL enabled
Change-Id: Ie1619def1b5d8e2079d849b2e9e23ebeed6e2936
parent 4608daca
Loading
Loading
Loading
Loading
+19 −0
Original line number Original line Diff line number Diff line
@@ -18,9 +18,28 @@


#include <string>
#include <string>
#include <string_view>
#include <string_view>
#include <vector>

#include <utils/String16.h>
#include <utils/Vector.h>


namespace android {
namespace android {


class Args {
  public:
    explicit Args(const Vector<String16>& args)
            : mValues(args.size()), mPtrs(args.size()) {
        for (size_t i = 0; i < args.size(); ++i) {
            mValues[i] = std::string(String8(args[i]));
            mPtrs[i] = mValues[i].c_str();
        }
    }
    const char** args() { return mPtrs.data(); }
  private:
    std::vector<std::string> mValues;
    std::vector<const char*> mPtrs;
};

class ConversionHelperAidl {
class ConversionHelperAidl {
  protected:
  protected:
    ConversionHelperAidl(std::string_view className) : mClassName(className) {}
    ConversionHelperAidl(std::string_view className) : mClassName(className) {}
+46 −30
Original line number Original line Diff line number Diff line
@@ -16,15 +16,22 @@


#define LOG_TAG "DeviceHalAidl"
#define LOG_TAG "DeviceHalAidl"


#include <aidl/android/hardware/audio/core/StreamDescriptor.h>
#include <error/expected_utils.h>
#include <media/AidlConversionCppNdk.h>
#include <media/AidlConversionUtil.h>
#include <mediautils/TimeCheck.h>
#include <mediautils/TimeCheck.h>
#include <utils/Log.h>
#include <utils/Log.h>


#include <aidl/android/hardware/audio/core/StreamDescriptor.h>

#include "DeviceHalAidl.h"
#include "DeviceHalAidl.h"
#include "StreamHalAidl.h"
#include "StreamHalAidl.h"


using ::aidl::android::hardware::audio::core::StreamDescriptor;
using aidl::android::aidl_utils::statusTFromBinderStatus;
using aidl::android::media::audio::common::AudioMode;
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;


namespace android {
namespace android {


@@ -41,58 +48,66 @@ status_t DeviceHalAidl::initCheck() {


status_t DeviceHalAidl::setVoiceVolume(float volume) {
status_t DeviceHalAidl::setVoiceVolume(float volume) {
    TIME_CHECK();
    TIME_CHECK();
    mVoiceVolume = volume;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %f", __func__, volume);
    std::shared_ptr<ITelephony> telephony;
    return OK;
    if (ndk::ScopedAStatus status = mModule->getTelephony(&telephony);
            status.isOk() && telephony != nullptr) {
        ITelephony::TelecomConfig inConfig{ .voiceVolume = Float{volume} }, outConfig;
        RETURN_STATUS_IF_ERROR(
                statusTFromBinderStatus(telephony->setTelecomConfig(inConfig, &outConfig)));
        ALOGW_IF(outConfig.voiceVolume.has_value() && volume != outConfig.voiceVolume.value().value,
                "%s: the resulting voice volume %f is not the same as requested %f",
                __func__, outConfig.voiceVolume.value().value, volume);
    }
    return INVALID_OPERATION;
}
}


status_t DeviceHalAidl::setMasterVolume(float volume) {
status_t DeviceHalAidl::setMasterVolume(float volume) {
    TIME_CHECK();
    TIME_CHECK();
    mMasterVolume = volume;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %f", __func__, volume);
    return statusTFromBinderStatus(mModule->setMasterVolume(volume));
    return OK;
}
}


status_t DeviceHalAidl::getMasterVolume(float *volume) {
status_t DeviceHalAidl::getMasterVolume(float *volume) {
    TIME_CHECK();
    TIME_CHECK();
    *volume = mMasterVolume;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %f", __func__, *volume);
    return statusTFromBinderStatus(mModule->getMasterVolume(volume));
    return OK;
}
}


status_t DeviceHalAidl::setMode(audio_mode_t mode __unused) {
status_t DeviceHalAidl::setMode(audio_mode_t mode) {
    TIME_CHECK();
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    AudioMode audioMode = VALUE_OR_FATAL(::aidl::android::legacy2aidl_audio_mode_t_AudioMode(mode));
    return OK;
    std::shared_ptr<ITelephony> telephony;
    if (ndk::ScopedAStatus status = mModule->getTelephony(&telephony);
            status.isOk() && telephony != nullptr) {
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(telephony->switchAudioMode(audioMode)));
    }
    return statusTFromBinderStatus(mModule->updateAudioMode(audioMode));
}
}


status_t DeviceHalAidl::setMicMute(bool state) {
status_t DeviceHalAidl::setMicMute(bool state) {
    TIME_CHECK();
    TIME_CHECK();
    mMicMute = state;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %d", __func__, state);
    return statusTFromBinderStatus(mModule->setMicMute(state));
    return OK;
}
}


status_t DeviceHalAidl::getMicMute(bool *state) {
status_t DeviceHalAidl::getMicMute(bool *state) {
    TIME_CHECK();
    TIME_CHECK();
    *state = mMicMute;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %d", __func__, *state);
    return statusTFromBinderStatus(mModule->getMicMute(state));
    return OK;
}
}


status_t DeviceHalAidl::setMasterMute(bool state) {
status_t DeviceHalAidl::setMasterMute(bool state) {
    TIME_CHECK();
    TIME_CHECK();
    mMasterMute = state;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %d", __func__, state);
    return statusTFromBinderStatus(mModule->setMasterMute(state));
    return OK;
}
}


status_t DeviceHalAidl::getMasterMute(bool *state) {
status_t DeviceHalAidl::getMasterMute(bool *state) {
    TIME_CHECK();
    TIME_CHECK();
    *state = mMasterMute;
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet %d", __func__, *state);
    return statusTFromBinderStatus(mModule->getMasterMute(state));
    return OK;
}
}


status_t DeviceHalAidl::setParameters(const String8& kvPairs __unused) {
status_t DeviceHalAidl::setParameters(const String8& kvPairs __unused) {
@@ -259,9 +274,10 @@ error::Result<audio_hw_sync_t> DeviceHalAidl::getHwAvSync() {
    return base::unexpected(INVALID_OPERATION);
    return base::unexpected(INVALID_OPERATION);
}
}


status_t DeviceHalAidl::dump(int __unused, const Vector<String16>& __unused) {
status_t DeviceHalAidl::dump(int fd, const Vector<String16>& args) {
    ALOGE("%s not implemented yet", __func__);
    TIME_CHECK();
    return OK;
    if (!mModule) return NO_INIT;
    return mModule->dump(fd, Args(args).args(), args.size());
};
};


int32_t DeviceHalAidl::supportsBluetoothVariableLatency(bool* supports __unused) {
int32_t DeviceHalAidl::supportsBluetoothVariableLatency(bool* supports __unused) {
+0 −5
Original line number Original line Diff line number Diff line
@@ -121,11 +121,6 @@ class DeviceHalAidl : public DeviceHalInterface, public ConversionHelperAidl {
    friend class sp<DeviceHalAidl>;
    friend class sp<DeviceHalAidl>;


    const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mModule;
    const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mModule;
    // FIXME: Remove these after implementing calls into the HAL.
    float mMasterVolume = 0.0f;
    float mVoiceVolume = 0.0f;
    bool mMasterMute = false;
    bool mMicMute = false;


    // Can not be constructed directly by clients.
    // Can not be constructed directly by clients.
    explicit DeviceHalAidl(
    explicit DeviceHalAidl(
+18 −2
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@


#include <aidl/android/hardware/audio/core/IModule.h>
#include <aidl/android/hardware/audio/core/IModule.h>
#include <android/binder_manager.h>
#include <android/binder_manager.h>
#include <binder/IServiceManager.h>
#include <memory>
#include <memory>
#include <utils/Log.h>
#include <utils/Log.h>


@@ -64,8 +65,23 @@ status_t DevicesFactoryHalAidl::getHalPids(std::vector<pid_t> *pids) {
    if (pids == nullptr) {
    if (pids == nullptr) {
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }
    ALOGE("%s not implemented yet", __func__);
    // The functionality for retrieving debug infos of services is not exposed via the NDK.
    return INVALID_OPERATION;
    sp<IServiceManager> sm = defaultServiceManager();
    if (sm == nullptr) {
        return NO_INIT;
    }
    std::set<pid_t> pidsSet;
    const auto moduleServiceName = std::string(IModule::descriptor) + "/";
    auto debugInfos = sm->getServiceDebugInfo();
    for (const auto& info : debugInfos) {
        if (info.pid > 0 &&
                info.name.size() > moduleServiceName.size() && // '>' as there must be instance name
                info.name.substr(0, moduleServiceName.size()) == moduleServiceName) {
            pidsSet.insert(info.pid);
        }
    }
    *pids = {pidsSet.begin(), pidsSet.end()};
    return NO_ERROR;
}
}


status_t DevicesFactoryHalAidl::setCallbackOnce(sp<DevicesFactoryHalCallback> callback) {
status_t DevicesFactoryHalAidl::setCallbackOnce(sp<DevicesFactoryHalCallback> callback) {
+22 −16
Original line number Original line Diff line number Diff line
@@ -31,6 +31,20 @@ using ::aidl::android::hardware::audio::core::StreamDescriptor;


namespace android {
namespace android {


// static
template<class T>
std::shared_ptr<IStreamCommon> StreamHalAidl::getStreamCommon(const std::shared_ptr<T>& stream) {
    std::shared_ptr<::aidl::android::hardware::audio::core::IStreamCommon> streamCommon;
    if (stream != nullptr) {
        if (ndk::ScopedAStatus status = stream->getStreamCommon(&streamCommon);
                !status.isOk()) {
            ALOGE("%s: failed to retrieve IStreamCommon instance: %s", __func__,
                    status.getDescription().c_str());
        }
    }
    return streamCommon;
}

StreamHalAidl::StreamHalAidl(
StreamHalAidl::StreamHalAidl(
        std::string_view className, bool isInput, const StreamDescriptor& descriptor,
        std::string_view className, bool isInput, const StreamDescriptor& descriptor,
        const std::shared_ptr<IStreamCommon>& stream)
        const std::shared_ptr<IStreamCommon>& stream)
@@ -130,11 +144,10 @@ status_t StreamHalAidl::standby() {
    return OK;
    return OK;
}
}


status_t StreamHalAidl::dump(int fd __unused, const Vector<String16>& args __unused) {
status_t StreamHalAidl::dump(int fd, const Vector<String16>& args) {
    TIME_CHECK();
    TIME_CHECK();
    if (!mStream) return NO_INIT;
    if (!mStream) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return mStream->dump(fd, Args(args).args(), args.size());
    return OK;
}
}


status_t StreamHalAidl::start() {
status_t StreamHalAidl::start() {
@@ -190,18 +203,13 @@ bool StreamHalAidl::requestHalThreadPriority(pid_t threadPid __unused, pid_t thr
status_t StreamHalAidl::legacyCreateAudioPatch(const struct audio_port_config& port __unused,
status_t StreamHalAidl::legacyCreateAudioPatch(const struct audio_port_config& port __unused,
                                               std::optional<audio_source_t> source __unused,
                                               std::optional<audio_source_t> source __unused,
                                               audio_devices_t type __unused) {
                                               audio_devices_t type __unused) {
    TIME_CHECK();
    // Obsolete since 'DeviceHalAidl.supportsAudioPatches' always returns 'true'.
    LOG_ALWAYS_FATAL_IF(port.type != AUDIO_PORT_TYPE_DEVICE, "port type must be device");
    return INVALID_OPERATION;
    if (!mStream) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}
}


status_t StreamHalAidl::legacyReleaseAudioPatch() {
status_t StreamHalAidl::legacyReleaseAudioPatch() {
    TIME_CHECK();
    // Obsolete since 'DeviceHalAidl.supportsAudioPatches' always returns 'true'.
    if (!mStream) return NO_INIT;
    return INVALID_OPERATION;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}
}


namespace {
namespace {
@@ -237,8 +245,7 @@ class StreamCallback : public ::aidl::android::hardware::audio::core::BnStreamCa


StreamOutHalAidl::StreamOutHalAidl(
StreamOutHalAidl::StreamOutHalAidl(
        const StreamDescriptor& descriptor, const std::shared_ptr<IStreamOut>& stream)
        const StreamDescriptor& descriptor, const std::shared_ptr<IStreamOut>& stream)
        : StreamHalAidl("StreamOutHalAidl", false /*isInput*/, descriptor,
        : StreamHalAidl("StreamOutHalAidl", false /*isInput*/, descriptor, getStreamCommon(stream)),
                nullptr /* FIXME: Retrieve IStreamCommon */),
          mStream(stream) {}
          mStream(stream) {}


status_t StreamOutHalAidl::getLatency(uint32_t *latency) {
status_t StreamOutHalAidl::getLatency(uint32_t *latency) {
@@ -452,8 +459,7 @@ status_t StreamOutHalAidl::exit() {


StreamInHalAidl::StreamInHalAidl(
StreamInHalAidl::StreamInHalAidl(
        const StreamDescriptor& descriptor, const std::shared_ptr<IStreamIn>& stream)
        const StreamDescriptor& descriptor, const std::shared_ptr<IStreamIn>& stream)
        : StreamHalAidl("StreamInHalAidl", true /*isInput*/, descriptor,
        : StreamHalAidl("StreamInHalAidl", true /*isInput*/, descriptor, getStreamCommon(stream)),
                nullptr /* FIXME: Retrieve IStreamCommon */),
          mStream(stream) {}
          mStream(stream) {}


status_t StreamInHalAidl::setGain(float gain __unused) {
status_t StreamInHalAidl::setGain(float gain __unused) {
Loading