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

Commit 0d1542a8 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

Add AudioSystem.listDeclaredDevicePorts method am: 15f46713 am: 58fb2c57

parents dd0b32b0 58fb2c57
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1544,6 +1544,15 @@ status_t AudioSystem::listAudioPorts(audio_port_role_t role,
    return OK;
}

status_t AudioSystem::listDeclaredDevicePorts(media::AudioPortRole role,
                                              std::vector<media::AudioPortFw>* result) {
    if (result == nullptr) return BAD_VALUE;
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aps->listDeclaredDevicePorts(role, result)));
    return OK;
}

status_t AudioSystem::getAudioPort(struct audio_port_v7* port) {
    if (port == nullptr) {
        return BAD_VALUE;
+10 −1
Original line number Diff line number Diff line
@@ -202,7 +202,9 @@ interface IAudioPolicyService {
                                    in AudioAttributesInternal attributes);

    /**
     * List available audio ports and their attributes. Returns the generation.
     * List currently attached audio ports and their attributes. Returns the generation.
     * The generation is incremented each time when anything changes in the ports
     * configuration.
     *
     * On input, count represents the maximum length of the returned array.
     * On output, count is the total number of elements, which may be larger than the array size.
@@ -214,6 +216,13 @@ interface IAudioPolicyService {
                       inout Int count,
                       out AudioPortFw[] ports);

    /**
     * List all device ports declared in the configuration (including currently detached ones)
     * 'role' can be 'NONE' to get both input and output devices,
     * 'SINK' for output devices, and 'SOURCE' for input devices.
     */
    AudioPortFw[] listDeclaredDevicePorts(AudioPortRole role);

    /** Get attributes for the audio port with the given id (AudioPort.hal.id field). */
    AudioPortFw getAudioPort(int /* audio_port_handle_t */ portId);

+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <vector>

#include <android/content/AttributionSourceState.h>
#include <android/media/AudioPortFw.h>
#include <android/media/AudioVibratorInfo.h>
#include <android/media/BnAudioFlingerClient.h>
#include <android/media/BnAudioPolicyServiceClient.h>
@@ -378,6 +379,9 @@ public:
                                   struct audio_port_v7 *ports,
                                   unsigned int *generation);

    static status_t listDeclaredDevicePorts(media::AudioPortRole role,
                                            std::vector<media::AudioPortFw>* result);

    /* Get attributes for a given audio port. On input, the port
     * only needs the 'id' field to be filled in. */
    static status_t getAudioPort(struct audio_port_v7 *port);
+2 −0
Original line number Diff line number Diff line
@@ -245,6 +245,8 @@ public:
                                    unsigned int *num_ports,
                                    struct audio_port_v7 *ports,
                                    unsigned int *generation) = 0;
    virtual status_t listDeclaredDevicePorts(media::AudioPortRole role,
                                             std::vector<media::AudioPortFw>* result) = 0;
    virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;
    virtual status_t createAudioPatch(const struct audio_patch *patch,
                                       audio_patch_handle_t *handle,
+22 −0
Original line number Diff line number Diff line
@@ -4251,6 +4251,28 @@ status_t AudioPolicyManager::listAudioPorts(audio_port_role_t role,
    return NO_ERROR;
}

status_t AudioPolicyManager::listDeclaredDevicePorts(media::AudioPortRole role,
        std::vector<media::AudioPortFw>* _aidl_return) {
    auto pushPort = [&](const sp<DeviceDescriptor>& dev) -> status_t {
        audio_port_v7 port;
        dev->toAudioPort(&port);
        auto aidlPort = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_v7_AudioPortFw(port));
        _aidl_return->push_back(std::move(aidlPort));
        return OK;
    };

    for (const auto& module : mHwModulesAll) {
        for (const auto& dev : module->getDeclaredDevices()) {
            if (role == media::AudioPortRole::NONE ||
                    ((role == media::AudioPortRole::SOURCE)
                            == audio_is_input_device(dev->type()))) {
                RETURN_STATUS_IF_ERROR(pushPort(dev));
            }
        }
    }
    return OK;
}

status_t AudioPolicyManager::getAudioPort(struct audio_port_v7 *port)
{
    if (port == nullptr || port->id == AUDIO_PORT_HANDLE_NONE) {
Loading