Skip to content

Commit 0889fda

Browse files
author
James Dong
committed
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
1 parent f83d2d6 commit 0889fda

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

drm/java/android/drm/DrmManagerClient.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import android.provider.MediaStore;
3030
import android.util.Log;
3131

32+
import java.io.File;
33+
import java.io.FileDescriptor;
34+
import java.io.FileInputStream;
3235
import java.io.IOException;
3336
import java.lang.ref.WeakReference;
3437
import java.util.ArrayList;
@@ -582,7 +585,28 @@ public String getOriginalMimeType(String path) {
582585
if (null == path || path.equals("")) {
583586
throw new IllegalArgumentException("Given path should be non null");
584587
}
585-
return _getOriginalMimeType(mUniqueId, path);
588+
589+
String mime = null;
590+
591+
FileInputStream is = null;
592+
try {
593+
FileDescriptor fd = null;
594+
File file = new File(path);
595+
if (file.exists()) {
596+
is = new FileInputStream(file);
597+
fd = is.getFD();
598+
}
599+
mime = _getOriginalMimeType(mUniqueId, path, fd);
600+
} catch (IOException ioe) {
601+
} finally {
602+
if (is != null) {
603+
try {
604+
is.close();
605+
} catch(IOException e) {}
606+
}
607+
}
608+
609+
return mime;
586610
}
587611

588612
/**
@@ -848,7 +872,7 @@ private native int _saveRights(
848872

849873
private native int _getDrmObjectType(int uniqueId, String path, String mimeType);
850874

851-
private native String _getOriginalMimeType(int uniqueId, String path);
875+
private native String _getOriginalMimeType(int uniqueId, String path, FileDescriptor fd);
852876

853877
private native int _checkRightsStatus(int uniqueId, String path, int action);
854878

drm/jni/android_drm_DrmManagerClient.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,22 +578,28 @@ static jint android_drm_DrmManagerClient_getDrmObjectType(
578578
}
579579

580580
static jstring android_drm_DrmManagerClient_getOriginalMimeType(
581-
JNIEnv* env, jobject thiz, jint uniqueId, jstring path) {
581+
JNIEnv* env, jobject thiz, jint uniqueId, jstring path, jobject fileDescriptor) {
582582
ALOGV("getOriginalMimeType Enter");
583+
584+
int fd = (fileDescriptor == NULL)
585+
? -1
586+
: jniGetFDFromFileDescriptor(env, fileDescriptor);
587+
583588
String8 mimeType
584589
= getDrmManagerClientImpl(env, thiz)
585-
->getOriginalMimeType(uniqueId, Utility::getStringValue(env, path));
590+
->getOriginalMimeType(uniqueId,
591+
Utility::getStringValue(env, path), fd);
586592
ALOGV("getOriginalMimeType Exit");
587593
return env->NewStringUTF(mimeType.string());
588594
}
589595

590596
static jint android_drm_DrmManagerClient_checkRightsStatus(
591597
JNIEnv* env, jobject thiz, jint uniqueId, jstring path, int action) {
592-
ALOGV("getOriginalMimeType Enter");
598+
ALOGV("checkRightsStatus Enter");
593599
int rightsStatus
594600
= getDrmManagerClientImpl(env, thiz)
595601
->checkRightsStatus(uniqueId, Utility::getStringValue(env, path), action);
596-
ALOGV("getOriginalMimeType Exit");
602+
ALOGV("checkRightsStatus Exit");
597603
return rightsStatus;
598604
}
599605

@@ -721,7 +727,7 @@ static JNINativeMethod nativeMethods[] = {
721727
{"_getDrmObjectType", "(ILjava/lang/String;Ljava/lang/String;)I",
722728
(void*)android_drm_DrmManagerClient_getDrmObjectType},
723729

724-
{"_getOriginalMimeType", "(ILjava/lang/String;)Ljava/lang/String;",
730+
{"_getOriginalMimeType", "(ILjava/lang/String;Ljava/io/FileDescriptor;)Ljava/lang/String;",
725731
(void*)android_drm_DrmManagerClient_getOriginalMimeType},
726732

727733
{"_checkRightsStatus", "(ILjava/lang/String;I)I",

0 commit comments

Comments
 (0)