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

Commit 2ffbb180 authored by Andreas Huber's avatar Andreas Huber
Browse files

Protect notification callback parameters with a mutex.

This avoids the race condition where notifications are dispatched to a NULL receiver
after notifications have been disabled.

Change-Id: I6d351ffbee97616e2c35559c132a6c5e6a66948a
related-to-bug: 3394139
parent ff3b3ade
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -126,8 +126,6 @@ public:
    virtual status_t    setLooping(int loop) = 0;
    virtual player_type playerType() = 0;

    virtual void        setNotifyCallback(void* cookie, notify_callback_f notifyFunc) {
                            mCookie = cookie; mNotify = notifyFunc; }
    // Invoke a generic method on the player by using opaque parcels
    // for the request and reply.
    //
@@ -149,9 +147,21 @@ public:
        return INVALID_OPERATION;
    };

    virtual void        sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); }
    void        setNotifyCallback(
            void* cookie, notify_callback_f notifyFunc) {
        Mutex::Autolock autoLock(mNotifyLock);
        mCookie = cookie; mNotify = notifyFunc;
    }

protected:
    void        sendEvent(int msg, int ext1=0, int ext2=0) {
        Mutex::Autolock autoLock(mNotifyLock);
        if (mNotify) mNotify(mCookie, msg, ext1, ext2);
    }

private:
    friend class MediaPlayerService;

    Mutex               mNotifyLock;
    void*               mCookie;
    notify_callback_f   mNotify;
};