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

Commit 9472e5f3 authored by Jeff Tinker's avatar Jeff Tinker
Browse files

Implement MediaCrypto.setMediaDrmSession in clearkey plugin

To support adding cts tests for new APIs in M, the
clearkey DRM plugin needs to be updated.

Change-Id: If672ecec8f570d1dd5130e8e4419d37bd931a9e2
related-to-bug: 21527003
parent 2d6b6601
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -43,10 +43,18 @@ android::status_t CryptoFactory::createPlugin(
        return android::BAD_VALUE;
    }

    android::sp<Session> session = SessionLibrary::get()->findSession(
            data, size);
    *plugin = new CryptoPlugin(session);
    return android::OK;
    android::Vector<uint8_t> sessionId;
    sessionId.appendArray(reinterpret_cast<const uint8_t*>(data), size);

    CryptoPlugin *clearKeyPlugin = new CryptoPlugin(sessionId);
    android::status_t result = clearKeyPlugin->getInitStatus();
    if (result == android::OK) {
        *plugin = clearKeyPlugin;
    } else {
        delete clearKeyPlugin;
        *plugin = NULL;
    }
    return result;
}

} // namespace clearkeydrm
+15 −1
Original line number Diff line number Diff line
@@ -19,9 +19,9 @@
#include <utils/Log.h>

#include <media/stagefright/MediaErrors.h>
#include <utils/Errors.h>

#include "CryptoPlugin.h"
#include "SessionLibrary.h"

namespace clearkeydrm {

@@ -80,4 +80,18 @@ ssize_t CryptoPlugin::decrypt(bool secure, const KeyId keyId, const Iv iv,
    }
}

android::status_t CryptoPlugin::setMediaDrmSession(
        const android::Vector<uint8_t>& sessionId) {
    if (!sessionId.size()) {
        mSession.clear();
    } else {
        mSession = SessionLibrary::get()->findSession(sessionId);
        if (!mSession.get()) {
            return android::ERROR_DRM_SESSION_NOT_OPENED;
        }
    }
    return android::OK;
}


}  // namespace clearkeydrm
+10 −1
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@ namespace clearkeydrm {

class CryptoPlugin : public android::CryptoPlugin {
public:
    CryptoPlugin(const android::sp<Session>& session) : mSession(session) {}
    CryptoPlugin(const android::Vector<uint8_t>& sessionId) {
        mInitStatus = setMediaDrmSession(sessionId);
    }

    virtual ~CryptoPlugin() {}

    virtual bool requiresSecureDecoderComponent(const char* mime) const {
@@ -45,10 +48,16 @@ public:
            const SubSample* subSamples, size_t numSubSamples,
            void* dstPtr, android::AString* errorDetailMsg);

    virtual android::status_t setMediaDrmSession(
            const android::Vector<uint8_t>& sessionId);

    android::status_t getInitStatus() const {return mInitStatus;}

private:
    DISALLOW_EVIL_CONSTRUCTORS(CryptoPlugin);

    android::sp<Session> mSession;
    android::status_t mInitStatus;
};

} // namespace clearkeydrm
+10 −2
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@ status_t DrmPlugin::openSession(Vector<uint8_t>& sessionId) {

status_t DrmPlugin::closeSession(const Vector<uint8_t>& sessionId) {
    sp<Session> session = mSessionLibrary->findSession(sessionId);
    if (session.get()) {
        mSessionLibrary->destroySession(session);
    }
    return android::OK;
}

@@ -55,8 +57,11 @@ status_t DrmPlugin::getKeyRequest(
        return android::ERROR_DRM_CANNOT_HANDLE;
    }
    *keyRequestType = DrmPlugin::kKeyRequestType_Initial;
    sp<Session> session = mSessionLibrary->findSession(scope);
    defaultUrl.clear();
    sp<Session> session = mSessionLibrary->findSession(scope);
    if (!session.get()) {
        return android::ERROR_DRM_SESSION_NOT_OPENED;
    }
    return session->getKeyRequest(initData, initDataType, &request);
}

@@ -65,6 +70,9 @@ status_t DrmPlugin::provideKeyResponse(
        const Vector<uint8_t>& response,
        Vector<uint8_t>& keySetId) {
    sp<Session> session = mSessionLibrary->findSession(scope);
    if (!session.get()) {
        return android::ERROR_DRM_SESSION_NOT_OPENED;
    }
    status_t res = session->provideKeyResponse(response);
    if (res == android::OK) {
        keySetId.clear();
+0 −7
Original line number Diff line number Diff line
@@ -63,13 +63,6 @@ const sp<Session>& SessionLibrary::findSession(
    return mSessions.valueFor(sessionId);
}

const sp<Session>& SessionLibrary::findSession(
        const void* data, size_t size) {
    Vector<uint8_t> sessionId;
    sessionId.appendArray(reinterpret_cast<const uint8_t*>(data), size);
    return findSession(sessionId);
}

void SessionLibrary::destroySession(const sp<Session>& session) {
    Mutex::Autolock lock(mSessionsLock);\
    mSessions.removeItem(session->sessionId());
Loading