From 9472e5f3ab44f04c92e44ad0f3e94c0ee508ec11 Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Fri, 29 May 2015 16:35:28 -0700 Subject: 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 --- drm/mediadrm/plugins/clearkey/CryptoFactory.cpp | 16 ++++++++++++---- drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp | 16 +++++++++++++++- drm/mediadrm/plugins/clearkey/CryptoPlugin.h | 11 ++++++++++- drm/mediadrm/plugins/clearkey/DrmPlugin.cpp | 12 ++++++++++-- drm/mediadrm/plugins/clearkey/SessionLibrary.cpp | 7 ------- drm/mediadrm/plugins/clearkey/SessionLibrary.h | 4 +--- 6 files changed, 48 insertions(+), 18 deletions(-) (limited to 'drm') diff --git a/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp b/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp index ee3189b..eeb64c3 100644 --- a/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp +++ b/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp @@ -43,10 +43,18 @@ android::status_t CryptoFactory::createPlugin( return android::BAD_VALUE; } - android::sp session = SessionLibrary::get()->findSession( - data, size); - *plugin = new CryptoPlugin(session); - return android::OK; + android::Vector sessionId; + sessionId.appendArray(reinterpret_cast(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 diff --git a/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp b/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp index adad136..53cbf80 100644 --- a/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp +++ b/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp @@ -19,9 +19,9 @@ #include #include -#include #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& 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 diff --git a/drm/mediadrm/plugins/clearkey/CryptoPlugin.h b/drm/mediadrm/plugins/clearkey/CryptoPlugin.h index 002d9e0..fd38f28 100644 --- a/drm/mediadrm/plugins/clearkey/CryptoPlugin.h +++ b/drm/mediadrm/plugins/clearkey/CryptoPlugin.h @@ -31,7 +31,10 @@ namespace clearkeydrm { class CryptoPlugin : public android::CryptoPlugin { public: - CryptoPlugin(const android::sp& session) : mSession(session) {} + CryptoPlugin(const android::Vector& 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& sessionId); + + android::status_t getInitStatus() const {return mInitStatus;} + private: DISALLOW_EVIL_CONSTRUCTORS(CryptoPlugin); android::sp mSession; + android::status_t mInitStatus; }; } // namespace clearkeydrm diff --git a/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp b/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp index 6b8c772..e5ee403 100644 --- a/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp +++ b/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp @@ -37,7 +37,9 @@ status_t DrmPlugin::openSession(Vector& sessionId) { status_t DrmPlugin::closeSession(const Vector& sessionId) { sp session = mSessionLibrary->findSession(sessionId); - mSessionLibrary->destroySession(session); + 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 = mSessionLibrary->findSession(scope); defaultUrl.clear(); + sp 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& response, Vector& keySetId) { sp 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(); diff --git a/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp b/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp index d047c53..46d7f77 100644 --- a/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp +++ b/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp @@ -63,13 +63,6 @@ const sp& SessionLibrary::findSession( return mSessions.valueFor(sessionId); } -const sp& SessionLibrary::findSession( - const void* data, size_t size) { - Vector sessionId; - sessionId.appendArray(reinterpret_cast(data), size); - return findSession(sessionId); -} - void SessionLibrary::destroySession(const sp& session) { Mutex::Autolock lock(mSessionsLock);\ mSessions.removeItem(session->sessionId()); diff --git a/drm/mediadrm/plugins/clearkey/SessionLibrary.h b/drm/mediadrm/plugins/clearkey/SessionLibrary.h index 56c8828..199ad64 100644 --- a/drm/mediadrm/plugins/clearkey/SessionLibrary.h +++ b/drm/mediadrm/plugins/clearkey/SessionLibrary.h @@ -36,8 +36,6 @@ public: const android::sp& findSession( const android::Vector& sessionId); - const android::sp& findSession(const void* data, size_t size); - void destroySession(const android::sp& session); private: @@ -50,7 +48,7 @@ private: android::Mutex mSessionsLock; uint32_t mNextSessionId; - android::KeyedVector, android::sp > + android::DefaultKeyedVector, android::sp > mSessions; }; -- cgit v1.1