diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java index 8c73211cccf14..f901ff05deb32 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java @@ -750,7 +750,12 @@ class MtpDatabase { values.putNull(Document.COLUMN_SUMMARY); values.putNull(Document.COLUMN_LAST_MODIFIED); values.put(Document.COLUMN_ICON, R.drawable.ic_root_mtp); - values.put(Document.COLUMN_FLAGS, 0); + values.put(Document.COLUMN_FLAGS, getDocumentFlags( + device.operationsSupported, + Document.MIME_TYPE_DIR, + 0, + MtpConstants.PROTECTION_STATUS_NONE, + DOCUMENT_TYPE_DEVICE)); values.putNull(Document.COLUMN_SIZE); extraValues.clear(); @@ -765,7 +770,7 @@ class MtpDatabase { * @param values {@link ContentValues} that receives values. * @param extraValues {@link ContentValues} that receives extra values for roots. * @param parentDocumentId Parent document ID. - * @param supportedOperations Array of Operation code supported by the device. + * @param operationsSupported Array of Operation code supported by the device. * @param root Root to be converted {@link ContentValues}. */ static void getStorageDocumentValues( @@ -786,7 +791,12 @@ class MtpDatabase { values.putNull(Document.COLUMN_SUMMARY); values.putNull(Document.COLUMN_LAST_MODIFIED); values.put(Document.COLUMN_ICON, R.drawable.ic_root_mtp); - values.put(Document.COLUMN_FLAGS, 0); + values.put(Document.COLUMN_FLAGS, getDocumentFlags( + operationsSupported, + Document.MIME_TYPE_DIR, + 0, + MtpConstants.PROTECTION_STATUS_NONE, + DOCUMENT_TYPE_STORAGE)); values.put(Document.COLUMN_SIZE, root.mMaxCapacity - root.mFreeSpace); extraValues.put(Root.COLUMN_FLAGS, getRootFlags(operationsSupported)); @@ -803,8 +813,8 @@ class MtpDatabase { * @param info MTP object info. */ static void getObjectDocumentValues( - ContentValues values, int deviceId, String parentId, int[] operationsSupported, - MtpObjectInfo info) { + ContentValues values, int deviceId, String parentId, + int[] operationsSupported, MtpObjectInfo info) { values.clear(); final String mimeType = getMimeType(info); values.put(COLUMN_DEVICE_ID, deviceId); @@ -822,7 +832,7 @@ class MtpDatabase { values.putNull(Document.COLUMN_ICON); values.put(Document.COLUMN_FLAGS, getDocumentFlags( operationsSupported, mimeType, info.getThumbCompressedSizeLong(), - info.getProtectionStatus())); + info.getProtectionStatus(), DOCUMENT_TYPE_OBJECT)); values.put(Document.COLUMN_SIZE, info.getCompressedSizeLong()); } @@ -861,16 +871,19 @@ class MtpDatabase { } private static int getDocumentFlags( - int[] operationsSupported, String mimeType, long thumbnailSize, int protectionState) { + @Nullable int[] operationsSupported, String mimeType, long thumbnailSize, + int protectionState, @DocumentType int documentType) { int flag = 0; - if (MtpDeviceRecord.isWritingSupported(operationsSupported) && + if (!mimeType.equals(Document.MIME_TYPE_DIR) && + MtpDeviceRecord.isWritingSupported(operationsSupported) && protectionState == MtpConstants.PROTECTION_STATUS_NONE) { flag |= Document.FLAG_SUPPORTS_WRITE; } if (MtpDeviceRecord.isSupported( operationsSupported, MtpConstants.OPERATION_DELETE_OBJECT) && (protectionState == MtpConstants.PROTECTION_STATUS_NONE || - protectionState == MtpConstants.PROTECTION_STATUS_NON_TRANSFERABLE_DATA)) { + protectionState == MtpConstants.PROTECTION_STATUS_NON_TRANSFERABLE_DATA) && + documentType == DOCUMENT_TYPE_OBJECT) { flag |= Document.FLAG_SUPPORTS_DELETE; } if (mimeType.equals(Document.MIME_TYPE_DIR) && diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java index b74069ae36bbe..284223ba93973 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java @@ -103,7 +103,7 @@ public class MtpDatabaseTest extends AndroidTestCase { assertTrue(isNull(cursor, COLUMN_SUMMARY)); assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); assertEquals(R.drawable.ic_root_mtp, getInt(cursor, COLUMN_ICON)); - assertEquals(0, getInt(cursor, COLUMN_FLAGS)); + assertEquals(Document.FLAG_DIR_SUPPORTS_CREATE, getInt(cursor, COLUMN_FLAGS)); assertEquals(1000, getInt(cursor, COLUMN_SIZE)); assertEquals( MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE, @@ -165,7 +165,7 @@ public class MtpDatabaseTest extends AndroidTestCase { assertTrue(isNull(cursor, COLUMN_SUMMARY)); assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); assertEquals(R.drawable.ic_root_mtp, getInt(cursor, COLUMN_ICON)); - assertEquals(0, getInt(cursor, COLUMN_FLAGS)); + assertEquals(Document.FLAG_DIR_SUPPORTS_CREATE, getInt(cursor, COLUMN_FLAGS)); assertEquals(1000, getInt(cursor, COLUMN_SIZE)); assertEquals( MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE, getInt(cursor, COLUMN_DOCUMENT_TYPE)); diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java index 0cfe1e6c95fa2..da6af37af0754 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java @@ -351,7 +351,6 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { assertEquals(1422716400000L, cursor.getLong(3)); assertEquals( DocumentsContract.Document.FLAG_SUPPORTS_DELETE | - DocumentsContract.Document.FLAG_SUPPORTS_WRITE | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE, cursor.getInt(4)); assertEquals(0, cursor.getInt(5));