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

Commit 4238a5d1 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 headset
Test: it should close the input stream.
Change-Id: I51f0517e719b847f519bb08d3e5b0afb9b4d2f36
Merged-In: I51f0517e719b847f519bb08d3e5b0afb9b4d2f36
(cherry picked from commit 7bc710b9)
parent 1f0ac9da
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ std::string AAudioServiceEndpointMMAP::dump() const {
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(
@@ -115,7 +117,7 @@ aaudio_result_t AAudioServiceEndpointMMAP::openWithFormat(audio_format_t audioFo

    const audio_attributes_t attributes = getAudioAttributesFrom(this);

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

    // Fill in config
    config.format = audioFormat;
@@ -151,6 +153,10 @@ aaudio_result_t AAudioServiceEndpointMMAP::openWithFormat(audio_format_t audioFo
    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, device=%d",
          __func__, config.format, config.sample_rate,
          config.channel_mask, deviceId);
    status_t status = MmapStreamInterface::openMmapStream(streamDirection,
                                                          &attributes,
                                                          &config,
@@ -221,6 +227,9 @@ aaudio_result_t AAudioServiceEndpointMMAP::openWithFormat(audio_format_t audioFo

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