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

Commit dcbda2a2 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: fix recording activity reporting

Add missing active clients management when an output or input
is force closed by the audio policy manager. This resulted in
stale activity monitoring entries in AuduiService.

Bug: 123312504
Test: connect and disconnect a headset while recording a video
Change-Id: I66fe96daed2475ae6ada700ef1210d38ad099da2
parent 049aa255
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -257,15 +257,21 @@ void AudioInputDescriptor::stop()
void AudioInputDescriptor::close()
{
    if (mIoHandle != AUDIO_IO_HANDLE_NONE) {
        // clean up active clients if any (can happen if close() is called to force
        // clients to reconnect
        for (const auto &client : getClientIterable()) {
            if (client->active()) {
                ALOGW("%s client with port ID %d still active on input %d",
                    __func__, client->portId(), mId);
                setClientActive(client, false);
                stop();
            }
        }

        mClientInterface->closeInput(mIoHandle);
        LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount < 1, "%s profile open count %u",
                            __FUNCTION__, mProfile->curOpenCount);
        // do not call stop() here as stop() is supposed to be called after
        //  setClientActive(client, false) and we don't know how many clients
        // are still active at this time
        if (isActive()) {
            mProfile->curActiveCount--;
        }

        mProfile->curOpenCount--;
        LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount <  mProfile->curActiveCount,
                "%s(%d): mProfile->curOpenCount %d < mProfile->curActiveCount %d.",
+11 −5
Original line number Diff line number Diff line
@@ -563,6 +563,17 @@ void SwAudioOutputDescriptor::stop()
void SwAudioOutputDescriptor::close()
{
    if (mIoHandle != AUDIO_IO_HANDLE_NONE) {
        // clean up active clients if any (can happen if close() is called to force
        // clients to reconnect
        for (const auto &client : getClientIterable()) {
            if (client->active()) {
                ALOGW("%s client with port ID %d still active on output %d",
                      __func__, client->portId(), mId);
                setClientActive(client, false);
                stop();
            }
        }

        AudioParameter param;
        param.add(String8("closing"), String8("true"));
        mClientInterface->setParameters(mIoHandle, param.toString());
@@ -571,11 +582,6 @@ void SwAudioOutputDescriptor::close()

        LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount < 1, "%s profile open count %u",
                            __FUNCTION__, mProfile->curOpenCount);
        // do not call stop() here as stop() is supposed to be called after setClientActive(false)
        // and we don't know how many streams are still active at this time
        if (isActive()) {
            mProfile->curActiveCount--;
        }
        mProfile->curOpenCount--;
        mIoHandle = AUDIO_IO_HANDLE_NONE;
    }