From 523571c3e8957d77fcf81411d0fcf94b9656b05c Mon Sep 17 00:00:00 2001 From: Francois Gaffie Date: Tue, 20 Apr 2021 08:59:46 +0200 Subject: [PATCH] AudioSystem: startAudioSource: ensure port handle initialized In case of failure, port handle reported is not initialized by JNI layer. Any failing call to native AudioSystem::startAudioSource will not set the port handle, but returning an error status. JNI checks for port handle validity rather than error status. This CL ensures JNI checks first status to report an error, otherwise asserts on handle validity. Signed-off-by: Francois Gaffie Change-Id: I4eb8046a1263aeb7d464d35a360a8adb77c4b1a5 Merged-In: I4eb8046a1263aeb7d464d35a360a8adb77c4b1a5 --- core/jni/android_media_AudioSystem.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp index 20e64ffe94712..feb8930a0dbf8 100644 --- a/core/jni/android_media_AudioSystem.cpp +++ b/core/jni/android_media_AudioSystem.cpp @@ -1869,7 +1869,11 @@ android_media_AudioSystem_startAudioSource(JNIEnv *env, jobject clazz, audio_port_handle_t handle; status_t status = AudioSystem::startAudioSource(&nAudioPortConfig, paa.get(), &handle); ALOGV("AudioSystem::startAudioSource() returned %d handle %d", status, handle); - return handle > 0 ? handle : nativeToJavaStatus(status); + if (status != NO_ERROR) { + return nativeToJavaStatus(status); + } + ALOG_ASSERT(handle > 0, "%s: invalid handle reported on successful call", __func__); + return handle; } static jint