Pass application packagename to drm plugin.

Get the application packagename to be used as part of a unique
identifier for drm plugin.

Test: Stream movies through Play Movies, Netflix and
Gts MediaCodecCencPlayer tests.
Verify the application's packagename is reachable in the drm plugin's
debug log.

bug: 27101531

Change-Id: I6473b58d78bc34191aca5896bb1f5fb79107ae47
This commit is contained in:
Edwin Wong
2017-01-04 09:37:49 -08:00
parent 1dbb3f1135
commit 4d1d84e8a0
3 changed files with 22 additions and 11 deletions

View File

@@ -28,6 +28,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.annotation.SystemApi;
import android.app.ActivityThread;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -213,7 +214,7 @@ public final class MediaDrm {
* It's easier to create it here than in C++.
*/
native_setup(new WeakReference<MediaDrm>(this),
getByteArrayFromUUID(uuid));
getByteArrayFromUUID(uuid), ActivityThread.currentOpPackageName());
}
/**
@@ -1307,7 +1308,8 @@ public final class MediaDrm {
public native final void release();
private static native final void native_init();
private native final void native_setup(Object mediadrm_this, byte[] uuid);
private native final void native_setup(Object mediadrm_this, byte[] uuid,
String appPackageName);
private native final void native_finalize();

View File

@@ -335,9 +335,10 @@ static sp<IDrm> GetDrm(JNIEnv *env, jobject thiz) {
}
JDrm::JDrm(
JNIEnv *env, jobject thiz, const uint8_t uuid[16]) {
JNIEnv *env, jobject thiz, const uint8_t uuid[16],
const String8 &appPackageName) {
mObject = env->NewWeakGlobalRef(thiz);
mDrm = MakeDrm(uuid);
mDrm = MakeDrm(uuid, appPackageName);
if (mDrm != NULL) {
mDrm->setListener(this);
}
@@ -369,14 +370,14 @@ sp<IDrm> JDrm::MakeDrm() {
}
// static
sp<IDrm> JDrm::MakeDrm(const uint8_t uuid[16]) {
sp<IDrm> JDrm::MakeDrm(const uint8_t uuid[16], const String8 &appPackageName) {
sp<IDrm> drm = MakeDrm();
if (drm == NULL) {
return NULL;
}
status_t err = drm->createPlugin(uuid);
status_t err = drm->createPlugin(uuid, appPackageName);
if (err != OK) {
return NULL;
@@ -683,7 +684,7 @@ static void android_media_MediaDrm_native_init(JNIEnv *env) {
static void android_media_MediaDrm_native_setup(
JNIEnv *env, jobject thiz,
jobject weak_this, jbyteArray uuidObj) {
jobject weak_this, jbyteArray uuidObj, jstring jappPackageName) {
if (uuidObj == NULL) {
jniThrowException(env, "java/lang/IllegalArgumentException", "uuid is null");
@@ -698,7 +699,15 @@ static void android_media_MediaDrm_native_setup(
return;
}
sp<JDrm> drm = new JDrm(env, thiz, uuid.array());
String8 packageName;
if (jappPackageName == NULL) {
jniThrowException(env, "java/lang/IllegalArgumentException",
"application package name cannot be null");
return;
}
packageName = JStringToString8(env, jappPackageName);
sp<JDrm> drm = new JDrm(env, thiz, uuid.array(), packageName);
status_t err = drm->initCheck();
@@ -1439,7 +1448,7 @@ static const JNINativeMethod gMethods[] = {
{ "release", "()V", (void *)android_media_MediaDrm_release },
{ "native_init", "()V", (void *)android_media_MediaDrm_native_init },
{ "native_setup", "(Ljava/lang/Object;[B)V",
{ "native_setup", "(Ljava/lang/Object;[BLjava/lang/String;)V",
(void *)android_media_MediaDrm_native_setup },
{ "native_finalize", "()V",

View File

@@ -39,7 +39,7 @@ public:
struct JDrm : public BnDrmClient {
static bool IsCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType);
JDrm(JNIEnv *env, jobject thiz, const uint8_t uuid[16]);
JDrm(JNIEnv *env, jobject thiz, const uint8_t uuid[16], const String8 &appPackageName);
status_t initCheck() const;
sp<IDrm> getDrm() { return mDrm; }
@@ -61,7 +61,7 @@ private:
Mutex mLock;
static sp<IDrm> MakeDrm();
static sp<IDrm> MakeDrm(const uint8_t uuid[16]);
static sp<IDrm> MakeDrm(const uint8_t uuid[16], const String8 &appPackageName);
DISALLOW_EVIL_CONSTRUCTORS(JDrm);
};