From 69330d4c9c96a4770d2ac3b06298f3345bb76cd4 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 8 Apr 2020 19:29:50 +0000 Subject: [PATCH] Move AudioSystem errorCallback call out from gLock Since the error callback ends up calling into Java, there is a potential for a deadlock with Java code that takes AudioSystem.class lock and calls into native code that takes gLock in its own turn. Bug: 152819012 Test: use audio on a phone, also killing native audioserver while watching YT, also while making cellular calls Change-Id: Ib288ba96ae2f7b5ab36c1b0a1db4adde487d6a49 --- media/libaudioclient/AudioSystem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/media/libaudioclient/AudioSystem.cpp b/media/libaudioclient/AudioSystem.cpp index 74fa343427..6357da4316 100644 --- a/media/libaudioclient/AudioSystem.cpp +++ b/media/libaudioclient/AudioSystem.cpp @@ -55,6 +55,7 @@ const sp AudioSystem::get_audio_flinger() { sp af; sp afc; + bool reportNoError = false; { Mutex::Autolock _l(gLock); if (gAudioFlinger == 0) { @@ -70,7 +71,7 @@ const sp AudioSystem::get_audio_flinger() if (gAudioFlingerClient == NULL) { gAudioFlingerClient = new AudioFlingerClient(); } else { - reportError(NO_ERROR); + reportNoError = true; } binder->linkToDeath(gAudioFlingerClient); gAudioFlinger = interface_cast(binder); @@ -86,6 +87,7 @@ const sp AudioSystem::get_audio_flinger() af->registerClient(afc); IPCThreadState::self()->restoreCallingIdentity(token); } + if (reportNoError) reportError(NO_ERROR); return af; }