From f83ccbd7edd32e728785fb7aad44f11886e79645 Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Thu, 4 Feb 2016 16:58:55 +0900 Subject: [PATCH] Drop device name from storage document name. When device has multiple storages, storage are shown as directory under the device root. In this case, we would not like to add device name to storage. Note that we still use "device name + storage name" for root name if the device has a single storage because we skip storage directory in this case and shows storage's contents directly under the device. BUG=26625708 Change-Id: Ie13b044e71ae9b5131c4a01ee9d605023d05f168 --- .../src/com/android/mtp/Mapper.java | 8 +- .../src/com/android/mtp/MtpDatabase.java | 17 +- .../com/android/mtp/MtpDocumentsProvider.java | 8 +- .../src/com/android/mtp/MtpManager.java | 4 +- .../src/com/android/mtp/MtpRoot.java | 21 +-- .../src/com/android/mtp/RootScanner.java | 7 +- .../com/android/mtp/DocumentLoaderTest.java | 4 +- .../src/com/android/mtp/MtpDatabaseTest.java | 178 +++++++++--------- .../android/mtp/MtpDocumentsProviderTest.java | 33 ++-- .../src/com/android/mtp/TestResources.java | 5 + 10 files changed, 130 insertions(+), 155 deletions(-) diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java b/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java index ac470671a582c..3faa8f4394f79 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java @@ -20,11 +20,9 @@ import static com.android.mtp.MtpDatabaseConstants.*; import android.annotation.Nullable; import android.content.ContentValues; -import android.content.res.Resources; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteException; import android.mtp.MtpObjectInfo; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Root; @@ -87,12 +85,10 @@ class Mapper { /** * Puts root information to database. * @param parentDocumentId Document ID of device document. - * @param resources Resources required to localize root name. * @param roots List of root information. * @return If roots are added or removed from the database. */ - synchronized boolean putStorageDocuments( - String parentDocumentId, Resources resources, MtpRoot[] roots) { + synchronized boolean putStorageDocuments(String parentDocumentId, MtpRoot[] roots) { final SQLiteDatabase database = mDatabase.getSQLiteDatabase(); database.beginTransaction(); try { @@ -117,7 +113,7 @@ class Mapper { valuesList[i] = new ContentValues(); extraValuesList[i] = new ContentValues(); MtpDatabase.getStorageDocumentValues( - valuesList[i], extraValuesList[i], resources, parentDocumentId, roots[i]); + valuesList[i], extraValuesList[i], parentDocumentId, roots[i]); } final boolean changed = putDocuments( valuesList, diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java index 59d85c1ef8f45..b44f9af3c3bc7 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java @@ -108,7 +108,7 @@ class MtpDatabase { * @param columnNames Column names defined in {@link android.provider.DocumentsContract.Root}. * @return Database cursor. */ - Cursor queryRoots(String[] columnNames) { + Cursor queryRoots(Resources resources, String[] columnNames) { final String selection = COLUMN_ROW_STATE + " IN (?, ?) AND " + COLUMN_DOCUMENT_TYPE + " = ?"; final Cursor deviceCursor = mDatabase.query( @@ -183,10 +183,14 @@ class MtpDatabase { } if (storageCursor.getCount() == 1 && values.containsKey(Root.COLUMN_TITLE)) { storageCursor.moveToFirst(); + // Add storage name to device name if we have only 1 storage. values.put( Root.COLUMN_TITLE, - storageCursor.getString( - storageCursor.getColumnIndex(Root.COLUMN_TITLE))); + resources.getString( + R.string.root_name, + values.getAsString(Root.COLUMN_TITLE), + storageCursor.getString( + storageCursor.getColumnIndex(Root.COLUMN_TITLE)))); } } finally { storageCursor.close(); @@ -533,13 +537,11 @@ class MtpDatabase { /** * Gets {@link ContentValues} for the given root. * @param values {@link ContentValues} that receives values. - * @param resources Resources used to get localized root name. * @param root Root to be converted {@link ContentValues}. */ static void getStorageDocumentValues( ContentValues values, ContentValues extraValues, - Resources resources, String parentDocumentId, MtpRoot root) { values.clear(); @@ -550,13 +552,12 @@ class MtpDatabase { 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.put(Document.COLUMN_DISPLAY_NAME, root.mDescription); 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_SIZE, - (int) Math.min(root.mMaxCapacity - root.mFreeSpace, Integer.MAX_VALUE)); + values.put(Document.COLUMN_SIZE, root.mMaxCapacity - root.mFreeSpace); extraValues.put( Root.COLUMN_FLAGS, diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java index cc7aefc8ad4c8..70a1aae86b959 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java @@ -58,7 +58,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { Document.COLUMN_FLAGS, Document.COLUMN_SIZE, }; - static final boolean DEBUG = true; + static final boolean DEBUG = false; private final Object mDeviceListLock = new Object(); @@ -89,7 +89,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { mResolver = getContext().getContentResolver(); mDeviceToolkits = new HashMap(); mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_FILE); - mRootScanner = new RootScanner(mResolver, mResources, mMtpManager, mDatabase); + mRootScanner = new RootScanner(mResolver, mMtpManager, mDatabase); mAppFuse = new AppFuse(TAG, new AppFuseCallback()); mIntentSender = new ServiceIntentSender(getContext()); // TODO: Mount AppFuse on demands. @@ -116,7 +116,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { mResolver = resolver; mDeviceToolkits = new HashMap(); mDatabase = database; - mRootScanner = new RootScanner(mResolver, mResources, mMtpManager, mDatabase); + mRootScanner = new RootScanner(mResolver, mMtpManager, mDatabase); mAppFuse = new AppFuse(TAG, new AppFuseCallback()); mIntentSender = intentSender; // TODO: Mount AppFuse on demands. @@ -135,7 +135,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { if (projection == null) { projection = MtpDocumentsProvider.DEFAULT_ROOT_PROJECTION; } - final Cursor cursor = mDatabase.queryRoots(projection); + final Cursor cursor = mDatabase.queryRoots(mResources, projection); cursor.setNotificationUri( mResolver, DocumentsContract.buildRootsUri(MtpDocumentsProvider.AUTHORITY)); return cursor; diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java index efe5ff172d78a..5519efd5a323b 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java @@ -273,9 +273,7 @@ class MtpManager { final MtpRoot[] results = new MtpRoot[storageIds.length]; for (int i = 0; i < storageIds.length; i++) { results[i] = new MtpRoot( - device.getDeviceId(), - device.getDeviceInfo().getModel(), - device.getStorageInfo(storageIds[i])); + device.getDeviceId(), device.getStorageInfo(storageIds[i])); } return results; } diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java index ec338c33bc7b8..8530aaff7f958 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java @@ -16,7 +16,6 @@ package com.android.mtp; -import android.content.res.Resources; import android.mtp.MtpStorageInfo; import com.android.internal.annotations.VisibleForTesting; @@ -24,7 +23,6 @@ import com.android.internal.annotations.VisibleForTesting; class MtpRoot { final int mDeviceId; final int mStorageId; - final String mDeviceModelName; final String mDescription; final long mFreeSpace; final long mMaxCapacity; @@ -33,24 +31,21 @@ class MtpRoot { @VisibleForTesting MtpRoot(int deviceId, int storageId, - String deviceName, String description, long freeSpace, long maxCapacity, String volumeIdentifier) { mDeviceId = deviceId; mStorageId = storageId; - mDeviceModelName = deviceName; mDescription = description; mFreeSpace = freeSpace; mMaxCapacity = maxCapacity; mVolumeIdentifier = volumeIdentifier; } - MtpRoot(int deviceId, String deviceModelName, MtpStorageInfo storageInfo) { + MtpRoot(int deviceId, MtpStorageInfo storageInfo) { mDeviceId = deviceId; mStorageId = storageInfo.getStorageId(); - mDeviceModelName = deviceModelName; mDescription = storageInfo.getDescription(); mFreeSpace = storageInfo.getFreeSpace(); mMaxCapacity = storageInfo.getMaxCapacity(); @@ -64,7 +59,6 @@ class MtpRoot { final MtpRoot other = (MtpRoot) object; return mDeviceId == other.mDeviceId && mStorageId == other.mStorageId && - mDeviceModelName.equals(other.mDeviceModelName) && mDescription.equals(other.mDescription) && mFreeSpace == other.mFreeSpace && mMaxCapacity == other.mMaxCapacity && @@ -73,19 +67,12 @@ class MtpRoot { @Override public int hashCode() { - return mDeviceId ^ mStorageId ^ mDeviceModelName.hashCode() ^ mDescription.hashCode() ^ + return mDeviceId ^ mStorageId ^ mDescription.hashCode() ^ ((int) mFreeSpace) ^ ((int) mMaxCapacity) ^ mVolumeIdentifier.hashCode(); } - + @Override public String toString() { - return "MtpRoot{Name: " + mDeviceModelName + " " + mDescription + "}"; - } - - String getRootName(Resources resources) { - return String.format( - resources.getString(R.string.root_name), - mDeviceModelName, - mDescription); + return "MtpRoot{Name: " + mDescription + "}"; } } diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/RootScanner.java b/packages/MtpDocumentsProvider/src/com/android/mtp/RootScanner.java index 39bea49ea6759..a4c3cf4fa5b49 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/RootScanner.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/RootScanner.java @@ -17,7 +17,6 @@ package com.android.mtp; import android.content.ContentResolver; -import android.content.res.Resources; import android.net.Uri; import android.os.Process; import android.provider.DocumentsContract; @@ -52,7 +51,6 @@ final class RootScanner { private final static long AWAIT_TERMINATION_TIMEOUT = 2000; final ContentResolver mResolver; - final Resources mResources; final MtpManager mManager; final MtpDatabase mDatabase; @@ -61,11 +59,9 @@ final class RootScanner { RootScanner( ContentResolver resolver, - Resources resources, MtpManager manager, MtpDatabase database) { mResolver = resolver; - mResources = resources; mManager = manager; mDatabase = database; } @@ -144,8 +140,7 @@ final class RootScanner { continue; } mDatabase.getMapper().startAddingDocuments(documentId); - if (mDatabase.getMapper().putStorageDocuments( - documentId, mResources, device.roots)) { + if (mDatabase.getMapper().putStorageDocuments(documentId, device.roots)) { changed = true; } if (mDatabase.getMapper().stopAddingDocuments(documentId)) { diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/DocumentLoaderTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/DocumentLoaderTest.java index 5f71606dffc59..af1fed49f272f 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/DocumentLoaderTest.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/DocumentLoaderTest.java @@ -42,8 +42,8 @@ public class DocumentLoaderTest extends AndroidTestCase { public void setUp() { mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", new TestResources(), new MtpRoot[] { - new MtpRoot(0, 0, "Device", "Storage", 1000, 1000, "") + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 0, "Storage", 1000, 1000, "") }); mDatabase.getMapper().stopAddingDocuments("deviceDocId"); mManager = new BlockableTestMtpManager(getContext()); diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java index 40228864d4fb3..a49dc6784af42 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java @@ -81,8 +81,8 @@ public class MtpDatabaseTest extends AndroidTestCase { mDatabase.getMapper().stopAddingDocuments(null); mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 1, "Device", "Storage", 1000, 2000, "") + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 1, "Storage", 1000, 2000, "") }); mDatabase.getMapper().stopAddingDocuments("1"); @@ -96,7 +96,7 @@ public class MtpDatabaseTest extends AndroidTestCase { assertEquals(1, getInt(cursor, COLUMN_STORAGE_ID)); assertTrue(isNull(cursor, COLUMN_OBJECT_HANDLE)); assertEquals(DocumentsContract.Document.MIME_TYPE_DIR, getString(cursor, COLUMN_MIME_TYPE)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); assertTrue(isNull(cursor, COLUMN_SUMMARY)); assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); assertEquals(R.drawable.ic_root_mtp, getInt(cursor, COLUMN_ICON)); @@ -109,7 +109,7 @@ public class MtpDatabaseTest extends AndroidTestCase { } { - final Cursor cursor = mDatabase.queryRoots(new String [] { + final Cursor cursor = mDatabase.queryRoots(resources, new String [] { Root.COLUMN_ROOT_ID, Root.COLUMN_FLAGS, Root.COLUMN_ICON, @@ -139,10 +139,10 @@ public class MtpDatabaseTest extends AndroidTestCase { public void testPutStorageDocuments() throws Exception { mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 1, "Device", "Storage", 1000, 2000, ""), - new MtpRoot(0, 2, "Device", "Storage", 2000, 4000, ""), - new MtpRoot(0, 3, "Device", "/@#%&<>Storage", 3000, 6000,"") + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 1, "Storage", 1000, 2000, ""), + new MtpRoot(0, 2, "Storage", 2000, 4000, ""), + new MtpRoot(0, 3, "/@#%&<>Storage", 3000, 6000,"") }); { @@ -155,7 +155,7 @@ public class MtpDatabaseTest extends AndroidTestCase { assertEquals(1, getInt(cursor, COLUMN_STORAGE_ID)); assertTrue(isNull(cursor, COLUMN_OBJECT_HANDLE)); assertEquals(DocumentsContract.Document.MIME_TYPE_DIR, getString(cursor, COLUMN_MIME_TYPE)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); assertTrue(isNull(cursor, COLUMN_SUMMARY)); assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); assertEquals(R.drawable.ic_root_mtp, getInt(cursor, COLUMN_ICON)); @@ -166,11 +166,11 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); - assertEquals("Device /@#%&<>Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("/@#%&<>Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } @@ -264,9 +264,9 @@ public class MtpDatabaseTest extends AndroidTestCase { }; mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 1000, 0, ""), - new MtpRoot(0, 101, "Device", "Storage B", 1001, 0, "") + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 1000, 0, ""), + new MtpRoot(0, 101, "Storage B", 1001, 0, "") }); { @@ -275,11 +275,11 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(1, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(101, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } @@ -291,18 +291,18 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(1, getInt(cursor, COLUMN_DOCUMENT_ID)); assertTrue(isNull(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); assertTrue(isNull(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 200, "Device", "Storage A", 2000, 0, ""), - new MtpRoot(0, 202, "Device", "Storage C", 2002, 0, "") + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 200, "Storage A", 2000, 0, ""), + new MtpRoot(0, 202, "Storage C", 2002, 0, "") }); { @@ -311,15 +311,15 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(1, getInt(cursor, COLUMN_DOCUMENT_ID)); assertTrue(isNull(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); assertTrue(isNull(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(202, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage C", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage C", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } @@ -331,11 +331,11 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(1, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(200, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(202, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage C", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage C", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } } @@ -432,11 +432,11 @@ public class MtpDatabaseTest extends AndroidTestCase { mDatabase.getMapper().startAddingDocuments("1"); mDatabase.getMapper().startAddingDocuments("2"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device A", "Storage", 0, 0, "") + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage", 0, 0, "") }); - mDatabase.getMapper().putStorageDocuments("2", resources, new MtpRoot[] { - new MtpRoot(1, 100, "Device B", "Storage", 0, 0, "") + mDatabase.getMapper().putStorageDocuments("2", new MtpRoot[] { + new MtpRoot(1, 100, "Storage", 0, 0, "") }); { @@ -445,16 +445,16 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device A Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device B Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } { - final Cursor cursor = mDatabase.queryRoots(rootColumns); + final Cursor cursor = mDatabase.queryRoots(resources, rootColumns); assertEquals(2, cursor.getCount()); cursor.moveToNext(); assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); @@ -469,11 +469,11 @@ public class MtpDatabaseTest extends AndroidTestCase { mDatabase.getMapper().startAddingDocuments("1"); mDatabase.getMapper().startAddingDocuments("2"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 200, "Device", "Storage", 2000, 0, "") + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 200, "Storage", 2000, 0, "") }); - mDatabase.getMapper().putStorageDocuments("2", resources, new MtpRoot[] { - new MtpRoot(1, 300, "Device", "Storage", 3000, 0, "") + mDatabase.getMapper().putStorageDocuments("2", new MtpRoot[] { + new MtpRoot(1, 300, "Storage", 3000, 0, "") }); mDatabase.getMapper().stopAddingDocuments("1"); mDatabase.getMapper().stopAddingDocuments("2"); @@ -482,18 +482,18 @@ public class MtpDatabaseTest extends AndroidTestCase { final Cursor cursor = mDatabase.queryRootDocuments(columns); assertEquals(2, cursor.getCount()); cursor.moveToNext(); - assertEquals(5, getInt(cursor, COLUMN_DOCUMENT_ID)); + assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(200, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); - assertEquals(6, getInt(cursor, COLUMN_DOCUMENT_ID)); + assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(300, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } { - final Cursor cursor = mDatabase.queryRoots(rootColumns); + final Cursor cursor = mDatabase.queryRoots(resources, rootColumns); assertEquals(2, cursor.getCount()); cursor.moveToNext(); assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); @@ -562,24 +562,24 @@ public class MtpDatabaseTest extends AndroidTestCase { mDatabase.getMapper().startAddingDocuments(null); mDatabase.getMapper().putDeviceDocument( - new MtpDeviceRecord(0, "Device", false, new MtpRoot[0], null, null)); + new MtpDeviceRecord(0, "Device", false, new MtpRoot[0], null, null)); mDatabase.getMapper().stopAddingDocuments(null); mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage", 0, 0, ""), }); mDatabase.getMapper().clearMapping(); mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 200, "Device", "Storage", 2000, 0, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 200, "Storage", 2000, 0, ""), }); mDatabase.getMapper().clearMapping(); mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 300, "Device", "Storage", 3000, 0, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 300, "Storage", 3000, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("1"); @@ -589,11 +589,11 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(300, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } { - final Cursor cursor = mDatabase.queryRoots(rootColumns); + final Cursor cursor = mDatabase.queryRoots(resources, rootColumns); assertEquals(1, cursor.getCount()); cursor.moveToNext(); assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); @@ -610,15 +610,15 @@ public class MtpDatabaseTest extends AndroidTestCase { }; mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 100, "Storage", 0, 0, ""), }); mDatabase.getMapper().clearMapping(); mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 200, "Device", "Storage", 2000, 0, ""), - new MtpRoot(0, 201, "Device", "Storage", 2001, 0, ""), + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 200, "Storage", 2000, 0, ""), + new MtpRoot(0, 201, "Storage", 2001, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("deviceDocId"); @@ -628,11 +628,11 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(200, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.moveToNext(); assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(201, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } } @@ -646,14 +646,14 @@ public class MtpDatabaseTest extends AndroidTestCase { // The client code should be able to replace existing rows with new information. // Add one. mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("1"); // Replace it. mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage B", 1000, 1000, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage B", 1000, 1000, ""), }); mDatabase.getMapper().stopAddingDocuments("1"); { @@ -667,7 +667,7 @@ public class MtpDatabaseTest extends AndroidTestCase { cursor.moveToNext(); assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); - assertEquals("Device Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); + assertEquals("Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); cursor.close(); } { @@ -676,7 +676,7 @@ public class MtpDatabaseTest extends AndroidTestCase { Root.COLUMN_TITLE, Root.COLUMN_AVAILABLE_BYTES }; - final Cursor cursor = mDatabase.queryRoots(columns); + final Cursor cursor = mDatabase.queryRoots(resources, columns); assertEquals(1, cursor.getCount()); cursor.moveToNext(); assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); @@ -695,21 +695,21 @@ public class MtpDatabaseTest extends AndroidTestCase { mDatabase.getMapper().stopAddingDocuments(null); mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), }); mDatabase.getMapper().clearMapping(); - final Cursor oldCursor = mDatabase.queryRoots(strings(Root.COLUMN_ROOT_ID)); + final Cursor oldCursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_ROOT_ID)); assertEquals(1, oldCursor.getCount()); // Add one. mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 101, "Device", "Storage B", 1000, 1000, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 101, "Storage B", 1000, 1000, ""), }); // Add one more before resolving unmapped documents. - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 102, "Device", "Storage B", 1000, 1000, ""), + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 102, "Storage B", 1000, 1000, ""), }); mDatabase.getMapper().stopAddingDocuments("1"); @@ -729,15 +729,15 @@ public class MtpDatabaseTest extends AndroidTestCase { public void testQueryDocuments() { mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("deviceDocId"); final Cursor cursor = mDatabase.queryDocument("1", strings(Document.COLUMN_DISPLAY_NAME)); assertEquals(1, cursor.getCount()); cursor.moveToNext(); - assertEquals("Device Storage A", getString(cursor, Document.COLUMN_DISPLAY_NAME)); + assertEquals("Storage A", getString(cursor, Document.COLUMN_DISPLAY_NAME)); cursor.close(); } @@ -750,7 +750,7 @@ public class MtpDatabaseTest extends AndroidTestCase { // It the device does not have storages, it shows a device root. { - final Cursor cursor = mDatabase.queryRoots(strings(Root.COLUMN_TITLE)); + final Cursor cursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_TITLE)); assertEquals(1, cursor.getCount()); cursor.moveToNext(); assertEquals("Device", cursor.getString(0)); @@ -758,14 +758,14 @@ public class MtpDatabaseTest extends AndroidTestCase { } mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, "") + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, "") }); mDatabase.getMapper().stopAddingDocuments("1"); // It the device has single storage, it shows a storage root. { - final Cursor cursor = mDatabase.queryRoots(strings(Root.COLUMN_TITLE)); + final Cursor cursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_TITLE)); assertEquals(1, cursor.getCount()); cursor.moveToNext(); assertEquals("Device Storage A", cursor.getString(0)); @@ -773,15 +773,15 @@ public class MtpDatabaseTest extends AndroidTestCase { } mDatabase.getMapper().startAddingDocuments("1"); - mDatabase.getMapper().putStorageDocuments("1", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), - new MtpRoot(0, 101, "Device", "Storage B", 0, 0, "") + mDatabase.getMapper().putStorageDocuments("1", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), + new MtpRoot(0, 101, "Storage B", 0, 0, "") }); mDatabase.getMapper().stopAddingDocuments("1"); // It the device has multiple storages, it shows a device root. { - final Cursor cursor = mDatabase.queryRoots(strings(Root.COLUMN_TITLE)); + final Cursor cursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_TITLE)); assertEquals(1, cursor.getCount()); cursor.moveToNext(); assertEquals("Device", cursor.getString(0)); @@ -791,8 +791,8 @@ public class MtpDatabaseTest extends AndroidTestCase { public void testGetParentId() throws FileNotFoundException { mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("deviceDocId"); @@ -810,8 +810,8 @@ public class MtpDatabaseTest extends AndroidTestCase { public void testDeleteDocument() { mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("deviceDocId"); @@ -854,8 +854,8 @@ public class MtpDatabaseTest extends AndroidTestCase { public void testPutNewDocument() { mDatabase.getMapper().startAddingDocuments("deviceDocId"); - mDatabase.getMapper().putStorageDocuments("deviceDocId", resources, new MtpRoot[] { - new MtpRoot(0, 100, "Device", "Storage A", 0, 0, ""), + mDatabase.getMapper().putStorageDocuments("deviceDocId", new MtpRoot[] { + new MtpRoot(0, 100, "Storage A", 0, 0, ""), }); mDatabase.getMapper().stopAddingDocuments("deviceDocId"); @@ -911,7 +911,7 @@ public class MtpDatabaseTest extends AndroidTestCase { DocumentsContract.Root.COLUMN_TITLE, DocumentsContract.Root.COLUMN_AVAILABLE_BYTES }; - try (final Cursor cursor = mDatabase.queryRoots(columns)) { + try (final Cursor cursor = mDatabase.queryRoots(resources, columns)) { assertEquals(1, cursor.getCount()); assertTrue(cursor.moveToNext()); assertEquals(1, cursor.getLong(0)); diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java index d9e928b7142e3..5b0f55703a2b5 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java @@ -62,13 +62,12 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); mMtpManager.addValidDevice(new MtpDeviceRecord( 0, - "Device", + "Device A", false /* unopened */, new MtpRoot[] { new MtpRoot( 0 /* deviceId */, 1 /* storageId */, - "Device A" /* device model name */, "Storage A" /* volume description */, 1024 /* free space */, 2048 /* total space */, @@ -100,13 +99,12 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { // Check if the following notification is the first one or not. mMtpManager.addValidDevice(new MtpDeviceRecord( 0, - "Device", + "Device A", false /* unopened */, new MtpRoot[] { new MtpRoot( 0 /* deviceId */, 1 /* storageId */, - "Device A" /* device model name */, "Storage A" /* volume description */, 1024 /* free space */, 2048 /* total space */, @@ -130,7 +128,6 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { new MtpRoot( 0 /* deviceId */, 1 /* storageId */, - "Device A" /* device model name */, "Storage A" /* volume description */, 1024 /* free space */, 2048 /* total space */, @@ -169,13 +166,12 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); mMtpManager.addValidDevice(new MtpDeviceRecord( 0, - "Device", + "Device A", false /* unopened */, new MtpRoot[] { new MtpRoot( 0 /* deviceId */, 1 /* storageId */, - "Device A" /* device model name */, "Storage A" /* volume description */, 1024 /* free space */, 2048 /* total space */, @@ -185,13 +181,12 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { null)); mMtpManager.addValidDevice(new MtpDeviceRecord( 1, - "Device", + "Device B", false /* unopened */, new MtpRoot[] { new MtpRoot( 1 /* deviceId */, 1 /* storageId */, - "Device B" /* device model name */, "Storage B" /* volume description */, 2048 /* free space */, 4096 /* total space */, @@ -242,7 +237,6 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { new MtpRoot( 1 /* deviceId */, 1 /* storageId */, - "Device B" /* device model name */, "Storage B" /* volume description */, 2048 /* free space */, 4096 /* total space */, @@ -282,7 +276,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { public void testQueryDocument() throws IOException, InterruptedException, TimeoutException { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); - setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Device", "Storage", 1000, 1000, "") }); + setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 1000, 1000, "") }); setupDocuments( 0, 0, @@ -319,7 +313,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { public void testQueryDocument_directory() throws IOException, InterruptedException, TimeoutException { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); - setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Device", "Storage", 1000, 1000, "") }); + setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 1000, 1000, "") }); setupDocuments( 0, 0, @@ -358,7 +352,6 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { new MtpRoot( 0 /* deviceId */, 1 /* storageId */, - "Device A" /* device model name */, "Storage A" /* volume description */, 1024 /* free space */, 4096 /* total space */, @@ -370,7 +363,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { cursor.moveToNext(); assertEquals("2", cursor.getString(0)); assertEquals(DocumentsContract.Document.MIME_TYPE_DIR, cursor.getString(1)); - assertEquals("Device A Storage A", cursor.getString(2)); + assertEquals("Storage A", cursor.getString(2)); assertTrue(cursor.isNull(3)); assertEquals(0, cursor.getInt(4)); assertEquals(3072, cursor.getInt(5)); @@ -378,7 +371,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { public void testQueryChildDocuments() throws Exception { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); - setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Device", "Storage", 1000, 1000, "") }); + setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 1000, 1000, "") }); setupDocuments( 0, 0, @@ -421,7 +414,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { public void testQueryChildDocuments_documentError() throws Exception { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); - setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Device", "Storage", 1000, 1000, "") }); + setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 1000, 1000, "") }); mMtpManager.setObjectHandles(0, 0, -1, new int[] { 1 }); try { mProvider.queryChildDocuments("1", null, null); @@ -434,7 +427,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { public void testDeleteDocument() throws IOException, InterruptedException, TimeoutException { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); setupRoots(0, new MtpRoot[] { - new MtpRoot(0, 0, "Device", "Storage", 0, 0, "") + new MtpRoot(0, 0, "Storage", 0, 0, "") }); setupDocuments(0, 0, MtpManager.OBJECT_HANDLE_ROOT_CHILDREN, "1", new MtpObjectInfo[] { new MtpObjectInfo.Builder() @@ -454,7 +447,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { throws IOException, InterruptedException, TimeoutException { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); setupRoots(0, new MtpRoot[] { - new MtpRoot(0, 0, "Device", "Storage", 0, 0, "") + new MtpRoot(0, 0, "Storage", 0, 0, "") }); setupDocuments(0, 0, MtpManager.OBJECT_HANDLE_ROOT_CHILDREN, "1", new MtpObjectInfo[] { new MtpObjectInfo.Builder() @@ -477,7 +470,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { public void testOpenDocument() throws Exception { setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); setupRoots(0, new MtpRoot[] { - new MtpRoot(0, 0, "Device", "Storage", 0, 0, "") + new MtpRoot(0, 0, "Storage", 0, 0, "") }); final byte[] bytes = "Hello world".getBytes(); setupDocuments(0, 0, MtpManager.OBJECT_HANDLE_ROOT_CHILDREN, "1", new MtpObjectInfo[] { @@ -515,7 +508,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase { }; setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); setupRoots(0, new MtpRoot[] { - new MtpRoot(0, 0, "Device", "Storage", 0, 0, "") + new MtpRoot(0, 0, "Storage", 0, 0, "") }); final byte[] bytes = "Hello world".getBytes(); setupDocuments(0, 0, MtpManager.OBJECT_HANDLE_ROOT_CHILDREN, "1", new MtpObjectInfo[] { diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestResources.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestResources.java index eb80e3b60e6a5..b23038b6c3f60 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestResources.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestResources.java @@ -27,4 +27,9 @@ class TestResources extends MockResources { } throw new NotFoundException(); } + + @Override + public String getString(int id, Object... formatArgs) throws NotFoundException { + return String.format(getString(id), formatArgs); + } }