Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2273e0f0 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Implement efficient move on Internal Storage.

Bug:24884813
Change-Id: I5a8dfeb13313a3e60ba2993643eb547adca7b851
parent b29cb7c9
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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 {