Remove DISABLE_TREBLE_DRM
This flag is obsolete now that the conversion
to treble is complete.
Change-Id: I7073d337939da43bddf99644bfe52db9baa2f605
Merged-In: I7073d337939da43bddf99644bfe52db9baa2f605
related-to-bug: 32815560
(cherry picked from commit 99a5aba027cca8d3e69e333b56168a223e053d82)
diff --git a/drm/libmediadrm/Android.mk b/drm/libmediadrm/Android.mk
index 5b56501..14d5cab 100644
--- a/drm/libmediadrm/Android.mk
+++ b/drm/libmediadrm/Android.mk
@@ -25,16 +25,9 @@
IDrmClient.cpp \
IMediaDrmService.cpp \
MediaCasDefs.cpp \
- SharedLibrary.cpp
-ifneq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_SRC_FILES += \
+ SharedLibrary.cpp \
DrmHal.cpp \
CryptoHal.cpp
-else
-LOCAL_SRC_FILES += \
- Drm.cpp \
- Crypto.cpp
-endif
LOCAL_SHARED_LIBRARIES := \
libbinder \
@@ -43,15 +36,12 @@
liblog \
libmediautils \
libstagefright_foundation \
- libutils
-ifneq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_SHARED_LIBRARIES += \
+ libutils \
android.hidl.base@1.0 \
android.hardware.drm@1.0 \
libhidlbase \
libhidlmemory \
libhidltransport
-endif
LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
diff --git a/drm/libmediadrm/Crypto.cpp b/drm/libmediadrm/Crypto.cpp
deleted file mode 100644
index a5d7346..0000000
--- a/drm/libmediadrm/Crypto.cpp
+++ /dev/null
@@ -1,288 +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 <binder/IMemory.h>
-#include <media/Crypto.h>
-#include <media/DrmPluginPath.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(getDrmPluginPath());
- 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(const uint8_t key[16], const uint8_t iv[16],
- CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
- const sp<IMemory> &source, size_t offset,
- const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
- const ICrypto::DestinationBuffer &destination, AString *errorDetailMsg) {
-
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- const void *srcPtr = static_cast<uint8_t *>(source->pointer()) + offset;
-
- void *destPtr;
- bool secure = false;
- if (destination.mType == kDestinationTypeNativeHandle) {
- destPtr = static_cast<void *>(destination.mHandle);
- secure = true;
- } else {
- destPtr = destination.mSharedMemory->pointer();
- }
-
- ssize_t result = mPlugin->decrypt(secure, key, iv, mode, pattern, srcPtr, subSamples,
- numSubSamples, destPtr, errorDetailMsg);
-
- return result;
-}
-
-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/drm/libmediadrm/Drm.cpp b/drm/libmediadrm/Drm.cpp
deleted file mode 100644
index 1004eb8..0000000
--- a/drm/libmediadrm/Drm.cpp
+++ /dev/null
@@ -1,799 +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 <media/DrmPluginPath.h>
-#include <media/DrmSessionClientInterface.h>
-#include <media/DrmSessionManager.h>
-#include <media/Drm.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 {
- explicit 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(getDrmPluginPath());
- 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],
- const String8& /* appPackageName */) {
- 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);
- if (mPlugin) {
- mPlugin->setListener(this);
- } else {
- ALOGE("Failed to create plugin");
- return UNEXPECTED_NULL;
- }
- return result;
-}
-
-status_t Drm::destroyPlugin() {
- Mutex::Autolock autoLock(mLock);
-
- if (mInitCheck != OK) {
- return mInitCheck;
- }
-
- if (mPlugin == NULL) {
- return -EINVAL;
- }
-
- setListener(NULL);
- 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/services/mediadrm/Android.mk b/services/mediadrm/Android.mk
index fa3a02b..7594388 100644
--- a/services/mediadrm/Android.mk
+++ b/services/mediadrm/Android.mk
@@ -25,19 +25,13 @@
libbinder \
liblog \
libmediadrm \
- libutils
-ifneq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_SHARED_LIBRARIES += \
+ libutils \
libhidlbase \
libhidlmemory \
android.hidl.base@1.0 \
android.hardware.drm@1.0
-endif
LOCAL_CFLAGS += -Wall -Wextra -Werror
-ifeq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_CFLAGS += -DDISABLE_TREBLE_DRM=1
-endif
LOCAL_MODULE:= mediadrmserver
diff --git a/services/mediadrm/MediaDrmService.cpp b/services/mediadrm/MediaDrmService.cpp
index b9ec347..a368c11 100644
--- a/services/mediadrm/MediaDrmService.cpp
+++ b/services/mediadrm/MediaDrmService.cpp
@@ -24,13 +24,8 @@
#include <binder/IServiceManager.h>
#include <utils/Log.h>
-#ifdef DISABLE_TREBLE_DRM
-#include <media/Crypto.h>
-#include <media/Drm.h>
-#else
#include <media/CryptoHal.h>
#include <media/DrmHal.h>
-#endif
namespace android {
@@ -40,19 +35,11 @@
}
sp<ICrypto> MediaDrmService::makeCrypto() {
-#ifdef DISABLE_TREBLE_DRM
- return new Crypto;
-#else
return new CryptoHal;
-#endif
}
sp<IDrm> MediaDrmService::makeDrm() {
-#ifdef DISABLE_TREBLE_DRM
- return new Drm;
-#else
return new DrmHal;
-#endif
}
} // namespace android