Loading api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -18164,6 +18164,7 @@ package android.mtp { method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int); method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int); method public android.mtp.MtpObjectInfo.Builder setParent(int); method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int); method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int); api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -19676,6 +19676,7 @@ package android.mtp { method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int); method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int); method public android.mtp.MtpObjectInfo.Builder setParent(int); method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int); method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int); media/java/android/mtp/MtpObjectInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -294,6 +294,11 @@ public final class MtpObjectInfo { mObjectInfo.mThumbPixWidth = objectInfo.mThumbPixWidth; } public Builder setObjectHandle(int value) { mObjectInfo.mHandle = value; return this; } public Builder setAssociationDesc(int value) { mObjectInfo.mAssociationDesc = value; return this; Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocument.java→packages/MtpDocumentsProvider/src/com/android/mtp/CursorHelper.java +99 −0 Original line number Diff line number Diff line Loading @@ -23,83 +23,50 @@ import android.provider.DocumentsContract.Document; import java.util.Date; class MtpDocument { final class CursorHelper { static final int DUMMY_HANDLE_FOR_ROOT = 0; private final int mObjectHandle; private final int mFormat; private final String mName; private final Date mDateModified; private final int mSize; private final int mThumbSize; private final boolean mReadOnly; /** * Constructor for root document. */ MtpDocument(MtpRoot root) { this(DUMMY_HANDLE_FOR_ROOT, 0x3001, // Directory. root.mDescription, null, // Unknown name. (int) Math.min(root.mMaxCapacity - root.mFreeSpace, Integer.MAX_VALUE), 0, // Total size. true); // Writable. } MtpDocument(MtpObjectInfo objectInfo) { this(objectInfo.getObjectHandle(), objectInfo.getFormat(), objectInfo.getName(), objectInfo.getDateModified() != 0 ? new Date(objectInfo.getDateModified()) : null, objectInfo.getCompressedSize(), objectInfo.getThumbCompressedSize(), objectInfo.getProtectionStatus() != 0); private CursorHelper() { } MtpDocument(int objectHandle, int format, String name, Date dateModified, int size, int thumbSize, boolean readOnly) { this.mObjectHandle = objectHandle; this.mFormat = format; this.mName = name; this.mDateModified = dateModified; this.mSize = size; this.mThumbSize = thumbSize; this.mReadOnly = readOnly; static void addToCursor(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_MIME_TYPE, DocumentsContract.Document.MIME_TYPE_DIR); builder.add(Document.COLUMN_LAST_MODIFIED, null); builder.add(Document.COLUMN_FLAGS, 0); builder.add(Document.COLUMN_SIZE, (int) Math.min(root.mMaxCapacity - root.mFreeSpace, Integer.MAX_VALUE)); } void addToCursor(Identifier rootIdentifier, MatrixCursor.RowBuilder builder) { static void addToCursor(MtpObjectInfo objectInfo, Identifier rootIdentifier, MatrixCursor.RowBuilder builder) { final Identifier identifier = new Identifier( rootIdentifier.mDeviceId, rootIdentifier.mStorageId, mObjectHandle); final String mimeType = formatTypeToMimeType(mFormat); rootIdentifier.mDeviceId, rootIdentifier.mStorageId, objectInfo.getObjectHandle()); final String mimeType = formatTypeToMimeType(objectInfo.getFormat()); int flag = 0; if (mObjectHandle != DUMMY_HANDLE_FOR_ROOT) { if (mThumbSize > 0) { flag |= DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL; } if (!mReadOnly) { if (objectInfo.getProtectionStatus() == 0) { flag |= DocumentsContract.Document.FLAG_SUPPORTS_DELETE | DocumentsContract.Document.FLAG_SUPPORTS_WRITE; if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) { flag |= DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE; } } if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR && !mReadOnly) { flag |= DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE; if (objectInfo.getThumbCompressedSize() > 0) { flag |= DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL; } builder.add(Document.COLUMN_DOCUMENT_ID, identifier.toDocumentId()); builder.add(Document.COLUMN_DISPLAY_NAME, mName); builder.add(Document.COLUMN_DISPLAY_NAME, objectInfo.getName()); builder.add(Document.COLUMN_MIME_TYPE, mimeType); builder.add( Document.COLUMN_LAST_MODIFIED, mDateModified != null ? mDateModified.getTime() : null); objectInfo.getDateModified() != 0 ? objectInfo.getDateModified() : null); builder.add(Document.COLUMN_FLAGS, flag); builder.add(Document.COLUMN_SIZE, mSize); builder.add(Document.COLUMN_SIZE, objectInfo.getCompressedSize()); } static String formatTypeToMimeType(int format) { Loading packages/MtpDocumentsProvider/src/com/android/mtp/DocumentLoader.java +19 −17 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.mtp; import android.content.ContentResolver; import android.database.Cursor; import android.database.MatrixCursor; import android.mtp.MtpObjectInfo; import android.net.Uri; import android.os.Bundle; import android.os.Process; Loading @@ -34,6 +35,7 @@ import java.util.LinkedList; * Loader for MTP document. * At the first request, the loader returns only first NUM_INITIAL_ENTRIES. Then it launches * background thread to load the rest documents and caches its result for next requests. * TODO: Rename this class to ObjectInfoLoader */ class DocumentLoader { static final int NUM_INITIAL_ENTRIES = 10; Loading @@ -50,13 +52,13 @@ class DocumentLoader { mResolver = resolver; } private static MtpDocument[] loadDocuments(MtpManager manager, int deviceId, int[] handles) private static MtpObjectInfo[] loadDocuments(MtpManager manager, int deviceId, int[] handles) throws IOException { final MtpDocument[] documents = new MtpDocument[handles.length]; final MtpObjectInfo[] objectInfos = new MtpObjectInfo[handles.length]; for (int i = 0; i < handles.length; i++) { documents[i] = manager.getDocument(deviceId, handles[i]); objectInfos[i] = manager.getObjectInfo(deviceId, handles[i]); } return documents; return objectInfos; } synchronized Cursor queryChildDocuments(String[] columnNames, Identifier parent) Loading @@ -66,7 +68,7 @@ class DocumentLoader { 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 == MtpDocument.DUMMY_HANDLE_FOR_ROOT) { if (parentHandle == CursorHelper.DUMMY_HANDLE_FOR_ROOT) { parentHandle = MtpManager.OBJECT_HANDLE_ROOT_CHILDREN; } task = new LoaderTask(parent, mMtpManager.getObjectHandles( Loading Loading @@ -114,16 +116,16 @@ class DocumentLoader { deviceId = task.mIdentifier.mDeviceId; handles = task.getUnloadedObjectHandles(NUM_LOADING_ENTRIES); } MtpDocument[] documents; MtpObjectInfo[] objectInfos; try { documents = loadDocuments(mMtpManager, deviceId, handles); objectInfos = loadDocuments(mMtpManager, deviceId, handles); } catch (IOException exception) { documents = null; objectInfos = null; Log.d(MtpDocumentsProvider.TAG, exception.getMessage()); } synchronized (DocumentLoader.this) { if (documents != null) { task.fillDocuments(documents); if (objectInfos != null) { task.fillDocuments(objectInfos); final boolean shouldNotify = task.mLastNotified.getTime() < new Date().getTime() - NOTIFY_PERIOD_MS || Loading Loading @@ -182,14 +184,14 @@ class DocumentLoader { private static class LoaderTask { final Identifier mIdentifier; final int[] mObjectHandles; final MtpDocument[] mDocuments; final MtpObjectInfo[] mObjectInfos; Date mLastNotified; int mNumLoaded; LoaderTask(Identifier identifier, int[] objectHandles) { mIdentifier = identifier; mObjectHandles = objectHandles; mDocuments = new MtpDocument[mObjectHandles.length]; mObjectInfos = new MtpObjectInfo[mObjectHandles.length]; mNumLoaded = 0; mLastNotified = new Date(); } Loading @@ -199,7 +201,7 @@ class DocumentLoader { final Identifier rootIdentifier = new Identifier( mIdentifier.mDeviceId, mIdentifier.mStorageId); for (int i = 0; i < mNumLoaded; i++) { mDocuments[i].addToCursor(rootIdentifier, cursor.newRow()); CursorHelper.addToCursor(mObjectInfos[i], rootIdentifier, cursor.newRow()); } final Bundle extras = new Bundle(); extras.putBoolean(DocumentsContract.EXTRA_LOADING, !completed()); Loading @@ -209,7 +211,7 @@ class DocumentLoader { } boolean completed() { return mNumLoaded == mDocuments.length; return mNumLoaded == mObjectInfos.length; } int[] getUnloadedObjectHandles(int count) { Loading @@ -224,9 +226,9 @@ class DocumentLoader { mLastNotified = new Date(); } void fillDocuments(MtpDocument[] documents) { for (int i = 0; i < documents.length; i++) { mDocuments[mNumLoaded++] = documents[i]; void fillDocuments(MtpObjectInfo[] objectInfos) { for (int i = 0; i < objectInfos.length; i++) { mObjectInfos[mNumLoaded++] = objectInfos[i]; } } Loading Loading
api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -18164,6 +18164,7 @@ package android.mtp { method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int); method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int); method public android.mtp.MtpObjectInfo.Builder setParent(int); method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int); method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int);
api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -19676,6 +19676,7 @@ package android.mtp { method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int); method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String); method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int); method public android.mtp.MtpObjectInfo.Builder setParent(int); method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int); method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int);
media/java/android/mtp/MtpObjectInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -294,6 +294,11 @@ public final class MtpObjectInfo { mObjectInfo.mThumbPixWidth = objectInfo.mThumbPixWidth; } public Builder setObjectHandle(int value) { mObjectInfo.mHandle = value; return this; } public Builder setAssociationDesc(int value) { mObjectInfo.mAssociationDesc = value; return this; Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocument.java→packages/MtpDocumentsProvider/src/com/android/mtp/CursorHelper.java +99 −0 Original line number Diff line number Diff line Loading @@ -23,83 +23,50 @@ import android.provider.DocumentsContract.Document; import java.util.Date; class MtpDocument { final class CursorHelper { static final int DUMMY_HANDLE_FOR_ROOT = 0; private final int mObjectHandle; private final int mFormat; private final String mName; private final Date mDateModified; private final int mSize; private final int mThumbSize; private final boolean mReadOnly; /** * Constructor for root document. */ MtpDocument(MtpRoot root) { this(DUMMY_HANDLE_FOR_ROOT, 0x3001, // Directory. root.mDescription, null, // Unknown name. (int) Math.min(root.mMaxCapacity - root.mFreeSpace, Integer.MAX_VALUE), 0, // Total size. true); // Writable. } MtpDocument(MtpObjectInfo objectInfo) { this(objectInfo.getObjectHandle(), objectInfo.getFormat(), objectInfo.getName(), objectInfo.getDateModified() != 0 ? new Date(objectInfo.getDateModified()) : null, objectInfo.getCompressedSize(), objectInfo.getThumbCompressedSize(), objectInfo.getProtectionStatus() != 0); private CursorHelper() { } MtpDocument(int objectHandle, int format, String name, Date dateModified, int size, int thumbSize, boolean readOnly) { this.mObjectHandle = objectHandle; this.mFormat = format; this.mName = name; this.mDateModified = dateModified; this.mSize = size; this.mThumbSize = thumbSize; this.mReadOnly = readOnly; static void addToCursor(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_MIME_TYPE, DocumentsContract.Document.MIME_TYPE_DIR); builder.add(Document.COLUMN_LAST_MODIFIED, null); builder.add(Document.COLUMN_FLAGS, 0); builder.add(Document.COLUMN_SIZE, (int) Math.min(root.mMaxCapacity - root.mFreeSpace, Integer.MAX_VALUE)); } void addToCursor(Identifier rootIdentifier, MatrixCursor.RowBuilder builder) { static void addToCursor(MtpObjectInfo objectInfo, Identifier rootIdentifier, MatrixCursor.RowBuilder builder) { final Identifier identifier = new Identifier( rootIdentifier.mDeviceId, rootIdentifier.mStorageId, mObjectHandle); final String mimeType = formatTypeToMimeType(mFormat); rootIdentifier.mDeviceId, rootIdentifier.mStorageId, objectInfo.getObjectHandle()); final String mimeType = formatTypeToMimeType(objectInfo.getFormat()); int flag = 0; if (mObjectHandle != DUMMY_HANDLE_FOR_ROOT) { if (mThumbSize > 0) { flag |= DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL; } if (!mReadOnly) { if (objectInfo.getProtectionStatus() == 0) { flag |= DocumentsContract.Document.FLAG_SUPPORTS_DELETE | DocumentsContract.Document.FLAG_SUPPORTS_WRITE; if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) { flag |= DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE; } } if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR && !mReadOnly) { flag |= DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE; if (objectInfo.getThumbCompressedSize() > 0) { flag |= DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL; } builder.add(Document.COLUMN_DOCUMENT_ID, identifier.toDocumentId()); builder.add(Document.COLUMN_DISPLAY_NAME, mName); builder.add(Document.COLUMN_DISPLAY_NAME, objectInfo.getName()); builder.add(Document.COLUMN_MIME_TYPE, mimeType); builder.add( Document.COLUMN_LAST_MODIFIED, mDateModified != null ? mDateModified.getTime() : null); objectInfo.getDateModified() != 0 ? objectInfo.getDateModified() : null); builder.add(Document.COLUMN_FLAGS, flag); builder.add(Document.COLUMN_SIZE, mSize); builder.add(Document.COLUMN_SIZE, objectInfo.getCompressedSize()); } static String formatTypeToMimeType(int format) { Loading
packages/MtpDocumentsProvider/src/com/android/mtp/DocumentLoader.java +19 −17 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.mtp; import android.content.ContentResolver; import android.database.Cursor; import android.database.MatrixCursor; import android.mtp.MtpObjectInfo; import android.net.Uri; import android.os.Bundle; import android.os.Process; Loading @@ -34,6 +35,7 @@ import java.util.LinkedList; * Loader for MTP document. * At the first request, the loader returns only first NUM_INITIAL_ENTRIES. Then it launches * background thread to load the rest documents and caches its result for next requests. * TODO: Rename this class to ObjectInfoLoader */ class DocumentLoader { static final int NUM_INITIAL_ENTRIES = 10; Loading @@ -50,13 +52,13 @@ class DocumentLoader { mResolver = resolver; } private static MtpDocument[] loadDocuments(MtpManager manager, int deviceId, int[] handles) private static MtpObjectInfo[] loadDocuments(MtpManager manager, int deviceId, int[] handles) throws IOException { final MtpDocument[] documents = new MtpDocument[handles.length]; final MtpObjectInfo[] objectInfos = new MtpObjectInfo[handles.length]; for (int i = 0; i < handles.length; i++) { documents[i] = manager.getDocument(deviceId, handles[i]); objectInfos[i] = manager.getObjectInfo(deviceId, handles[i]); } return documents; return objectInfos; } synchronized Cursor queryChildDocuments(String[] columnNames, Identifier parent) Loading @@ -66,7 +68,7 @@ class DocumentLoader { 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 == MtpDocument.DUMMY_HANDLE_FOR_ROOT) { if (parentHandle == CursorHelper.DUMMY_HANDLE_FOR_ROOT) { parentHandle = MtpManager.OBJECT_HANDLE_ROOT_CHILDREN; } task = new LoaderTask(parent, mMtpManager.getObjectHandles( Loading Loading @@ -114,16 +116,16 @@ class DocumentLoader { deviceId = task.mIdentifier.mDeviceId; handles = task.getUnloadedObjectHandles(NUM_LOADING_ENTRIES); } MtpDocument[] documents; MtpObjectInfo[] objectInfos; try { documents = loadDocuments(mMtpManager, deviceId, handles); objectInfos = loadDocuments(mMtpManager, deviceId, handles); } catch (IOException exception) { documents = null; objectInfos = null; Log.d(MtpDocumentsProvider.TAG, exception.getMessage()); } synchronized (DocumentLoader.this) { if (documents != null) { task.fillDocuments(documents); if (objectInfos != null) { task.fillDocuments(objectInfos); final boolean shouldNotify = task.mLastNotified.getTime() < new Date().getTime() - NOTIFY_PERIOD_MS || Loading Loading @@ -182,14 +184,14 @@ class DocumentLoader { private static class LoaderTask { final Identifier mIdentifier; final int[] mObjectHandles; final MtpDocument[] mDocuments; final MtpObjectInfo[] mObjectInfos; Date mLastNotified; int mNumLoaded; LoaderTask(Identifier identifier, int[] objectHandles) { mIdentifier = identifier; mObjectHandles = objectHandles; mDocuments = new MtpDocument[mObjectHandles.length]; mObjectInfos = new MtpObjectInfo[mObjectHandles.length]; mNumLoaded = 0; mLastNotified = new Date(); } Loading @@ -199,7 +201,7 @@ class DocumentLoader { final Identifier rootIdentifier = new Identifier( mIdentifier.mDeviceId, mIdentifier.mStorageId); for (int i = 0; i < mNumLoaded; i++) { mDocuments[i].addToCursor(rootIdentifier, cursor.newRow()); CursorHelper.addToCursor(mObjectInfos[i], rootIdentifier, cursor.newRow()); } final Bundle extras = new Bundle(); extras.putBoolean(DocumentsContract.EXTRA_LOADING, !completed()); Loading @@ -209,7 +211,7 @@ class DocumentLoader { } boolean completed() { return mNumLoaded == mDocuments.length; return mNumLoaded == mObjectInfos.length; } int[] getUnloadedObjectHandles(int count) { Loading @@ -224,9 +226,9 @@ class DocumentLoader { mLastNotified = new Date(); } void fillDocuments(MtpDocument[] documents) { for (int i = 0; i < documents.length; i++) { mDocuments[mNumLoaded++] = documents[i]; void fillDocuments(MtpObjectInfo[] objectInfos) { for (int i = 0; i < objectInfos.length; i++) { mObjectInfos[mNumLoaded++] = objectInfos[i]; } } Loading