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

Commit c0f5a3bb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Close all open drm sessions before destroying a plugin."

parents 23f2b722 6133281c
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