diff --git a/libwvdrmengine/mediadrm/include/WVDrmPlugin.h b/libwvdrmengine/mediadrm/include/WVDrmPlugin.h index 93e98ebe..0dc0dc7b 100644 --- a/libwvdrmengine/mediadrm/include/WVDrmPlugin.h +++ b/libwvdrmengine/mediadrm/include/WVDrmPlugin.h @@ -161,7 +161,11 @@ class WVDrmPlugin : public android::DrmPlugin, WVGenericCryptoInterface* mCrypto; map mCryptoSessions; - static status_t mapOEMCryptoResult(OEMCryptoResult res); + status_t mapAndNotifyOfCdmResponseType(const Vector& sessionId, + CdmResponseType res); + + status_t mapAndNotifyOfOEMCryptoResult(const Vector& sessionId, + OEMCryptoResult res); }; } // namespace wvdrm diff --git a/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp index b5893c6b..1329a547 100644 --- a/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp @@ -48,7 +48,7 @@ status_t WVDrmPlugin::openSession(Vector& sessionId) { CdmResponseType res = mCDM->OpenSession("com.widevine", &cdmSessionId); if (!isCdmResponseTypeSuccess(res)) { - return mapCdmResponseType(res); + return mapAndNotifyOfCdmResponseType(sessionId, res); } bool success = false; @@ -94,7 +94,7 @@ status_t WVDrmPlugin::openSession(Vector& sessionId) { if (!isCdmResponseTypeSuccess(res)) { // We got an error code we can return. - return mapCdmResponseType(res); + return mapAndNotifyOfCdmResponseType(sessionId, res); } else { // We got a failure that did not give us an error code, such as a failure // of AttachEventListener() or the key being missing from the map. @@ -111,7 +111,7 @@ status_t WVDrmPlugin::closeSession(const Vector& sessionId) { mCryptoSessions.erase(cdmSessionId); } - return mapCdmResponseType(res); + return mapAndNotifyOfCdmResponseType(sessionId, res); } status_t WVDrmPlugin::getKeyRequest( @@ -177,7 +177,7 @@ status_t WVDrmPlugin::getKeyRequest( keyRequest.size()); } - return mapCdmResponseType(res); + return mapAndNotifyOfCdmResponseType(sessionId, res); } status_t WVDrmPlugin::provideKeyResponse( @@ -190,7 +190,7 @@ status_t WVDrmPlugin::provideKeyResponse( CdmResponseType res = mCDM->AddKey(cdmSessionId, cdmResponse); - return mapCdmResponseType(res); + return mapAndNotifyOfCdmResponseType(sessionId, res); } status_t WVDrmPlugin::removeKeys(const Vector& keySetId) { @@ -252,20 +252,15 @@ status_t WVDrmPlugin::getProvisionRequest(Vector& request, } status_t WVDrmPlugin::provideProvisionResponse( - const Vector& response) { - + const Vector& response) { CdmProvisioningResponse cdmResponse(response.begin(), response.end()); - CdmResponseType res = mCDM->HandleProvisioningResponse(cdmResponse); - return mapCdmResponseType(res); } status_t WVDrmPlugin::getSecureStops(List >& secureStops) { CdmSecureStops cdmSecureStops; - CdmResponseType res = mCDM->GetSecureStops(&cdmSecureStops); - if (isCdmResponseTypeSuccess(res)) { secureStops.clear(); for (CdmSecureStops::const_iterator iter = cdmSecureStops.begin(); @@ -280,7 +275,6 @@ status_t WVDrmPlugin::getSecureStops(List >& secureStops) { secureStops.push_back(stop); } } - return mapCdmResponseType(res); } @@ -430,7 +424,7 @@ status_t WVDrmPlugin::encrypt(const Vector& sessionId, if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } output.resize(input.size()); @@ -443,7 +437,7 @@ status_t WVDrmPlugin::encrypt(const Vector& sessionId, return android::OK; } else { ALOGE("OEMCrypto_Generic_Encrypt failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } } @@ -469,7 +463,7 @@ status_t WVDrmPlugin::decrypt(const Vector& sessionId, if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } output.resize(input.size()); @@ -482,7 +476,7 @@ status_t WVDrmPlugin::decrypt(const Vector& sessionId, return android::OK; } else { ALOGE("OEMCrypto_Generic_Decrypt failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } } @@ -507,7 +501,7 @@ status_t WVDrmPlugin::sign(const Vector& sessionId, if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } size_t signatureSize = 0; @@ -520,7 +514,7 @@ status_t WVDrmPlugin::sign(const Vector& sessionId, ALOGE("OEMCrypto_Generic_Sign failed with %u when requesting signature " "size", res); if (res != OEMCrypto_SUCCESS) { - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } else { return android::ERROR_DRM_UNKNOWN; } @@ -536,7 +530,7 @@ status_t WVDrmPlugin::sign(const Vector& sessionId, return android::OK; } else { ALOGE("OEMCrypto_Generic_Sign failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } } @@ -562,7 +556,7 @@ status_t WVDrmPlugin::verify(const Vector& sessionId, if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } res = mCrypto->verify(cryptoSession.oecSessionId(), message.array(), @@ -577,14 +571,14 @@ status_t WVDrmPlugin::verify(const Vector& sessionId, return android::OK; } else { ALOGE("OEMCrypto_Generic_Verify failed with %u", res); - return mapOEMCryptoResult(res); + return mapAndNotifyOfOEMCryptoResult(sessionId, res); } } void WVDrmPlugin::onEvent(const CdmSessionId& cdmSessionId, CdmEventType cdmEventType) { Vector sessionId; - EventType eventType; + EventType eventType = kDrmPluginEventVendorDefined; switch (cdmEventType) { case LICENSE_EXPIRED_EVENT: @@ -593,9 +587,6 @@ void WVDrmPlugin::onEvent(const CdmSessionId& cdmSessionId, case LICENSE_RENEWAL_NEEDED_EVENT: eventType = kDrmPluginEventKeyNeeded; break; - default: - ALOGE("Unknown CDM Event Received by WVDrmPlugin: %u", cdmEventType); - return; } sessionId.appendArray(reinterpret_cast(cdmSessionId.data()), @@ -605,7 +596,21 @@ void WVDrmPlugin::onEvent(const CdmSessionId& cdmSessionId, sendEvent(eventType, 0, &sessionId, NULL); } -status_t WVDrmPlugin::mapOEMCryptoResult(OEMCryptoResult res) { +status_t WVDrmPlugin::mapAndNotifyOfCdmResponseType( + const Vector& sessionId, + CdmResponseType res) { + if (res == wvcdm::NEED_PROVISIONING) { + sendEvent(kDrmPluginEventProvisionRequired, 0, &sessionId, NULL); + } else if (res == wvcdm::NEED_KEY) { + sendEvent(kDrmPluginEventKeyNeeded, 0, &sessionId, NULL); + } + + return mapCdmResponseType(res); +} + +status_t WVDrmPlugin::mapAndNotifyOfOEMCryptoResult( + const Vector& sessionId, + OEMCryptoResult res) { // Note that we only cover those errors that OEMCryptoCENC.h states may be // returned by the generic crypto methods. switch (res) { @@ -616,6 +621,7 @@ status_t WVDrmPlugin::mapOEMCryptoResult(OEMCryptoResult res) { case OEMCrypto_ERROR_SHORT_BUFFER: return kErrorIncorrectBufferSize; case OEMCrypto_ERROR_NO_DEVICE_KEY: + sendEvent(kDrmPluginEventProvisionRequired, 0, &sessionId, NULL); return android::ERROR_DRM_NOT_PROVISIONED; case OEMCrypto_ERROR_INVALID_SESSION: return android::ERROR_DRM_SESSION_NOT_OPENED;