Loading packages/MtpDocumentsProvider/res/values/strings.xml +5 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,11 @@ limitations under the License. --> <resources> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Title of the external storage application [CHAR LIMIT=32] --> <string name="app_label">MTP Storage</string> <!-- Name of MTP root shown in UI. Please align the two strings (device model and storage name) in proper order in the language. [CHAR LIMIT=32] --> <string name="root_name"><xliff:g id="device_model" example="Nexus 9">%1$s</xliff:g> <xliff:g id="storage_name" example="Internal Storage">%2$s</xliff:g></string> </resources> packages/MtpDocumentsProvider/src/com/android/mtp/CursorHelper.java +3 −4 Original line number Diff line number Diff line Loading @@ -16,25 +16,24 @@ package com.android.mtp; import android.content.res.Resources; import android.database.MatrixCursor; import android.mtp.MtpConstants; import android.mtp.MtpObjectInfo; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; import java.util.Date; final class CursorHelper { static final int DUMMY_HANDLE_FOR_ROOT = 0; private CursorHelper() { } static void addToCursor(MtpRoot root, MatrixCursor.RowBuilder builder) { static void addToCursor(Resources resources, MtpRoot root, MatrixCursor.RowBuilder builder) { final Identifier identifier = new Identifier( root.mDeviceId, root.mStorageId, DUMMY_HANDLE_FOR_ROOT); builder.add(Document.COLUMN_DOCUMENT_ID, identifier.toDocumentId()); builder.add(Document.COLUMN_DISPLAY_NAME, root.mDescription); builder.add(Document.COLUMN_DISPLAY_NAME, root.getRootName(resources)); builder.add(Document.COLUMN_MIME_TYPE, DocumentsContract.Document.MIME_TYPE_DIR); builder.add(Document.COLUMN_LAST_MODIFIED, null); builder.add(Document.COLUMN_FLAGS, 0); Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +8 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.mtp; import android.content.ContentResolver; import android.content.res.AssetFileDescriptor; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; import android.graphics.Point; Loading Loading @@ -59,8 +60,8 @@ public class MtpDocumentsProvider extends DocumentsProvider { private MtpManager mMtpManager; private ContentResolver mResolver; private Map<Integer, DeviceToolkit> mDeviceToolkits; private DocumentLoader mDocumentLoaders; private RootScanner mRootScanner; private Resources mResources; /** * Provides singleton instance to MtpDocumentsService. Loading @@ -72,6 +73,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { @Override public boolean onCreate() { sSingleton = this; mResources = getContext().getResources(); mMtpManager = new MtpManager(getContext()); mResolver = getContext().getContentResolver(); mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); Loading @@ -80,7 +82,8 @@ public class MtpDocumentsProvider extends DocumentsProvider { } @VisibleForTesting void onCreateForTesting(MtpManager mtpManager, ContentResolver resolver) { void onCreateForTesting(Resources resources, MtpManager mtpManager, ContentResolver resolver) { mResources = resources; mMtpManager = mtpManager; mResolver = resolver; mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); Loading @@ -99,10 +102,8 @@ public class MtpDocumentsProvider extends DocumentsProvider { final MatrixCursor.RowBuilder builder = cursor.newRow(); builder.add(Root.COLUMN_ROOT_ID, rootIdentifier.toRootId()); builder.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE); builder.add(Root.COLUMN_TITLE, root.mDescription); builder.add( Root.COLUMN_DOCUMENT_ID, rootIdentifier.toDocumentId()); builder.add(Root.COLUMN_TITLE, root.getRootName(mResources)); builder.add(Root.COLUMN_DOCUMENT_ID, rootIdentifier.toDocumentId()); builder.add(Root.COLUMN_AVAILABLE_BYTES , root.mFreeSpace); } cursor.setNotificationUri( Loading Loading @@ -143,7 +144,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { if (identifier.mStorageId != root.mStorageId) continue; final MatrixCursor cursor = new MatrixCursor(projection); CursorHelper.addToCursor(root, cursor.newRow()); CursorHelper.addToCursor(mResources, root, cursor.newRow()); return cursor; } } Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -107,7 +107,10 @@ class MtpManager { } final MtpRoot[] results = new MtpRoot[storageIds.length]; for (int i = 0; i < storageIds.length; i++) { results[i] = new MtpRoot(deviceId, device.getStorageInfo(storageIds[i])); results[i] = new MtpRoot( device.getDeviceId(), device.getDeviceInfo().getModel(), device.getStorageInfo(storageIds[i])); } return results; } Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java +21 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.mtp; import android.content.res.Resources; import android.mtp.MtpStorageInfo; import com.android.internal.annotations.VisibleForTesting; Loading @@ -23,6 +24,7 @@ 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 @@ -31,21 +33,24 @@ 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, MtpStorageInfo storageInfo) { MtpRoot(int deviceId, String deviceModelName, MtpStorageInfo storageInfo) { mDeviceId = deviceId; mStorageId = storageInfo.getStorageId(); mDeviceModelName = deviceModelName; mDescription = storageInfo.getDescription(); mFreeSpace = storageInfo.getFreeSpace(); mMaxCapacity = storageInfo.getMaxCapacity(); Loading @@ -59,6 +64,7 @@ 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 @@ -67,7 +73,19 @@ class MtpRoot { @Override public int hashCode() { return mDeviceId ^ mStorageId ^ mDescription.hashCode() ^ ((int) mFreeSpace) ^ ((int) mMaxCapacity) ^ mVolumeIdentifier.hashCode(); return mDeviceId ^ mStorageId ^ mDeviceModelName.hashCode() ^ 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); } } Loading
packages/MtpDocumentsProvider/res/values/strings.xml +5 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,11 @@ limitations under the License. --> <resources> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Title of the external storage application [CHAR LIMIT=32] --> <string name="app_label">MTP Storage</string> <!-- Name of MTP root shown in UI. Please align the two strings (device model and storage name) in proper order in the language. [CHAR LIMIT=32] --> <string name="root_name"><xliff:g id="device_model" example="Nexus 9">%1$s</xliff:g> <xliff:g id="storage_name" example="Internal Storage">%2$s</xliff:g></string> </resources>
packages/MtpDocumentsProvider/src/com/android/mtp/CursorHelper.java +3 −4 Original line number Diff line number Diff line Loading @@ -16,25 +16,24 @@ package com.android.mtp; import android.content.res.Resources; import android.database.MatrixCursor; import android.mtp.MtpConstants; import android.mtp.MtpObjectInfo; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; import java.util.Date; final class CursorHelper { static final int DUMMY_HANDLE_FOR_ROOT = 0; private CursorHelper() { } static void addToCursor(MtpRoot root, MatrixCursor.RowBuilder builder) { static void addToCursor(Resources resources, MtpRoot root, MatrixCursor.RowBuilder builder) { final Identifier identifier = new Identifier( root.mDeviceId, root.mStorageId, DUMMY_HANDLE_FOR_ROOT); builder.add(Document.COLUMN_DOCUMENT_ID, identifier.toDocumentId()); builder.add(Document.COLUMN_DISPLAY_NAME, root.mDescription); builder.add(Document.COLUMN_DISPLAY_NAME, root.getRootName(resources)); builder.add(Document.COLUMN_MIME_TYPE, DocumentsContract.Document.MIME_TYPE_DIR); builder.add(Document.COLUMN_LAST_MODIFIED, null); builder.add(Document.COLUMN_FLAGS, 0); Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +8 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.mtp; import android.content.ContentResolver; import android.content.res.AssetFileDescriptor; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; import android.graphics.Point; Loading Loading @@ -59,8 +60,8 @@ public class MtpDocumentsProvider extends DocumentsProvider { private MtpManager mMtpManager; private ContentResolver mResolver; private Map<Integer, DeviceToolkit> mDeviceToolkits; private DocumentLoader mDocumentLoaders; private RootScanner mRootScanner; private Resources mResources; /** * Provides singleton instance to MtpDocumentsService. Loading @@ -72,6 +73,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { @Override public boolean onCreate() { sSingleton = this; mResources = getContext().getResources(); mMtpManager = new MtpManager(getContext()); mResolver = getContext().getContentResolver(); mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); Loading @@ -80,7 +82,8 @@ public class MtpDocumentsProvider extends DocumentsProvider { } @VisibleForTesting void onCreateForTesting(MtpManager mtpManager, ContentResolver resolver) { void onCreateForTesting(Resources resources, MtpManager mtpManager, ContentResolver resolver) { mResources = resources; mMtpManager = mtpManager; mResolver = resolver; mDeviceToolkits = new HashMap<Integer, DeviceToolkit>(); Loading @@ -99,10 +102,8 @@ public class MtpDocumentsProvider extends DocumentsProvider { final MatrixCursor.RowBuilder builder = cursor.newRow(); builder.add(Root.COLUMN_ROOT_ID, rootIdentifier.toRootId()); builder.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE); builder.add(Root.COLUMN_TITLE, root.mDescription); builder.add( Root.COLUMN_DOCUMENT_ID, rootIdentifier.toDocumentId()); builder.add(Root.COLUMN_TITLE, root.getRootName(mResources)); builder.add(Root.COLUMN_DOCUMENT_ID, rootIdentifier.toDocumentId()); builder.add(Root.COLUMN_AVAILABLE_BYTES , root.mFreeSpace); } cursor.setNotificationUri( Loading Loading @@ -143,7 +144,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { if (identifier.mStorageId != root.mStorageId) continue; final MatrixCursor cursor = new MatrixCursor(projection); CursorHelper.addToCursor(root, cursor.newRow()); CursorHelper.addToCursor(mResources, root, cursor.newRow()); return cursor; } } Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -107,7 +107,10 @@ class MtpManager { } final MtpRoot[] results = new MtpRoot[storageIds.length]; for (int i = 0; i < storageIds.length; i++) { results[i] = new MtpRoot(deviceId, device.getStorageInfo(storageIds[i])); results[i] = new MtpRoot( device.getDeviceId(), device.getDeviceInfo().getModel(), device.getStorageInfo(storageIds[i])); } return results; } Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpRoot.java +21 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.mtp; import android.content.res.Resources; import android.mtp.MtpStorageInfo; import com.android.internal.annotations.VisibleForTesting; Loading @@ -23,6 +24,7 @@ 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 @@ -31,21 +33,24 @@ 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, MtpStorageInfo storageInfo) { MtpRoot(int deviceId, String deviceModelName, MtpStorageInfo storageInfo) { mDeviceId = deviceId; mStorageId = storageInfo.getStorageId(); mDeviceModelName = deviceModelName; mDescription = storageInfo.getDescription(); mFreeSpace = storageInfo.getFreeSpace(); mMaxCapacity = storageInfo.getMaxCapacity(); Loading @@ -59,6 +64,7 @@ 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 @@ -67,7 +73,19 @@ class MtpRoot { @Override public int hashCode() { return mDeviceId ^ mStorageId ^ mDescription.hashCode() ^ ((int) mFreeSpace) ^ ((int) mMaxCapacity) ^ mVolumeIdentifier.hashCode(); return mDeviceId ^ mStorageId ^ mDeviceModelName.hashCode() ^ 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); } }