Merge "audio: update setAudioPatch" into main am: b031448387
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/3391740
Change-Id: I8dfb292840cfc6d5a0b05305d7b9920bd0e5e8c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/audio/aidl/default/Module.cpp b/audio/aidl/default/Module.cpp
index e96cf81..2be7f51 100644
--- a/audio/aidl/default/Module.cpp
+++ b/audio/aidl/default/Module.cpp
@@ -1049,6 +1049,23 @@
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
+ auto& patches = getConfig().patches;
+ auto existing = patches.end();
+ if (in_requested.id != 0) {
+ existing = findById<AudioPatch>(patches, in_requested.id);
+ if (existing == patches.end()) {
+ LOG(ERROR) << __func__ << ": " << mType << ": not found existing patch id "
+ << in_requested.id;
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ if (in_requested == *existing) {
+ LOG(INFO) << __func__ << ": " << mType
+ << ": requested patch has no changes compared to already existing one, id "
+ << in_requested.id;
+ return ndk::ScopedAStatus::ok();
+ }
+ }
+
auto& configs = getConfig().portConfigs;
std::vector<int32_t> missingIds;
auto sources =
@@ -1088,20 +1105,12 @@
}
RETURN_STATUS_IF_ERROR(checkAudioPatchEndpointsMatch(sources, sinks));
- auto& patches = getConfig().patches;
- auto existing = patches.end();
std::optional<decltype(mPatches)> patchesBackup;
- if (in_requested.id != 0) {
- existing = findById<AudioPatch>(patches, in_requested.id);
- if (existing != patches.end()) {
- patchesBackup = mPatches;
- cleanUpPatch(existing->id);
- } else {
- LOG(ERROR) << __func__ << ": " << mType << ": not found existing patch id "
- << in_requested.id;
- return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
- }
+ if (existing != patches.end()) {
+ patchesBackup = mPatches;
+ cleanUpPatch(existing->id);
}
+
// Validate the requested patch.
for (const auto& [sinkPortId, nonExclusive] : allowedSinkPorts) {
if (!nonExclusive && mPatches.count(sinkPortId) != 0) {