Implement efficient move on Internal Storage.

Bug:24884813
Change-Id: I5a8dfeb13313a3e60ba2993643eb547adca7b851
This commit is contained in:
Tomasz Mikolajewski
2015-11-04 18:24:09 +09:00
parent b29cb7c9ae
commit 2273e0f095

View File

@@ -273,10 +273,12 @@ public class ExternalStorageProvider extends DocumentsProvider {
flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
flags |= Document.FLAG_SUPPORTS_DELETE;
flags |= Document.FLAG_SUPPORTS_RENAME;
flags |= Document.FLAG_SUPPORTS_MOVE;
} else {
flags |= Document.FLAG_SUPPORTS_WRITE;
flags |= Document.FLAG_SUPPORTS_DELETE;
flags |= Document.FLAG_SUPPORTS_RENAME;
flags |= Document.FLAG_SUPPORTS_MOVE;
}
}
@@ -408,6 +410,21 @@ public class ExternalStorageProvider extends DocumentsProvider {
new String[] { path, path });
}
@Override
public String moveDocument(String sourceDocumentId, String targetParentDocumentId)
throws FileNotFoundException {
final File before = getFileForDocId(sourceDocumentId);
final File after = new File(getFileForDocId(targetParentDocumentId), before.getName());
if (after.exists()) {
throw new IllegalStateException("Already exists " + after);
}
if (!before.renameTo(after)) {
throw new IllegalStateException("Failed to move to " + after);
}
return getDocIdForFile(after);
}
@Override
public Cursor queryDocument(String documentId, String[] projection)
throws FileNotFoundException {