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

Commit 7bc710b9 authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: preserve requested device ID, fix regression

This fixes a bug that caused the mDeviceId and the mRequestedDeviceId
to be set to a specific device even when UNSPECIFIED was requested.
That led to some streams not getting disconnected when they should.

Bug: 242648766
Test: OboeTester TEST DISCONNECT
Test: OboeTester TEST INPUT
Test: open an MMAP stream and then plug in a headet
Test: it should close the input stream.
Change-Id: I51f0517e719b847f519bb08d3e5b0afb9b4d2f36
parent 54c39be8
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ audio_format_t getNextFormatToTry(audio_format_t curFormat, audio_format_t retur
aaudio_result_t AAudioServiceEndpointMMAP::open(const aaudio::AAudioStreamRequest &request) {
    aaudio_result_t result = AAUDIO_OK;
    copyFrom(request.getConstantConfiguration());
    mRequestedDeviceId = getDeviceId();

    mMmapClient.attributionSource = request.getAttributionSource();
    // TODO b/182392769: use attribution source util
    mMmapClient.attributionSource.uid = VALUE_OR_FATAL(
@@ -136,7 +138,7 @@ aaudio_result_t AAudioServiceEndpointMMAP::openWithFormat(

    const audio_attributes_t attributes = getAudioAttributesFrom(this);

    mRequestedDeviceId = deviceId = getDeviceId();
    deviceId = mRequestedDeviceId;

    // Fill in config
    config.format = audioFormat;
@@ -172,8 +174,10 @@ aaudio_result_t AAudioServiceEndpointMMAP::openWithFormat(
    audio_session_t sessionId = AAudioConvert_aaudioToAndroidSessionId(requestedSessionId);

    // Open HAL stream. Set mMmapStream
    ALOGD("%s trying to open MMAP stream with format=%#x, sample_rate=%u, channel_mask=%#x",
          __func__, config.format, config.sample_rate, config.channel_mask);
    ALOGD("%s trying to open MMAP stream with format=%#x, "
          "sample_rate=%u, channel_mask=%#x, device=%d",
          __func__, config.format, config.sample_rate,
          config.channel_mask, deviceId);
    status_t status = MmapStreamInterface::openMmapStream(streamDirection,
                                                          &attributes,
                                                          &config,
@@ -248,6 +252,9 @@ aaudio_result_t AAudioServiceEndpointMMAP::openWithFormat(

error:
    close();
    // restore original requests
    setDeviceId(mRequestedDeviceId);
    setSessionId(requestedSessionId);
    return result;
}