Loading media/java/android/mtp/MtpDatabase.java +31 −0 Original line number Diff line number Diff line Loading @@ -27,10 +27,14 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.media.ApplicationMediaCapabilities; import android.media.ExifInterface; import android.media.MediaFormat; import android.media.ThumbnailUtils; import android.net.Uri; import android.os.BatteryManager; import android.os.Bundle; import android.os.RemoteException; import android.os.SystemProperties; import android.os.storage.StorageVolume; import android.provider.MediaStore; Loading @@ -52,6 +56,7 @@ import com.google.android.collect.Sets; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; Loading Loading @@ -754,6 +759,32 @@ public class MtpDatabase implements AutoCloseable { return MtpConstants.RESPONSE_OK; } @VisibleForNative private int openFilePath(String path, boolean transcode) { Uri uri = MediaStore.scanFile(mContext.getContentResolver(), new File(path)); if (uri == null) { Log.i(TAG, "Failed to obtain URI for openFile with transcode support: " + path); return -1; } try { Log.i(TAG, "openFile with transcode support: " + path); // TODO(b/158466651): Pass the |transcode| variable as flag to openFile Bundle bundle = null; if (!transcode) { bundle = new Bundle(); bundle.putParcelable(MediaStore.EXTRA_MEDIA_CAPABILITIES, new ApplicationMediaCapabilities.Builder().addSupportedVideoMimeType( MediaFormat.MIMETYPE_VIDEO_HEVC).build()); } return mMediaProvider.openTypedAssetFileDescriptor(uri, "*/*", bundle) .getParcelFileDescriptor().detachFd(); } catch (RemoteException | FileNotFoundException e) { Log.w(TAG, "Failed to openFile with transcode support: " + path, e); return -1; } } private int getObjectFormat(int handle) { MtpStorageManager.MtpObject obj = mManager.getObject(handle); if (obj == null) { Loading media/jni/android_mtp_MtpDatabase.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ static jmethodID method_setDeviceProperty; static jmethodID method_getObjectPropertyList; static jmethodID method_getObjectInfo; static jmethodID method_getObjectFilePath; static jmethodID method_openFilePath; static jmethodID method_getThumbnailInfo; static jmethodID method_getThumbnailData; static jmethodID method_beginDeleteObject; Loading Loading @@ -160,6 +161,7 @@ public: MtpStringBuffer& outFilePath, int64_t& outFileLength, MtpObjectFormat& outFormat); virtual int openFilePath(const char* path, bool transcode); virtual MtpResponseCode beginDeleteObject(MtpObjectHandle handle); virtual void endDeleteObject(MtpObjectHandle handle, bool succeeded); Loading Loading @@ -969,6 +971,17 @@ MtpResponseCode MtpDatabase::getObjectFilePath(MtpObjectHandle handle, return result; } int MtpDatabase::openFilePath(const char* path, bool transcode) { JNIEnv* env = AndroidRuntime::getJNIEnv(); jstring pathStr = env->NewStringUTF(path); jint result = env->CallIntMethod(mDatabase, method_openFilePath, pathStr, transcode); if (result < 0) { checkAndClearExceptionFromCallback(env, __FUNCTION__); } return result; } MtpResponseCode MtpDatabase::beginDeleteObject(MtpObjectHandle handle) { JNIEnv* env = AndroidRuntime::getJNIEnv(); MtpResponseCode result = env->CallIntMethod(mDatabase, method_beginDeleteObject, (jint)handle); Loading Loading @@ -1333,6 +1346,7 @@ int register_android_mtp_MtpDatabase(JNIEnv *env) GET_METHOD_ID(getObjectPropertyList, clazz, "(IIIII)Landroid/mtp/MtpPropertyList;"); GET_METHOD_ID(getObjectInfo, clazz, "(I[I[C[J)Z"); GET_METHOD_ID(getObjectFilePath, clazz, "(I[C[J)I"); GET_METHOD_ID(openFilePath, clazz, "(Ljava/lang/String;Z)I"); GET_METHOD_ID(getThumbnailInfo, clazz, "(I[J)Z"); GET_METHOD_ID(getThumbnailData, clazz, "(I)[B"); GET_METHOD_ID(beginDeleteObject, clazz, "(I)I"); Loading Loading
media/java/android/mtp/MtpDatabase.java +31 −0 Original line number Diff line number Diff line Loading @@ -27,10 +27,14 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.media.ApplicationMediaCapabilities; import android.media.ExifInterface; import android.media.MediaFormat; import android.media.ThumbnailUtils; import android.net.Uri; import android.os.BatteryManager; import android.os.Bundle; import android.os.RemoteException; import android.os.SystemProperties; import android.os.storage.StorageVolume; import android.provider.MediaStore; Loading @@ -52,6 +56,7 @@ import com.google.android.collect.Sets; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; Loading Loading @@ -754,6 +759,32 @@ public class MtpDatabase implements AutoCloseable { return MtpConstants.RESPONSE_OK; } @VisibleForNative private int openFilePath(String path, boolean transcode) { Uri uri = MediaStore.scanFile(mContext.getContentResolver(), new File(path)); if (uri == null) { Log.i(TAG, "Failed to obtain URI for openFile with transcode support: " + path); return -1; } try { Log.i(TAG, "openFile with transcode support: " + path); // TODO(b/158466651): Pass the |transcode| variable as flag to openFile Bundle bundle = null; if (!transcode) { bundle = new Bundle(); bundle.putParcelable(MediaStore.EXTRA_MEDIA_CAPABILITIES, new ApplicationMediaCapabilities.Builder().addSupportedVideoMimeType( MediaFormat.MIMETYPE_VIDEO_HEVC).build()); } return mMediaProvider.openTypedAssetFileDescriptor(uri, "*/*", bundle) .getParcelFileDescriptor().detachFd(); } catch (RemoteException | FileNotFoundException e) { Log.w(TAG, "Failed to openFile with transcode support: " + path, e); return -1; } } private int getObjectFormat(int handle) { MtpStorageManager.MtpObject obj = mManager.getObject(handle); if (obj == null) { Loading
media/jni/android_mtp_MtpDatabase.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ static jmethodID method_setDeviceProperty; static jmethodID method_getObjectPropertyList; static jmethodID method_getObjectInfo; static jmethodID method_getObjectFilePath; static jmethodID method_openFilePath; static jmethodID method_getThumbnailInfo; static jmethodID method_getThumbnailData; static jmethodID method_beginDeleteObject; Loading Loading @@ -160,6 +161,7 @@ public: MtpStringBuffer& outFilePath, int64_t& outFileLength, MtpObjectFormat& outFormat); virtual int openFilePath(const char* path, bool transcode); virtual MtpResponseCode beginDeleteObject(MtpObjectHandle handle); virtual void endDeleteObject(MtpObjectHandle handle, bool succeeded); Loading Loading @@ -969,6 +971,17 @@ MtpResponseCode MtpDatabase::getObjectFilePath(MtpObjectHandle handle, return result; } int MtpDatabase::openFilePath(const char* path, bool transcode) { JNIEnv* env = AndroidRuntime::getJNIEnv(); jstring pathStr = env->NewStringUTF(path); jint result = env->CallIntMethod(mDatabase, method_openFilePath, pathStr, transcode); if (result < 0) { checkAndClearExceptionFromCallback(env, __FUNCTION__); } return result; } MtpResponseCode MtpDatabase::beginDeleteObject(MtpObjectHandle handle) { JNIEnv* env = AndroidRuntime::getJNIEnv(); MtpResponseCode result = env->CallIntMethod(mDatabase, method_beginDeleteObject, (jint)handle); Loading Loading @@ -1333,6 +1346,7 @@ int register_android_mtp_MtpDatabase(JNIEnv *env) GET_METHOD_ID(getObjectPropertyList, clazz, "(IIIII)Landroid/mtp/MtpPropertyList;"); GET_METHOD_ID(getObjectInfo, clazz, "(I[I[C[J)Z"); GET_METHOD_ID(getObjectFilePath, clazz, "(I[C[J)I"); GET_METHOD_ID(openFilePath, clazz, "(Ljava/lang/String;Z)I"); GET_METHOD_ID(getThumbnailInfo, clazz, "(I[J)Z"); GET_METHOD_ID(getThumbnailData, clazz, "(I)[B"); GET_METHOD_ID(beginDeleteObject, clazz, "(I)I"); Loading