From 2443760584e8e9798b65b297f1636953c287e5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gaffie?= Date: Mon, 23 Apr 2018 15:08:59 +0200 Subject: [PATCH] audio policy service: fix audioserver port cb upon APS crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of an audioserver crash, clients that registered AudioPort cb are no more notified of Port and Patch update (only Service Died continues to work). The AudioPolicyService client shall upon registration set again the cb flag to continue beeing notified. Also clear binder caller identity before registering a client to audio flinger and audio policy services to avoid registering the wrong client when get_audio_flinger() or get_audio_policy_service() is called while executing a binder call. Bug: 78506562 Test: launch a test app registering to Port Callback. Check upon setDeviceConnectionState and createAudioPatch that cb are called. Kill the audio server, and check cb continue to be called. Change-Id: If1e803f59cb02fba84b6259e9da2d7031235d9c2 Signed-off-by: François Gaffie --- media/libaudioclient/AudioSystem.cpp | 6 ++++++ media/libaudioclient/include/media/AudioSystem.h | 1 + 2 files changed, 7 insertions(+) diff --git a/media/libaudioclient/AudioSystem.cpp b/media/libaudioclient/AudioSystem.cpp index 1c4a80e82a..39ee437044 100644 --- a/media/libaudioclient/AudioSystem.cpp +++ b/media/libaudioclient/AudioSystem.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,9 @@ const sp AudioSystem::get_audio_flinger() af = gAudioFlinger; } if (afc != 0) { + int64_t token = IPCThreadState::self()->clearCallingIdentity(); af->registerClient(afc); + IPCThreadState::self()->restoreCallingIdentity(token); } return af; } @@ -767,7 +770,10 @@ const sp AudioSystem::get_audio_policy_service() ap = gAudioPolicyService; } if (apc != 0) { + int64_t token = IPCThreadState::self()->clearCallingIdentity(); ap->registerClient(apc); + ap->setAudioPortCallbacksEnabled(apc->isAudioPortCbEnabled()); + IPCThreadState::self()->restoreCallingIdentity(token); } return ap; diff --git a/media/libaudioclient/include/media/AudioSystem.h b/media/libaudioclient/include/media/AudioSystem.h index 22b700d6b7..0c4d6ee9a8 100644 --- a/media/libaudioclient/include/media/AudioSystem.h +++ b/media/libaudioclient/include/media/AudioSystem.h @@ -431,6 +431,7 @@ private: int addAudioPortCallback(const sp& callback); int removeAudioPortCallback(const sp& callback); + bool isAudioPortCbEnabled() const { return (mAudioPortCallbacks.size() != 0); } // DeathRecipient virtual void binderDied(const wp& who);