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/KeyedVector.h"
|
||||
#include "utils/List.h"
|
||||
#include "utils/Mutex.h"
|
||||
#include "utils/String8.h"
|
||||
#include "utils/Vector.h"
|
||||
#include "wv_cdm_event_listener.h"
|
||||
@@ -27,7 +26,6 @@ namespace wvdrm {
|
||||
|
||||
using android::KeyedVector;
|
||||
using android::List;
|
||||
using android::Mutex;
|
||||
using android::status_t;
|
||||
using android::String8;
|
||||
using android::Vector;
|
||||
@@ -253,8 +251,6 @@ class WVDrmPlugin : public android::DrmPlugin,
|
||||
WvContentDecryptionModule* mCDM;
|
||||
WVGenericCryptoInterface* mCrypto;
|
||||
std::string mOrigin;
|
||||
|
||||
Mutex mCryptoSessionsMutex;
|
||||
map<CdmSessionId, CryptoSession> mCryptoSessions;
|
||||
|
||||
status_t queryProperty(const std::string& property,
|
||||
|
||||
@@ -75,12 +75,10 @@ DrmPlugin::KeyStatusType ConvertFromCdmKeyStatus(CdmKeyStatus keyStatus) {
|
||||
|
||||
WVDrmPlugin::WVDrmPlugin(WvContentDecryptionModule* cdm,
|
||||
WVGenericCryptoInterface* crypto)
|
||||
: mCDM(cdm), mCrypto(crypto), mOrigin(), mCryptoSessionsMutex(),
|
||||
mCryptoSessions() {}
|
||||
: mCDM(cdm), mCrypto(crypto), mOrigin(), mCryptoSessions() {}
|
||||
|
||||
WVDrmPlugin::~WVDrmPlugin() {
|
||||
typedef map<CdmSessionId, CryptoSession>::iterator mapIterator;
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
for (mapIterator iter = mCryptoSessions.begin();
|
||||
iter != mCryptoSessions.end();
|
||||
++iter) {
|
||||
@@ -112,12 +110,7 @@ status_t WVDrmPlugin::openSession(Vector<uint8_t>& sessionId) {
|
||||
info.count(QUERY_KEY_OEMCRYPTO_SESSION_ID)) {
|
||||
OEMCrypto_SESSION oecSessionId;
|
||||
istringstream(info[QUERY_KEY_OEMCRYPTO_SESSION_ID]) >> oecSessionId;
|
||||
|
||||
{
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
mCryptoSessions[cdmSessionId] = CryptoSession(oecSessionId);
|
||||
}
|
||||
|
||||
mCryptoSessions[cdmSessionId] = CryptoSession(oecSessionId);
|
||||
success = true;
|
||||
} else {
|
||||
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) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
CdmResponseType res = mCDM->CloseSession(cdmSessionId);
|
||||
|
||||
if (isCdmResponseTypeSuccess(res)) {
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
mCryptoSessions.erase(cdmSessionId);
|
||||
}
|
||||
|
||||
mCryptoSessions.erase(cdmSessionId);
|
||||
return mapAndNotifyOfCdmResponseType(sessionId, res);
|
||||
}
|
||||
|
||||
@@ -542,12 +530,7 @@ status_t WVDrmPlugin::getPropertyByteArray(const String8& name,
|
||||
status_t WVDrmPlugin::setPropertyString(const String8& name,
|
||||
const String8& value) {
|
||||
if (name == "securityLevel") {
|
||||
size_t sessionCount = 0;
|
||||
{
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
sessionCount = mCryptoSessions.size();
|
||||
}
|
||||
if (sessionCount == 0) {
|
||||
if (mCryptoSessions.size() == 0) {
|
||||
if (value == QUERY_VALUE_SECURITY_LEVEL_L3.c_str()) {
|
||||
mPropertySet.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3);
|
||||
} 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;
|
||||
}
|
||||
} else if (name == "sessionSharing") {
|
||||
size_t sessionCount = 0;
|
||||
{
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
sessionCount = mCryptoSessions.size();
|
||||
}
|
||||
if (sessionCount == 0) {
|
||||
if (mCryptoSessions.size() == 0) {
|
||||
if (value == kEnable) {
|
||||
mPropertySet.set_is_session_sharing_enabled(true);
|
||||
} else if (value == kDisable) {
|
||||
@@ -602,24 +580,14 @@ status_t WVDrmPlugin::setPropertyString(const String8& name,
|
||||
return kErrorSessionIsOpen;
|
||||
}
|
||||
} else if (name == "appId") {
|
||||
size_t sessionCount = 0;
|
||||
{
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
sessionCount = mCryptoSessions.size();
|
||||
}
|
||||
if (sessionCount == 0) {
|
||||
if (mCryptoSessions.size() == 0) {
|
||||
mPropertySet.set_app_id(value.string());
|
||||
} else {
|
||||
ALOGE("App tried to set the application id while sessions are opened.");
|
||||
return kErrorSessionIsOpen;
|
||||
}
|
||||
} else if (name == "origin") {
|
||||
size_t sessionCount = 0;
|
||||
{
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
sessionCount = mCryptoSessions.size();
|
||||
}
|
||||
if (sessionCount == 0) {
|
||||
if (mCryptoSessions.size() == 0) {
|
||||
mOrigin = value.string();
|
||||
} else {
|
||||
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,
|
||||
const String8& algorithm) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
|
||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||
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,
|
||||
const String8& algorithm) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
|
||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||
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,
|
||||
Vector<uint8_t>& output) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
|
||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||
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,
|
||||
Vector<uint8_t>& output) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
|
||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||
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,
|
||||
Vector<uint8_t>& signature) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
|
||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||
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,
|
||||
bool& match) {
|
||||
CdmSessionId cdmSessionId(sessionId.begin(), sessionId.end());
|
||||
Mutex::Autolock lock(mCryptoSessionsMutex);
|
||||
|
||||
if (!mCryptoSessions.count(cdmSessionId)) {
|
||||
return android::ERROR_DRM_SESSION_NOT_OPENED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user