Remove MediaDrm stack from mediaserver
Part of media security hardening
MediaDrm was temporarily allowed to
run in either mediaserver or mediadrmserver
while all nexus devices were implementing
support for the native_handle representation
of secure buffers. Now that all nexus
devices support native_handle, the MediaDrm
stack can be removed from mediaserver.
b/22990512
Change-Id: Ie5d83bfeb4c4a824e1d0edb4c9452c782d6fd386
diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk
index edad4be..68860d2 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -8,16 +8,12 @@
LOCAL_SRC_FILES:= \
ActivityManager.cpp \
- Crypto.cpp \
- Drm.cpp \
- DrmSessionManager.cpp \
HDCP.cpp \
MediaPlayerFactory.cpp \
MediaPlayerService.cpp \
MediaRecorderClient.cpp \
MetadataRetrieverClient.cpp \
RemoteDisplay.cpp \
- SharedLibrary.cpp \
StagefrightRecorder.cpp \
TestPlayerStub.cpp \
@@ -52,6 +48,7 @@
$(TOP)/frameworks/av/media/libstagefright/rtsp \
$(TOP)/frameworks/av/media/libstagefright/wifi-display \
$(TOP)/frameworks/av/media/libstagefright/webm \
+ $(TOP)/frameworks/av/include/media \
$(TOP)/frameworks/av/include/camera \
$(TOP)/frameworks/native/include/media/openmax \
$(TOP)/external/tremolo/Tremolo \
diff --git a/media/libmediaplayerservice/Crypto.cpp b/media/libmediaplayerservice/Crypto.cpp
deleted file mode 100644
index 9165b9d..0000000
--- a/media/libmediaplayerservice/Crypto.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Crypto"
-#include <utils/Log.h>
-#include <dirent.h>
-#include <dlfcn.h>
-
-#include "Crypto.h"
-
-#include <binder/IMemory.h>
-#include <media/hardware/CryptoAPI.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AString.h>
-#include <media/stagefright/foundation/hexdump.h>
-#include <media/stagefright/MediaErrors.h>
-
-namespace android {
-
-KeyedVector<Vector<uint8_t>, String8> Crypto::mUUIDToLibraryPathMap;
-KeyedVector<String8, wp<SharedLibrary> > Crypto::mLibraryPathToOpenLibraryMap;
-Mutex Crypto::mMapLock;
-
-static bool operator<(const Vector<uint8_t> &lhs, const Vector<uint8_t> &rhs) {
- if (lhs.size() < rhs.size()) {
- return true;
- } else if (lhs.size() > rhs.size()) {
- return false;
- }
-
- return memcmp((void *)lhs.array(), (void *)rhs.array(), rhs.size()) < 0;
-}
-
-Crypto::Crypto()
- : mInitCheck(NO_INIT),
- mFactory(NULL),
- mPlugin(NULL) {
-}
-
-Crypto::~Crypto() {
- delete mPlugin;
- mPlugin = NULL;
- closeFactory();
-}
-
-void Crypto::closeFactory() {
- delete mFactory;
- mFactory = NULL;
- mLibrary.clear();
-}
-
-status_t Crypto::initCheck() const {
- return mInitCheck;
-}
-
-/*
- * Search the plugins directory for a plugin that supports the scheme
- * specified by uuid
- *
- * If found:
- * mLibrary holds a strong pointer to the dlopen'd library
- * mFactory is set to the library's factory method
- * mInitCheck is set to OK
- *
- * If not found:
- * mLibrary is cleared and mFactory are set to NULL
- * mInitCheck is set to an error (!OK)
- */
-void Crypto::findFactoryForScheme(const uint8_t uuid[16]) {
-
- closeFactory();
-
- // lock static maps
- Mutex::Autolock autoLock(mMapLock);
-
- // first check cache
- Vector<uint8_t> uuidVector;
- uuidVector.appendArray(uuid, sizeof(uuid[0]) * 16);
- ssize_t index = mUUIDToLibraryPathMap.indexOfKey(uuidVector);
- if (index >= 0) {
- if (loadLibraryForScheme(mUUIDToLibraryPathMap[index], uuid)) {
- mInitCheck = OK;
- return;
- } else {
- ALOGE("Failed to load from cached library path!");
- mInitCheck = ERROR_UNSUPPORTED;
- return;
- }
- }
-
- // no luck, have to search
- String8 dirPath("/vendor/lib/mediadrm");
- String8 pluginPath;
-
- DIR* pDir = opendir(dirPath.string());
- if (pDir) {
- struct dirent* pEntry;
- while ((pEntry = readdir(pDir))) {
-
- pluginPath = dirPath + "/" + pEntry->d_name;
-
- if (pluginPath.getPathExtension() == ".so") {
-
- if (loadLibraryForScheme(pluginPath, uuid)) {
- mUUIDToLibraryPathMap.add(uuidVector, pluginPath);
- mInitCheck = OK;
- closedir(pDir);
- return;
- }
- }
- }
-
- closedir(pDir);
- }
-
- // try the legacy libdrmdecrypt.so
- pluginPath = "libdrmdecrypt.so";
- if (loadLibraryForScheme(pluginPath, uuid)) {
- mUUIDToLibraryPathMap.add(uuidVector, pluginPath);
- mInitCheck = OK;
- return;
- }
-
- mInitCheck = ERROR_UNSUPPORTED;
-}
-
-bool Crypto::loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]) {
-
- // get strong pointer to open shared library
- ssize_t index = mLibraryPathToOpenLibraryMap.indexOfKey(path);
- if (index >= 0) {
- mLibrary = mLibraryPathToOpenLibraryMap[index].promote();
- } else {
- index = mLibraryPathToOpenLibraryMap.add(path, NULL);
- }
-
- if (!mLibrary.get()) {
- mLibrary = new SharedLibrary(path);
- if (!*mLibrary) {
- ALOGE("loadLibraryForScheme failed:%s", mLibrary->lastError());
- return false;
- }
-
- mLibraryPathToOpenLibraryMap.replaceValueAt(index, mLibrary);
- }
-
- typedef CryptoFactory *(*CreateCryptoFactoryFunc)();
-
- CreateCryptoFactoryFunc createCryptoFactory =
- (CreateCryptoFactoryFunc)mLibrary->lookup("createCryptoFactory");
-
- if (createCryptoFactory == NULL ||
- (mFactory = createCryptoFactory()) == NULL ||
- !mFactory->isCryptoSchemeSupported(uuid)) {
- ALOGE("createCryptoFactory failed:%s", mLibrary->lastError());
- closeFactory();
- return false;
- }
- return true;
-}
-
-bool Crypto::isCryptoSchemeSupported(const uint8_t uuid[16]) {
- Mutex::Autolock autoLock(mLock);
-
- if (mFactory && mFactory->isCryptoSchemeSupported(uuid)) {
- return true;
- }
-
- findFactoryForScheme(uuid);
- return (mInitCheck == OK);
-}
-
-status_t Crypto::createPlugin(
- const uint8_t uuid[16], const void *data, size_t size) {
- Mutex::Autolock autoLock(mLock);
-
- if (mPlugin != NULL) {
- return -EINVAL;
- }
-
- if (!mFactory || !mFactory->isCryptoSchemeSupported(uuid)) {
- findFactoryForScheme(uuid);
- }
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- return mFactory->createPlugin(uuid, data, size, &mPlugin);
-}
-
-status_t Crypto::destroyPlugin() {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- delete mPlugin;
- mPlugin = NULL;
-
- return OK;
-}
-
-bool Crypto::requiresSecureDecoderComponent(const char *mime) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->requiresSecureDecoderComponent(mime);
-}
-
-ssize_t Crypto::decrypt(
- DestinationType dstType,
- const uint8_t key[16],
- const uint8_t iv[16],
- CryptoPlugin::Mode mode,
- const CryptoPlugin::Pattern &pattern,
- const sp<IMemory> &sharedBuffer, size_t offset,
- const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
- void *dstPtr,
- AString *errorDetailMsg) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- const void *srcPtr = static_cast<uint8_t *>(sharedBuffer->pointer()) + offset;
-
- return mPlugin->decrypt(
- dstType != kDestinationTypeVmPointer,
- key, iv, mode, pattern, srcPtr, subSamples, numSubSamples, dstPtr,
- errorDetailMsg);
-}
-
-void Crypto::notifyResolution(uint32_t width, uint32_t height) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck == OK && mPlugin != NULL) {
- mPlugin->notifyResolution(width, height);
- }
-}
-
-status_t Crypto::setMediaDrmSession(const Vector<uint8_t> &sessionId) {
- Mutex::Autolock autoLock(mLock);
-
- status_t result = NO_INIT;
- if (mInitCheck == OK && mPlugin != NULL) {
- result = mPlugin->setMediaDrmSession(sessionId);
- }
- return result;
-}
-
-} // namespace android
diff --git a/media/libmediaplayerservice/Crypto.h b/media/libmediaplayerservice/Crypto.h
deleted file mode 100644
index 7d181d3..0000000
--- a/media/libmediaplayerservice/Crypto.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CRYPTO_H_
-
-#define CRYPTO_H_
-
-#include <media/ICrypto.h>
-#include <utils/threads.h>
-#include <utils/KeyedVector.h>
-
-#include "SharedLibrary.h"
-
-namespace android {
-
-struct CryptoFactory;
-struct CryptoPlugin;
-
-struct Crypto : public BnCrypto {
- Crypto();
- virtual ~Crypto();
-
- virtual status_t initCheck() const;
-
- virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
-
- virtual status_t createPlugin(
- const uint8_t uuid[16], const void *data, size_t size);
-
- virtual status_t destroyPlugin();
-
- virtual bool requiresSecureDecoderComponent(
- const char *mime) const;
-
- virtual void notifyResolution(uint32_t width, uint32_t height);
-
- virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId);
-
- virtual ssize_t decrypt(
- DestinationType dstType,
- const uint8_t key[16],
- const uint8_t iv[16],
- CryptoPlugin::Mode mode,
- const CryptoPlugin::Pattern &pattern,
- const sp<IMemory> &sharedBuffer, size_t offset,
- const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
- void *dstPtr,
- AString *errorDetailMsg);
-
-private:
- mutable Mutex mLock;
-
- status_t mInitCheck;
- sp<SharedLibrary> mLibrary;
- CryptoFactory *mFactory;
- CryptoPlugin *mPlugin;
-
- static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap;
- static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap;
- static Mutex mMapLock;
-
- void findFactoryForScheme(const uint8_t uuid[16]);
- bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]);
- void closeFactory();
-
- DISALLOW_EVIL_CONSTRUCTORS(Crypto);
-};
-
-} // namespace android
-
-#endif // CRYPTO_H_
diff --git a/media/libmediaplayerservice/Drm.cpp b/media/libmediaplayerservice/Drm.cpp
deleted file mode 100644
index 321ccbf..0000000
--- a/media/libmediaplayerservice/Drm.cpp
+++ /dev/null
@@ -1,792 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Drm"
-#include <utils/Log.h>
-
-#include <dirent.h>
-#include <dlfcn.h>
-
-#include "Drm.h"
-
-#include "DrmSessionClientInterface.h"
-#include "DrmSessionManager.h"
-#include <media/drm/DrmAPI.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AString.h>
-#include <media/stagefright/foundation/hexdump.h>
-#include <media/stagefright/MediaErrors.h>
-#include <binder/IServiceManager.h>
-#include <binder/IPCThreadState.h>
-
-namespace android {
-
-static inline int getCallingPid() {
- return IPCThreadState::self()->getCallingPid();
-}
-
-static bool checkPermission(const char* permissionString) {
- if (getpid() == IPCThreadState::self()->getCallingPid()) return true;
- bool ok = checkCallingPermission(String16(permissionString));
- if (!ok) ALOGE("Request requires %s", permissionString);
- return ok;
-}
-
-KeyedVector<Vector<uint8_t>, String8> Drm::mUUIDToLibraryPathMap;
-KeyedVector<String8, wp<SharedLibrary> > Drm::mLibraryPathToOpenLibraryMap;
-Mutex Drm::mMapLock;
-Mutex Drm::mLock;
-
-static bool operator<(const Vector<uint8_t> &lhs, const Vector<uint8_t> &rhs) {
- if (lhs.size() < rhs.size()) {
- return true;
- } else if (lhs.size() > rhs.size()) {
- return false;
- }
-
- return memcmp((void *)lhs.array(), (void *)rhs.array(), rhs.size()) < 0;
-}
-
-struct DrmSessionClient : public DrmSessionClientInterface {
- DrmSessionClient(Drm* drm) : mDrm(drm) {}
-
- virtual bool reclaimSession(const Vector<uint8_t>& sessionId) {
- sp<Drm> drm = mDrm.promote();
- if (drm == NULL) {
- return true;
- }
- status_t err = drm->closeSession(sessionId);
- if (err != OK) {
- return false;
- }
- drm->sendEvent(DrmPlugin::kDrmPluginEventSessionReclaimed, 0, &sessionId, NULL);
- return true;
- }
-
-protected:
- virtual ~DrmSessionClient() {}
-
-private:
- wp<Drm> mDrm;
-
- DISALLOW_EVIL_CONSTRUCTORS(DrmSessionClient);
-};
-
-Drm::Drm()
- : mInitCheck(NO_INIT),
- mDrmSessionClient(new DrmSessionClient(this)),
- mListener(NULL),
- mFactory(NULL),
- mPlugin(NULL) {
-}
-
-Drm::~Drm() {
- DrmSessionManager::Instance()->removeDrm(mDrmSessionClient);
- delete mPlugin;
- mPlugin = NULL;
- closeFactory();
-}
-
-void Drm::closeFactory() {
- delete mFactory;
- mFactory = NULL;
- mLibrary.clear();
-}
-
-status_t Drm::initCheck() const {
- return mInitCheck;
-}
-
-status_t Drm::setListener(const sp<IDrmClient>& listener)
-{
- Mutex::Autolock lock(mEventLock);
- if (mListener != NULL){
- IInterface::asBinder(mListener)->unlinkToDeath(this);
- }
- if (listener != NULL) {
- IInterface::asBinder(listener)->linkToDeath(this);
- }
- mListener = listener;
- return NO_ERROR;
-}
-
-void Drm::sendEvent(DrmPlugin::EventType eventType, int extra,
- Vector<uint8_t> const *sessionId,
- Vector<uint8_t> const *data)
-{
- mEventLock.lock();
- sp<IDrmClient> listener = mListener;
- mEventLock.unlock();
-
- if (listener != NULL) {
- Parcel obj;
- writeByteArray(obj, sessionId);
- writeByteArray(obj, data);
-
- Mutex::Autolock lock(mNotifyLock);
- listener->notify(eventType, extra, &obj);
- }
-}
-
-void Drm::sendExpirationUpdate(Vector<uint8_t> const *sessionId,
- int64_t expiryTimeInMS)
-{
- mEventLock.lock();
- sp<IDrmClient> listener = mListener;
- mEventLock.unlock();
-
- if (listener != NULL) {
- Parcel obj;
- writeByteArray(obj, sessionId);
- obj.writeInt64(expiryTimeInMS);
-
- Mutex::Autolock lock(mNotifyLock);
- listener->notify(DrmPlugin::kDrmPluginEventExpirationUpdate, 0, &obj);
- }
-}
-
-void Drm::sendKeysChange(Vector<uint8_t> const *sessionId,
- Vector<DrmPlugin::KeyStatus> const *keyStatusList,
- bool hasNewUsableKey)
-{
- mEventLock.lock();
- sp<IDrmClient> listener = mListener;
- mEventLock.unlock();
-
- if (listener != NULL) {
- Parcel obj;
- writeByteArray(obj, sessionId);
-
- size_t nkeys = keyStatusList->size();
- obj.writeInt32(keyStatusList->size());
- for (size_t i = 0; i < nkeys; ++i) {
- const DrmPlugin::KeyStatus *keyStatus = &keyStatusList->itemAt(i);
- writeByteArray(obj, &keyStatus->mKeyId);
- obj.writeInt32(keyStatus->mType);
- }
- obj.writeInt32(hasNewUsableKey);
-
- Mutex::Autolock lock(mNotifyLock);
- listener->notify(DrmPlugin::kDrmPluginEventKeysChange, 0, &obj);
- }
-}
-
-/*
- * Search the plugins directory for a plugin that supports the scheme
- * specified by uuid
- *
- * If found:
- * mLibrary holds a strong pointer to the dlopen'd library
- * mFactory is set to the library's factory method
- * mInitCheck is set to OK
- *
- * If not found:
- * mLibrary is cleared and mFactory are set to NULL
- * mInitCheck is set to an error (!OK)
- */
-void Drm::findFactoryForScheme(const uint8_t uuid[16]) {
-
- closeFactory();
-
- // lock static maps
- Mutex::Autolock autoLock(mMapLock);
-
- // first check cache
- Vector<uint8_t> uuidVector;
- uuidVector.appendArray(uuid, sizeof(uuid[0]) * 16);
- ssize_t index = mUUIDToLibraryPathMap.indexOfKey(uuidVector);
- if (index >= 0) {
- if (loadLibraryForScheme(mUUIDToLibraryPathMap[index], uuid)) {
- mInitCheck = OK;
- return;
- } else {
- ALOGE("Failed to load from cached library path!");
- mInitCheck = ERROR_UNSUPPORTED;
- return;
- }
- }
-
- // no luck, have to search
- String8 dirPath("/vendor/lib/mediadrm");
- DIR* pDir = opendir(dirPath.string());
-
- if (pDir == NULL) {
- mInitCheck = ERROR_UNSUPPORTED;
- ALOGE("Failed to open plugin directory %s", dirPath.string());
- return;
- }
-
-
- struct dirent* pEntry;
- while ((pEntry = readdir(pDir))) {
-
- String8 pluginPath = dirPath + "/" + pEntry->d_name;
-
- if (pluginPath.getPathExtension() == ".so") {
-
- if (loadLibraryForScheme(pluginPath, uuid)) {
- mUUIDToLibraryPathMap.add(uuidVector, pluginPath);
- mInitCheck = OK;
- closedir(pDir);
- return;
- }
- }
- }
-
- closedir(pDir);
-
- ALOGE("Failed to find drm plugin");
- mInitCheck = ERROR_UNSUPPORTED;
-}
-
-bool Drm::loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]) {
-
- // get strong pointer to open shared library
- ssize_t index = mLibraryPathToOpenLibraryMap.indexOfKey(path);
- if (index >= 0) {
- mLibrary = mLibraryPathToOpenLibraryMap[index].promote();
- } else {
- index = mLibraryPathToOpenLibraryMap.add(path, NULL);
- }
-
- if (!mLibrary.get()) {
- mLibrary = new SharedLibrary(path);
- if (!*mLibrary) {
- return false;
- }
-
- mLibraryPathToOpenLibraryMap.replaceValueAt(index, mLibrary);
- }
-
- typedef DrmFactory *(*CreateDrmFactoryFunc)();
-
- CreateDrmFactoryFunc createDrmFactory =
- (CreateDrmFactoryFunc)mLibrary->lookup("createDrmFactory");
-
- if (createDrmFactory == NULL ||
- (mFactory = createDrmFactory()) == NULL ||
- !mFactory->isCryptoSchemeSupported(uuid)) {
- closeFactory();
- return false;
- }
- return true;
-}
-
-bool Drm::isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) {
-
- Mutex::Autolock autoLock(mLock);
-
- if (!mFactory || !mFactory->isCryptoSchemeSupported(uuid)) {
- findFactoryForScheme(uuid);
- if (mInitCheck != OK) {
- return false;
- }
- }
-
- if (mimeType != "") {
- return mFactory->isContentTypeSupported(mimeType);
- }
-
- return true;
-}
-
-status_t Drm::createPlugin(const uint8_t uuid[16]) {
- Mutex::Autolock autoLock(mLock);
-
- if (mPlugin != NULL) {
- return -EINVAL;
- }
-
- if (!mFactory || !mFactory->isCryptoSchemeSupported(uuid)) {
- findFactoryForScheme(uuid);
- }
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- status_t result = mFactory->createDrmPlugin(uuid, &mPlugin);
- mPlugin->setListener(this);
- return result;
-}
-
-status_t Drm::destroyPlugin() {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- delete mPlugin;
- mPlugin = NULL;
-
- return OK;
-}
-
-status_t Drm::openSession(Vector<uint8_t> &sessionId) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- status_t err = mPlugin->openSession(sessionId);
- if (err == ERROR_DRM_RESOURCE_BUSY) {
- bool retry = false;
- mLock.unlock();
- // reclaimSession may call back to closeSession, since mLock is shared between Drm
- // instances, we should unlock here to avoid deadlock.
- retry = DrmSessionManager::Instance()->reclaimSession(getCallingPid());
- mLock.lock();
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
- if (retry) {
- err = mPlugin->openSession(sessionId);
- }
- }
- if (err == OK) {
- DrmSessionManager::Instance()->addSession(getCallingPid(), mDrmSessionClient, sessionId);
- }
- return err;
-}
-
-status_t Drm::closeSession(Vector<uint8_t> const &sessionId) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- status_t err = mPlugin->closeSession(sessionId);
- if (err == OK) {
- DrmSessionManager::Instance()->removeSession(sessionId);
- }
- return err;
-}
-
-status_t Drm::getKeyRequest(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &initData,
- String8 const &mimeType, DrmPlugin::KeyType keyType,
- KeyedVector<String8, String8> const &optionalParameters,
- Vector<uint8_t> &request, String8 &defaultUrl,
- DrmPlugin::KeyRequestType *keyRequestType) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->getKeyRequest(sessionId, initData, mimeType, keyType,
- optionalParameters, request, defaultUrl,
- keyRequestType);
-}
-
-status_t Drm::provideKeyResponse(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &response,
- Vector<uint8_t> &keySetId) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->provideKeyResponse(sessionId, response, keySetId);
-}
-
-status_t Drm::removeKeys(Vector<uint8_t> const &keySetId) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->removeKeys(keySetId);
-}
-
-status_t Drm::restoreKeys(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keySetId) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->restoreKeys(sessionId, keySetId);
-}
-
-status_t Drm::queryKeyStatus(Vector<uint8_t> const &sessionId,
- KeyedVector<String8, String8> &infoMap) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->queryKeyStatus(sessionId, infoMap);
-}
-
-status_t Drm::getProvisionRequest(String8 const &certType, String8 const &certAuthority,
- Vector<uint8_t> &request, String8 &defaultUrl) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->getProvisionRequest(certType, certAuthority,
- request, defaultUrl);
-}
-
-status_t Drm::provideProvisionResponse(Vector<uint8_t> const &response,
- Vector<uint8_t> &certificate,
- Vector<uint8_t> &wrappedKey) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->provideProvisionResponse(response, certificate, wrappedKey);
-}
-
-status_t Drm::getSecureStops(List<Vector<uint8_t> > &secureStops) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->getSecureStops(secureStops);
-}
-
-status_t Drm::getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->getSecureStop(ssid, secureStop);
-}
-
-status_t Drm::releaseSecureStops(Vector<uint8_t> const &ssRelease) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->releaseSecureStops(ssRelease);
-}
-
-status_t Drm::releaseAllSecureStops() {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->releaseAllSecureStops();
-}
-
-status_t Drm::getPropertyString(String8 const &name, String8 &value ) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->getPropertyString(name, value);
-}
-
-status_t Drm::getPropertyByteArray(String8 const &name, Vector<uint8_t> &value ) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->getPropertyByteArray(name, value);
-}
-
-status_t Drm::setPropertyString(String8 const &name, String8 const &value ) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->setPropertyString(name, value);
-}
-
-status_t Drm::setPropertyByteArray(String8 const &name,
- Vector<uint8_t> const &value ) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- return mPlugin->setPropertyByteArray(name, value);
-}
-
-
-status_t Drm::setCipherAlgorithm(Vector<uint8_t> const &sessionId,
- String8 const &algorithm) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->setCipherAlgorithm(sessionId, algorithm);
-}
-
-status_t Drm::setMacAlgorithm(Vector<uint8_t> const &sessionId,
- String8 const &algorithm) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->setMacAlgorithm(sessionId, algorithm);
-}
-
-status_t Drm::encrypt(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &input,
- Vector<uint8_t> const &iv,
- Vector<uint8_t> &output) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->encrypt(sessionId, keyId, input, iv, output);
-}
-
-status_t Drm::decrypt(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &input,
- Vector<uint8_t> const &iv,
- Vector<uint8_t> &output) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->decrypt(sessionId, keyId, input, iv, output);
-}
-
-status_t Drm::sign(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &message,
- Vector<uint8_t> &signature) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->sign(sessionId, keyId, message, signature);
-}
-
-status_t Drm::verify(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &message,
- Vector<uint8_t> const &signature,
- bool &match) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->verify(sessionId, keyId, message, signature, match);
-}
-
-status_t Drm::signRSA(Vector<uint8_t> const &sessionId,
- String8 const &algorithm,
- Vector<uint8_t> const &message,
- Vector<uint8_t> const &wrappedKey,
- Vector<uint8_t> &signature) {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- if (!checkPermission("android.permission.ACCESS_DRM_CERTIFICATES")) {
- return -EPERM;
- }
-
- DrmSessionManager::Instance()->useSession(sessionId);
-
- return mPlugin->signRSA(sessionId, algorithm, message, wrappedKey, signature);
-}
-
-void Drm::binderDied(const wp<IBinder> &the_late_who __unused)
-{
- mEventLock.lock();
- mListener.clear();
- mEventLock.unlock();
-
- Mutex::Autolock autoLock(mLock);
- delete mPlugin;
- mPlugin = NULL;
- closeFactory();
-}
-
-void Drm::writeByteArray(Parcel &obj, Vector<uint8_t> const *array)
-{
- if (array && array->size()) {
- obj.writeInt32(array->size());
- obj.write(array->array(), array->size());
- } else {
- obj.writeInt32(0);
- }
-}
-
-} // namespace android
diff --git a/media/libmediaplayerservice/Drm.h b/media/libmediaplayerservice/Drm.h
deleted file mode 100644
index d40019b..0000000
--- a/media/libmediaplayerservice/Drm.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef DRM_H_
-
-#define DRM_H_
-
-#include "SharedLibrary.h"
-
-#include <media/IDrm.h>
-#include <media/IDrmClient.h>
-#include <utils/threads.h>
-
-namespace android {
-
-class DrmFactory;
-class DrmPlugin;
-struct DrmSessionClientInterface;
-
-struct Drm : public BnDrm,
- public IBinder::DeathRecipient,
- public DrmPluginListener {
- Drm();
- virtual ~Drm();
-
- virtual status_t initCheck() const;
-
- virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType);
-
- virtual status_t createPlugin(const uint8_t uuid[16]);
-
- virtual status_t destroyPlugin();
-
- virtual status_t openSession(Vector<uint8_t> &sessionId);
-
- virtual status_t closeSession(Vector<uint8_t> const &sessionId);
-
- virtual status_t
- getKeyRequest(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &initData,
- String8 const &mimeType, DrmPlugin::KeyType keyType,
- KeyedVector<String8, String8> const &optionalParameters,
- Vector<uint8_t> &request, String8 &defaultUrl,
- DrmPlugin::KeyRequestType *keyRequestType);
-
- virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &response,
- Vector<uint8_t> &keySetId);
-
- virtual status_t removeKeys(Vector<uint8_t> const &keySetId);
-
- virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keySetId);
-
- virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
- KeyedVector<String8, String8> &infoMap) const;
-
- virtual status_t getProvisionRequest(String8 const &certType,
- String8 const &certAuthority,
- Vector<uint8_t> &request,
- String8 &defaulUrl);
-
- virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
- Vector<uint8_t> &certificate,
- Vector<uint8_t> &wrappedKey);
-
- virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops);
- virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop);
-
- virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease);
- virtual status_t releaseAllSecureStops();
-
- virtual status_t getPropertyString(String8 const &name, String8 &value ) const;
- virtual status_t getPropertyByteArray(String8 const &name,
- Vector<uint8_t> &value ) const;
- virtual status_t setPropertyString(String8 const &name, String8 const &value ) const;
- virtual status_t setPropertyByteArray(String8 const &name,
- Vector<uint8_t> const &value ) const;
-
- virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
- String8 const &algorithm);
-
- virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
- String8 const &algorithm);
-
- virtual status_t encrypt(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &input,
- Vector<uint8_t> const &iv,
- Vector<uint8_t> &output);
-
- virtual status_t decrypt(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &input,
- Vector<uint8_t> const &iv,
- Vector<uint8_t> &output);
-
- virtual status_t sign(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &message,
- Vector<uint8_t> &signature);
-
- virtual status_t verify(Vector<uint8_t> const &sessionId,
- Vector<uint8_t> const &keyId,
- Vector<uint8_t> const &message,
- Vector<uint8_t> const &signature,
- bool &match);
-
- virtual status_t signRSA(Vector<uint8_t> const &sessionId,
- String8 const &algorithm,
- Vector<uint8_t> const &message,
- Vector<uint8_t> const &wrappedKey,
- Vector<uint8_t> &signature);
-
- virtual status_t setListener(const sp<IDrmClient>& listener);
-
- virtual void sendEvent(DrmPlugin::EventType eventType, int extra,
- Vector<uint8_t> const *sessionId,
- Vector<uint8_t> const *data);
-
- virtual void sendExpirationUpdate(Vector<uint8_t> const *sessionId,
- int64_t expiryTimeInMS);
-
- virtual void sendKeysChange(Vector<uint8_t> const *sessionId,
- Vector<DrmPlugin::KeyStatus> const *keyStatusList,
- bool hasNewUsableKey);
-
- virtual void binderDied(const wp<IBinder> &the_late_who);
-
-private:
- static Mutex mLock;
-
- status_t mInitCheck;
-
- sp<DrmSessionClientInterface> mDrmSessionClient;
-
- sp<IDrmClient> mListener;
- mutable Mutex mEventLock;
- mutable Mutex mNotifyLock;
-
- sp<SharedLibrary> mLibrary;
- DrmFactory *mFactory;
- DrmPlugin *mPlugin;
-
- static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap;
- static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap;
- static Mutex mMapLock;
-
- void findFactoryForScheme(const uint8_t uuid[16]);
- bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]);
- void closeFactory();
- void writeByteArray(Parcel &obj, Vector<uint8_t> const *array);
-
- DISALLOW_EVIL_CONSTRUCTORS(Drm);
-};
-
-} // namespace android
-
-#endif // CRYPTO_H_
diff --git a/media/libmediaplayerservice/DrmSessionClientInterface.h b/media/libmediaplayerservice/DrmSessionClientInterface.h
deleted file mode 100644
index 17faf08..0000000
--- a/media/libmediaplayerservice/DrmSessionClientInterface.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef DRM_PROXY_INTERFACE_H_
-#define DRM_PROXY_INTERFACE_H_
-
-#include <utils/RefBase.h>
-#include <utils/Vector.h>
-
-namespace android {
-
-struct DrmSessionClientInterface : public RefBase {
- virtual bool reclaimSession(const Vector<uint8_t>& sessionId) = 0;
-
-protected:
- virtual ~DrmSessionClientInterface() {}
-};
-
-} // namespace android
-
-#endif // DRM_PROXY_INTERFACE_H_
diff --git a/media/libmediaplayerservice/DrmSessionManager.cpp b/media/libmediaplayerservice/DrmSessionManager.cpp
deleted file mode 100644
index 641f881..0000000
--- a/media/libmediaplayerservice/DrmSessionManager.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "DrmSessionManager"
-#include <utils/Log.h>
-
-#include "DrmSessionManager.h"
-
-#include "DrmSessionClientInterface.h"
-#include <binder/IPCThreadState.h>
-#include <binder/IProcessInfoService.h>
-#include <binder/IServiceManager.h>
-#include <media/stagefright/ProcessInfo.h>
-#include <unistd.h>
-#include <utils/String8.h>
-
-namespace android {
-
-static String8 GetSessionIdString(const Vector<uint8_t> &sessionId) {
- String8 sessionIdStr;
- for (size_t i = 0; i < sessionId.size(); ++i) {
- sessionIdStr.appendFormat("%u ", sessionId[i]);
- }
- return sessionIdStr;
-}
-
-bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2) {
- if (sessionId1.size() != sessionId2.size()) {
- return false;
- }
- for (size_t i = 0; i < sessionId1.size(); ++i) {
- if (sessionId1[i] != sessionId2[i]) {
- return false;
- }
- }
- return true;
-}
-
-sp<DrmSessionManager> DrmSessionManager::Instance() {
- static sp<DrmSessionManager> drmSessionManager = new DrmSessionManager();
- return drmSessionManager;
-}
-
-DrmSessionManager::DrmSessionManager()
- : mProcessInfo(new ProcessInfo()),
- mTime(0) {}
-
-DrmSessionManager::DrmSessionManager(sp<ProcessInfoInterface> processInfo)
- : mProcessInfo(processInfo),
- mTime(0) {}
-
-DrmSessionManager::~DrmSessionManager() {}
-
-void DrmSessionManager::addSession(
- int pid, sp<DrmSessionClientInterface> drm, const Vector<uint8_t> &sessionId) {
- ALOGV("addSession(pid %d, drm %p, sessionId %s)", pid, drm.get(),
- GetSessionIdString(sessionId).string());
-
- Mutex::Autolock lock(mLock);
- SessionInfo info;
- info.drm = drm;
- info.sessionId = sessionId;
- info.timeStamp = getTime_l();
- ssize_t index = mSessionMap.indexOfKey(pid);
- if (index < 0) {
- // new pid
- SessionInfos infosForPid;
- infosForPid.push_back(info);
- mSessionMap.add(pid, infosForPid);
- } else {
- mSessionMap.editValueAt(index).push_back(info);
- }
-}
-
-void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) {
- ALOGV("useSession(%s)", GetSessionIdString(sessionId).string());
-
- Mutex::Autolock lock(mLock);
- for (size_t i = 0; i < mSessionMap.size(); ++i) {
- SessionInfos& infos = mSessionMap.editValueAt(i);
- for (size_t j = 0; j < infos.size(); ++j) {
- SessionInfo& info = infos.editItemAt(j);
- if (isEqualSessionId(sessionId, info.sessionId)) {
- info.timeStamp = getTime_l();
- return;
- }
- }
- }
-}
-
-void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) {
- ALOGV("removeSession(%s)", GetSessionIdString(sessionId).string());
-
- Mutex::Autolock lock(mLock);
- for (size_t i = 0; i < mSessionMap.size(); ++i) {
- SessionInfos& infos = mSessionMap.editValueAt(i);
- for (size_t j = 0; j < infos.size(); ++j) {
- if (isEqualSessionId(sessionId, infos[j].sessionId)) {
- infos.removeAt(j);
- return;
- }
- }
- }
-}
-
-void DrmSessionManager::removeDrm(sp<DrmSessionClientInterface> drm) {
- ALOGV("removeDrm(%p)", drm.get());
-
- Mutex::Autolock lock(mLock);
- bool found = false;
- for (size_t i = 0; i < mSessionMap.size(); ++i) {
- SessionInfos& infos = mSessionMap.editValueAt(i);
- for (size_t j = 0; j < infos.size();) {
- if (infos[j].drm == drm) {
- ALOGV("removed session (%s)", GetSessionIdString(infos[j].sessionId).string());
- j = infos.removeAt(j);
- found = true;
- } else {
- ++j;
- }
- }
- if (found) {
- break;
- }
- }
-}
-
-bool DrmSessionManager::reclaimSession(int callingPid) {
- ALOGV("reclaimSession(%d)", callingPid);
-
- sp<DrmSessionClientInterface> drm;
- Vector<uint8_t> sessionId;
- int lowestPriorityPid;
- int lowestPriority;
- {
- Mutex::Autolock lock(mLock);
- int callingPriority;
- if (!mProcessInfo->getPriority(callingPid, &callingPriority)) {
- return false;
- }
- if (!getLowestPriority_l(&lowestPriorityPid, &lowestPriority)) {
- return false;
- }
- if (lowestPriority <= callingPriority) {
- return false;
- }
-
- if (!getLeastUsedSession_l(lowestPriorityPid, &drm, &sessionId)) {
- return false;
- }
- }
-
- if (drm == NULL) {
- return false;
- }
-
- ALOGV("reclaim session(%s) opened by pid %d",
- GetSessionIdString(sessionId).string(), lowestPriorityPid);
-
- return drm->reclaimSession(sessionId);
-}
-
-int64_t DrmSessionManager::getTime_l() {
- return mTime++;
-}
-
-bool DrmSessionManager::getLowestPriority_l(int* lowestPriorityPid, int* lowestPriority) {
- int pid = -1;
- int priority = -1;
- for (size_t i = 0; i < mSessionMap.size(); ++i) {
- if (mSessionMap.valueAt(i).size() == 0) {
- // no opened session by this process.
- continue;
- }
- int tempPid = mSessionMap.keyAt(i);
- int tempPriority;
- if (!mProcessInfo->getPriority(tempPid, &tempPriority)) {
- // shouldn't happen.
- return false;
- }
- if (pid == -1) {
- pid = tempPid;
- priority = tempPriority;
- } else {
- if (tempPriority > priority) {
- pid = tempPid;
- priority = tempPriority;
- }
- }
- }
- if (pid != -1) {
- *lowestPriorityPid = pid;
- *lowestPriority = priority;
- }
- return (pid != -1);
-}
-
-bool DrmSessionManager::getLeastUsedSession_l(
- int pid, sp<DrmSessionClientInterface>* drm, Vector<uint8_t>* sessionId) {
- ssize_t index = mSessionMap.indexOfKey(pid);
- if (index < 0) {
- return false;
- }
-
- int leastUsedIndex = -1;
- int64_t minTs = LLONG_MAX;
- const SessionInfos& infos = mSessionMap.valueAt(index);
- for (size_t j = 0; j < infos.size(); ++j) {
- if (leastUsedIndex == -1) {
- leastUsedIndex = j;
- minTs = infos[j].timeStamp;
- } else {
- if (infos[j].timeStamp < minTs) {
- leastUsedIndex = j;
- minTs = infos[j].timeStamp;
- }
- }
- }
- if (leastUsedIndex != -1) {
- *drm = infos[leastUsedIndex].drm;
- *sessionId = infos[leastUsedIndex].sessionId;
- }
- return (leastUsedIndex != -1);
-}
-
-} // namespace android
diff --git a/media/libmediaplayerservice/DrmSessionManager.h b/media/libmediaplayerservice/DrmSessionManager.h
deleted file mode 100644
index ba5c268..0000000
--- a/media/libmediaplayerservice/DrmSessionManager.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef DRM_SESSION_MANAGER_H_
-
-#define DRM_SESSION_MANAGER_H_
-
-#include <media/stagefright/foundation/ABase.h>
-#include <utils/RefBase.h>
-#include <utils/KeyedVector.h>
-#include <utils/threads.h>
-#include <utils/Vector.h>
-
-namespace android {
-
-class DrmSessionManagerTest;
-struct DrmSessionClientInterface;
-struct ProcessInfoInterface;
-
-bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2);
-
-struct SessionInfo {
- sp<DrmSessionClientInterface> drm;
- Vector<uint8_t> sessionId;
- int64_t timeStamp;
-};
-
-typedef Vector<SessionInfo > SessionInfos;
-typedef KeyedVector<int, SessionInfos > PidSessionInfosMap;
-
-struct DrmSessionManager : public RefBase {
- static sp<DrmSessionManager> Instance();
-
- DrmSessionManager();
- DrmSessionManager(sp<ProcessInfoInterface> processInfo);
-
- void addSession(int pid, sp<DrmSessionClientInterface> drm, const Vector<uint8_t>& sessionId);
- void useSession(const Vector<uint8_t>& sessionId);
- void removeSession(const Vector<uint8_t>& sessionId);
- void removeDrm(sp<DrmSessionClientInterface> drm);
- bool reclaimSession(int callingPid);
-
-protected:
- virtual ~DrmSessionManager();
-
-private:
- friend class DrmSessionManagerTest;
-
- int64_t getTime_l();
- bool getLowestPriority_l(int* lowestPriorityPid, int* lowestPriority);
- bool getLeastUsedSession_l(
- int pid, sp<DrmSessionClientInterface>* drm, Vector<uint8_t>* sessionId);
-
- sp<ProcessInfoInterface> mProcessInfo;
- mutable Mutex mLock;
- PidSessionInfosMap mSessionMap;
- int64_t mTime;
-
- DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager);
-};
-
-} // namespace android
-
-#endif // DRM_SESSION_MANAGER_H_
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 9b081e9..7d3c671 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -78,8 +78,6 @@
#include <OMX.h>
-#include "Crypto.h"
-#include "Drm.h"
#include "HDCP.h"
#include "HTTPBase.h"
#include "RemoteDisplay.h"
@@ -359,14 +357,6 @@
return mOMX;
}
-sp<ICrypto> MediaPlayerService::makeCrypto() {
- return new Crypto;
-}
-
-sp<IDrm> MediaPlayerService::makeDrm() {
- return new Drm;
-}
-
sp<IHDCP> MediaPlayerService::makeHDCP(bool createEncryptionModule) {
return new HDCP(createEncryptionModule);
}
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index 80593b2..1cf648e 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -219,8 +219,6 @@
virtual sp<IMediaCodecList> getCodecList() const;
virtual sp<IOMX> getOMX();
- virtual sp<ICrypto> makeCrypto();
- virtual sp<IDrm> makeDrm();
virtual sp<IHDCP> makeHDCP(bool createEncryptionModule);
virtual sp<IRemoteDisplay> listenForRemoteDisplay(const String16 &opPackageName,
@@ -410,7 +408,6 @@
SortedVector< wp<MediaRecorderClient> > mMediaRecorderClients;
int32_t mNextConnId;
sp<IOMX> mOMX;
- sp<ICrypto> mCrypto;
};
// ----------------------------------------------------------------------------
diff --git a/media/libmediaplayerservice/SharedLibrary.cpp b/media/libmediaplayerservice/SharedLibrary.cpp
deleted file mode 100644
index 34db761..0000000
--- a/media/libmediaplayerservice/SharedLibrary.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Drm"
-#include <utils/Log.h>
-#include <media/stagefright/foundation/ADebug.h>
-
-#include <dlfcn.h>
-
-#include "SharedLibrary.h"
-
-namespace android {
-
- SharedLibrary::SharedLibrary(const String8 &path) {
- mLibHandle = dlopen(path.string(), RTLD_NOW);
- }
-
- SharedLibrary::~SharedLibrary() {
- if (mLibHandle != NULL) {
- dlclose(mLibHandle);
- mLibHandle = NULL;
- }
- }
-
- bool SharedLibrary::operator!() const {
- return mLibHandle == NULL;
- }
-
- void *SharedLibrary::lookup(const char *symbol) const {
- if (!mLibHandle) {
- return NULL;
- }
- return dlsym(mLibHandle, symbol);
- }
-
- const char *SharedLibrary::lastError() const {
- const char *error = dlerror();
- return error ? error : "No errors or unknown error";
- }
-
-};
diff --git a/media/libmediaplayerservice/SharedLibrary.h b/media/libmediaplayerservice/SharedLibrary.h
deleted file mode 100644
index 88451a0..0000000
--- a/media/libmediaplayerservice/SharedLibrary.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SHARED_LIBRARY_H_
-#define SHARED_LIBRARY_H_
-
-#include <utils/RefBase.h>
-#include <utils/String8.h>
-#include <media/stagefright/foundation/ABase.h>
-
-namespace android {
- class SharedLibrary : public RefBase {
- public:
- SharedLibrary(const String8 &path);
- ~SharedLibrary();
-
- bool operator!() const;
- void *lookup(const char *symbol) const;
- const char *lastError() const;
-
- private:
- void *mLibHandle;
- DISALLOW_EVIL_CONSTRUCTORS(SharedLibrary);
- };
-};
-
-#endif // SHARED_LIBRARY_H_
diff --git a/media/libmediaplayerservice/tests/Android.mk b/media/libmediaplayerservice/tests/Android.mk
index 8cbf782..ea75a97 100644
--- a/media/libmediaplayerservice/tests/Android.mk
+++ b/media/libmediaplayerservice/tests/Android.mk
@@ -12,6 +12,7 @@
LOCAL_SHARED_LIBRARIES := \
liblog \
libmediaplayerservice \
+ libmediadrm \
libutils \
LOCAL_C_INCLUDES := \
diff --git a/media/libmediaplayerservice/tests/DrmSessionManager_test.cpp b/media/libmediaplayerservice/tests/DrmSessionManager_test.cpp
index ef4c833..c5212fc 100644
--- a/media/libmediaplayerservice/tests/DrmSessionManager_test.cpp
+++ b/media/libmediaplayerservice/tests/DrmSessionManager_test.cpp
@@ -20,9 +20,9 @@
#include <gtest/gtest.h>
-#include "Drm.h"
-#include "DrmSessionClientInterface.h"
-#include "DrmSessionManager.h"
+#include <media/Drm.h>
+#include <media/DrmSessionClientInterface.h>
+#include <media/DrmSessionManager.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/ProcessInfoInterface.h>