Clean up get/set property code
Merged from Widevine CDM repo: https://widevine-internal-review.googlesource.com/#/c/13970 Change-Id: I2b52248e71c18808f36730a438390f855309cc14
This commit is contained in:
@@ -258,6 +258,15 @@ class WVDrmPlugin : public android::DrmPlugin,
|
||||
Mutex mCryptoSessionsMutex;
|
||||
map<CdmSessionId, CryptoSession> mCryptoSessions;
|
||||
|
||||
status_t queryProperty(const std::string& property,
|
||||
std::string& string_value) const;
|
||||
|
||||
status_t queryProperty(const std::string& property,
|
||||
String8& string8_value) const;
|
||||
|
||||
status_t queryProperty(const std::string& property,
|
||||
Vector<uint8_t>& vector_value) const;
|
||||
|
||||
status_t mapAndNotifyOfCdmResponseType(const Vector<uint8_t>& sessionId,
|
||||
CdmResponseType res);
|
||||
|
||||
|
||||
@@ -33,6 +33,13 @@ using namespace std;
|
||||
using namespace wvcdm;
|
||||
|
||||
namespace {
|
||||
|
||||
Vector<uint8_t> ToVector(const std::string& str) {
|
||||
Vector<uint8_t> vector;
|
||||
vector.appendArray(reinterpret_cast<const uint8_t*>(str.data()), str.size());
|
||||
return vector;
|
||||
}
|
||||
|
||||
DrmPlugin::KeyRequestType ConvertFromCdmKeyRequestType(
|
||||
CdmKeyRequestType keyRequestType) {
|
||||
switch (keyRequestType) {
|
||||
@@ -459,28 +466,10 @@ status_t WVDrmPlugin::getPropertyString(const String8& name,
|
||||
if (requestedLevel.length() > 0) {
|
||||
value = requestedLevel.c_str();
|
||||
} else {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_SECURITY_LEVEL)) {
|
||||
ALOGE("CDM did not report a security level");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_SECURITY_LEVEL].c_str();
|
||||
return queryProperty(QUERY_KEY_SECURITY_LEVEL, value);
|
||||
}
|
||||
} else if (name == "systemId") {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_SYSTEM_ID)) {
|
||||
ALOGE("CDM did not report a system ID");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_SYSTEM_ID].c_str();
|
||||
return queryProperty(QUERY_KEY_SYSTEM_ID, value);
|
||||
} else if (name == "privacyMode") {
|
||||
if (mPropertySet.use_privacy_mode()) {
|
||||
value = kEnable;
|
||||
@@ -494,60 +483,15 @@ status_t WVDrmPlugin::getPropertyString(const String8& name,
|
||||
value = kDisable;
|
||||
}
|
||||
} else if (name == "hdcpLevel") {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_CURRENT_HDCP_LEVEL)) {
|
||||
ALOGE("CDM did not report a current HDCP level");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_CURRENT_HDCP_LEVEL].c_str();
|
||||
return queryProperty(QUERY_KEY_CURRENT_HDCP_LEVEL, value);
|
||||
} else if (name == "maxHdcpLevel") {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_MAX_HDCP_LEVEL)) {
|
||||
ALOGE("CDM did not report a maximum HDCP level");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_MAX_HDCP_LEVEL].c_str();
|
||||
return queryProperty(QUERY_KEY_MAX_HDCP_LEVEL, value);
|
||||
} else if (name == "usageReportingSupport") {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_USAGE_SUPPORT)) {
|
||||
ALOGE("CDM did not report whether it supports usage reporting");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_USAGE_SUPPORT].c_str();
|
||||
return queryProperty(QUERY_KEY_USAGE_SUPPORT, value);
|
||||
} else if (name == "numberOfOpenSessions") {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_NUMBER_OF_OPEN_SESSIONS)) {
|
||||
ALOGE("CDM did not report number of open media drm sessions");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_NUMBER_OF_OPEN_SESSIONS].c_str();
|
||||
return queryProperty(QUERY_KEY_NUMBER_OF_OPEN_SESSIONS, value);
|
||||
} else if (name == "maxNumberOfSessions") {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_MAX_NUMBER_OF_SESSIONS)) {
|
||||
ALOGE("CDM did not report maximum number of media drm sessions");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
value = status[QUERY_KEY_MAX_NUMBER_OF_SESSIONS].c_str();
|
||||
return queryProperty(QUERY_KEY_MAX_NUMBER_OF_SESSIONS, value);
|
||||
} else {
|
||||
ALOGE("App requested unknown string property %s", name.string());
|
||||
return android::ERROR_DRM_CANNOT_HANDLE;
|
||||
@@ -559,45 +503,11 @@ status_t WVDrmPlugin::getPropertyString(const String8& name,
|
||||
status_t WVDrmPlugin::getPropertyByteArray(const String8& name,
|
||||
Vector<uint8_t>& value) const {
|
||||
if (name == "deviceUniqueId") {
|
||||
CdmQueryMap status;
|
||||
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_DEVICE_ID)) {
|
||||
ALOGE("CDM did not report a device unique ID");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
|
||||
const string& uniqueId = status[QUERY_KEY_DEVICE_ID];
|
||||
|
||||
value.clear();
|
||||
value.appendArray(reinterpret_cast<const uint8_t*>(uniqueId.data()),
|
||||
uniqueId.size());
|
||||
return queryProperty(QUERY_KEY_DEVICE_ID, value);
|
||||
} else if (name == "provisioningUniqueId") {
|
||||
CdmQueryMap status;
|
||||
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_PROVISIONING_ID)) {
|
||||
ALOGE("CDM did not report a provisioning unique ID");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
|
||||
const string& uniqueId = status[QUERY_KEY_PROVISIONING_ID];
|
||||
|
||||
value.clear();
|
||||
value.appendArray(reinterpret_cast<const uint8_t*>(uniqueId.data()),
|
||||
uniqueId.size());
|
||||
return queryProperty(QUERY_KEY_PROVISIONING_ID, value);
|
||||
} else if (name == "serviceCertificate") {
|
||||
std::string cert = mPropertySet.service_certificate();
|
||||
value.clear();
|
||||
value.appendArray(reinterpret_cast<const uint8_t*>(&cert[0]), cert.size());
|
||||
value = ToVector(mPropertySet.service_certificate());
|
||||
} else {
|
||||
ALOGE("App requested unknown byte array property %s", name.string());
|
||||
return android::ERROR_DRM_CANNOT_HANDLE;
|
||||
@@ -619,17 +529,12 @@ status_t WVDrmPlugin::setPropertyString(const String8& name,
|
||||
mPropertySet.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3);
|
||||
} else if (value == QUERY_VALUE_SECURITY_LEVEL_L1.c_str()) {
|
||||
// We must be sure we CAN set the security level to L1.
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(QUERY_KEY_SECURITY_LEVEL)) {
|
||||
ALOGE("CDM did not report a security level");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
std::string current_security_level;
|
||||
status_t status =
|
||||
queryProperty(QUERY_KEY_SECURITY_LEVEL, current_security_level);
|
||||
if (status != android::OK) return status;
|
||||
|
||||
if (status[QUERY_KEY_SECURITY_LEVEL] != QUERY_VALUE_SECURITY_LEVEL_L1) {
|
||||
if (current_security_level != QUERY_VALUE_SECURITY_LEVEL_L1) {
|
||||
ALOGE("App requested L1 security on a non-L1 device.");
|
||||
return android::BAD_VALUE;
|
||||
} else {
|
||||
@@ -978,6 +883,39 @@ void WVDrmPlugin::OnExpirationUpdate(const CdmSessionId& cdmSessionId,
|
||||
// new_expiry_time is in seconds while Android API is in milliseconds.
|
||||
}
|
||||
|
||||
status_t WVDrmPlugin::queryProperty(const std::string& property,
|
||||
std::string& string_value) const {
|
||||
CdmQueryMap status;
|
||||
CdmResponseType res = mCDM->QueryStatus(&status);
|
||||
if (res != wvcdm::NO_ERROR) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return mapCdmResponseType(res);
|
||||
} else if (!status.count(property)) {
|
||||
ALOGE("CDM did not report %s", property.c_str());
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
string_value = status[property];
|
||||
return android::OK;
|
||||
}
|
||||
|
||||
status_t WVDrmPlugin::queryProperty(const std::string& property,
|
||||
String8& string8_value) const {
|
||||
std::string string_value;
|
||||
status_t status = queryProperty(property, string_value);
|
||||
if (status != android::OK) return status;
|
||||
string8_value = string_value.c_str();
|
||||
return android::OK;
|
||||
}
|
||||
|
||||
status_t WVDrmPlugin::queryProperty(const std::string& property,
|
||||
Vector<uint8_t>& vector_value) const {
|
||||
std::string string_value;
|
||||
status_t status = queryProperty(property, string_value);
|
||||
if (status != android::OK) return status;
|
||||
vector_value = ToVector(string_value);
|
||||
return android::OK;
|
||||
}
|
||||
|
||||
status_t WVDrmPlugin::mapAndNotifyOfCdmResponseType(
|
||||
const Vector<uint8_t>& sessionId,
|
||||
CdmResponseType res) {
|
||||
|
||||
Reference in New Issue
Block a user