Move logic to skip single storage.

The tree structure of MTP model looks like /device/storage/objects. But
almost all MTP device has only single storage, so it's redundant to show
a single storage as a child of device in UI.

MtpDocumentsProvider has a special logic to skip single storage, and
shows storage's object as a children of device in such case. Previously
the logic was applied when MtpDocumentsProvider returned a root
list. The provider returns a storage as a Documents.Root, instead of
device if the device has only one storage.

However the number of root cannot be obtain for closed device. Thus the
previous logic did not work for closed devices that have a single
storage. The CL moves the logic from queryRoot to
queryChildDocuments. Now MtpDocumentsProvider always returns a device as
root, then it returns storage's objects as the device's children, where
we has already opened the device.

BUG=26481574

Change-Id: I25af0fc220410e321a378d67f226798ec4bba19c
diff --git a/src/com/android/mtp/DocumentLoader.java b/src/com/android/mtp/DocumentLoader.java
index 1d72647..1829746 100644
--- a/src/com/android/mtp/DocumentLoader.java
+++ b/src/com/android/mtp/DocumentLoader.java
@@ -74,7 +74,7 @@
             int parentHandle = parent.mObjectHandle;
             // Need to pass the special value MtpManager.OBJECT_HANDLE_ROOT_CHILDREN to
             // getObjectHandles if we would like to obtain children under the root.
-            if (parentHandle == Identifier.DUMMY_HANDLE_FOR_ROOT) {
+            if (parent.mDocumentType == MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE) {
                 parentHandle = MtpManager.OBJECT_HANDLE_ROOT_CHILDREN;
             }
             // TODO: Handle nit race around here.
diff --git a/src/com/android/mtp/Identifier.java b/src/com/android/mtp/Identifier.java
index 20b3bf5..76a1fad 100644
--- a/src/com/android/mtp/Identifier.java
+++ b/src/com/android/mtp/Identifier.java
@@ -17,32 +17,34 @@
 package com.android.mtp;
 
 import java.util.Objects;
+import static com.android.mtp.MtpDatabaseConstants.DocumentType;
 
 /**
  * Static utilities for ID.
  */
 class Identifier {
-    final static int DUMMY_HANDLE_FOR_ROOT = 0;
-
     final int mDeviceId;
     final int mStorageId;
     final int mObjectHandle;
     final String mDocumentId;
+    final @DocumentType int mDocumentType;
 
-    Identifier(int deviceId, int storageId, int objectHandle, String documentId) {
+    Identifier(int deviceId, int storageId, int objectHandle, String documentId,
+            @DocumentType int documentType) {
         mDeviceId = deviceId;
         mStorageId = storageId;
         mObjectHandle = objectHandle;
         mDocumentId = documentId;
+        mDocumentType = documentType;
     }
 
     @Override
     public boolean equals(Object obj) {
         if (!(obj instanceof Identifier))
             return false;
-        final Identifier other = (Identifier)obj;
+        final Identifier other = (Identifier) obj;
         return mDeviceId == other.mDeviceId && mStorageId == other.mStorageId &&
-                mObjectHandle == other.mObjectHandle;
+                mObjectHandle == other.mObjectHandle && mDocumentId == other.mDocumentId;
     }
 
     @Override
diff --git a/src/com/android/mtp/MtpDatabase.java b/src/com/android/mtp/MtpDatabase.java
index 959fac6..59d85c1 100644
--- a/src/com/android/mtp/MtpDatabase.java
+++ b/src/com/android/mtp/MtpDatabase.java
@@ -143,49 +143,50 @@
                         null);
                 try {
                     values.clear();
-                    if (storageCursor.getCount() == 1) {
-                        storageCursor.moveToNext();
-                        DatabaseUtils.cursorRowToContentValues(storageCursor, values);
-                    } else {
-                        final Cursor cursor = builder.query(
-                                mDatabase,
-                                columnNames,
-                                selection + " AND " + COLUMN_DEVICE_ID + " = ?",
-                                strings(ROW_STATE_VALID,
-                                        ROW_STATE_INVALIDATED,
-                                        DOCUMENT_TYPE_DEVICE,
-                                        deviceId),
-                                null,
-                                null,
-                                null);
-                        try {
-                            cursor.moveToNext();
-                            DatabaseUtils.cursorRowToContentValues(cursor, values);
-                        } finally {
-                            cursor.close();
-                        }
+                    try (final Cursor deviceRoot = builder.query(
+                            mDatabase,
+                            columnNames,
+                            selection + " AND " + COLUMN_DEVICE_ID + " = ?",
+                            strings(ROW_STATE_VALID,
+                                    ROW_STATE_INVALIDATED,
+                                    DOCUMENT_TYPE_DEVICE,
+                                    deviceId),
+                            null,
+                            null,
+                            null)) {
+                        deviceRoot.moveToNext();
+                        DatabaseUtils.cursorRowToContentValues(deviceRoot, values);
+                    }
 
-                        if (storageCursor.getCount() != 0) {
-                            long capacityBytes = 0;
-                            long availableBytes = 0;
-                            int capacityIndex = cursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
-                            int availableIndex = cursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
-                            while (storageCursor.moveToNext()) {
-                                // If requested columnNames does not include COLUMN_XXX_BYTES, we
-                                // don't calculate corresponding values.
-                                if (capacityIndex != -1) {
-                                    capacityBytes += cursor.getLong(capacityIndex);
-                                }
-                                if (availableIndex != -1) {
-                                    availableBytes += cursor.getLong(availableIndex);
-                                }
+                    if (storageCursor.getCount() != 0) {
+                        long capacityBytes = 0;
+                        long availableBytes = 0;
+                        final int capacityIndex =
+                                storageCursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
+                        final int availableIndex =
+                                storageCursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
+                        while (storageCursor.moveToNext()) {
+                            // If requested columnNames does not include COLUMN_XXX_BYTES, we
+                            // don't calculate corresponding values.
+                            if (capacityIndex != -1) {
+                                capacityBytes += storageCursor.getLong(capacityIndex);
                             }
-                            values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
-                            values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
-                        } else {
-                            values.putNull(Root.COLUMN_CAPACITY_BYTES);
-                            values.putNull(Root.COLUMN_AVAILABLE_BYTES);
+                            if (availableIndex != -1) {
+                                availableBytes += storageCursor.getLong(availableIndex);
+                            }
                         }
+                        values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
+                        values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
+                    } else {
+                        values.putNull(Root.COLUMN_CAPACITY_BYTES);
+                        values.putNull(Root.COLUMN_AVAILABLE_BYTES);
+                    }
+                    if (storageCursor.getCount() == 1 && values.containsKey(Root.COLUMN_TITLE)) {
+                        storageCursor.moveToFirst();
+                        values.put(
+                                Root.COLUMN_TITLE,
+                                storageCursor.getString(
+                                        storageCursor.getColumnIndex(Root.COLUMN_TITLE)));
                     }
                 } finally {
                     storageCursor.close();
@@ -239,12 +240,45 @@
     }
 
     /**
+     * Returns identifier of single storage if given document points device and it has only one
+     * storage. Otherwise null.
+     *
+     * @param documentId Document ID that may point a device.
+     * @return Identifier for single storage or null.
+     * @throws FileNotFoundException The given document ID is not registered in database.
+     */
+    @Nullable Identifier getSingleStorageIdentifier(String documentId)
+            throws FileNotFoundException {
+        // Check if the parent document is device that has single storage.
+        try (final Cursor cursor = mDatabase.query(
+                TABLE_DOCUMENTS,
+                strings(Document.COLUMN_DOCUMENT_ID),
+                COLUMN_ROW_STATE + " IN (?, ?) AND " +
+                COLUMN_PARENT_DOCUMENT_ID + " = ? AND " +
+                COLUMN_DOCUMENT_TYPE + " = ?",
+                strings(ROW_STATE_VALID,
+                        ROW_STATE_INVALIDATED,
+                        documentId,
+                        DOCUMENT_TYPE_STORAGE),
+                null,
+                null,
+                null)) {
+            if (cursor.getCount() == 1) {
+                cursor.moveToNext();
+                return createIdentifier(cursor.getString(0));
+            } else {
+                return null;
+            }
+        }
+    }
+
+    /**
      * Queries a single document.
      * @param documentId
      * @param projection
      * @return Database cursor.
      */
-    public Cursor queryDocument(String documentId, String[] projection) {
+    Cursor queryDocument(String documentId, String[] projection) {
         return mDatabase.query(
                 TABLE_DOCUMENTS,
                 projection,
@@ -287,12 +321,12 @@
     }
 
     /**
-     * Obtains parent document ID.
+     * Obtains parent identifier.
      * @param documentId
-     * @return parent document ID.
+     * @return parent identifier.
      * @throws FileNotFoundException
      */
-    String getParentId(String documentId) throws FileNotFoundException {
+    Identifier getParentIdentifier(String documentId) throws FileNotFoundException {
         final Cursor cursor = mDatabase.query(
                 TABLE_DOCUMENTS,
                 strings(COLUMN_PARENT_DOCUMENT_ID),
@@ -304,7 +338,7 @@
                 "1");
         try {
             if (cursor.moveToNext()) {
-                return cursor.getString(0);
+                return createIdentifier(cursor.getString(0));
             } else {
                 throw new FileNotFoundException("Cannot find a row having ID=" + documentId);
             }
@@ -352,7 +386,10 @@
         // Currently documentId is old format.
         final Cursor cursor = mDatabase.query(
                 TABLE_DOCUMENTS,
-                strings(COLUMN_DEVICE_ID, COLUMN_STORAGE_ID, COLUMN_OBJECT_HANDLE),
+                strings(COLUMN_DEVICE_ID,
+                        COLUMN_STORAGE_ID,
+                        COLUMN_OBJECT_HANDLE,
+                        COLUMN_DOCUMENT_TYPE),
                 SELECTION_DOCUMENT_ID,
                 strings(documentId),
                 null,
@@ -367,8 +404,9 @@
                 return new Identifier(
                         cursor.getInt(0),
                         cursor.getInt(1),
-                        cursor.isNull(2) ? Identifier.DUMMY_HANDLE_FOR_ROOT : cursor.getInt(2),
-                        documentId);
+                        cursor.getInt(2),
+                        documentId,
+                        cursor.getInt(3));
             }
         } finally {
             cursor.close();
diff --git a/src/com/android/mtp/MtpDatabaseConstants.java b/src/com/android/mtp/MtpDatabaseConstants.java
index f252e0f..3cfb82f 100644
--- a/src/com/android/mtp/MtpDatabaseConstants.java
+++ b/src/com/android/mtp/MtpDatabaseConstants.java
@@ -16,10 +16,13 @@
 
 package com.android.mtp;
 
+import android.annotation.IntDef;
 import android.database.sqlite.SQLiteQueryBuilder;
 import android.provider.DocumentsContract.Document;
 import android.provider.DocumentsContract.Root;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -92,6 +95,10 @@
      */
     static final int MAP_BY_NAME = 1;
 
+    @IntDef(value = { DOCUMENT_TYPE_DEVICE, DOCUMENT_TYPE_STORAGE, DOCUMENT_TYPE_OBJECT })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface DocumentType {}
+
     /**
      * Document that represents a MTP device.
      */
diff --git a/src/com/android/mtp/MtpDocumentsProvider.java b/src/com/android/mtp/MtpDocumentsProvider.java
index 6b5f16a..775f976 100644
--- a/src/com/android/mtp/MtpDocumentsProvider.java
+++ b/src/com/android/mtp/MtpDocumentsProvider.java
@@ -150,11 +150,22 @@
         if (projection == null) {
             projection = MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION;
         }
-        final Identifier parentIdentifier = mDatabase.createIdentifier(parentDocumentId);
+        Identifier parentIdentifier = mDatabase.createIdentifier(parentDocumentId);
         try {
+            if (parentIdentifier.mDocumentType == MtpDatabaseConstants.DOCUMENT_TYPE_DEVICE) {
+                final Identifier singleStorageIdentifier =
+                        mDatabase.getSingleStorageIdentifier(parentDocumentId);
+                if (singleStorageIdentifier == null) {
+                    // Returns storage list from database.
+                    return mDatabase.queryChildDocuments(projection, parentDocumentId);
+                }
+                parentIdentifier = singleStorageIdentifier;
+            }
+            // Returns object list from document loader.
             return getDocumentLoader(parentIdentifier).queryChildDocuments(
                     projection, parentIdentifier);
         } catch (IOException exception) {
+            Log.e(MtpDocumentsProvider.TAG, "queryChildDocuments", exception);
             throw new FileNotFoundException(exception.getMessage());
         }
     }
@@ -190,6 +201,7 @@
                     throw new IllegalArgumentException("Unknown mode for openDocument: " + mode);
             }
         } catch (IOException error) {
+            Log.e(MtpDocumentsProvider.TAG, "openDocument", error);
             throw new FileNotFoundException(error.getMessage());
         }
     }
@@ -206,6 +218,7 @@
                     0,  // Start offset.
                     AssetFileDescriptor.UNKNOWN_LENGTH);
         } catch (IOException error) {
+            Log.e(MtpDocumentsProvider.TAG, "openDocumentThumbnail", error);
             throw new FileNotFoundException(error.getMessage());
         }
     }
@@ -214,13 +227,20 @@
     public void deleteDocument(String documentId) throws FileNotFoundException {
         try {
             final Identifier identifier = mDatabase.createIdentifier(documentId);
-            final Identifier parentIdentifier =
-                    mDatabase.createIdentifier(mDatabase.getParentId(documentId));
+            final Identifier parentIdentifier = mDatabase.getParentIdentifier(documentId);
             mMtpManager.deleteDocument(identifier.mDeviceId, identifier.mObjectHandle);
             mDatabase.deleteDocument(documentId);
             getDocumentLoader(parentIdentifier).clearTask(parentIdentifier);
             notifyChildDocumentsChange(parentIdentifier.mDocumentId);
+            if (parentIdentifier.mDocumentType == MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE) {
+                // If the parent is storage, the object might be appeared as child of device because
+                // we skip storage when the device has only one storage.
+                final Identifier deviceIdentifier = mDatabase.getParentIdentifier(
+                        parentIdentifier.mDocumentId);
+                notifyChildDocumentsChange(deviceIdentifier.mDocumentId);
+            }
         } catch (IOException error) {
+            Log.e(MtpDocumentsProvider.TAG, "deleteDocument", error);
             throw new FileNotFoundException(error.getMessage());
         }
     }
@@ -259,7 +279,7 @@
             notifyChildDocumentsChange(parentDocumentId);
             return documentId;
         } catch (IOException error) {
-            Log.e(TAG, error.getMessage());
+            Log.e(TAG, "createDocument", error);
             throw new FileNotFoundException(error.getMessage());
         }
     }
diff --git a/tests/src/com/android/mtp/DocumentLoaderTest.java b/tests/src/com/android/mtp/DocumentLoaderTest.java
index f37a55c..5f71606 100644
--- a/tests/src/com/android/mtp/DocumentLoaderTest.java
+++ b/tests/src/com/android/mtp/DocumentLoaderTest.java
@@ -35,7 +35,8 @@
     private BlockableTestMtpManager mManager;
     private TestContentResolver mResolver;
     private DocumentLoader mLoader;
-    final private Identifier mParentIdentifier = new Identifier(0, 0, 0, "1");
+    final private Identifier mParentIdentifier = new Identifier(
+            0, 0, 0, "1", MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE);
 
     @Override
     public void setUp() {
diff --git a/tests/src/com/android/mtp/MtpDatabaseTest.java b/tests/src/com/android/mtp/MtpDatabaseTest.java
index 8075999..4022886 100644
--- a/tests/src/com/android/mtp/MtpDatabaseTest.java
+++ b/tests/src/com/android/mtp/MtpDatabaseTest.java
@@ -122,14 +122,14 @@
             assertEquals(1, cursor.getCount());
 
             cursor.moveToNext();
-            assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals(
                     Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE,
                     getInt(cursor, Root.COLUMN_FLAGS));
             assertEquals(R.drawable.ic_root_mtp, getInt(cursor, Root.COLUMN_ICON));
             assertEquals("Device Storage", getString(cursor, Root.COLUMN_TITLE));
             assertTrue(isNull(cursor, Root.COLUMN_SUMMARY));
-            assertEquals(2, getInt(cursor, Root.COLUMN_DOCUMENT_ID));
+            assertEquals(1, getInt(cursor, Root.COLUMN_DOCUMENT_ID));
             assertEquals(1000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             assertEquals(2000, getInt(cursor, Root.COLUMN_CAPACITY_BYTES));
 
@@ -457,10 +457,10 @@
             final Cursor cursor = mDatabase.queryRoots(rootColumns);
             assertEquals(2, cursor.getCount());
             cursor.moveToNext();
-            assertEquals(3, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals(0, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             cursor.moveToNext();
-            assertEquals(4, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals(0, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             cursor.close();
         }
@@ -496,10 +496,10 @@
             final Cursor cursor = mDatabase.queryRoots(rootColumns);
             assertEquals(2, cursor.getCount());
             cursor.moveToNext();
-            assertEquals(5, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals(2000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             cursor.moveToNext();
-            assertEquals(6, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals(3000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             cursor.close();
         }
@@ -596,7 +596,7 @@
             final Cursor cursor = mDatabase.queryRoots(rootColumns);
             assertEquals(1, cursor.getCount());
             cursor.moveToNext();
-            assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals(3000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             cursor.close();
         }
@@ -679,7 +679,7 @@
             final Cursor cursor = mDatabase.queryRoots(columns);
             assertEquals(1, cursor.getCount());
             cursor.moveToNext();
-            assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID));
+            assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID));
             assertEquals("Device Storage B", getString(cursor, Root.COLUMN_TITLE));
             assertEquals(1000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES));
             cursor.close();
@@ -805,7 +805,7 @@
                 });
         mDatabase.getMapper().stopAddingDocuments("1");
 
-        assertEquals("1", mDatabase.getParentId("2"));
+        assertEquals("1", mDatabase.getParentIdentifier("2").mDocumentId);
     }
 
     public void testDeleteDocument() {
diff --git a/tests/src/com/android/mtp/MtpDocumentsProviderTest.java b/tests/src/com/android/mtp/MtpDocumentsProviderTest.java
index 7066f7d..3606612 100644
--- a/tests/src/com/android/mtp/MtpDocumentsProviderTest.java
+++ b/tests/src/com/android/mtp/MtpDocumentsProviderTest.java
@@ -164,11 +164,11 @@
             final Cursor cursor = mProvider.queryRoots(null);
             assertEquals(2, cursor.getCount());
             cursor.moveToNext();
-            assertEquals("3", cursor.getString(0));
+            assertEquals("1", cursor.getString(0));
             assertEquals(Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE, cursor.getInt(1));
             assertEquals(R.drawable.ic_root_mtp, cursor.getInt(2));
             assertEquals("Device A Storage A", cursor.getString(3));
-            assertEquals("3", cursor.getString(4));
+            assertEquals("1", cursor.getString(4));
             assertEquals(1024, cursor.getInt(5));
         }
 
@@ -179,11 +179,11 @@
             assertEquals(2, cursor.getCount());
             cursor.moveToNext();
             cursor.moveToNext();
-            assertEquals("4", cursor.getString(0));
+            assertEquals("2", cursor.getString(0));
             assertEquals(Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE, cursor.getInt(1));
             assertEquals(R.drawable.ic_root_mtp, cursor.getInt(2));
             assertEquals("Device B Storage B", cursor.getString(3));
-            assertEquals("4", cursor.getString(4));
+            assertEquals("2", cursor.getString(4));
             assertEquals(2048, cursor.getInt(5));
         }
     }
@@ -225,11 +225,11 @@
             assertEquals(0, cursor.getInt(5));
 
             cursor.moveToNext();
-            assertEquals("3", cursor.getString(0));
+            assertEquals("2", cursor.getString(0));
             assertEquals(Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE, cursor.getInt(1));
             assertEquals(R.drawable.ic_root_mtp, cursor.getInt(2));
             assertEquals("Device B Storage B", cursor.getString(3));
-            assertEquals("3", cursor.getString(4));
+            assertEquals("2", cursor.getString(4));
             assertEquals(2048, cursor.getInt(5));
         }
     }
diff --git a/tests/src/com/android/mtp/PipeManagerTest.java b/tests/src/com/android/mtp/PipeManagerTest.java
index ccdea03..4dfc785 100644
--- a/tests/src/com/android/mtp/PipeManagerTest.java
+++ b/tests/src/com/android/mtp/PipeManagerTest.java
@@ -44,13 +44,15 @@
     public void testReadDocument_basic() throws Exception {
         mtpManager.setImportFileBytes(0, 1, HELLO_BYTES);
         final ParcelFileDescriptor descriptor = mPipeManager.readDocument(
-                mtpManager, new Identifier(0, 0, 1, null));
+                mtpManager,
+                new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
         assertDescriptor(descriptor, HELLO_BYTES);
     }
 
     public void testReadDocument_error() throws Exception {
-        final ParcelFileDescriptor descriptor =
-                mPipeManager.readDocument(mtpManager, new Identifier(0, 0, 1, null));
+        final ParcelFileDescriptor descriptor = mPipeManager.readDocument(
+                mtpManager,
+                new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
         assertDescriptorError(descriptor);
     }
 
@@ -62,7 +64,9 @@
 
         // Upload testing bytes.
         final ParcelFileDescriptor descriptor = mPipeManager.writeDocument(
-                getContext(), mtpManager, new Identifier(0, 0, 1, null));
+                getContext(),
+                mtpManager,
+                new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
         final ParcelFileDescriptor.AutoCloseOutputStream outputStream =
                 new ParcelFileDescriptor.AutoCloseOutputStream(descriptor);
         outputStream.write(HELLO_BYTES, 0, HELLO_BYTES.length);
@@ -94,13 +98,15 @@
     public void testReadThumbnail_basic() throws Exception {
         mtpManager.setThumbnail(0, 1, HELLO_BYTES);
         final ParcelFileDescriptor descriptor = mPipeManager.readThumbnail(
-                mtpManager, new Identifier(0, 0, 1, null));
+                mtpManager,
+                new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
         assertDescriptor(descriptor, HELLO_BYTES);
     }
 
     public void testReadThumbnail_error() throws Exception {
-        final ParcelFileDescriptor descriptor =
-                mPipeManager.readThumbnail(mtpManager, new Identifier(0, 0, 1, null));
+        final ParcelFileDescriptor descriptor = mPipeManager.readThumbnail(
+                mtpManager,
+                new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
         assertDescriptorError(descriptor);
     }