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

Commit 2623d365 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "APM: support querying of audio playback routing"

parents f0a91423 f41599b1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1017,6 +1017,16 @@ audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
    return aps->getDevicesForStream(stream);
}

status_t AudioSystem::getDevicesForAttributes(const AudioAttributes &aa,
                                              AudioDeviceTypeAddrVector *devices) {
    if (devices == nullptr) {
        return BAD_VALUE;
    }
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;
    return aps->getDevicesForAttributes(aa, devices);
}

audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
+69 −1
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ enum {
    SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY,
    REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY,
    GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY,
    GET_DEVICES_FOR_ATTRIBUTES,
};

#define MAX_ITEMS_PER_LIST 1024
@@ -1348,6 +1349,41 @@ public:
        }
        return static_cast<status_t>(reply.readInt32());
    }

    virtual status_t getDevicesForAttributes(const AudioAttributes &aa,
            AudioDeviceTypeAddrVector *devices) const
    {
        if (devices == nullptr) {
            return BAD_VALUE;
        }
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        status_t status = aa.writeToParcel(&data);
        if (status != NO_ERROR) {
            return status;
        }
        status = remote()->transact(GET_DEVICES_FOR_ATTRIBUTES, data, &reply);
        if (status != NO_ERROR) {
            // transaction failed, return error
            return status;
        }
        status = static_cast<status_t>(reply.readInt32());
        if (status != NO_ERROR) {
            // APM method call failed, return error
            return status;
        }

        const size_t numberOfDevices = (size_t)reply.readInt32();
        for (size_t i = 0; i < numberOfDevices; i++) {
            AudioDeviceTypeAddr device;
            if (device.readFromParcel((Parcel*)&reply) == NO_ERROR) {
                devices->push_back(device);
            } else {
                return FAILED_TRANSACTION;
            }
        }
        return NO_ERROR;
    }
};

IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
@@ -1414,7 +1450,8 @@ status_t BnAudioPolicyService::onTransact(
        case IS_CALL_SCREEN_MODE_SUPPORTED:
        case SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY:
        case REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY:
        case GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: {
        case GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY:
        case GET_DEVICES_FOR_ATTRIBUTES: {
            if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
                ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
                      __func__, code, IPCThreadState::self()->getCallingPid(),
@@ -2473,6 +2510,37 @@ status_t BnAudioPolicyService::onTransact(
            return NO_ERROR;
        }

        case GET_DEVICES_FOR_ATTRIBUTES: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            AudioAttributes attributes;
            status_t status = attributes.readFromParcel(&data);
            if (status != NO_ERROR) {
                return status;
            }
            AudioDeviceTypeAddrVector devices;
            status = getDevicesForAttributes(attributes.getAttributes(), &devices);
            // reply data formatted as:
            //  - (int32) method call result from APM
            //  - (int32) number of devices (n) if method call returned NO_ERROR
            //  - n AudioDeviceTypeAddr         if method call returned NO_ERROR
            reply->writeInt32(status);
            if (status != NO_ERROR) {
                return NO_ERROR;
            }
            status = reply->writeInt32(devices.size());
            if (status != NO_ERROR) {
                return status;
            }
            for (const auto& device : devices) {
                status = device.writeToParcel(reply);
                if (status != NO_ERROR) {
                    return status;
                }
            }

            return NO_ERROR;
        }

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+2 −0
Original line number Diff line number Diff line
@@ -279,6 +279,8 @@ public:

    static uint32_t getStrategyForStream(audio_stream_type_t stream);
    static audio_devices_t getDevicesForStream(audio_stream_type_t stream);
    static status_t getDevicesForAttributes(const AudioAttributes &aa,
                                            AudioDeviceTypeAddrVector *devices);

    static audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
    static status_t registerEffect(const effect_descriptor_t *desc,
+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,8 @@ public:

    virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
    virtual status_t getDevicesForAttributes(const AudioAttributes &aa,
            AudioDeviceTypeAddrVector *devices) const = 0;
    virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
    virtual status_t registerEffect(const effect_descriptor_t *desc,
                                    audio_io_handle_t io,
+4 −0
Original line number Diff line number Diff line
@@ -192,6 +192,10 @@ public:
    // return the enabled output devices for the given stream type
    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;

    // retrieves the list of enabled output devices for the given audio attributes
    virtual status_t getDevicesForAttributes(const audio_attributes_t &attr,
                                             AudioDeviceTypeAddrVector *devices) = 0;

    // Audio effect management
    virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
    virtual status_t registerEffect(const effect_descriptor_t *desc,
Loading