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

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

Keep the death recipient alive

Binder doesn't hold on to the death recipient.
This caused audio server to miss notifications about system server
death.

Fixes: 153080001
Test: Manual verification of killing the system process.
Change-Id: Iad1b2d4c5348d3d9917efc6838e86b736fa33094
parent 944e2551
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
#include "CaptureStateNotifier.h"

#define LOG_TAG "CaptureStateNotifier"

#include "CaptureStateNotifier.h"

#include <android/media/ICaptureStateListener.h>
#include <binder/IBinder.h>
#include <utils/Log.h>
@@ -22,9 +22,9 @@ private:
    CaptureStateNotifier* const mNotifier;
};

CaptureStateNotifier::CaptureStateNotifier(bool initialActive) {
    mActive = initialActive;
}
CaptureStateNotifier::CaptureStateNotifier(bool initialActive)
    : mDeathRecipient(new DeathRecipient(this)), mActive(
    initialActive) {}

CaptureStateNotifier::~CaptureStateNotifier() {
    LOG_ALWAYS_FATAL_IF(mListener != nullptr);
@@ -33,11 +33,20 @@ CaptureStateNotifier::~CaptureStateNotifier() {
bool CaptureStateNotifier::RegisterListener(const sp<ICaptureStateListener>& listener) {
    std::lock_guard<std::mutex> _l(mMutex);
    LOG_ALWAYS_FATAL_IF(mListener != nullptr);
    LOG_ALWAYS_FATAL_IF(listener == nullptr);

    ALOGI("Registering a listener");
    sp<IBinder> binder = IInterface::asBinder(listener);
    if (binder != nullptr) {
        status_t status = binder->linkToDeath(mDeathRecipient);
        if (status == NO_ERROR) {
            mListener = listener;
    sp<IBinder> binder = IInterface::asBinder(mListener);
    binder->linkToDeath(new DeathRecipient(this));
        } else {
            ALOGE("Failed to register death listener: %u", status);
        }
    } else {
        ALOGE("Listener failed to cast to a binder.");
    }
    return mActive;
}

+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <mutex>
#include <binder/IBinder.h>
#include <utils/StrongPointer.h>

namespace android {
@@ -63,6 +64,7 @@ public:
private:
    std::mutex mMutex;
    sp<media::ICaptureStateListener> mListener;
    sp<IBinder::DeathRecipient> mDeathRecipient;
    bool mActive;

    class DeathRecipient;