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

Commit 6133281c authored by Jeff Tinker's avatar Jeff Tinker
Browse files

Close all open drm sessions before destroying a plugin.

MediaDrm relies on each plugin to close its open sessions
when the plugin is destroyed. This change ensures that all
sessions will be closed even if the plugin does not do it.

b/38323088

Change-Id: I8b6e36182f3b3bc765963819101868fc46001527
parent bc282920
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -194,7 +194,18 @@ DrmHal::DrmHal()
     mInitCheck((mFactories.size() == 0) ? ERROR_UNSUPPORTED : NO_INIT) {
}

void DrmHal::closeOpenSessions() {
    if (mPlugin != NULL) {
        for (size_t i = 0; i < mOpenSessions.size(); i++) {
            mPlugin->closeSession(toHidlVec(mOpenSessions[i]));
            DrmSessionManager::Instance()->removeSession(mOpenSessions[i]);
        }
    }
    mOpenSessions.clear();
}

DrmHal::~DrmHal() {
    closeOpenSessions();
    DrmSessionManager::Instance()->removeDrm(mDrmSessionClient);
}

@@ -405,11 +416,11 @@ status_t DrmHal::createPlugin(const uint8_t uuid[16],

status_t DrmHal::destroyPlugin() {
    Mutex::Autolock autoLock(mLock);

    if (mInitCheck != OK) {
        return mInitCheck;
    }

    closeOpenSessions();
    setListener(NULL);
    if (mPlugin != NULL) {
        mPlugin->setListener(NULL);
@@ -461,6 +472,7 @@ status_t DrmHal::openSession(Vector<uint8_t> &sessionId) {
    if (err == OK) {
        DrmSessionManager::Instance()->addSession(getCallingPid(),
                mDrmSessionClient, sessionId);
        mOpenSessions.push(sessionId);
    }
    return err;
}
@@ -475,6 +487,12 @@ status_t DrmHal::closeSession(Vector<uint8_t> const &sessionId) {
    Status status = mPlugin->closeSession(toHidlVec(sessionId));
    if (status == Status::OK) {
        DrmSessionManager::Instance()->removeSession(sessionId);
        for (size_t i = 0; i < mOpenSessions.size(); i++) {
            if (mOpenSessions[i] == sessionId) {
                mOpenSessions.removeAt(i);
                break;
            }
        }
    }
    return toStatusT(status);
}
@@ -962,6 +980,7 @@ status_t DrmHal::signRSA(Vector<uint8_t> const &sessionId,
void DrmHal::binderDied(const wp<IBinder> &the_late_who __unused)
{
    Mutex::Autolock autoLock(mLock);
    closeOpenSessions();
    setListener(NULL);
    if (mPlugin != NULL) {
        mPlugin->setListener(NULL);
+8 −0
Original line number Diff line number Diff line
@@ -39,6 +39,11 @@ namespace android {

struct DrmSessionClientInterface;

inline bool operator==(const Vector<uint8_t> &l, const Vector<uint8_t> &r) {
    if (l.size() != r.size()) return false;
    return memcmp(l.array(), r.array(), l.size()) == 0;
}

struct DrmHal : public BnDrm,
             public IBinder::DeathRecipient,
             public IDrmPluginListener {
@@ -161,6 +166,9 @@ private:
    const Vector<sp<IDrmFactory>> mFactories;
    sp<IDrmPlugin> mPlugin;

    Vector<Vector<uint8_t>> mOpenSessions;
    void closeOpenSessions();

    /**
     * mInitCheck is:
     *   NO_INIT if a plugin hasn't been created yet