aaudio: fix hang in client when audioserver dies
Fix timeout detection so that callback thread can die.
Prevent AAudioBinderClient singleton from getting deleted,
which caused a subsequent lock on a dead object to hang.
Bug: 64988439
Test: "write_sine -m2 -pl" and "adb shell killall audioserver"
Change-Id: I044bce385b66e69007d1997f051c9d6c042b7871
diff --git a/media/libaaudio/src/binding/AAudioBinderClient.h b/media/libaaudio/src/binding/AAudioBinderClient.h
index 89ae85c..f9da8b4 100644
--- a/media/libaaudio/src/binding/AAudioBinderClient.h
+++ b/media/libaaudio/src/binding/AAudioBinderClient.h
@@ -118,13 +118,13 @@
{
public:
AAudioClient(android::wp<AAudioBinderClient> aaudioBinderClient)
- : mBinderClient(aaudioBinderClient) {
+ : mBinderClient(aaudioBinderClient) {
}
// implement DeathRecipient
virtual void binderDied(const android::wp<android::IBinder>& who __unused) {
android::sp<AAudioBinderClient> client = mBinderClient.promote();
- if (client != 0) {
+ if (client.get() != nullptr) {
client->dropAAudioService();
}
ALOGW("AAudio service binderDied()!");
@@ -133,7 +133,7 @@
// implement BnAAudioClient
void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) {
android::sp<AAudioBinderClient> client = mBinderClient.promote();
- if (client != 0) {
+ if (client.get() != nullptr) {
client->onStreamChange(handle, opcode, value);
}
}
@@ -141,10 +141,11 @@
android::wp<AAudioBinderClient> mBinderClient;
};
+private:
- android::Mutex mServiceLock;
+ android::Mutex mServiceLock;
android::sp<android::IAAudioService> mAAudioService;
- android::sp<AAudioClient> mAAudioClient;
+ android::sp<AAudioClient> mAAudioClient;
};