Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a46b6d3e authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

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
parent bc430769
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -1641,16 +1641,17 @@ public:
    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 @@ status_t AudioSystem::registerSoundTriggerCaptureStateListener(

    Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock);
    gSoundTriggerCaptureStateListener = new CaptureStateListenerImpl(aps, listener);
    gSoundTriggerCaptureStateListener->init();

    return NO_ERROR;
}