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

Commit 98ab408b authored by Phil Burk's avatar Phil Burk
Browse files

audioflinger: only hold wakeLock when started

The AAudio MMAP streams used to hold a wakeLock from
the time they were opened until closed.
Now it is acquired when the first stream is started
and released when the first stream is stopped.

This was tested by creating shared streams using
OboeTester and write_sine_callback and input_monitor_callback and
then adding lots of logs to see when the
wakeLock was acquired and released.

Note that ~ThreadBase() calls releaseWakeLock_l() so ~MmapThread()
does not need to.

Bug: 167345722
Test: Launch OboeTester
Test: Tap TEST OUTPUT
Test: Tap OPEN
Test: Enter: adb shell dumpsys power
Test: See no MmapPlayback wakelock
Test: Tap START
Test: Enter: adb shell dumpsys power
Test: See "ACQ MmapPlayback"
Test: Tap STOP
Test: Enter: adb shell dumpsys power
Test: See "REL MmapPlayback"

Test: atest AAudioTests
Change-Id: Iad87f5ebd22f20c89699e8b1a75d8df482046360
parent 2f0bf51f
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -8781,7 +8781,6 @@ AudioFlinger::MmapThread::MmapThread(

AudioFlinger::MmapThread::~MmapThread()
{
    releaseWakeLock_l();
}

void AudioFlinger::MmapThread::onFirstRef()
@@ -8831,7 +8830,6 @@ status_t AudioFlinger::MmapThread::createMmapBuffer(int32_t minSizeFrames,
        return NO_INIT;
    }
    mStandby = true;
    acquireWakeLock();
    return mHalStream->createMmapBuffer(minSizeFrames, info);
}

@@ -8870,8 +8868,12 @@ status_t AudioFlinger::MmapThread::start(const AudioClient& client,
    status_t ret;

    if (*handle == mPortId) {
        // for the first track, reuse portId and session allocated when the stream was opened
        return exitStandby();
        // For the first track, reuse portId and session allocated when the stream was opened.
        ret = exitStandby();
        if (ret == NO_ERROR) {
            acquireWakeLock();
        }
        return ret;
    }

    audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
@@ -8992,6 +8994,7 @@ status_t AudioFlinger::MmapThread::stop(audio_port_handle_t handle)

    if (handle == mPortId) {
        mHalStream->stop();
        releaseWakeLock();
        return NO_ERROR;
    }