From 0889fdae87abd9ec78a6c1d00c2771acfa4e4d34 Mon Sep 17 00:00:00 2001 From: James Dong Date: Wed, 8 Aug 2012 17:45:59 -0700 Subject: Let getOriginalMimeType() take a fd passed from drm java applications At present, we did not actually pass the fd. This patch allows us to make the changes necessary in the future without worrying too much about broken build. related-to-bug: 6426185 Change-Id: I125decff9be621a72f2631fd439994a94a526606 --- drm/java/android/drm/DrmManagerClient.java | 28 ++++++++++++++++++++++++++-- drm/jni/android_drm_DrmManagerClient.cpp | 16 +++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'drm') diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java index 4b51994..2907f10 100755 --- a/drm/java/android/drm/DrmManagerClient.java +++ b/drm/java/android/drm/DrmManagerClient.java @@ -29,6 +29,9 @@ import android.os.Message; import android.provider.MediaStore; import android.util.Log; +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileInputStream; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -582,7 +585,28 @@ public class DrmManagerClient { if (null == path || path.equals("")) { throw new IllegalArgumentException("Given path should be non null"); } - return _getOriginalMimeType(mUniqueId, path); + + String mime = null; + + FileInputStream is = null; + try { + FileDescriptor fd = null; + File file = new File(path); + if (file.exists()) { + is = new FileInputStream(file); + fd = is.getFD(); + } + mime = _getOriginalMimeType(mUniqueId, path, fd); + } catch (IOException ioe) { + } finally { + if (is != null) { + try { + is.close(); + } catch(IOException e) {} + } + } + + return mime; } /** @@ -848,7 +872,7 @@ public class DrmManagerClient { private native int _getDrmObjectType(int uniqueId, String path, String mimeType); - private native String _getOriginalMimeType(int uniqueId, String path); + private native String _getOriginalMimeType(int uniqueId, String path, FileDescriptor fd); private native int _checkRightsStatus(int uniqueId, String path, int action); diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp index 14ec4d6..1ee32fa 100644 --- a/drm/jni/android_drm_DrmManagerClient.cpp +++ b/drm/jni/android_drm_DrmManagerClient.cpp @@ -578,22 +578,28 @@ static jint android_drm_DrmManagerClient_getDrmObjectType( } static jstring android_drm_DrmManagerClient_getOriginalMimeType( - JNIEnv* env, jobject thiz, jint uniqueId, jstring path) { + JNIEnv* env, jobject thiz, jint uniqueId, jstring path, jobject fileDescriptor) { ALOGV("getOriginalMimeType Enter"); + + int fd = (fileDescriptor == NULL) + ? -1 + : jniGetFDFromFileDescriptor(env, fileDescriptor); + String8 mimeType = getDrmManagerClientImpl(env, thiz) - ->getOriginalMimeType(uniqueId, Utility::getStringValue(env, path)); + ->getOriginalMimeType(uniqueId, + Utility::getStringValue(env, path), fd); ALOGV("getOriginalMimeType Exit"); return env->NewStringUTF(mimeType.string()); } static jint android_drm_DrmManagerClient_checkRightsStatus( JNIEnv* env, jobject thiz, jint uniqueId, jstring path, int action) { - ALOGV("getOriginalMimeType Enter"); + ALOGV("checkRightsStatus Enter"); int rightsStatus = getDrmManagerClientImpl(env, thiz) ->checkRightsStatus(uniqueId, Utility::getStringValue(env, path), action); - ALOGV("getOriginalMimeType Exit"); + ALOGV("checkRightsStatus Exit"); return rightsStatus; } @@ -721,7 +727,7 @@ static JNINativeMethod nativeMethods[] = { {"_getDrmObjectType", "(ILjava/lang/String;Ljava/lang/String;)I", (void*)android_drm_DrmManagerClient_getDrmObjectType}, - {"_getOriginalMimeType", "(ILjava/lang/String;)Ljava/lang/String;", + {"_getOriginalMimeType", "(ILjava/lang/String;Ljava/io/FileDescriptor;)Ljava/lang/String;", (void*)android_drm_DrmManagerClient_getOriginalMimeType}, {"_checkRightsStatus", "(ILjava/lang/String;I)I", -- cgit v1.1