From 66351e5a9f72e855cf5aee3797f6bef9aafc82cf Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Tue, 16 Apr 2024 16:27:10 +0000 Subject: [PATCH] audio: Align bluetooth start behavior When staring data transfer, if resuming of BT session fails, the legacy implementation does not indicate an error, thus causing an automatic retry on next transfer. The AIDL implementation was switching the stream into an error state instead. This could cause audio mute when the BT stack is slow on resuming. This CL aligns AIDL with legacy behavior. Bug: 333307789 Test: repro steps in the bug (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3f4c7fca29db4b82d597bb56478f40a75cef618c) Merged-In: I5080a7275671287f188930f041c5ff2215ed2e1e Change-Id: I5080a7275671287f188930f041c5ff2215ed2e1e --- audio/aidl/default/bluetooth/StreamBluetooth.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/audio/aidl/default/bluetooth/StreamBluetooth.cpp b/audio/aidl/default/bluetooth/StreamBluetooth.cpp index f22b7a97d6..efab4708e3 100644 --- a/audio/aidl/default/bluetooth/StreamBluetooth.cpp +++ b/audio/aidl/default/bluetooth/StreamBluetooth.cpp @@ -93,17 +93,18 @@ StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadat ::android::status_t StreamBluetooth::transfer(void* buffer, size_t frameCount, size_t* actualFrameCount, int32_t* latencyMs) { std::lock_guard guard(mLock); + *actualFrameCount = 0; + *latencyMs = StreamDescriptor::LATENCY_UNKNOWN; if (mBtDeviceProxy == nullptr || mBtDeviceProxy->getState() == BluetoothStreamState::DISABLED) { - *actualFrameCount = 0; - *latencyMs = StreamDescriptor::LATENCY_UNKNOWN; + // The BT session is turned down, silently ignore write. return ::android::OK; } - *actualFrameCount = 0; - *latencyMs = 0; if (!mBtDeviceProxy->start()) { - LOG(ERROR) << __func__ << ": state= " << mBtDeviceProxy->getState() << " failed to start"; - return -EIO; + LOG(WARNING) << __func__ << ": state= " << mBtDeviceProxy->getState() + << " failed to start, will retry"; + return ::android::OK; } + *latencyMs = 0; const size_t bytesToTransfer = frameCount * mFrameSizeBytes; const size_t bytesTransferred = mIsInput ? mBtDeviceProxy->readData(buffer, bytesToTransfer) : mBtDeviceProxy->writeData(buffer, bytesToTransfer);