Loading packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java +2 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading @@ -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, Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +9 −8 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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, resources.getString( R.string.root_name, values.getAsString(Root.COLUMN_TITLE), storageCursor.getString( storageCursor.getColumnIndex(Root.COLUMN_TITLE))); storageCursor.getColumnIndex(Root.COLUMN_TITLE)))); } } finally { storageCursor.close(); Loading Loading @@ -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(); Loading @@ -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, Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +4 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -89,7 +89,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { mResolver = getContext().getContentResolver(); mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); 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. Loading @@ -116,7 +116,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { mResolver = resolver; mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); 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. Loading @@ -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; Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -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; } Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java +4 −17 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.mtp; import android.content.res.Resources; import android.mtp.MtpStorageInfo; import com.android.internal.annotations.VisibleForTesting; Loading @@ -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; Loading @@ -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(); Loading @@ -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 && Loading @@ -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 + "}"; } } Loading
packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java +2 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading @@ -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, Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +9 −8 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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, resources.getString( R.string.root_name, values.getAsString(Root.COLUMN_TITLE), storageCursor.getString( storageCursor.getColumnIndex(Root.COLUMN_TITLE))); storageCursor.getColumnIndex(Root.COLUMN_TITLE)))); } } finally { storageCursor.close(); Loading Loading @@ -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(); Loading @@ -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, Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +4 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -89,7 +89,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { mResolver = getContext().getContentResolver(); mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); 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. Loading @@ -116,7 +116,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { mResolver = resolver; mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); 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. Loading @@ -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; Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -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; } Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java +4 −17 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.mtp; import android.content.res.Resources; import android.mtp.MtpStorageInfo; import com.android.internal.annotations.VisibleForTesting; Loading @@ -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; Loading @@ -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(); Loading @@ -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 && Loading @@ -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 + "}"; } }