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

Commit 21a3b657 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Allow files to be created under download dirs from MediaStore.

Also, allow files to be renamed if they are not in pending state and
trigger a media scan when a new file is created.

Bug: 127844893
Bug: 127802924
Test: manual
Change-Id: I162f1827dacc422bfa33c54904e92a4aecb7747d
parent 4f8ad9cb
Loading
Loading
Loading
Loading
+1 −11
Original line number Original line Diff line number Diff line
@@ -247,7 +247,6 @@ public abstract class FileSystemProvider extends DocumentsProvider {
            }
            }
            childId = getDocIdForFile(file);
            childId = getDocIdForFile(file);
            onDocIdChanged(childId);
            onDocIdChanged(childId);
            addFolderToMediaStore(getFileForDocId(childId, true));
        } else {
        } else {
            try {
            try {
                if (!file.createNewFile()) {
                if (!file.createNewFile()) {
@@ -259,19 +258,11 @@ public abstract class FileSystemProvider extends DocumentsProvider {
                throw new IllegalStateException("Failed to touch " + file + ": " + e);
                throw new IllegalStateException("Failed to touch " + file + ": " + e);
            }
            }
        }
        }
        MediaStore.scanFile(getContext(), file);


        return childId;
        return childId;
    }
    }


    private void addFolderToMediaStore(@Nullable File visibleFolder) {
        // visibleFolder is null if we're adding a folder to external thumb drive or SD card.
        if (visibleFolder != null) {
            assert (visibleFolder.isDirectory());

            MediaStore.scanFile(getContext(), visibleFolder);
        }
    }

    @Override
    @Override
    public String renameDocument(String docId, String displayName) throws FileNotFoundException {
    public String renameDocument(String docId, String displayName) throws FileNotFoundException {
        // Since this provider treats renames as generating a completely new
        // Since this provider treats renames as generating a completely new
@@ -293,7 +284,6 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        moveInMediaStore(beforeVisibleFile, afterVisibleFile);
        moveInMediaStore(beforeVisibleFile, afterVisibleFile);


        if (!TextUtils.equals(docId, afterDocId)) {
        if (!TextUtils.equals(docId, afterDocId)) {
            scanFile(afterVisibleFile);
            return afterDocId;
            return afterDocId;
        } else {
        } else {
            return null;
            return null;