diff options
author | Mike Lockwood <lockwood@google.com> | 2015-01-23 10:50:08 -0800 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2015-01-23 10:58:38 -0800 |
commit | 71827748105252791854b87da8e0e0c66ff0d2cb (patch) | |
tree | e3ffca39288af31a6eeef44a75e74a9571549fdf /media/java/android/mtp/MtpDatabase.java | |
parent | 06ab0ca4812450ec297722957e18b34cbfa733b2 (diff) | |
download | frameworks_base-71827748105252791854b87da8e0e0c66ff0d2cb.zip frameworks_base-71827748105252791854b87da8e0e0c66ff0d2cb.tar.gz frameworks_base-71827748105252791854b87da8e0e0c66ff0d2cb.tar.bz2 |
MTP: Fix partial implementation of 5 new audio specific properties
In change Ic5b3fb75309893caae1a4f4b56068a543847f1f7, we added partial
support for the MTP properties:
MTP_PROPERTY_AUDIO_WAVE_CODE,
MTP_PROPERTY_BITRATE_TYPE
MTP_PROPERTY_AUDIO_BITRATE
MTP_PROPERTY_NUMBER_OF_CHANNELS
MTP_PROPERTY_SAMPLE_RATE
However we were not returning any values for these properties in the result
of the MTP GetObjectPropList command. Strangely, this triggers a nasty bug
in Windows 7 that results in data loss. When copying a directory containing
several MP3 files from one location on the device to another, Windows will
copy only some of the files to the new location, but delete all of the originals.
Finishing the implementation of these new object properties for some unknown
reason stops this bad behavior in Windows 7.
Bug: 19018427
Change-Id: I5fd3b91a89b31827d3100686445cef6795fe0f3f
Diffstat (limited to 'media/java/android/mtp/MtpDatabase.java')
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 68 |
1 files changed, 29 insertions, 39 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index 13cdc69..5d9355a 100755 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -88,6 +88,10 @@ public class MtpDatabase { Files.FileColumns._ID, // 0 Files.FileColumns.DATA, // 1 }; + private static final String[] FORMAT_PROJECTION = new String[] { + Files.FileColumns._ID, // 0 + Files.FileColumns.FORMAT, // 1 + }; private static final String[] PATH_FORMAT_PROJECTION = new String[] { Files.FileColumns._ID, // 0 Files.FileColumns.DATA, // 1 @@ -597,6 +601,7 @@ public class MtpDatabase { MtpConstants.PROPERTY_PARENT_OBJECT, MtpConstants.PROPERTY_PERSISTENT_UID, MtpConstants.PROPERTY_NAME, + MtpConstants.PROPERTY_DISPLAY_NAME, MtpConstants.PROPERTY_DATE_ADDED, }; @@ -669,43 +674,6 @@ public class MtpDatabase { MtpConstants.PROPERTY_DESCRIPTION, }; - static final int[] ALL_PROPERTIES = { - // NOTE must match FILE_PROPERTIES above - MtpConstants.PROPERTY_STORAGE_ID, - MtpConstants.PROPERTY_OBJECT_FORMAT, - MtpConstants.PROPERTY_PROTECTION_STATUS, - MtpConstants.PROPERTY_OBJECT_SIZE, - MtpConstants.PROPERTY_OBJECT_FILE_NAME, - MtpConstants.PROPERTY_DATE_MODIFIED, - MtpConstants.PROPERTY_PARENT_OBJECT, - MtpConstants.PROPERTY_PERSISTENT_UID, - MtpConstants.PROPERTY_NAME, - MtpConstants.PROPERTY_DISPLAY_NAME, - MtpConstants.PROPERTY_DATE_ADDED, - - // image specific properties - MtpConstants.PROPERTY_DESCRIPTION, - - // audio specific properties - MtpConstants.PROPERTY_ARTIST, - MtpConstants.PROPERTY_ALBUM_NAME, - MtpConstants.PROPERTY_ALBUM_ARTIST, - MtpConstants.PROPERTY_TRACK, - MtpConstants.PROPERTY_ORIGINAL_RELEASE_DATE, - MtpConstants.PROPERTY_DURATION, - MtpConstants.PROPERTY_GENRE, - MtpConstants.PROPERTY_COMPOSER, - - // video specific properties - MtpConstants.PROPERTY_ARTIST, - MtpConstants.PROPERTY_ALBUM_NAME, - MtpConstants.PROPERTY_DURATION, - MtpConstants.PROPERTY_DESCRIPTION, - - // image specific properties - MtpConstants.PROPERTY_DESCRIPTION, - }; - private int[] getSupportedObjectProperties(int format) { switch (format) { case MtpConstants.FORMAT_MP3: @@ -723,8 +691,6 @@ public class MtpDatabase { case MtpConstants.FORMAT_PNG: case MtpConstants.FORMAT_BMP: return IMAGE_PROPERTIES; - case 0: - return ALL_PROPERTIES; default: return FILE_PROPERTIES; } @@ -749,6 +715,10 @@ public class MtpDatabase { MtpPropertyGroup propertyGroup; if (property == 0xFFFFFFFFL) { + if (format == 0 && handle > 0) { + // return properties based on the object's format + format = getObjectFormat((int)handle); + } propertyGroup = mPropertyGroupsByFormat.get(format); if (propertyGroup == null) { int[] propertyList = getSupportedObjectProperties(format); @@ -988,6 +958,26 @@ public class MtpDatabase { } } + private int getObjectFormat(int handle) { + Cursor c = null; + try { + c = mMediaProvider.query(mPackageName, mObjectsUri, FORMAT_PROJECTION, + ID_WHERE, new String[] { Integer.toString(handle) }, null, null); + if (c != null && c.moveToNext()) { + return c.getInt(1); + } else { + return -1; + } + } catch (RemoteException e) { + Log.e(TAG, "RemoteException in getObjectFilePath", e); + return -1; + } finally { + if (c != null) { + c.close(); + } + } + } + private int deleteFile(int handle) { mDatabaseModified = true; String path = null; |