diff options
-rw-r--r-- | audio/6.0/IDevice.hal | 19 | ||||
-rw-r--r-- | audio/core/all-versions/default/Device.cpp | 29 | ||||
-rw-r--r-- | audio/core/all-versions/default/PrimaryDevice.cpp | 7 | ||||
-rw-r--r-- | audio/core/all-versions/default/include/core/default/Device.h | 6 | ||||
-rw-r--r-- | audio/core/all-versions/default/include/core/default/PrimaryDevice.h | 3 | ||||
-rw-r--r-- | audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp | 9 | ||||
-rw-r--r-- | current.txt | 2 |
7 files changed, 70 insertions, 5 deletions
diff --git a/audio/6.0/IDevice.hal b/audio/6.0/IDevice.hal index 2347696035..c2e310ce69 100644 --- a/audio/6.0/IDevice.hal +++ b/audio/6.0/IDevice.hal @@ -168,6 +168,25 @@ interface IDevice { generates (Result retval, AudioPatchHandle patch); /** + * Updates an audio patch. + * + * Use of this function is preferred to releasing and re-creating a patch + * as the HAL module can figure out a way of switching the route without + * causing audio disruption. + * + * @param previousPatch handle of the previous patch to update. + * @param sources new patch sources. + * @param sinks new patch sinks. + * @return retval operation completion status. + * @return patch updated patch handle. + */ + updateAudioPatch( + AudioPatchHandle previousPatch, + vec<AudioPortConfig> sources, + vec<AudioPortConfig> sinks) generates ( + Result retval, AudioPatchHandle patch); + + /** * Release an audio patch. * * @param patch patch handle. diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp index ad841caf2e..47e31c1801 100644 --- a/audio/core/all-versions/default/Device.cpp +++ b/audio/core/all-versions/default/Device.cpp @@ -269,12 +269,21 @@ Return<bool> Device::supportsAudioPatches() { Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources, const hidl_vec<AudioPortConfig>& sinks, createAudioPatch_cb _hidl_cb) { + auto [retval, patch] = createOrUpdateAudioPatch( + static_cast<AudioPatchHandle>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), sources, + sinks); + _hidl_cb(retval, patch); + return Void(); +} + +std::tuple<Result, AudioPatchHandle> Device::createOrUpdateAudioPatch( + AudioPatchHandle patch, const hidl_vec<AudioPortConfig>& sources, + const hidl_vec<AudioPortConfig>& sinks) { Result retval(Result::NOT_SUPPORTED); - AudioPatchHandle patch = 0; if (version() >= AUDIO_DEVICE_API_VERSION_3_0) { std::unique_ptr<audio_port_config[]> halSources(HidlUtils::audioPortConfigsToHal(sources)); std::unique_ptr<audio_port_config[]> halSinks(HidlUtils::audioPortConfigsToHal(sinks)); - audio_patch_handle_t halPatch = AUDIO_PATCH_HANDLE_NONE; + audio_patch_handle_t halPatch = static_cast<audio_patch_handle_t>(patch); retval = analyzeStatus("create_audio_patch", mDevice->create_audio_patch(mDevice, sources.size(), &halSources[0], sinks.size(), &halSinks[0], &halPatch)); @@ -282,8 +291,7 @@ Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources, patch = static_cast<AudioPatchHandle>(halPatch); } } - _hidl_cb(retval, patch); - return Void(); + return {retval, patch}; } Return<Result> Device::releaseAudioPatch(int32_t patch) { @@ -438,6 +446,19 @@ Return<Result> Device::removeDeviceEffect(AudioPortHandle device, uint64_t effec } } +Return<void> Device::updateAudioPatch(int32_t previousPatch, + const hidl_vec<AudioPortConfig>& sources, + const hidl_vec<AudioPortConfig>& sinks, + createAudioPatch_cb _hidl_cb) { + if (previousPatch != static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE)) { + auto [retval, patch] = createOrUpdateAudioPatch(previousPatch, sources, sinks); + _hidl_cb(retval, patch); + } else { + _hidl_cb(Result::INVALID_ARGUMENTS, previousPatch); + } + return Void(); +} + #endif } // namespace implementation diff --git a/audio/core/all-versions/default/PrimaryDevice.cpp b/audio/core/all-versions/default/PrimaryDevice.cpp index 0f1aba0f2f..679f85dad3 100644 --- a/audio/core/all-versions/default/PrimaryDevice.cpp +++ b/audio/core/all-versions/default/PrimaryDevice.cpp @@ -176,6 +176,13 @@ Return<Result> PrimaryDevice::addDeviceEffect(AudioPortHandle device, uint64_t e Return<Result> PrimaryDevice::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) { return mDevice->removeDeviceEffect(device, effectId); } + +Return<void> PrimaryDevice::updateAudioPatch(int32_t previousPatch, + const hidl_vec<AudioPortConfig>& sources, + const hidl_vec<AudioPortConfig>& sinks, + updateAudioPatch_cb _hidl_cb) { + return mDevice->updateAudioPatch(previousPatch, sources, sinks, _hidl_cb); +} #endif // Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow. diff --git a/audio/core/all-versions/default/include/core/default/Device.h b/audio/core/all-versions/default/include/core/default/Device.h index 80a9638004..b0e72d9600 100644 --- a/audio/core/all-versions/default/include/core/default/Device.h +++ b/audio/core/all-versions/default/include/core/default/Device.h @@ -118,6 +118,9 @@ struct Device : public IDevice, public ParametersUtil { Return<Result> close() override; Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; + Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources, + const hidl_vec<AudioPortConfig>& sinks, + createAudioPatch_cb _hidl_cb) override; #endif Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override; @@ -136,6 +139,9 @@ struct Device : public IDevice, public ParametersUtil { virtual ~Device(); Result doClose(); + std::tuple<Result, AudioPatchHandle> createOrUpdateAudioPatch( + AudioPatchHandle patch, const hidl_vec<AudioPortConfig>& sources, + const hidl_vec<AudioPortConfig>& sinks); // Methods from ParametersUtil. char* halGetParameters(const char* keys) override; diff --git a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h index 9fc90c39fe..ccdb7b26c1 100644 --- a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h +++ b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h @@ -100,6 +100,9 @@ struct PrimaryDevice : public IPrimaryDevice { Return<Result> close() override; Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; + Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources, + const hidl_vec<AudioPortConfig>& sinks, + updateAudioPatch_cb _hidl_cb) override; #endif Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override; diff --git a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp index 2afbbb8fc4..09ef330be6 100644 --- a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp @@ -181,3 +181,12 @@ TEST_P(AudioHidlDeviceTest, CloseDeviceWithOpenedInputStreams) { ASSERT_OK(getDevice()->close()); ASSERT_TRUE(resetDevice()); } + +TEST_P(AudioPatchHidlTest, UpdatePatchInvalidHandle) { + doc::test("Verify that passing an invalid handle to updateAudioPatch is checked"); + AudioPatchHandle ignored; + ASSERT_OK(getDevice()->updateAudioPatch( + static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), + hidl_vec<AudioPortConfig>(), hidl_vec<AudioPortConfig>(), returnIn(res, ignored))); + ASSERT_RESULT(Result::INVALID_ARGUMENTS, res); +} diff --git a/current.txt b/current.txt index 999b207899..1fe17d5ca4 100644 --- a/current.txt +++ b/current.txt @@ -598,7 +598,7 @@ fd65298e1e09e0e3c781ab18305920d757dbe55a3b459ce17814ec5cf6dfee99 android.hardwar # HALs released in Android R e966a3437d6a98d9d9e14e9d672088771716031900c0deb55a0946c751a03a44 android.hardware.audio@6.0::types -4540d12fe1cea996f21bd1712d4ae0906dcbd58177dac494efc605b004902d43 android.hardware.audio@6.0::IDevice +dd3e9280be60a5e042331c1046d13938e2cc323dc4b267cc74d544bf62fc0314 android.hardware.audio@6.0::IDevice 2402876cbc23c0de3690a665eca84fd3857d1808dba5cad25ce272f81ecef8c9 android.hardware.audio@6.0::IDevicesFactory bca5379d5065e2e08b6ad7308ffc8a71a972fc0698bec678ea32eea786d01cb5 android.hardware.audio@6.0::IPrimaryDevice fd1f1b29f26b42e886220f04a08086c00e5ade9d7b53f095438e578ab9d42a93 android.hardware.audio@6.0::IStream |