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

Commit 12033a5b authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi Committed by Automerger Merge Worker
Browse files

Keep the death recipient alive am: 95ec1b8e am: 0c25f727 am: da2a2dde

Change-Id: Ifc36ae25dd9a652949b4fd6f18f2c984790d6c1d
parents e74ee1c1 da2a2dde
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;