diff options
author | Mikhail Naganov <mnaganov@google.com> | 2019-11-20 15:17:08 -0800 |
---|---|---|
committer | Mikhail Naganov <mnaganov@google.com> | 2019-11-21 12:32:09 -0800 |
commit | ed261bbfb1b44e15aeb8fce208f22860c21d4a67 (patch) | |
tree | fe884875977b5a7fa0f79b441ba44811c66d1bd7 /audio/core/all-versions/default/Device.cpp | |
parent | 422afc131a003d9958ac306bc9360da3e3569157 (diff) |
audio: Add check to IDevice.close for currently opened streams
IDevice.close must not proceed if there are streams
that are currently opened on this device.
Bug: 114451103
Test: atest VtsHalAudioV6_0TargetTest
Change-Id: I61d81bc0333098c341d5d551bf59331e49fcf682
Diffstat (limited to 'audio/core/all-versions/default/Device.cpp')
-rw-r--r-- | audio/core/all-versions/default/Device.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp index 5ea4c8df59..21dab00387 100644 --- a/audio/core/all-versions/default/Device.cpp +++ b/audio/core/all-versions/default/Device.cpp @@ -53,10 +53,14 @@ Result Device::analyzeStatus(const char* funcName, int status, void Device::closeInputStream(audio_stream_in_t* stream) { mDevice->close_input_stream(mDevice, stream); + LOG_ALWAYS_FATAL_IF(mOpenedStreamsCount == 0, "mOpenedStreamsCount is already 0"); + --mOpenedStreamsCount; } void Device::closeOutputStream(audio_stream_out_t* stream) { mDevice->close_output_stream(mDevice, stream); + LOG_ALWAYS_FATAL_IF(mOpenedStreamsCount == 0, "mOpenedStreamsCount is already 0"); + --mOpenedStreamsCount; } char* Device::halGetParameters(const char* keys) { @@ -158,6 +162,7 @@ std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamImpl(int32_t ioHandle sp<IStreamOut> streamOut; if (status == OK) { streamOut = new StreamOut(this, halStream); + ++mOpenedStreamsCount; } HidlUtils::audioConfigFromHal(halConfig, suggestedConfig); return {analyzeStatus("open_output_stream", status, {EINVAL} /*ignore*/), streamOut}; @@ -184,6 +189,7 @@ std::tuple<Result, sp<IStreamIn>> Device::openInputStreamImpl( sp<IStreamIn> streamIn; if (status == OK) { streamIn = new StreamIn(this, halStream); + ++mOpenedStreamsCount; } HidlUtils::audioConfigFromHal(halConfig, suggestedConfig); return {analyzeStatus("open_input_stream", status, {EINVAL} /*ignore*/), streamIn}; @@ -383,7 +389,7 @@ Return<Result> Device::setConnectedState(const DeviceAddress& address, bool conn #endif Result Device::doClose() { - if (mIsClosed) return Result::INVALID_STATE; + if (mIsClosed || mOpenedStreamsCount != 0) return Result::INVALID_STATE; mIsClosed = true; return analyzeStatus("close", audio_hw_device_close(mDevice)); } |