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

Commit f579db5a authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audiopolicy: exclusive Preferred Device



It allows to force the routing of music during call without
affecting clients that does not explicitely requested to use
another device than the one decided by the policy during call
(which is TELEPHONY TX).

It fixes differently Bug 111467967.

Test: make

Change-Id: I6034f0d2568e1b2a1e600d9ae1453fd0c60ed02e
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent c005e569
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -42,9 +42,11 @@ class ClientDescriptor: public RefBase
public:
    ClientDescriptor(audio_port_handle_t portId, uid_t uid, audio_session_t sessionId,
                     audio_attributes_t attributes, audio_config_base_t config,
                   audio_port_handle_t preferredDeviceId) :
                     audio_port_handle_t preferredDeviceId,
                     bool isPreferredDeviceForExclusiveUse = false) :
        mPortId(portId), mUid(uid), mSessionId(sessionId), mAttributes(attributes),
        mConfig(config), mPreferredDeviceId(preferredDeviceId), mActive(false) {}
        mConfig(config), mPreferredDeviceId(preferredDeviceId), mActive(false),
        mPreferredDeviceForExclusiveUse(isPreferredDeviceForExclusiveUse){}
    ~ClientDescriptor() override = default;

    virtual void dump(String8 *dst, int spaces, int index) const;
@@ -58,7 +60,8 @@ public:
    audio_port_handle_t preferredDeviceId() const { return mPreferredDeviceId; };
    void setPreferredDeviceId(audio_port_handle_t preferredDeviceId) {
        mPreferredDeviceId = preferredDeviceId;
    };
    }
    bool isPreferredDeviceForExclusiveUse() const { return mPreferredDeviceForExclusiveUse; }
    void setActive(bool active) { mActive = active; }
    bool active() const { return mActive; }
    bool hasPreferredDevice(bool activeOnly = false) const {
@@ -73,6 +76,7 @@ private:
    const audio_config_base_t mConfig;
          audio_port_handle_t mPreferredDeviceId;  // selected input device port ID
          bool mActive;
          bool mPreferredDeviceForExclusiveUse = false;
};

class TrackClientDescriptor: public ClientDescriptor
@@ -81,8 +85,10 @@ public:
    TrackClientDescriptor(audio_port_handle_t portId, uid_t uid, audio_session_t sessionId,
                          audio_attributes_t attributes, audio_config_base_t config,
                          audio_port_handle_t preferredDeviceId, audio_stream_type_t stream,
                          product_strategy_t strategy, audio_output_flags_t flags) :
        ClientDescriptor(portId, uid, sessionId, attributes, config, preferredDeviceId),
                          product_strategy_t strategy, audio_output_flags_t flags,
                          bool isPreferredDeviceForExclusiveUse) :
        ClientDescriptor(portId, uid, sessionId, attributes, config, preferredDeviceId,
                         isPreferredDeviceForExclusiveUse),
        mStream(stream), mStrategy(strategy), mFlags(flags) {}
    ~TrackClientDescriptor() override = default;

+2 −1
Original line number Diff line number Diff line
@@ -258,7 +258,8 @@ TrackClientVector AudioOutputDescriptor::clientsList(bool activeOnly, product_st
    for (const auto &client : getClientIterable()) {
        if ((!activeOnly || client->active())
            && (strategy == PRODUCT_STRATEGY_NONE || strategy == client->strategy())
            && (!preferredDeviceOnly || client->hasPreferredDevice())) {
            && (!preferredDeviceOnly ||
                (client->hasPreferredDevice() && !client->isPreferredDeviceForExclusiveUse()))) {
            clients.push_back(client);
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t
         product_strategy_t strategy) :
    TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
        AUDIO_CONFIG_BASE_INITIALIZER, AUDIO_PORT_HANDLE_NONE,
        stream, strategy, AUDIO_OUTPUT_FLAG_NONE),
        stream, strategy, AUDIO_OUTPUT_FLAG_NONE, false),
        mPatchDesc(patchDesc), mSrcDevice(srcDevice)
{
}
+9 −5
Original line number Diff line number Diff line
@@ -916,7 +916,8 @@ status_t AudioPolicyManager::getOutputForAttrInt(audio_attributes_t *resultAttr,
                                                 uid_t uid,
                                                 const audio_config_t *config,
                                                 audio_output_flags_t *flags,
                                                 audio_port_handle_t *selectedDeviceId)
                                                 audio_port_handle_t *selectedDeviceId,
                                                 bool *isRequestedDeviceForExclusiveUse)
{
    DeviceVector outputDevices;
    const audio_port_handle_t requestedPortId = *selectedDeviceId;
@@ -980,7 +981,7 @@ status_t AudioPolicyManager::getOutputForAttrInt(audio_attributes_t *resultAttr,
        isInCall()) {
        if (requestedPortId != AUDIO_PORT_HANDLE_NONE) {
            *flags = (audio_output_flags_t)AUDIO_OUTPUT_FLAG_INCALL_MUSIC;
            // @todo: provide another solution (separated CL)
            *isRequestedDeviceForExclusiveUse = true;
        }
    }

@@ -1030,8 +1031,9 @@ status_t AudioPolicyManager::getOutputForAttr(const audio_attributes_t *attr,
    }
    const audio_port_handle_t requestedPortId = *selectedDeviceId;
    audio_attributes_t resultAttr;
    bool isRequestedDeviceForExclusiveUse = false;
    status_t status = getOutputForAttrInt(&resultAttr, output, session, attr, stream, uid,
            config, flags, selectedDeviceId);
            config, flags, selectedDeviceId, &isRequestedDeviceForExclusiveUse);
    if (status != NO_ERROR) {
        return status;
    }
@@ -1045,7 +1047,7 @@ status_t AudioPolicyManager::getOutputForAttr(const audio_attributes_t *attr,
        new TrackClientDescriptor(*portId, uid, session, resultAttr, clientConfig,
                                  requestedPortId, *stream,
                                  mEngine->getProductStrategyForAttributes(resultAttr),
                                  *flags);
                                  *flags, isRequestedDeviceForExclusiveUse);
    sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(*output);
    outputDesc->addClient(clientDesc);

@@ -3633,8 +3635,10 @@ status_t AudioPolicyManager::connectAudioSource(const sp<SourceClientDescriptor>
        config.format = sourceDesc->config().format;
        audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE;
        audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
        bool isRequestedDeviceForExclusiveUse = false;
        getOutputForAttrInt(&resultAttr, &output, AUDIO_SESSION_NONE,
                &attributes, &stream, sourceDesc->uid(), &config, &flags, &selectedDeviceId);
                &attributes, &stream, sourceDesc->uid(), &config, &flags,
                &selectedDeviceId, &isRequestedDeviceForExclusiveUse);
        if (output == AUDIO_IO_HANDLE_NONE) {
            ALOGV("%s no output for device %08x", __FUNCTION__, sinkDevices.types());
            return INVALID_OPERATION;
+2 −1
Original line number Diff line number Diff line
@@ -710,7 +710,8 @@ private:
                uid_t uid,
                const audio_config_t *config,
                audio_output_flags_t *flags,
                audio_port_handle_t *selectedDeviceId);
                audio_port_handle_t *selectedDeviceId,
                bool *isRequestedDeviceForExclusiveUse);
        // internal method to return the output handle for the given device and format
        audio_io_handle_t getOutputForDevices(
                const DeviceVector &devices,