Set document flag by referring MTP supported operations.

BUG=26147375

Change-Id: I6c4244f1f1153c1bbbf21ea9d608dc1a92ca70cd
This commit is contained in:
Daichi Hirono
2016-02-26 12:58:39 +09:00
parent 0f32537e40
commit 61ba923ca0
11 changed files with 165 additions and 77 deletions

View File

@@ -47,16 +47,16 @@ class DocumentLoader implements AutoCloseable {
static final int NUM_LOADING_ENTRIES = 20;
static final int NOTIFY_PERIOD_MS = 500;
private final int mDeviceId;
private final MtpDeviceRecord mDevice;
private final MtpManager mMtpManager;
private final ContentResolver mResolver;
private final MtpDatabase mDatabase;
private final TaskList mTaskList = new TaskList();
private Thread mBackgroundThread;
DocumentLoader(int deviceId, MtpManager mtpManager, ContentResolver resolver,
DocumentLoader(MtpDeviceRecord device, MtpManager mtpManager, ContentResolver resolver,
MtpDatabase database) {
mDeviceId = deviceId;
mDevice = device;
mMtpManager = mtpManager;
mResolver = resolver;
mDatabase = database;
@@ -69,7 +69,7 @@ class DocumentLoader implements AutoCloseable {
*/
synchronized Cursor queryChildDocuments(String[] columnNames, Identifier parent)
throws IOException {
Preconditions.checkArgument(parent.mDeviceId == mDeviceId);
Preconditions.checkArgument(parent.mDeviceId == mDevice.deviceId);
LoaderTask task = mTaskList.findTask(parent);
if (task == null) {
if (parent.mDocumentId == null) {
@@ -81,7 +81,7 @@ class DocumentLoader implements AutoCloseable {
// 3. startAddingChildDocuemnts.
// 4. stopAddingChildDocuments - It removes the new document added at the step 2,
// because it is not updated between start/stopAddingChildDocuments.
task = LoaderTask.create(mDatabase, mMtpManager, parent);
task = LoaderTask.create(mDatabase, mMtpManager, mDevice.operationsSupported, parent);
task.fillDocuments(loadDocuments(
mMtpManager,
parent.mDeviceId,
@@ -123,7 +123,7 @@ class DocumentLoader implements AutoCloseable {
return task;
}
final Identifier identifier = mDatabase.getUnmappedDocumentsParent(mDeviceId);
final Identifier identifier = mDatabase.getUnmappedDocumentsParent(mDevice.deviceId);
if (identifier != null) {
final LoaderTask existingTask = mTaskList.findTask(identifier);
if (existingTask != null) {
@@ -131,7 +131,8 @@ class DocumentLoader implements AutoCloseable {
mTaskList.remove(existingTask);
}
try {
final LoaderTask newTask = LoaderTask.create(mDatabase, mMtpManager, identifier);
final LoaderTask newTask = LoaderTask.create(
mDatabase, mMtpManager, mDevice.operationsSupported, identifier);
mTaskList.addFirst(newTask);
return newTask;
} catch (IOException exception) {
@@ -275,14 +276,17 @@ class DocumentLoader implements AutoCloseable {
static final int STATE_ERROR = 2;
final MtpDatabase mDatabase;
int[] mOperationsSupported;
final Identifier mIdentifier;
final int[] mObjectHandles;
Date mLastNotified;
int mNumLoaded;
Exception mError;
LoaderTask(MtpDatabase database, Identifier identifier, int[] objectHandles) {
LoaderTask(MtpDatabase database, int[] operationsSupported, Identifier identifier,
int[] objectHandles) {
mDatabase = database;
mOperationsSupported = operationsSupported;
mIdentifier = identifier;
mObjectHandles = objectHandles;
mNumLoaded = 0;
@@ -355,7 +359,8 @@ class DocumentLoader implements AutoCloseable {
mDatabase.getMapper().startAddingDocuments(mIdentifier.mDocumentId);
}
mDatabase.getMapper().putChildDocuments(
mIdentifier.mDeviceId, mIdentifier.mDocumentId, objectInfoList);
mIdentifier.mDeviceId, mIdentifier.mDocumentId, mOperationsSupported,
objectInfoList);
mNumLoaded += objectInfoList.length;
if (getState() != STATE_LOADING) {
mDatabase.getMapper().stopAddingDocuments(mIdentifier.mDocumentId);
@@ -394,7 +399,8 @@ class DocumentLoader implements AutoCloseable {
/**
* Creates a LoaderTask that loads children of the given document.
*/
static LoaderTask create(MtpDatabase database, MtpManager manager, Identifier parent)
static LoaderTask create(MtpDatabase database, MtpManager manager,
int[] operationsSupported, Identifier parent)
throws IOException {
int parentHandle = parent.mObjectHandle;
// Need to pass the special value MtpManager.OBJECT_HANDLE_ROOT_CHILDREN to
@@ -402,7 +408,7 @@ class DocumentLoader implements AutoCloseable {
if (parent.mDocumentType == MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE) {
parentHandle = MtpManager.OBJECT_HANDLE_ROOT_CHILDREN;
}
return new LoaderTask(database, parent, manager.getObjectHandles(
return new LoaderTask(database, operationsSupported, parent, manager.getObjectHandles(
parent.mDeviceId, parent.mStorageId, parentHandle));
}
}

View File

@@ -130,12 +130,14 @@ class Mapper {
* @param documents List of document information.
* @throws FileNotFoundException
*/
synchronized void putChildDocuments(int deviceId, String parentId, MtpObjectInfo[] documents)
synchronized void putChildDocuments(
int deviceId, String parentId, int[] operationsSupported, MtpObjectInfo[] documents)
throws FileNotFoundException {
final ContentValues[] valuesList = new ContentValues[documents.length];
for (int i = 0; i < documents.length; i++) {
valuesList[i] = new ContentValues();
MtpDatabase.getObjectDocumentValues(valuesList[i], deviceId, parentId, documents[i]);
MtpDatabase.getObjectDocumentValues(
valuesList[i], deviceId, parentId, operationsSupported, documents[i]);
}
putDocuments(
parentId,

View File

@@ -372,9 +372,10 @@ class MtpDatabase {
* @param info
* @return Document ID of added document.
*/
String putNewDocument(int deviceId, String parentDocumentId, MtpObjectInfo info) {
String putNewDocument(
int deviceId, String parentDocumentId, int[] operationsSupported, MtpObjectInfo info) {
final ContentValues values = new ContentValues();
getObjectDocumentValues(values, deviceId, parentDocumentId, info);
getObjectDocumentValues(values, deviceId, parentDocumentId, operationsSupported, info);
mDatabase.beginTransaction();
try {
final long id = mDatabase.insert(TABLE_DOCUMENTS, null, values);
@@ -582,9 +583,10 @@ class MtpDatabase {
}
}
void updateObject(String documentId, int deviceId, String parentId, MtpObjectInfo info) {
void updateObject(String documentId, int deviceId, String parentId, int[] operationsSupported,
MtpObjectInfo info) {
final ContentValues values = new ContentValues();
getObjectDocumentValues(values, deviceId, parentId, info);
getObjectDocumentValues(values, deviceId, parentId, operationsSupported, info);
mDatabase.beginTransaction();
try {
@@ -738,20 +740,10 @@ class MtpDatabase {
* @param info MTP object info.
*/
static void getObjectDocumentValues(
ContentValues values, int deviceId, String parentId, MtpObjectInfo info) {
ContentValues values, int deviceId, String parentId, int[] operationsSupported,
MtpObjectInfo info) {
values.clear();
final String mimeType = getMimeType(info);
int flag = 0;
if (info.getProtectionStatus() == 0) {
flag |= Document.FLAG_SUPPORTS_DELETE |
Document.FLAG_SUPPORTS_WRITE;
if (mimeType == Document.MIME_TYPE_DIR) {
flag |= Document.FLAG_DIR_SUPPORTS_CREATE;
}
}
if (info.getThumbCompressedSize() > 0) {
flag |= Document.FLAG_SUPPORTS_THUMBNAIL;
}
values.put(COLUMN_DEVICE_ID, deviceId);
values.put(COLUMN_STORAGE_ID, info.getStorageId());
values.put(COLUMN_OBJECT_HANDLE, info.getObjectHandle());
@@ -765,8 +757,10 @@ class MtpDatabase {
Document.COLUMN_LAST_MODIFIED,
info.getDateModified() != 0 ? info.getDateModified() : null);
values.putNull(Document.COLUMN_ICON);
values.put(Document.COLUMN_FLAGS, flag);
values.put(Document.COLUMN_SIZE, info.getCompressedSize());
values.put(Document.COLUMN_FLAGS, getDocumentFlags(
operationsSupported, mimeType, info.getThumbCompressedSizeLong(),
info.getProtectionStatus()));
values.put(Document.COLUMN_SIZE, info.getCompressedSizeLong());
}
private static String getMimeType(MtpObjectInfo info) {
@@ -793,6 +787,30 @@ class MtpDatabase {
return rootFlag;
}
private static int getDocumentFlags(
int[] operationsSupported, String mimeType, long thumbnailSize, int protectionState) {
int flag = 0;
if (MtpDeviceRecord.isWritingSupported(operationsSupported) &&
protectionState == MtpConstants.PROTECTION_STATUS_NONE) {
flag |= Document.FLAG_SUPPORTS_WRITE;
}
if (MtpDeviceRecord.isSupported(
operationsSupported, MtpConstants.OPERATION_DELETE_OBJECT) &&
(protectionState == MtpConstants.PROTECTION_STATUS_NONE ||
protectionState == MtpConstants.PROTECTION_STATUS_NON_TRANSFERABLE_DATA)) {
flag |= Document.FLAG_SUPPORTS_DELETE;
}
if (mimeType.equals(Document.MIME_TYPE_DIR) &&
MtpDeviceRecord.isWritingSupported(operationsSupported) &&
protectionState == MtpConstants.PROTECTION_STATUS_NONE) {
flag |= Document.FLAG_DIR_SUPPORTS_CREATE;
}
if (thumbnailSize > 0) {
flag |= Document.FLAG_SUPPORTS_THUMBNAIL;
}
return flag;
}
static String[] strings(Object... args) {
final String[] results = new String[args.length];
for (int i = 0; i < args.length; i++) {

View File

@@ -220,7 +220,7 @@ public class MtpDocumentsProvider extends DocumentsProvider {
// when writing is completed.
if (MtpDeviceRecord.isWritingSupported(device.operationsSupported)) {
return getPipeManager(identifier).writeDocument(
getContext(), mMtpManager, identifier);
getContext(), mMtpManager, identifier, device.operationsSupported);
} else {
throw new UnsupportedOperationException(
"The device does not support writing operation.");
@@ -316,7 +316,8 @@ public class MtpDocumentsProvider extends DocumentsProvider {
final MtpObjectInfo infoWithHandle =
new MtpObjectInfo.Builder(info).setObjectHandle(objectHandle).build();
final String documentId = mDatabase.putNewDocument(
parentId.mDeviceId, parentDocumentId, infoWithHandle);
parentId.mDeviceId, parentDocumentId, record.operationsSupported,
infoWithHandle);
getDocumentLoader(parentId).clearTask(parentId);
notifyChildDocumentsChange(parentDocumentId);
return documentId;
@@ -336,7 +337,7 @@ public class MtpDocumentsProvider extends DocumentsProvider {
}
final MtpDeviceRecord device = mMtpManager.openDevice(deviceId);
final DeviceToolkit toolkit =
new DeviceToolkit(deviceId, mMtpManager, mResolver, mDatabase, device);
new DeviceToolkit(mMtpManager, mResolver, mDatabase, device);
mDeviceToolkits.put(deviceId, toolkit);
mIntentSender.sendUpdateNotificationIntent();
try {
@@ -499,11 +500,12 @@ public class MtpDocumentsProvider extends DocumentsProvider {
public final DocumentLoader mDocumentLoader;
public final MtpDeviceRecord mDeviceRecord;
public DeviceToolkit(
int deviceId, MtpManager manager, ContentResolver resolver, MtpDatabase database,
MtpDeviceRecord record) {
public DeviceToolkit(MtpManager manager,
ContentResolver resolver,
MtpDatabase database,
MtpDeviceRecord record) {
mPipeManager = new PipeManager(database);
mDocumentLoader = new DocumentLoader(deviceId, manager, resolver, database);
mDocumentLoader = new DocumentLoader(record, manager, resolver, database);
mDeviceRecord = record;
}
}

View File

@@ -155,7 +155,6 @@ class MtpManager {
}
}
@VisibleForTesting
long getPartialObject(int deviceId, int objectHandle, long offset, long size, byte[] buffer)
throws IOException {
final MtpDevice device = getDevice(deviceId);

View File

@@ -46,9 +46,11 @@ class PipeManager {
return task.getReadingFileDescriptor();
}
ParcelFileDescriptor writeDocument(Context context, MtpManager model, Identifier identifier)
ParcelFileDescriptor writeDocument(Context context, MtpManager model, Identifier identifier,
int[] operationsSupported)
throws IOException {
final Task task = new WriteDocumentTask(context, model, identifier, mDatabase);
final Task task = new WriteDocumentTask(
context, model, identifier, operationsSupported, mDatabase);
mExecutor.execute(task);
return task.getWritingFileDescriptor();
}
@@ -103,13 +105,18 @@ class PipeManager {
private static class WriteDocumentTask extends Task {
private final Context mContext;
private final MtpDatabase mDatabase;
private final int[] mOperationsSupported;
WriteDocumentTask(
Context context, MtpManager model, Identifier identifier, MtpDatabase database)
WriteDocumentTask(Context context,
MtpManager model,
Identifier identifier,
int[] supportedOperations,
MtpDatabase database)
throws IOException {
super(model, identifier);
mContext = context;
mDatabase = database;
mOperationsSupported = supportedOperations;
}
@Override
@@ -160,6 +167,7 @@ class PipeManager {
mIdentifier.mDocumentId,
mIdentifier.mDeviceId,
parentIdentifier.mDocumentId,
mOperationsSupported,
newObjectInfo);
} catch (IOException error) {
Log.w(MtpDocumentsProvider.TAG,

View File

@@ -55,7 +55,13 @@ public class DocumentLoaderTest extends AndroidTestCase {
mManager = new BlockableTestMtpManager(getContext());
mResolver = new TestContentResolver();
mLoader = new DocumentLoader(0, mManager, mResolver, mDatabase);
mLoader = new DocumentLoader(
new MtpDeviceRecord(
0, "Device", "Key", true, new MtpRoot[0],
TestUtil.OPERATIONS_SUPPORTED, new int[0]),
mManager,
mResolver,
mDatabase);
}
@Override

View File

@@ -192,7 +192,7 @@ public class MtpDatabaseTest extends AndroidTestCase {
addTestStorage("1");
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
createDocument(101, "image.jpg", MtpConstants.FORMAT_EXIF_JPEG, 2 * 1024 * 1024),
createDocument(102, "music.mp3", MtpConstants.FORMAT_MP3, 3 * 1024 * 1024)
@@ -261,6 +261,58 @@ public class MtpDatabaseTest extends AndroidTestCase {
cursor.close();
}
public void testPutChildDocuments_operationsSupported() throws Exception {
addTestDevice();
addTestStorage("1");
// Put a document with empty supported operations.
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new int[0], new MtpObjectInfo[] {
createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024)
});
mDatabase.getMapper().stopAddingDocuments("2");
try (final Cursor cursor =
mDatabase.queryChildDocuments(strings(Document.COLUMN_FLAGS), "2")) {
assertEquals(1, cursor.getCount());
cursor.moveToNext();
assertEquals(0, cursor.getInt(0));
}
// Put a document with writable operations.
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new int[] {
MtpConstants.OPERATION_SEND_OBJECT,
MtpConstants.OPERATION_SEND_OBJECT_INFO,
}, new MtpObjectInfo[] {
createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024)
});
mDatabase.getMapper().stopAddingDocuments("2");
try (final Cursor cursor =
mDatabase.queryChildDocuments(strings(Document.COLUMN_FLAGS), "2")) {
assertEquals(1, cursor.getCount());
cursor.moveToNext();
assertEquals(Document.FLAG_SUPPORTS_WRITE, cursor.getInt(0));
}
// Put a document with deletable operations.
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new int[] {
MtpConstants.OPERATION_DELETE_OBJECT
}, new MtpObjectInfo[] {
createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024)
});
mDatabase.getMapper().stopAddingDocuments("2");
try (final Cursor cursor =
mDatabase.queryChildDocuments(strings(Document.COLUMN_FLAGS), "2")) {
assertEquals(1, cursor.getCount());
cursor.moveToNext();
assertEquals(Document.FLAG_SUPPORTS_DELETE, cursor.getInt(0));
}
}
public void testRestoreIdForRootDocuments() throws Exception {
final String[] columns = new String[] {
DocumentsContract.Document.COLUMN_DOCUMENT_ID,
@@ -335,7 +387,7 @@ public class MtpDatabaseTest extends AndroidTestCase {
addTestStorage("1");
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
createDocument(101, "image.jpg", MtpConstants.FORMAT_EXIF_JPEG, 2 * 1024 * 1024),
createDocument(102, "music.mp3", MtpConstants.FORMAT_MP3, 3 * 1024 * 1024)
@@ -353,7 +405,7 @@ public class MtpDatabaseTest extends AndroidTestCase {
}
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
createDocument(203, "video.mp4", MtpConstants.FORMAT_MP4_CONTAINER, 1024),
});
@@ -486,7 +538,7 @@ public class MtpDatabaseTest extends AndroidTestCase {
addTestDevice();
addTestStorage("1");
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(50, "A", MtpConstants.FORMAT_ASSOCIATION, 0),
createDocument(51, "B", MtpConstants.FORMAT_ASSOCIATION, 0),
});
@@ -495,10 +547,10 @@ public class MtpDatabaseTest extends AndroidTestCase {
// Put note.txt in each directory.
mDatabase.getMapper().startAddingDocuments("3");
mDatabase.getMapper().startAddingDocuments("4");
mDatabase.getMapper().putChildDocuments(0, "3", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "3", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().putChildDocuments(0, "4", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "4", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(101, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
@@ -509,7 +561,7 @@ public class MtpDatabaseTest extends AndroidTestCase {
addTestDevice();
addTestStorage("1");
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(50, "A", MtpConstants.FORMAT_ASSOCIATION, 0),
createDocument(51, "B", MtpConstants.FORMAT_ASSOCIATION, 0),
});
@@ -518,10 +570,10 @@ public class MtpDatabaseTest extends AndroidTestCase {
// Add note.txt in each directory again.
mDatabase.getMapper().startAddingDocuments("3");
mDatabase.getMapper().startAddingDocuments("4");
mDatabase.getMapper().putChildDocuments(0, "3", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "3", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().putChildDocuments(0, "4", new MtpObjectInfo[] {
mDatabase.getMapper().putChildDocuments(0, "4", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(201, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().stopAddingDocuments("3");
@@ -802,12 +854,9 @@ public class MtpDatabaseTest extends AndroidTestCase {
mDatabase.getMapper().stopAddingDocuments("1");
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(
0,
"2",
new MtpObjectInfo[] {
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().stopAddingDocuments("2");
assertEquals("2", mDatabase.getParentIdentifier("3").mDocumentId);
@@ -818,21 +867,15 @@ public class MtpDatabaseTest extends AndroidTestCase {
addTestStorage("1");
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(
0,
"2",
new MtpObjectInfo[] {
createDocument(200, "dir", MtpConstants.FORMAT_ASSOCIATION, 1024),
});
mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(200, "dir", MtpConstants.FORMAT_ASSOCIATION, 1024),
});
mDatabase.getMapper().stopAddingDocuments("2");
mDatabase.getMapper().startAddingDocuments("3");
mDatabase.getMapper().putChildDocuments(
0,
"3",
new MtpObjectInfo[] {
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().putChildDocuments(0, "3", OPERATIONS_SUPPORTED, new MtpObjectInfo[] {
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024),
});
mDatabase.getMapper().stopAddingDocuments("3");
mDatabase.deleteDocument("3");
@@ -861,7 +904,8 @@ public class MtpDatabaseTest extends AndroidTestCase {
assertEquals(
"3",
mDatabase.putNewDocument(
0, "2", createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024)));
0, "2", OPERATIONS_SUPPORTED,
createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024)));
{
final Cursor cursor =
@@ -879,8 +923,7 @@ public class MtpDatabaseTest extends AndroidTestCase {
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.putNewDocument(
0,
"2",
0, "2", OPERATIONS_SUPPORTED,
createDocument(201, "note.txt", MtpConstants.FORMAT_TEXT, 1024));
mDatabase.getMapper().stopAddingDocuments("2");

View File

@@ -412,7 +412,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase {
assertEquals("image/jpeg", cursor.getString(1));
assertEquals("image.jpg", cursor.getString(2));
assertEquals(0, cursor.getLong(3));
assertEquals(DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL, cursor.getInt(4));
assertEquals(Document.FLAG_SUPPORTS_THUMBNAIL, cursor.getInt(4));
assertEquals(1024 * 1024 * 5, cursor.getInt(5));
cursor.close();

View File

@@ -67,7 +67,9 @@ public class PipeManagerTest extends AndroidTestCase {
final MtpObjectInfo info =
new MtpObjectInfo.Builder().setObjectHandle(1).setName("note.txt").build();
mDatabase.getMapper().startAddingDocuments("2");
mDatabase.getMapper().putChildDocuments(0, "2", new MtpObjectInfo[] { info });
mDatabase.getMapper().putChildDocuments(
0, "2", TestUtil.OPERATIONS_SUPPORTED,
new MtpObjectInfo[] { info });
mDatabase.getMapper().stopAddingDocuments("2");
// Create a placeholder file which should be replaced by a real file later.
mtpManager.setObjectInfo(0, info);
@@ -76,7 +78,8 @@ public class PipeManagerTest extends AndroidTestCase {
final ParcelFileDescriptor descriptor = mPipeManager.writeDocument(
getContext(),
mtpManager,
new Identifier(0, 0, 1, "2", MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
new Identifier(0, 0, 1, "2", MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT),
TestUtil.OPERATIONS_SUPPORTED);
final ParcelFileDescriptor.AutoCloseOutputStream outputStream =
new ParcelFileDescriptor.AutoCloseOutputStream(descriptor);
outputStream.write(HELLO_BYTES, 0, HELLO_BYTES.length);

View File

@@ -37,6 +37,7 @@ final class TestUtil {
MtpConstants.OPERATION_GET_PARTIAL_OBJECT,
MtpConstants.OPERATION_SEND_OBJECT,
MtpConstants.OPERATION_SEND_OBJECT_INFO,
MtpConstants.OPERATION_DELETE_OBJECT,
};
/**