Fix for b/3501089 Require an API in the DRM client to specify the license type (offline/streaming) and b/4084670 Define events in DRM API to support license expiration, revocation, license failure. Implements events and license changes as documented in the Widevine_Java_API_for_Android_DRM_Framework spec
Change-Id: I3d0440e4f64d2279ab3b272a5287db5144e41eb1
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <drm/DrmRights.h>
|
||||
#include <drm/DrmConstraints.h>
|
||||
#include <drm/DrmInfo.h>
|
||||
#include <drm/DrmInfoEvent.h>
|
||||
#include <drm/DrmInfoStatus.h>
|
||||
#include <drm/DrmConvertedStatus.h>
|
||||
#include <drm/DrmInfoRequest.h>
|
||||
@@ -45,11 +46,15 @@ extern "C" void destroy(IDrmEngine* pPlugIn) {
|
||||
delete pPlugIn;
|
||||
}
|
||||
|
||||
// Needed for event callout from implementation object
|
||||
IDrmEngine::OnInfoListener *WVMDrmPlugin::sOnInfoListener = NULL;
|
||||
int WVMDrmPlugin::sUniqueId;
|
||||
|
||||
WVMDrmPlugin::WVMDrmPlugin()
|
||||
: DrmEngineBase(),
|
||||
mOnInfoListener(NULL),
|
||||
mDrmPluginImpl(WVDRMPluginAPI::create())
|
||||
{
|
||||
mDrmPluginImpl->SetEventHandler(&SendEvent);
|
||||
}
|
||||
|
||||
WVMDrmPlugin::~WVMDrmPlugin() {
|
||||
@@ -96,10 +101,38 @@ status_t WVMDrmPlugin::onTerminate(int uniqueId) {
|
||||
status_t WVMDrmPlugin::onSetOnInfoListener(
|
||||
int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
|
||||
//LOGD("WVMDrmPlugin::onSetOnInfoListener : %d", uniqueId);
|
||||
mOnInfoListener = infoListener;
|
||||
sOnInfoListener = const_cast<IDrmEngine::OnInfoListener *>(infoListener);
|
||||
sUniqueId = uniqueId;
|
||||
return DRM_NO_ERROR;
|
||||
}
|
||||
|
||||
void WVMDrmPlugin::SendEvent(WVDRMPluginAPI::EventType type, const std::string &path)
|
||||
{
|
||||
int code = -1;
|
||||
|
||||
switch(type) {
|
||||
EventType_AcquireFailed:
|
||||
code = DrmInfoEvent::TYPE_ACQUIRE_DRM_INFO_FAILED;
|
||||
break;
|
||||
EventType_ProcessDrmInfoFailed:
|
||||
code = DrmInfoEvent::TYPE_PROCESS_DRM_INFO_FAILED;
|
||||
break;
|
||||
EventType_RightsInstalled:
|
||||
code = DrmInfoEvent::TYPE_RIGHTS_INSTALLED;
|
||||
break;
|
||||
EventType_RightsRemoved:
|
||||
code = DrmInfoEvent::TYPE_RIGHTS_REMOVED;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (sOnInfoListener) {
|
||||
DrmInfoEvent event(sUniqueId, code, String8(path.c_str()));
|
||||
sOnInfoListener->onInfo(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves necessary information for registration, unregistration or rights
|
||||
* acquisition information.
|
||||
@@ -141,6 +174,7 @@ DrmInfo* WVMDrmPlugin::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmI
|
||||
string systemIdStr = drmInfoRequest->get(String8("WVSystemIDKey")).string();
|
||||
string assetIdStr = drmInfoRequest->get(String8("WVAssetIDKey")).string();
|
||||
string keyIdStr = drmInfoRequest->get(String8("WVKeyIDKey")).string();
|
||||
string licenseTypeStr = drmInfoRequest->get(String8("WVLicenseTypeKey")).string();
|
||||
|
||||
uint32_t systemId, assetId, keyId;
|
||||
|
||||
@@ -166,6 +200,7 @@ DrmInfo* WVMDrmPlugin::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmI
|
||||
drmInfo->put(String8("WVCAUserDataKey"), String8(credentials.userData.c_str()));
|
||||
drmInfo->put(String8("WVDeviceIDKey"), String8(credentials.deviceID.c_str()));
|
||||
drmInfo->put(String8("WVStreamIDKey"), String8(credentials.streamID.c_str()));
|
||||
drmInfo->put(String8("WVLicenseTypeKey"), String8(licenseTypeStr.c_str()));
|
||||
|
||||
char buffer[16];
|
||||
sprintf(buffer, "%lu", (unsigned long)systemId);
|
||||
@@ -239,8 +274,9 @@ DrmInfoStatus* WVMDrmPlugin::onProcessDrmInfo(int uniqueId, const DrmInfo* drmIn
|
||||
if (NULL != drmInfo) {
|
||||
if (drmInfo->getInfoType() == DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO) {
|
||||
std::string assetPath = drmInfo->get(String8("WVAssetURIKey")).string();
|
||||
int playbackMode = atol(drmInfo->get(String8("WVLicenseTypeKey")).string());
|
||||
|
||||
if (mDrmPluginImpl->ProcessDrmInfo(assetPath))
|
||||
if (mDrmPluginImpl->ProcessDrmInfo(assetPath, playbackMode))
|
||||
status = DrmInfoStatus::STATUS_OK;
|
||||
} else if ((drmInfo->getInfoType() == DrmInfoRequest::TYPE_REGISTRATION_INFO) ||
|
||||
(drmInfo->getInfoType() == DrmInfoRequest::TYPE_UNREGISTRATION_INFO)) {
|
||||
@@ -288,9 +324,15 @@ DrmConstraints* WVMDrmPlugin::onGetConstraints(int uniqueId, const String8* path
|
||||
uint32_t licenseDuration = 0;
|
||||
uint32_t timeSincePlayback = 0;
|
||||
uint32_t timeRemaining = 0;
|
||||
std::string lastError;
|
||||
bool allowOffline;
|
||||
bool allowStreaming;
|
||||
bool denyHD;
|
||||
|
||||
std::string assetPath(path->string());
|
||||
if (!mDrmPluginImpl->GetConstraints(assetPath, &timeSincePlayback, &timeRemaining, &licenseDuration))
|
||||
if (!mDrmPluginImpl->GetConstraints(assetPath, &timeSincePlayback, &timeRemaining,
|
||||
&licenseDuration, lastError, allowOffline,
|
||||
allowStreaming, denyHD))
|
||||
return NULL;
|
||||
|
||||
DrmConstraints* drmConstraints = new DrmConstraints();
|
||||
@@ -308,6 +350,16 @@ DrmConstraints* WVMDrmPlugin::onGetConstraints(int uniqueId, const String8* path
|
||||
sprintf(charValue, "%lu", (unsigned long)licenseDuration);
|
||||
drmConstraints->put(&(DrmConstraints::LICENSE_AVAILABLE_TIME), charValue);
|
||||
|
||||
String8 key = String8("WVLicenseTypeKey");
|
||||
sprintf(charValue, "%u", (allowStreaming ? 1 : 0) | (allowOffline ? 2 : 0));
|
||||
drmConstraints->put(&key, charValue);
|
||||
|
||||
key = String8("WVLicensedResolutionKey");
|
||||
sprintf(charValue, "%u", (denyHD ? 1 : 2));
|
||||
drmConstraints->put(&key, charValue);
|
||||
|
||||
key = String8("WVLastErrorKey");
|
||||
drmConstraints->put(&key, lastError.c_str());
|
||||
return drmConstraints;
|
||||
}
|
||||
|
||||
@@ -755,4 +807,3 @@ DrmConvertedStatus* WVMDrmPlugin::onCloseConvertSession(int uniqueId, int conver
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user