Merge "IAudioFlinger: fix incorrect audio patch handle" into sc-dev am: 3718813a75

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/15376098

Change-Id: Icfa6179812a73b5767635a628446048eae0f1e09
diff --git a/media/libaudioclient/IAudioFlinger.cpp b/media/libaudioclient/IAudioFlinger.cpp
index ef0f244..2af1c50 100644
--- a/media/libaudioclient/IAudioFlinger.cpp
+++ b/media/libaudioclient/IAudioFlinger.cpp
@@ -665,7 +665,11 @@
 status_t AudioFlingerClientAdapter::createAudioPatch(const struct audio_patch* patch,
                                                      audio_patch_handle_t* handle) {
     media::AudioPatch patchAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_AudioPatch(*patch));
-    int32_t aidlRet;
+    int32_t aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(
+                    AUDIO_PATCH_HANDLE_NONE));
+    if (handle != nullptr) {
+        aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(*handle));
+    }
     RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
             mDelegate->createAudioPatch(patchAidl, &aidlRet)));
     if (handle != nullptr) {
@@ -1144,7 +1148,8 @@
 Status AudioFlingerServerAdapter::createAudioPatch(const media::AudioPatch& patch,
                                                    int32_t* _aidl_return) {
     audio_patch patchLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPatch_audio_patch(patch));
-    audio_patch_handle_t handleLegacy;
+    audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER(
+            aidl2legacy_int32_t_audio_patch_handle_t(*_aidl_return));
     RETURN_BINDER_IF_ERROR(mDelegate->createAudioPatch(&patchLegacy, &handleLegacy));
     *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_patch_handle_t_int32_t(handleLegacy));
     return Status::ok();