Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b54e036 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Add document type to MtpDatabase.

Currently all document roots represent MTP storage, but we will not have
this assumption after starting show MTP devices (not storage) as
document roots.

To distinguish these two types of roots, the CL adds document type
column to the document table in MtpDatabase.

BUG=26120019

Change-Id: I6ee930008aea0b43c1c42b21a198b07eccbd443d
parent 02668807
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
@@ -35,9 +34,10 @@ import android.provider.DocumentsContract.Root;

import com.android.internal.annotations.VisibleForTesting;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * Database for MTP objects.
@@ -397,6 +397,7 @@ class MtpDatabase {
        values.putNull(COLUMN_OBJECT_HANDLE);
        values.putNull(COLUMN_PARENT_DOCUMENT_ID);
        values.put(COLUMN_ROW_STATE, ROW_STATE_VALID);
        values.put(COLUMN_DOCUMENT_TYPE, DOCUMENT_TYPE_STORAGE);
        values.put(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
        values.put(Document.COLUMN_DISPLAY_NAME, root.getRootName(resources));
        values.putNull(Document.COLUMN_SUMMARY);
@@ -436,6 +437,7 @@ class MtpDatabase {
        values.put(COLUMN_OBJECT_HANDLE, info.getObjectHandle());
        values.put(COLUMN_PARENT_DOCUMENT_ID, parentId);
        values.put(COLUMN_ROW_STATE, ROW_STATE_VALID);
        values.put(COLUMN_DOCUMENT_TYPE, DOCUMENT_TYPE_OBJECT);
        values.put(Document.COLUMN_MIME_TYPE, mimeType);
        values.put(Document.COLUMN_DISPLAY_NAME, info.getName());
        values.putNull(Document.COLUMN_SUMMARY);
+19 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ class MtpDatabaseConstants {
    static final String COLUMN_STORAGE_ID = "storage_id";
    static final String COLUMN_OBJECT_HANDLE = "object_handle";
    static final String COLUMN_PARENT_DOCUMENT_ID = "parent_document_id";
    static final String COLUMN_DOCUMENT_TYPE = "document_type";
    static final String COLUMN_ROW_STATE = "row_state";

    /**
@@ -83,6 +84,23 @@ class MtpDatabaseConstants {
     */
    static final int MAP_BY_NAME = 1;

    /**
     * Document that represents a MTP device.
     * Note we have "device" document only when the device has multiple storage volumes. Otherwise
     * we regard the single "storage" document as root.
     */
    static final int DOCUMENT_TYPE_DEVICE = 0;

    /**
     * Document that represents a MTP storage.
     */
    static final int DOCUMENT_TYPE_STORAGE = 1;

    /**
     * Document that represents a MTP object.
     */
    static final int DOCUMENT_TYPE_OBJECT = 2;

    static final String SELECTION_DOCUMENT_ID = Document.COLUMN_DOCUMENT_ID + " = ?";
    static final String SELECTION_ROOT_ID = Root.COLUMN_ROOT_ID + " = ?";
    static final String SELECTION_ROOT_DOCUMENTS =
@@ -98,6 +116,7 @@ class MtpDatabaseConstants {
            COLUMN_OBJECT_HANDLE + " INTEGER," +
            COLUMN_PARENT_DOCUMENT_ID + " INTEGER," +
            COLUMN_ROW_STATE + " INTEGER NOT NULL," +
            COLUMN_DOCUMENT_TYPE + " INTEGER NOT NULL," +
            Document.COLUMN_MIME_TYPE + " TEXT," +
            Document.COLUMN_DISPLAY_NAME + " TEXT NOT NULL," +
            Document.COLUMN_SUMMARY + " TEXT," +
+10 −1
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ public class MtpDatabaseTest extends AndroidTestCase {
        DocumentsContract.Document.COLUMN_LAST_MODIFIED,
        DocumentsContract.Document.COLUMN_ICON,
        DocumentsContract.Document.COLUMN_FLAGS,
        DocumentsContract.Document.COLUMN_SIZE
        DocumentsContract.Document.COLUMN_SIZE,
        MtpDatabaseConstants.COLUMN_DOCUMENT_TYPE
    };

    private final TestResources resources = new TestResources();
@@ -83,6 +84,8 @@ public class MtpDatabaseTest extends AndroidTestCase {
            assertEquals("icon", R.drawable.ic_root_mtp, cursor.getInt(8));
            assertEquals("flag", 0, cursor.getInt(9));
            assertEquals("size", 1000, cursor.getInt(10));
            assertEquals(
                    "documentType", MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE, cursor.getInt(11));

            cursor.moveToNext();
            assertEquals("documentId", 2, cursor.getInt(0));
@@ -178,6 +181,8 @@ public class MtpDatabaseTest extends AndroidTestCase {
                DocumentsContract.Document.FLAG_SUPPORTS_WRITE,
                cursor.getInt(9));
        assertEquals("size", 1024, cursor.getInt(10));
        assertEquals(
                "documentType", MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT, cursor.getInt(11));

        cursor.moveToNext();
        assertEquals("documentId", 2, cursor.getInt(0));
@@ -195,6 +200,8 @@ public class MtpDatabaseTest extends AndroidTestCase {
                DocumentsContract.Document.FLAG_SUPPORTS_WRITE,
                cursor.getInt(9));
        assertEquals("size", 2 * 1024 * 1024, cursor.getInt(10));
        assertEquals(
                "documentType", MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT, cursor.getInt(11));

        cursor.moveToNext();
        assertEquals("documentId", 3, cursor.getInt(0));
@@ -212,6 +219,8 @@ public class MtpDatabaseTest extends AndroidTestCase {
                DocumentsContract.Document.FLAG_SUPPORTS_WRITE,
                cursor.getInt(9));
        assertEquals("size", 3 * 1024 * 1024, cursor.getInt(10));
        assertEquals(
                "documentType", MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT, cursor.getInt(11));

        cursor.close();
    }