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

Commit b0f8a1af authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4784261 from cce82540 to pi-release

Change-Id: I10b3d04b5e40f02642849012dd8cc2bce4e8181d
parents ab4f202c cce82540
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -1286,6 +1286,24 @@ status_t AudioSystem::getMicrophones(std::vector<media::MicrophoneInfo> *microph
    return af->getMicrophones(microphones);
}

status_t AudioSystem::getSurroundFormats(unsigned int *numSurroundFormats,
                                         audio_format_t *surroundFormats,
                                         bool *surroundFormatsEnabled,
                                         bool reported)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;
    return aps->getSurroundFormats(
            numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
}

status_t AudioSystem::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;
    return aps->setSurroundFormatEnabled(audioFormat, enabled);
}

// ---------------------------------------------------------------------------

int AudioSystem::AudioPolicyServiceClient::addAudioPortCallback(
+98 −2
Original line number Diff line number Diff line
@@ -80,7 +80,9 @@ enum {
    SET_AUDIO_PORT_CALLBACK_ENABLED,
    SET_MASTER_MONO,
    GET_MASTER_MONO,
    GET_STREAM_VOLUME_DB
    GET_STREAM_VOLUME_DB,
    GET_SURROUND_FORMATS,
    SET_SURROUND_FORMAT_ENABLED
};

#define MAX_ITEMS_PER_LIST 1024
@@ -829,6 +831,54 @@ public:
        }
        return reply.readFloat();
    }

    virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
                                        audio_format_t *surroundFormats,
                                        bool *surroundFormatsEnabled,
                                        bool reported)
    {
        if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
                (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
            return BAD_VALUE;
        }
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        unsigned int numSurroundFormatsReq = *numSurroundFormats;
        data.writeUint32(numSurroundFormatsReq);
        data.writeBool(reported);
        status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
        if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
            *numSurroundFormats = reply.readUint32();
        }
        if (status == NO_ERROR) {
            if (numSurroundFormatsReq > *numSurroundFormats) {
                numSurroundFormatsReq = *numSurroundFormats;
            }
            if (numSurroundFormatsReq > 0) {
                status = reply.read(surroundFormats,
                                    numSurroundFormatsReq * sizeof(audio_format_t));
                if (status != NO_ERROR) {
                    return status;
                }
                status = reply.read(surroundFormatsEnabled,
                                    numSurroundFormatsReq * sizeof(bool));
            }
        }
        return status;
    }

    virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        data.writeInt32(audioFormat);
        data.writeBool(enabled);
        status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        return reply.readInt32();
    }
};

IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
@@ -883,7 +933,9 @@ status_t BnAudioPolicyService::onTransact(
        case REGISTER_POLICY_MIXES:
        case SET_MASTER_MONO:
        case START_AUDIO_SOURCE:
        case STOP_AUDIO_SOURCE: {
        case STOP_AUDIO_SOURCE:
        case GET_SURROUND_FORMATS:
        case SET_SURROUND_FORMAT_ENABLED: {
            if (multiuser_get_app_id(IPCThreadState::self()->getCallingUid()) >= AID_APP_START) {
                ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
                      __func__, code, IPCThreadState::self()->getCallingPid(),
@@ -1489,6 +1541,50 @@ status_t BnAudioPolicyService::onTransact(
            return NO_ERROR;
        }

        case GET_SURROUND_FORMATS: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            unsigned int numSurroundFormatsReq = data.readUint32();
            if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
                numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
            }
            bool reported = data.readBool();
            unsigned int numSurroundFormats = numSurroundFormatsReq;
            audio_format_t *surroundFormats = (audio_format_t *)calloc(
                    numSurroundFormats, sizeof(audio_format_t));
            bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
            if (numSurroundFormatsReq > 0 &&
                    (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
                free(surroundFormats);
                free(surroundFormatsEnabled);
                reply->writeInt32(NO_MEMORY);
                return NO_ERROR;
            }
            status_t status = getSurroundFormats(
                    &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
            reply->writeInt32(status);

            if (status == NO_ERROR) {
                reply->writeUint32(numSurroundFormats);
                if (numSurroundFormatsReq > numSurroundFormats) {
                    numSurroundFormatsReq = numSurroundFormats;
                }
                reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
                reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
            }
            free(surroundFormats);
            free(surroundFormatsEnabled);
            return NO_ERROR;
        }

        case SET_SURROUND_FORMAT_ENABLED: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            audio_format_t audioFormat = (audio_format_t) data.readInt32();
            bool enabled = data.readBool();
            status_t status = setSurroundFormatEnabled(audioFormat, enabled);
            reply->writeInt32(status);
            return NO_ERROR;
        }

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

    static status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones);

    // numSurroundFormats holds the maximum number of formats and bool value allowed in the array.
    // When numSurroundFormats is 0, surroundFormats and surroundFormatsEnabled will not be
    // populated. The actual number of surround formats should be returned at numSurroundFormats.
    static status_t getSurroundFormats(unsigned int *numSurroundFormats,
                                       audio_format_t *surroundFormats,
                                       bool *surroundFormatsEnabled,
                                       bool reported);
    static status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled);

    // ----------------------------------------------------------------------------

    class AudioPortCallback : public RefBase
+6 −0
Original line number Diff line number Diff line
@@ -166,6 +166,12 @@ public:
    virtual status_t getMasterMono(bool *mono) = 0;
    virtual float    getStreamVolumeDB(
            audio_stream_type_t stream, int index, audio_devices_t device) = 0;

    virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
                                        audio_format_t *surroundFormats,
                                        bool *surroundFormatsEnabled,
                                        bool reported) = 0;
    virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) = 0;
};


+143 −0
Original line number Diff line number Diff line
@@ -436,6 +436,94 @@ struct HIDE _AData_deleter<Flagger, U> {
    }
};

/**
 * Helper template that copy assigns an object of a specific type (member) in an
 * AUnion.
 *
 * \param Flagger type flagger class (see AData)
 * \param U AUnion object in which the member should be copy assigned
 * \param Ts types to consider for the member
 */
template<typename Flagger, typename U, typename ...Ts>
struct HIDE _AData_copy_assigner;

/**
 * Template specialization when there are still types to consider (T and rest)
 */
template<typename Flagger, typename U, typename T, typename ...Ts>
struct HIDE _AData_copy_assigner<Flagger, U, T, Ts...> {
    static bool assign(typename Flagger::type flags, U &dst, const U &src) {
        static_assert(std::is_copy_constructible<T>::value, "T must be copy constructible");
        // if we can delete as, we can also assign as
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
            dst.template emplace<T>(src.template get<T>());
            return true;
        }
        return _AData_copy_assigner<Flagger, U, Ts...>::assign(flags, dst, src);
    }
};

/**
 * Template specialization when there are no more types to consider.
 */
template<typename Flagger, typename U>
struct HIDE _AData_copy_assigner<Flagger, U> {
    inline static bool assign(typename Flagger::type, U &, const U &) {
        return false;
    }
};

/**
 * Helper template that move assigns an object of a specific type (member) in an
 * AUnion.
 *
 * \param Flagger type flagger class (see AData)
 * \param U AUnion object in which the member should be copy assigned
 * \param Ts types to consider for the member
 */
template<typename Flagger, typename U, typename ...Ts>
struct HIDE _AData_move_assigner;

/**
 * Template specialization when there are still types to consider (T and rest)
 */
template<typename Flagger, typename U, typename T, typename ...Ts>
struct HIDE _AData_move_assigner<Flagger, U, T, Ts...> {
    template<typename V = T>
    static typename std::enable_if<std::is_move_constructible<V>::value, bool>::type
    assign(typename Flagger::type flags, U &dst, U &src) {
        // if we can delete as, we can also assign as
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
            dst.template emplace<T>(std::move(src.template get<T>()));
            return true;
        }
        return _AData_move_assigner<Flagger, U, Ts...>::assign(flags, dst, src);
    }

    // Fall back to copy construction if T is not move constructible
    template<typename V = T>
    static typename std::enable_if<!std::is_move_constructible<V>::value, bool>::type
    assign(typename Flagger::type flags, U &dst, U &src) {
        static_assert(std::is_copy_constructible<T>::value, "T must be copy constructible");
        // if we can delete as, we can also assign as
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
            dst.template emplace<T>(src.template get<T>());
            return true;
        }
        return _AData_move_assigner<Flagger, U, Ts...>::assign(flags, dst, src);
    }
};

/**
 * Template specialization when there are no more types to consider.
 */
template<typename Flagger, typename U>
struct HIDE _AData_move_assigner<Flagger, U> {
    inline static bool assign(typename Flagger::type, U &, U &) {
        return false;
    }
};

/**
 * Container that can store an arbitrary object of a set of specified types.
 *
@@ -656,6 +744,61 @@ public:
         */
        Custom() : base_t(Flagger::flagFor((void*)0)) { }

        /**
         * Copy assignment operator.
         */
        Custom& operator=(const Custom &o) {
            if (&o != this) {
                if (this->used() && !this->clear()) {
                    __builtin_trap();
                }
                if (o.used()) {
                    if (_AData_copy_assigner<Flagger, data_t, Ts...>::assign(
                            o.flags(), this->get(), o.get())) {
                        this->setFlags(o.flags());
                    } else {
                        __builtin_trap();
                    }
                }
            }
            return *this;
        }

        /**
         * Copy constructor.
         */
        Custom(const Custom &o) : Custom() {
            *this = o;
        }

        /**
         * Move assignment operator.
         */
        Custom& operator=(Custom &&o) {
            if (&o != this) {
                if (this->used() && !this->clear()) {
                    __builtin_trap();
                }
                if (o.used()) {
                    if (_AData_move_assigner<Flagger, data_t, Ts...>::assign(
                            o.flags(), this->get(), o.get())) {
                        this->setFlags(o.flags());
                        o.clear();
                    } else {
                        __builtin_trap();
                    }
                }
            }
            return *this;
        }

        /**
         * Move constructor.
         */
        Custom(Custom &&o) : Custom() {
            *this = std::move(o);
        }

        /**
         * Removes the contained object, if any.
         */
Loading