diff options
author | Jeff Tinker <jtinker@google.com> | 2015-04-10 04:10:59 -0700 |
---|---|---|
committer | Jeff Tinker <jtinker@google.com> | 2015-04-10 04:10:59 -0700 |
commit | 1849570240443d1f75775c205fa658f7070849c6 (patch) | |
tree | 86ad28892b0e8b49c8666ad39e340234c610e709 | |
parent | 2fb25c873e1a7f346bd8c7c072a85ca6a74b0e95 (diff) | |
download | frameworks_av-1849570240443d1f75775c205fa658f7070849c6.zip frameworks_av-1849570240443d1f75775c205fa658f7070849c6.tar.gz frameworks_av-1849570240443d1f75775c205fa658f7070849c6.tar.bz2 |
Add a method to associate MediaDrm session with MediaCrypto
Previously, to associate a MediaDrm session with MediaCrypto,
the MediaDrm sessionId was passed as initData to the MediaCrypto
constructor. This is not ideal for two reasons: it's pretty
obscure and you can't change the association without tearing
down the MediaCodec/MediaCrypto and starting all over. Use
cases like key rotation require being able to update the
MediaDrm session post-construction. This CL addresses both of
these issues.
bug: 19570317
Change-Id: Ieb32d04d61742fc1dee2105dd904690d44c46c7b
-rw-r--r-- | include/media/ICrypto.h | 5 | ||||
-rw-r--r-- | media/libmedia/ICrypto.cpp | 42 | ||||
-rw-r--r-- | media/libmediaplayerservice/Crypto.cpp | 10 | ||||
-rw-r--r-- | media/libmediaplayerservice/Crypto.h | 2 |
4 files changed, 59 insertions, 0 deletions
diff --git a/include/media/ICrypto.h b/include/media/ICrypto.h index ac2b3ba..aa04dbe 100644 --- a/include/media/ICrypto.h +++ b/include/media/ICrypto.h @@ -44,6 +44,8 @@ struct ICrypto : public IInterface { virtual void notifyResolution(uint32_t width, uint32_t height) = 0; + virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) = 0; + virtual ssize_t decrypt( bool secure, const uint8_t key[16], @@ -62,6 +64,9 @@ struct BnCrypto : public BnInterface<ICrypto> { virtual status_t onTransact( uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags = 0); +private: + void readVector(const Parcel &data, Vector<uint8_t> &vector) const; + void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const; }; } // namespace android diff --git a/media/libmedia/ICrypto.cpp b/media/libmedia/ICrypto.cpp index 23308c1..9246a7c 100644 --- a/media/libmedia/ICrypto.cpp +++ b/media/libmedia/ICrypto.cpp @@ -35,6 +35,7 @@ enum { REQUIRES_SECURE_COMPONENT, DECRYPT, NOTIFY_RESOLUTION, + SET_MEDIADRM_SESSION, }; struct BpCrypto : public BpInterface<ICrypto> { @@ -161,7 +162,28 @@ struct BpCrypto : public BpInterface<ICrypto> { remote()->transact(NOTIFY_RESOLUTION, data, &reply); } + virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) { + Parcel data, reply; + data.writeInterfaceToken(ICrypto::getInterfaceDescriptor()); + + writeVector(data, sessionId); + remote()->transact(SET_MEDIADRM_SESSION, data, &reply); + + return reply.readInt32(); + } + private: + void readVector(Parcel &reply, Vector<uint8_t> &vector) const { + uint32_t size = reply.readInt32(); + vector.insertAt((size_t)0, size); + reply.read(vector.editArray(), size); + } + + void writeVector(Parcel &data, Vector<uint8_t> const &vector) const { + data.writeInt32(vector.size()); + data.write(vector.array(), vector.size()); + } + DISALLOW_EVIL_CONSTRUCTORS(BpCrypto); }; @@ -169,6 +191,17 @@ IMPLEMENT_META_INTERFACE(Crypto, "android.hardware.ICrypto"); //////////////////////////////////////////////////////////////////////////////// +void BnCrypto::readVector(const Parcel &data, Vector<uint8_t> &vector) const { + uint32_t size = data.readInt32(); + vector.insertAt((size_t)0, size); + data.read(vector.editArray(), size); +} + +void BnCrypto::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const { + reply->writeInt32(vector.size()); + reply->write(vector.array(), vector.size()); +} + status_t BnCrypto::onTransact( uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { switch (code) { @@ -317,6 +350,15 @@ status_t BnCrypto::onTransact( return OK; } + case SET_MEDIADRM_SESSION: + { + CHECK_INTERFACE(IDrm, data, reply); + Vector<uint8_t> sessionId; + readVector(data, sessionId); + reply->writeInt32(setMediaDrmSession(sessionId)); + return OK; + } + default: return BBinder::onTransact(code, data, reply, flags); } diff --git a/media/libmediaplayerservice/Crypto.cpp b/media/libmediaplayerservice/Crypto.cpp index e768772..f639193 100644 --- a/media/libmediaplayerservice/Crypto.cpp +++ b/media/libmediaplayerservice/Crypto.cpp @@ -268,4 +268,14 @@ void Crypto::notifyResolution(uint32_t width, uint32_t height) { } } +status_t Crypto::setMediaDrmSession(const Vector<uint8_t> &sessionId) { + Mutex::Autolock autoLock(mLock); + + status_t result = NO_INIT; + if (mInitCheck == OK && mPlugin != NULL) { + result = mPlugin->setMediaDrmSession(sessionId); + } + return result; +} + } // namespace android diff --git a/media/libmediaplayerservice/Crypto.h b/media/libmediaplayerservice/Crypto.h index d5f3c50..99ea95d 100644 --- a/media/libmediaplayerservice/Crypto.h +++ b/media/libmediaplayerservice/Crypto.h @@ -47,6 +47,8 @@ struct Crypto : public BnCrypto { virtual void notifyResolution(uint32_t width, uint32_t height); + virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId); + virtual ssize_t decrypt( bool secure, const uint8_t key[16], |