OSDN Git Service

Enhancement for OnInfo callback on DRM Framework
authorTakeshi Aimi <takeshi.aimi@sonymobile.com>
Wed, 11 Jul 2012 08:13:38 +0000 (17:13 +0900)
committerJeff Tinker <jtinker@google.com>
Sat, 24 Aug 2013 01:02:40 +0000 (18:02 -0700)
In DRM framework, plugins can transmit DrmInfoEvent to Java layer.
Although DrmInfoEvent has several entries, current implementation
can only convey integer and String. This change enables plugins
uto propagate a hashmap to Java layer. The hashmap can have
one or more Strings and one byte array as value.

Changes are made by Sony Corporation.

bug: 10459159

Change-Id: I5f2bfb43b676863ef4d220fd4ef1e48777e92752
(cherry picked from commit 84a5b5cab40711e20ba70c5ed4dfeab6b558b53b)

drm/java/android/drm/DrmManagerClient.java
drm/jni/android_drm_DrmManagerClient.cpp

index 10cdab0..e2606d6 100644 (file)
@@ -63,6 +63,8 @@ public class DrmManagerClient {
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
+    private static final String EXTENDED_INFO_DATA = "extended_info_data";
+
     static {
         // Load the respective library
         System.loadLibrary("drmframework_jni");
@@ -184,8 +186,22 @@ public class DrmManagerClient {
         DrmManagerClient instance = (DrmManagerClient)((WeakReference)thisReference).get();
 
         if (null != instance && null != instance.mInfoHandler) {
+            DrmInfoEvent event = new DrmInfoEvent(uniqueId, infoType, message);
+            Message m = instance.mInfoHandler.obtainMessage(
+                    InfoHandler.INFO_EVENT_TYPE, event);
+            instance.mInfoHandler.sendMessage(m);
+        }
+    }
+
+    private static void notify(
+            Object thisReference, int uniqueId, int infoType, String message,
+            HashMap<String, Object> attributes) {
+        DrmManagerClient instance = (DrmManagerClient)((WeakReference)thisReference).get();
+
+        if (null != instance && null != instance.mInfoHandler) {
+            DrmInfoEvent event = new DrmInfoEvent(uniqueId, infoType, message, attributes);
             Message m = instance.mInfoHandler.obtainMessage(
-                InfoHandler.INFO_EVENT_TYPE, uniqueId, infoType, message);
+                    InfoHandler.INFO_EVENT_TYPE, event);
             instance.mInfoHandler.sendMessage(m);
         }
     }
@@ -198,23 +214,25 @@ public class DrmManagerClient {
         }
 
         public void handleMessage(Message msg) {
-            DrmInfoEvent info = null;
+            DrmInfoEvent info = (DrmInfoEvent) msg.obj;
             DrmErrorEvent error = null;
+            int uniqueId;
+            int eventType;
+            String message;
 
             switch (msg.what) {
             case InfoHandler.INFO_EVENT_TYPE:
-                int uniqueId = msg.arg1;
-                int infoType = msg.arg2;
-                String message = msg.obj.toString();
+                uniqueId = info.getUniqueId();
+                eventType = info.getType();
+                message = info.getMessage();
 
-                switch (infoType) {
+                switch (eventType) {
                 case DrmInfoEvent.TYPE_REMOVE_RIGHTS: {
                     try {
                         DrmUtils.removeFile(message);
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
-                    info = new DrmInfoEvent(uniqueId, infoType, message);
                     break;
                 }
                 case DrmInfoEvent.TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT:
@@ -222,11 +240,11 @@ public class DrmManagerClient {
                 case DrmInfoEvent.TYPE_WAIT_FOR_RIGHTS:
                 case DrmInfoEvent.TYPE_ACCOUNT_ALREADY_REGISTERED:
                 case DrmInfoEvent.TYPE_RIGHTS_REMOVED: {
-                    info = new DrmInfoEvent(uniqueId, infoType, message);
                     break;
                 }
                 default:
-                    error = new DrmErrorEvent(uniqueId, infoType, message);
+                    info = null;
+                    error = new DrmErrorEvent(uniqueId, eventType, message);
                     break;
                 }
 
index baddf62..7fce3d0 100644 (file)
@@ -169,11 +169,49 @@ void JNIOnInfoListener::onInfo(const DrmInfoEvent& event) {
     JNIEnv *env = AndroidRuntime::getJNIEnv();
     jstring message = env->NewStringUTF(event.getMessage().string());
     ALOGV("JNIOnInfoListener::onInfo => %d | %d | %s", uniqueId, type, event.getMessage().string());
-
-    env->CallStaticVoidMethod(
-            mClass,
-            env->GetStaticMethodID(mClass, "notify", "(Ljava/lang/Object;IILjava/lang/String;)V"),
-            mObject, uniqueId, type, message);
+    const DrmBuffer& drmBuffer = event.getData();
+    if (event.getCount() > 0 || drmBuffer.length > 0) {
+        jclass hashMapClazz = env->FindClass("java/util/HashMap");
+        jmethodID hashMapInitId = env->GetMethodID(hashMapClazz, "<init>", "()V");
+        jmethodID hashMapPutId = env->GetMethodID(hashMapClazz, "put",
+                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+        jobject hashMapObject = env->NewObject(hashMapClazz, hashMapInitId);
+        env->DeleteLocalRef(hashMapClazz);
+
+        if (0 < drmBuffer.length) {
+            jfieldID fid = env->GetStaticFieldID(
+                mClass, "EXTENDED_INFO_DATA", "Ljava/lang/String;");
+            jstring key = (jstring) env->GetStaticObjectField(mClass, fid);
+
+            jbyteArray valueByte = env->NewByteArray(drmBuffer.length);
+            env->SetByteArrayRegion(valueByte, 0, drmBuffer.length, (jbyte*) drmBuffer.data);
+            env->CallObjectMethod(hashMapObject, hashMapPutId, key, valueByte);
+            env->DeleteLocalRef(valueByte);
+            env->DeleteLocalRef(key);
+        }
+        DrmInfoEvent::KeyIterator keyIt = event.keyIterator();
+        while (keyIt.hasNext()) {
+            String8 mapKey = keyIt.next();
+            jstring key = env->NewStringUTF(mapKey.string());
+            jstring value = env->NewStringUTF(event.get(mapKey).string());
+            env->CallObjectMethod(hashMapObject, hashMapPutId, key, value);
+            env->DeleteLocalRef(value);
+            env->DeleteLocalRef(key);
+        }
+        env->CallStaticVoidMethod(
+                mClass,
+                env->GetStaticMethodID(mClass, "notify",
+                        "(Ljava/lang/Object;IILjava/lang/String;Ljava/util/HashMap;)V"),
+                mObject, uniqueId, type, message, hashMapObject);
+        env->DeleteLocalRef(hashMapObject);
+    } else {
+        env->CallStaticVoidMethod(
+                mClass,
+                env->GetStaticMethodID(mClass, "notify",
+                        "(Ljava/lang/Object;IILjava/lang/String;)V"),
+                mObject, uniqueId, type, message);
+    }
+    env->DeleteLocalRef(message);
 }
 
 static Mutex sLock;