@@ -84,20 +84,18 @@ public class MtpDatabase {
8484 Files .FileColumns ._ID , // 0
8585 Files .FileColumns .DATA , // 1
8686 };
87- private static final String [] PATH_SIZE_FORMAT_PROJECTION = new String [] {
87+ private static final String [] PATH_FORMAT_PROJECTION = new String [] {
8888 Files .FileColumns ._ID , // 0
8989 Files .FileColumns .DATA , // 1
90- Files .FileColumns .SIZE , // 2
91- Files .FileColumns .FORMAT , // 3
90+ Files .FileColumns .FORMAT , // 2
9291 };
9392 private static final String [] OBJECT_INFO_PROJECTION = new String [] {
9493 Files .FileColumns ._ID , // 0
9594 Files .FileColumns .STORAGE_ID , // 1
9695 Files .FileColumns .FORMAT , // 2
9796 Files .FileColumns .PARENT , // 3
9897 Files .FileColumns .DATA , // 4
99- Files .FileColumns .SIZE , // 5
100- Files .FileColumns .DATE_MODIFIED , // 6
98+ Files .FileColumns .DATE_MODIFIED , // 5
10199 };
102100 private static final String ID_WHERE = Files .FileColumns ._ID + "=?" ;
103101 private static final String PATH_WHERE = Files .FileColumns .DATA + "=?" ;
@@ -834,7 +832,7 @@ private int setDeviceProperty(int property, long intValue, String stringValue) {
834832 }
835833
836834 private boolean getObjectInfo (int handle , int [] outStorageFormatParent ,
837- char [] outName , long [] outSizeModified ) {
835+ char [] outName , long [] outModified ) {
838836 Cursor c = null ;
839837 try {
840838 c = mMediaProvider .query (mObjectsUri , OBJECT_INFO_PROJECTION ,
@@ -855,8 +853,7 @@ private boolean getObjectInfo(int handle, int[] outStorageFormatParent,
855853 path .getChars (start , end , outName , 0 );
856854 outName [end - start ] = 0 ;
857855
858- outSizeModified [0 ] = c .getLong (5 );
859- outSizeModified [1 ] = c .getLong (6 );
856+ outModified [0 ] = c .getLong (5 );
860857 return true ;
861858 }
862859 } catch (RemoteException e ) {
@@ -880,14 +877,16 @@ private int getObjectFilePath(int handle, char[] outFilePath, long[] outFileLeng
880877 }
881878 Cursor c = null ;
882879 try {
883- c = mMediaProvider .query (mObjectsUri , PATH_SIZE_FORMAT_PROJECTION ,
880+ c = mMediaProvider .query (mObjectsUri , PATH_FORMAT_PROJECTION ,
884881 ID_WHERE , new String [] { Integer .toString (handle ) }, null , null );
885882 if (c != null && c .moveToNext ()) {
886883 String path = c .getString (1 );
887884 path .getChars (0 , path .length (), outFilePath , 0 );
888885 outFilePath [path .length ()] = 0 ;
889- outFileLengthFormat [0 ] = c .getLong (2 );
890- outFileLengthFormat [1 ] = c .getLong (3 );
886+ // File transfers from device to host will likely fail if the size is incorrect.
887+ // So to be safe, use the actual file size here.
888+ outFileLengthFormat [0 ] = new File (path ).length ();
889+ outFileLengthFormat [1 ] = c .getLong (2 );
891890 return MtpConstants .RESPONSE_OK ;
892891 } else {
893892 return MtpConstants .RESPONSE_INVALID_OBJECT_HANDLE ;
@@ -909,13 +908,13 @@ private int deleteFile(int handle) {
909908
910909 Cursor c = null ;
911910 try {
912- c = mMediaProvider .query (mObjectsUri , PATH_SIZE_FORMAT_PROJECTION ,
911+ c = mMediaProvider .query (mObjectsUri , PATH_FORMAT_PROJECTION ,
913912 ID_WHERE , new String [] { Integer .toString (handle ) }, null , null );
914913 if (c != null && c .moveToNext ()) {
915914 // don't convert to media path here, since we will be matching
916915 // against paths in the database matching /data/media
917916 path = c .getString (1 );
918- format = c .getInt (3 );
917+ format = c .getInt (2 );
919918 } else {
920919 return MtpConstants .RESPONSE_INVALID_OBJECT_HANDLE ;
921920 }
0 commit comments