Fix segfault in capture state registration
Using 'this' from within the ctor of a RefBase is disallowed.
Fixes: 167242344
Test: Rerun the failed tests referenced in the bug.
Change-Id: I9737f245a2f735bdca1513beedcca93891af59b6
diff --git a/media/libaudioclient/AudioSystem.cpp b/media/libaudioclient/AudioSystem.cpp
index d918a50..2c20221 100644
--- a/media/libaudioclient/AudioSystem.cpp
+++ b/media/libaudioclient/AudioSystem.cpp
@@ -1641,16 +1641,17 @@
CaptureStateListenerImpl(
const sp<IAudioPolicyService>& aps,
const sp<AudioSystem::CaptureStateListener>& listener)
- : mAps(aps), mListener(listener) {
+ : mAps(aps), mListener(listener) {}
+
+ void init() {
bool active;
- status_t status = aps->registerSoundTriggerCaptureStateListener(this, &active);
+ status_t status = mAps->registerSoundTriggerCaptureStateListener(this, &active);
if (status != NO_ERROR) {
mListener->onServiceDied();
return;
}
mListener->onStateChanged(active);
- sp<IBinder> binder = IInterface::asBinder(aps);
- binder->linkToDeath(this);
+ IInterface::asBinder(mAps)->linkToDeath(this);
}
binder::Status setCaptureState(bool active) override {
@@ -1683,6 +1684,7 @@
Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock);
gSoundTriggerCaptureStateListener = new CaptureStateListenerImpl(aps, listener);
+ gSoundTriggerCaptureStateListener->init();
return NO_ERROR;
}