Revert "Revert "Fix MediaDrm security level APIs""
This reverts commit 5f5e43fa83551a3636b92871bd2ad6b260a8815b.
Change-Id: I72d585fd3768730eef6ad9effdbda81b32418dea
diff --git a/drm/libmediadrm/DrmHal.cpp b/drm/libmediadrm/DrmHal.cpp
index 07cec01..3bbc34b 100644
--- a/drm/libmediadrm/DrmHal.cpp
+++ b/drm/libmediadrm/DrmHal.cpp
@@ -510,24 +510,62 @@
return OK;
}
-status_t DrmHal::openSession(Vector<uint8_t> &sessionId) {
+status_t DrmHal::openSession(DrmPlugin::SecurityLevel level,
+ Vector<uint8_t> &sessionId) {
Mutex::Autolock autoLock(mLock);
INIT_CHECK();
- status_t err = UNKNOWN_ERROR;
+ SecurityLevel hSecurityLevel;
+ bool setSecurityLevel = true;
+ switch(level) {
+ case DrmPlugin::kSecurityLevelSwSecureCrypto:
+ hSecurityLevel = SecurityLevel::SW_SECURE_CRYPTO;
+ break;
+ case DrmPlugin::kSecurityLevelSwSecureDecode:
+ hSecurityLevel = SecurityLevel::SW_SECURE_DECODE;
+ break;
+ case DrmPlugin::kSecurityLevelHwSecureCrypto:
+ hSecurityLevel = SecurityLevel::HW_SECURE_CRYPTO;
+ break;
+ case DrmPlugin::kSecurityLevelHwSecureDecode:
+ hSecurityLevel = SecurityLevel::HW_SECURE_DECODE;
+ break;
+ case DrmPlugin::kSecurityLevelHwSecureAll:
+ hSecurityLevel = SecurityLevel::HW_SECURE_ALL;
+ break;
+ case DrmPlugin::kSecurityLevelMax:
+ setSecurityLevel = false;
+ break;
+ default:
+ return ERROR_DRM_CANNOT_HANDLE;
+ }
+
+ status_t err = UNKNOWN_ERROR;
bool retry = true;
do {
hidl_vec<uint8_t> hSessionId;
- Return<void> hResult = mPlugin->openSession(
- [&](Status status, const hidl_vec<uint8_t>& id) {
- if (status == Status::OK) {
- sessionId = toVector(id);
+ Return<void> hResult;
+ if (mPluginV1_1 == NULL || !setSecurityLevel) {
+ hResult = mPlugin->openSession(
+ [&](Status status,const hidl_vec<uint8_t>& id) {
+ if (status == Status::OK) {
+ sessionId = toVector(id);
+ }
+ err = toStatusT(status);
}
- err = toStatusT(status);
- }
- );
+ );
+ } else {
+ hResult = mPluginV1_1->openSession_1_1(hSecurityLevel,
+ [&](Status status, const hidl_vec<uint8_t>& id) {
+ if (status == Status::OK) {
+ sessionId = toVector(id);
+ }
+ err = toStatusT(status);
+ }
+ );
+ }
if (!hResult.isOk()) {
err = DEAD_OBJECT;
@@ -979,42 +1017,6 @@
return hResult.isOk() ? err : DEAD_OBJECT;
}
-status_t DrmHal::setSecurityLevel(Vector<uint8_t> const &sessionId,
- const DrmPlugin::SecurityLevel& level) {
- Mutex::Autolock autoLock(mLock);
- INIT_CHECK();
-
- if (mPluginV1_1 == NULL) {
- return ERROR_DRM_CANNOT_HANDLE;
- }
-
- SecurityLevel hSecurityLevel;
-
- switch(level) {
- case DrmPlugin::kSecurityLevelSwSecureCrypto:
- hSecurityLevel = SecurityLevel::SW_SECURE_CRYPTO;
- break;
- case DrmPlugin::kSecurityLevelSwSecureDecode:
- hSecurityLevel = SecurityLevel::SW_SECURE_DECODE;
- break;
- case DrmPlugin::kSecurityLevelHwSecureCrypto:
- hSecurityLevel = SecurityLevel::HW_SECURE_CRYPTO;
- break;
- case DrmPlugin::kSecurityLevelHwSecureDecode:
- hSecurityLevel = SecurityLevel::HW_SECURE_DECODE;
- break;
- case DrmPlugin::kSecurityLevelHwSecureAll:
- hSecurityLevel = SecurityLevel::HW_SECURE_ALL;
- break;
- default:
- return ERROR_DRM_CANNOT_HANDLE;
- }
-
- Status status = mPluginV1_1->setSecurityLevel(toHidlVec(sessionId),
- hSecurityLevel);
- return toStatusT(status);
-}
-
status_t DrmHal::getPropertyString(String8 const &name, String8 &value ) const {
Mutex::Autolock autoLock(mLock);
return getPropertyStringInternal(name, value);
diff --git a/drm/libmediadrm/IDrm.cpp b/drm/libmediadrm/IDrm.cpp
index 63a9562..9f54dba 100644
--- a/drm/libmediadrm/IDrm.cpp
+++ b/drm/libmediadrm/IDrm.cpp
@@ -60,7 +60,6 @@
GET_HDCP_LEVELS,
GET_NUMBER_OF_SESSIONS,
GET_SECURITY_LEVEL,
- SET_SECURITY_LEVEL,
REMOVE_SECURE_STOP,
GET_SECURE_STOP_IDS
};
@@ -121,9 +120,11 @@
return reply.readInt32();
}
- virtual status_t openSession(Vector<uint8_t> &sessionId) {
+ virtual status_t openSession(DrmPlugin::SecurityLevel securityLevel,
+ Vector<uint8_t> &sessionId) {
Parcel data, reply;
data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
+ data.writeInt32(securityLevel);
status_t status = remote()->transact(OPEN_SESSION, data, &reply);
if (status != OK) {
@@ -448,23 +449,6 @@
return reply.readInt32();
}
- virtual status_t setSecurityLevel(Vector<uint8_t> const &sessionId,
- const DrmPlugin::SecurityLevel& level) {
- Parcel data, reply;
-
- data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
-
- writeVector(data, sessionId);
- data.writeInt32(static_cast<uint32_t>(level));
-
- status_t status = remote()->transact(SET_SECURITY_LEVEL, data, &reply);
- if (status != OK) {
- return status;
- }
-
- return reply.readInt32();
- }
-
virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const {
Parcel data, reply;
data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
@@ -742,8 +726,10 @@
case OPEN_SESSION:
{
CHECK_INTERFACE(IDrm, data, reply);
+ DrmPlugin::SecurityLevel level =
+ static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
Vector<uint8_t> sessionId;
- status_t result = openSession(sessionId);
+ status_t result = openSession(level, sessionId);
writeVector(reply, sessionId);
reply->writeInt32(result);
return OK;
@@ -977,18 +963,6 @@
return OK;
}
- case SET_SECURITY_LEVEL:
- {
- CHECK_INTERFACE(IDrm, data, reply);
- Vector<uint8_t> sessionId;
- readVector(data, sessionId);
- DrmPlugin::SecurityLevel level =
- static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
- status_t result = setSecurityLevel(sessionId, level);
- reply->writeInt32(result);
- return OK;
- }
-
case GET_PROPERTY_STRING:
{
CHECK_INTERFACE(IDrm, data, reply);