Merge "Remove Unnecessary Locking from Android" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f18021f99a
@@ -16,7 +16,6 @@
|
|||||||
#include "utils/Errors.h"
|
#include "utils/Errors.h"
|
||||||
#include "utils/KeyedVector.h"
|
#include "utils/KeyedVector.h"
|
||||||
#include "utils/List.h"
|
#include "utils/List.h"
|
||||||
#include "utils/Mutex.h"
|
|
||||||
#include "utils/String8.h"
|
#include "utils/String8.h"
|
||||||
#include "utils/Vector.h"
|
#include "utils/Vector.h"
|
||||||
#include "wv_cdm_event_listener.h"
|
#include "wv_cdm_event_listener.h"
|
||||||
@@ -27,7 +26,6 @@ namespace wvdrm {
|
|||||||
|
|
||||||
using android::KeyedVector;
|
using android::KeyedVector;
|
||||||
using android::List;
|
using android::List;
|
||||||
using android::Mutex;
|
|
||||||
using android::status_t;
|
using android::status_t;
|
||||||
using android::String8;
|
using android::String8;
|
||||||
using android::Vector;
|
using android::Vector;
|
||||||
@@ -253,8 +251,6 @@ class WVDrmPlugin : public android::DrmPlugin,
|
|||||||
WvContentDecryptionModule* mCDM;
|
WvContentDecryptionModule* mCDM;
|
||||||
WVGenericCryptoInterface* mCrypto;
|
WVGenericCryptoInterface* mCrypto;
|
||||||
std::string mOrigin;
|
std::string mOrigin;
|
||||||
|
|
||||||
Mutex mCryptoSessionsMutex;
|
|
||||||
map<CdmSessionId, CryptoSession> mCryptoSessions;
|
map<CdmSessionId, CryptoSession> mCryptoSessions;
|
||||||
|
|
||||||
status_t queryProperty(const std::string& property,
|
status_t queryProperty(const std::string& property,
|
||||||
|
|||||||
@@ -75,12 +75,10 @@ DrmPlugin::KeyStatusType ConvertFromCdmKeyStatus(CdmKeyStatus keyStatus) {
|
|||||||
|
|
||||||
WVDrmPlugin::WVDrmPlugin(WvContentDecryptionModule* cdm,
|
WVDrmPlugin::WVDrmPlugin(WvContentDecryptionModule* cdm,
|
||||||
WVGenericCryptoInterface* crypto)
|
WVGenericCryptoInterface* crypto)
|
||||||
: mCDM(cdm), mCrypto(crypto), mOrigin(), mCryptoSessionsMutex(),
|
: mCDM(cdm), mCrypto(crypto), mOrigin(), mCryptoSessions() {}
|
||||||
mCryptoSessions() {}
|
|
||||||
|
|
||||||
WVDrmPlugin::~WVDrmPlugin() {
|
WVDrmPlugin::~WVDrmPlugin() {
|
||||||
typedef map<CdmSessionId, CryptoSession>::iterator mapIterator;
|
typedef map<CdmSessionId, CryptoSession>::iterator mapIterator;
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
for (mapIterator iter = mCryptoSessions.begin();
|
for (mapIterator iter = mCryptoSessions.begin();
|
||||||
iter != mCryptoSessions.end();
|
iter != mCryptoSessions.end();
|
||||||
++iter) {
|
++iter) {
|
||||||
@@ -112,12 +110,7 @@ status_t WVDrmPlugin::openSession(Vector<uint8_t>& sessionId) {
|
|||||||
info.count(QUERY_KEY_OEMCRYPTO_SESSION_ID)) {
|
info.count(QUERY_KEY_OEMCRYPTO_SESSION_ID)) {
|
||||||
OEMCrypto_SESSION oecSessionId;
|
OEMCrypto_SESSION oecSessionId;
|
||||||
istringstream(info[QUERY_KEY_OEMCRYPTO_SESSION_ID]) >> oecSessionId;
|
istringstream(info[QUERY_KEY_OEMCRYPTO_SESSION_ID]) >> oecSessionId;
|
||||||
|
mCryptoSessions[cdmSessionId] = CryptoSession(oecSessionId);
|
||||||
{
|
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
mCryptoSessions[cdmSessionId] = CryptoSession(oecSessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
ALOGE("Unable to query key control info.");
|
ALOGE("Unable to query key control info.");
|
||||||
@@ -147,12 +140,7 @@ status_t WVDrmPlugin::openSession(Vector<uint8_t>& sessionId) {
|
|||||||
status_t WVDrmPlugin::closeSession(const Vector<uint8_t>& sessionId) {
|
status_t WVDrmPlugin::closeSession(const Vector<uint8_t>& sessionId) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
CdmResponseType res = mCDM->CloseSession(cdmSessionId);
|
CdmResponseType res = mCDM->CloseSession(cdmSessionId);
|
||||||
|
mCryptoSessions.erase(cdmSessionId);
|
||||||
if (isCdmResponseTypeSuccess(res)) {
|
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
mCryptoSessions.erase(cdmSessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapAndNotifyOfCdmResponseType(sessionId, res);
|
return mapAndNotifyOfCdmResponseType(sessionId, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,12 +530,7 @@ status_t WVDrmPlugin::getPropertyByteArray(const String8& name,
|
|||||||
status_t WVDrmPlugin::setPropertyString(const String8& name,
|
status_t WVDrmPlugin::setPropertyString(const String8& name,
|
||||||
const String8& value) {
|
const String8& value) {
|
||||||
if (name == "securityLevel") {
|
if (name == "securityLevel") {
|
||||||
size_t sessionCount = 0;
|
if (mCryptoSessions.size() == 0) {
|
||||||
{
|
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
sessionCount = mCryptoSessions.size();
|
|
||||||
}
|
|
||||||
if (sessionCount == 0) {
|
|
||||||
if (value == QUERY_VALUE_SECURITY_LEVEL_L3.c_str()) {
|
if (value == QUERY_VALUE_SECURITY_LEVEL_L3.c_str()) {
|
||||||
mPropertySet.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3);
|
mPropertySet.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3);
|
||||||
} else if (value == QUERY_VALUE_SECURITY_LEVEL_L1.c_str()) {
|
} else if (value == QUERY_VALUE_SECURITY_LEVEL_L1.c_str()) {
|
||||||
@@ -583,12 +566,7 @@ status_t WVDrmPlugin::setPropertyString(const String8& name,
|
|||||||
return android::BAD_VALUE;
|
return android::BAD_VALUE;
|
||||||
}
|
}
|
||||||
} else if (name == "sessionSharing") {
|
} else if (name == "sessionSharing") {
|
||||||
size_t sessionCount = 0;
|
if (mCryptoSessions.size() == 0) {
|
||||||
{
|
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
sessionCount = mCryptoSessions.size();
|
|
||||||
}
|
|
||||||
if (sessionCount == 0) {
|
|
||||||
if (value == kEnable) {
|
if (value == kEnable) {
|
||||||
mPropertySet.set_is_session_sharing_enabled(true);
|
mPropertySet.set_is_session_sharing_enabled(true);
|
||||||
} else if (value == kDisable) {
|
} else if (value == kDisable) {
|
||||||
@@ -602,24 +580,14 @@ status_t WVDrmPlugin::setPropertyString(const String8& name,
|
|||||||
return kErrorSessionIsOpen;
|
return kErrorSessionIsOpen;
|
||||||
}
|
}
|
||||||
} else if (name == "appId") {
|
} else if (name == "appId") {
|
||||||
size_t sessionCount = 0;
|
if (mCryptoSessions.size() == 0) {
|
||||||
{
|
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
sessionCount = mCryptoSessions.size();
|
|
||||||
}
|
|
||||||
if (sessionCount == 0) {
|
|
||||||
mPropertySet.set_app_id(value.string());
|
mPropertySet.set_app_id(value.string());
|
||||||
} else {
|
} else {
|
||||||
ALOGE("App tried to set the application id while sessions are opened.");
|
ALOGE("App tried to set the application id while sessions are opened.");
|
||||||
return kErrorSessionIsOpen;
|
return kErrorSessionIsOpen;
|
||||||
}
|
}
|
||||||
} else if (name == "origin") {
|
} else if (name == "origin") {
|
||||||
size_t sessionCount = 0;
|
if (mCryptoSessions.size() == 0) {
|
||||||
{
|
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
sessionCount = mCryptoSessions.size();
|
|
||||||
}
|
|
||||||
if (sessionCount == 0) {
|
|
||||||
mOrigin = value.string();
|
mOrigin = value.string();
|
||||||
} else {
|
} else {
|
||||||
ALOGE("App tried to set the origin while sessions are opened.");
|
ALOGE("App tried to set the origin while sessions are opened.");
|
||||||
@@ -649,8 +617,6 @@ status_t WVDrmPlugin::setPropertyByteArray(const String8& name,
|
|||||||
status_t WVDrmPlugin::setCipherAlgorithm(const Vector<uint8_t>& sessionId,
|
status_t WVDrmPlugin::setCipherAlgorithm(const Vector<uint8_t>& sessionId,
|
||||||
const String8& algorithm) {
|
const String8& algorithm) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
|
|
||||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||||
}
|
}
|
||||||
@@ -669,8 +635,6 @@ status_t WVDrmPlugin::setCipherAlgorithm(const Vector<uint8_t>& sessionId,
|
|||||||
status_t WVDrmPlugin::setMacAlgorithm(const Vector<uint8_t>& sessionId,
|
status_t WVDrmPlugin::setMacAlgorithm(const Vector<uint8_t>& sessionId,
|
||||||
const String8& algorithm) {
|
const String8& algorithm) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
|
|
||||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||||
}
|
}
|
||||||
@@ -692,8 +656,6 @@ status_t WVDrmPlugin::encrypt(const Vector<uint8_t>& sessionId,
|
|||||||
const Vector<uint8_t>& iv,
|
const Vector<uint8_t>& iv,
|
||||||
Vector<uint8_t>& output) {
|
Vector<uint8_t>& output) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
|
|
||||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||||
}
|
}
|
||||||
@@ -732,8 +694,6 @@ status_t WVDrmPlugin::decrypt(const Vector<uint8_t>& sessionId,
|
|||||||
const Vector<uint8_t>& iv,
|
const Vector<uint8_t>& iv,
|
||||||
Vector<uint8_t>& output) {
|
Vector<uint8_t>& output) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
|
|
||||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||||
}
|
}
|
||||||
@@ -771,8 +731,6 @@ status_t WVDrmPlugin::sign(const Vector<uint8_t>& sessionId,
|
|||||||
const Vector<uint8_t>& message,
|
const Vector<uint8_t>& message,
|
||||||
Vector<uint8_t>& signature) {
|
Vector<uint8_t>& signature) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
|
|
||||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||||
}
|
}
|
||||||
@@ -827,8 +785,6 @@ status_t WVDrmPlugin::verify(const Vector<uint8_t>& sessionId,
|
|||||||
const Vector<uint8_t>& signature,
|
const Vector<uint8_t>& signature,
|
||||||
bool& match) {
|
bool& match) {
|
||||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
|
||||||
|
|
||||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user