diff options
author | Jeff Tinker <jtinker@google.com> | 2015-03-31 15:40:16 -0700 |
---|---|---|
committer | Jeff Tinker <jtinker@google.com> | 2015-04-09 22:44:26 +0000 |
commit | 2fb25c873e1a7f346bd8c7c072a85ca6a74b0e95 (patch) | |
tree | d087aa2f16546cc08efaaf756d446cf27f6bd9d1 | |
parent | 079e121934106860af5ff5491bd3884453d1fdb3 (diff) | |
download | frameworks_av-2fb25c873e1a7f346bd8c7c072a85ca6a74b0e95.zip frameworks_av-2fb25c873e1a7f346bd8c7c072a85ca6a74b0e95.tar.gz frameworks_av-2fb25c873e1a7f346bd8c7c072a85ca6a74b0e95.tar.bz2 |
Add expiration update and keys change events
In support of unprefixed EME
bug: 19771612
bug: 19771431
Change-Id: Ib19d4c8db25f5b09f9a30ebd4992b668cad9bfc4
-rw-r--r-- | drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp | 81 | ||||
-rw-r--r-- | media/libmediaplayerservice/Drm.cpp | 66 | ||||
-rw-r--r-- | media/libmediaplayerservice/Drm.h | 9 |
3 files changed, 132 insertions, 24 deletions
diff --git a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp index 9b786c5..851ad2c 100644 --- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp +++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp @@ -56,7 +56,7 @@ namespace android { return true; } - status_t MockDrmFactory::createDrmPlugin(const uint8_t uuid[16], DrmPlugin **plugin) + status_t MockDrmFactory::createDrmPlugin(const uint8_t /* uuid */[16], DrmPlugin **plugin) { *plugin = new MockDrmPlugin(); return OK; @@ -68,8 +68,9 @@ namespace android { return (!memcmp(uuid, mock_uuid, sizeof(mock_uuid))); } - status_t MockCryptoFactory::createPlugin(const uint8_t uuid[16], const void *data, - size_t size, CryptoPlugin **plugin) + status_t MockCryptoFactory::createPlugin(const uint8_t /* uuid */[16], + const void * /* data */, + size_t /* size */, CryptoPlugin **plugin) { *plugin = new MockCryptoPlugin(); return OK; @@ -150,7 +151,7 @@ namespace android { // Properties used in mock test, set by cts test app returned from mock plugin // byte[] mock-request -> request // string mock-default-url -> defaultUrl - // string mock-key-request-type -> keyRequestType + // string mock-keyRequestType -> keyRequestType index = mByteArrayProperties.indexOfKey(String8("mock-request")); if (index < 0) { @@ -266,8 +267,8 @@ namespace android { return OK; } - status_t MockDrmPlugin::getProvisionRequest(String8 const &certType, - String8 const &certAuthority, + status_t MockDrmPlugin::getProvisionRequest(String8 const & /* certType */, + String8 const & /* certAuthority */, Vector<uint8_t> &request, String8 &defaultUrl) { @@ -297,8 +298,8 @@ namespace android { } status_t MockDrmPlugin::provideProvisionResponse(Vector<uint8_t> const &response, - Vector<uint8_t> &certificate, - Vector<uint8_t> &wrappedKey) + Vector<uint8_t> & /* certificate */, + Vector<uint8_t> & /* wrappedKey */) { Mutex::Autolock lock(mLock); ALOGD("MockDrmPlugin::provideProvisionResponse(%s)", @@ -317,7 +318,8 @@ namespace android { return OK; } - status_t MockDrmPlugin::getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) + status_t MockDrmPlugin::getSecureStop(Vector<uint8_t> const & /* ssid */, + Vector<uint8_t> & secureStop) { Mutex::Autolock lock(mLock); ALOGD("MockDrmPlugin::getSecureStop()"); @@ -439,6 +441,63 @@ namespace android { pData ? vectorToString(*pData) : "{}"); sendEvent(eventType, extra, pSessionId, pData); + } else if (name == "mock-send-expiration-update") { + int64_t expiryTimeMS; + sscanf(value.string(), "%jd", &expiryTimeMS); + + Vector<uint8_t> const *pSessionId = NULL; + ssize_t index = mByteArrayProperties.indexOfKey(String8("mock-event-session-id")); + if (index >= 0) { + pSessionId = &mByteArrayProperties[index]; + } + + ALOGD("sending expiration-update from mock drm plugin: %jd %s", + expiryTimeMS, pSessionId ? vectorToString(*pSessionId) : "{}"); + + sendExpirationUpdate(pSessionId, expiryTimeMS); + } else if (name == "mock-send-keys-change") { + Vector<uint8_t> const *pSessionId = NULL; + ssize_t index = mByteArrayProperties.indexOfKey(String8("mock-event-session-id")); + if (index >= 0) { + pSessionId = &mByteArrayProperties[index]; + } + + ALOGD("sending keys-change from mock drm plugin: %s", + pSessionId ? vectorToString(*pSessionId) : "{}"); + + Vector<DrmPlugin::KeyStatus> keyStatusList; + DrmPlugin::KeyStatus keyStatus; + uint8_t keyId1[] = {'k', 'e', 'y', '1'}; + keyStatus.mKeyId.clear(); + keyStatus.mKeyId.appendArray(keyId1, sizeof(keyId1)); + keyStatus.mType = DrmPlugin::kKeyStatusType_Usable; + keyStatusList.add(keyStatus); + + uint8_t keyId2[] = {'k', 'e', 'y', '2'}; + keyStatus.mKeyId.clear(); + keyStatus.mKeyId.appendArray(keyId2, sizeof(keyId2)); + keyStatus.mType = DrmPlugin::kKeyStatusType_Expired; + keyStatusList.add(keyStatus); + + uint8_t keyId3[] = {'k', 'e', 'y', '3'}; + keyStatus.mKeyId.clear(); + keyStatus.mKeyId.appendArray(keyId3, sizeof(keyId3)); + keyStatus.mType = DrmPlugin::kKeyStatusType_OutputNotAllowed; + keyStatusList.add(keyStatus); + + uint8_t keyId4[] = {'k', 'e', 'y', '4'}; + keyStatus.mKeyId.clear(); + keyStatus.mKeyId.appendArray(keyId4, sizeof(keyId4)); + keyStatus.mType = DrmPlugin::kKeyStatusType_StatusPending; + keyStatusList.add(keyStatus); + + uint8_t keyId5[] = {'k', 'e', 'y', '5'}; + keyStatus.mKeyId.clear(); + keyStatus.mKeyId.appendArray(keyId5, sizeof(keyId5)); + keyStatus.mType = DrmPlugin::kKeyStatusType_InternalError; + keyStatusList.add(keyStatus); + + sendKeysChange(pSessionId, &keyStatusList, true); } else { mStringProperties.add(name, value); } @@ -740,7 +799,7 @@ namespace android { ssize_t MockCryptoPlugin::decrypt(bool secure, const uint8_t key[16], const uint8_t iv[16], Mode mode, const void *srcPtr, const SubSample *subSamples, - size_t numSubSamples, void *dstPtr, AString *errorDetailMsg) + size_t numSubSamples, void *dstPtr, AString * /* errorDetailMsg */) { ALOGD("MockCryptoPlugin::decrypt(secure=%d, key=%s, iv=%s, mode=%d, src=%p, " "subSamples=%s, dst=%p)", @@ -769,7 +828,7 @@ namespace android { { String8 result; for (size_t i = 0; i < numSubSamples; i++) { - result.appendFormat("[%zu] {clear:%zu, encrypted:%zu} ", i, + result.appendFormat("[%zu] {clear:%u, encrypted:%u} ", i, subSamples[i].mNumBytesOfClearData, subSamples[i].mNumBytesOfEncryptedData); } diff --git a/media/libmediaplayerservice/Drm.cpp b/media/libmediaplayerservice/Drm.cpp index 49e01d1..62cf3e5 100644 --- a/media/libmediaplayerservice/Drm.cpp +++ b/media/libmediaplayerservice/Drm.cpp @@ -136,22 +136,54 @@ void Drm::sendEvent(DrmPlugin::EventType eventType, int extra, if (listener != NULL) { Parcel obj; - if (sessionId && sessionId->size()) { - obj.writeInt32(sessionId->size()); - obj.write(sessionId->array(), sessionId->size()); - } else { - obj.writeInt32(0); - } + writeByteArray(obj, sessionId); + writeByteArray(obj, data); - if (data && data->size()) { - obj.writeInt32(data->size()); - obj.write(data->array(), data->size()); - } else { - obj.writeInt32(0); + Mutex::Autolock lock(mNotifyLock); + listener->notify(eventType, extra, &obj); + } +} + +void Drm::sendExpirationUpdate(Vector<uint8_t> const *sessionId, + int64_t expiryTimeInMS) +{ + mEventLock.lock(); + sp<IDrmClient> listener = mListener; + mEventLock.unlock(); + + if (listener != NULL) { + Parcel obj; + writeByteArray(obj, sessionId); + obj.writeInt64(expiryTimeInMS); + + Mutex::Autolock lock(mNotifyLock); + listener->notify(DrmPlugin::kDrmPluginEventExpirationUpdate, 0, &obj); + } +} + +void Drm::sendKeysChange(Vector<uint8_t> const *sessionId, + Vector<DrmPlugin::KeyStatus> const *keyStatusList, + bool hasNewUsableKey) +{ + mEventLock.lock(); + sp<IDrmClient> listener = mListener; + mEventLock.unlock(); + + if (listener != NULL) { + Parcel obj; + writeByteArray(obj, sessionId); + + size_t nkeys = keyStatusList->size(); + obj.writeInt32(keyStatusList->size()); + for (size_t i = 0; i < nkeys; ++i) { + const DrmPlugin::KeyStatus *keyStatus = &keyStatusList->itemAt(i); + writeByteArray(obj, &keyStatus->mKeyId); + obj.writeInt32(keyStatus->mType); } + obj.writeInt32(hasNewUsableKey); Mutex::Autolock lock(mNotifyLock); - listener->notify(eventType, extra, &obj); + listener->notify(DrmPlugin::kDrmPluginEventKeysChange, 0, &obj); } } @@ -756,4 +788,14 @@ void Drm::binderDied(const wp<IBinder> &the_late_who) closeFactory(); } +void Drm::writeByteArray(Parcel &obj, Vector<uint8_t> const *array) +{ + if (array && array->size()) { + obj.writeInt32(array->size()); + obj.write(array->array(), array->size()); + } else { + obj.writeInt32(0); + } +} + } // namespace android diff --git a/media/libmediaplayerservice/Drm.h b/media/libmediaplayerservice/Drm.h index 7e8f246..1591738 100644 --- a/media/libmediaplayerservice/Drm.h +++ b/media/libmediaplayerservice/Drm.h @@ -133,6 +133,13 @@ struct Drm : public BnDrm, Vector<uint8_t> const *sessionId, Vector<uint8_t> const *data); + virtual void sendExpirationUpdate(Vector<uint8_t> const *sessionId, + int64_t expiryTimeInMS); + + virtual void sendKeysChange(Vector<uint8_t> const *sessionId, + Vector<DrmPlugin::KeyStatus> const *keyStatusList, + bool hasNewUsableKey); + virtual void binderDied(const wp<IBinder> &the_late_who); private: @@ -157,7 +164,7 @@ private: void findFactoryForScheme(const uint8_t uuid[16]); bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]); void closeFactory(); - + void writeByteArray(Parcel &obj, Vector<uint8_t> const *array); DISALLOW_EVIL_CONSTRUCTORS(Drm); }; |