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

Commit cd95d710 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Codec2: Detect and release component if the client process terminates"...

Merge "Codec2: Detect and release component if the client process terminates" am: 0b505d42 am: b3834848

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2021481

Change-Id: I2b33b3893921bfc2138e074ac6f399878c2a3086
parents c4d6cd21 b3834848
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -520,6 +520,37 @@ void Component::initListener(const sp<Component>& self) {
    if (res != C2_OK) {
        mInit = res;
    }

    struct ListenerDeathRecipient : public HwDeathRecipient {
        ListenerDeathRecipient(const wp<Component>& comp)
            : component{comp} {
        }

        virtual void serviceDied(
                uint64_t /* cookie */,
                const wp<::android::hidl::base::V1_0::IBase>& /* who */
                ) override {
            auto strongComponent = component.promote();
            if (strongComponent) {
                LOG(INFO) << "Client died ! release the component !!";
                strongComponent->release();
            } else {
                LOG(ERROR) << "Client died ! no component to release !!";
            }
        }

        wp<Component> component;
    };

    mDeathRecipient = new ListenerDeathRecipient(self);
    Return<bool> transStatus = mListener->linkToDeath(
            mDeathRecipient, 0);
    if (!transStatus.isOk()) {
        LOG(ERROR) << "Listener linkToDeath() transaction failed.";
    }
    if (!static_cast<bool>(transStatus)) {
        LOG(DEBUG) << "Listener linkToDeath() call failed.";
    }
}

Component::~Component() {
+4 −0
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ protected:
    friend struct ComponentStore;

    struct Listener;

    using HwDeathRecipient = ::android::hardware::hidl_death_recipient;
    sp<HwDeathRecipient> mDeathRecipient;

};

} // namespace utils