From 81b0519f04c9b378403fff9f399a2d085eecbf7d 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. Bug: 186088557 Test: make Signed-off-by: Francois Gaffie Change-Id: 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 7c4c97036bd83..5eb1e00947254 100644 --- a/core/jni/android_media_AudioSystem.cpp +++ b/core/jni/android_media_AudioSystem.cpp @@ -1930,7 +1930,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