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

Commit 6183c32e authored by Ivan Chiang's avatar Ivan Chiang Committed by Kevin Haggerty
Browse files

Revoke the uri permission when the file is deleted

When the file is deleted, renamed or moved, revoke all uri
permissions with the file

Bug: 157474195
Test: manual test with DocumentsUI
Test: atest DocumentsTest#testAfterMoveDocumentInStorage_revokeUriPermission
Change-Id: I4ffb183630aadb2d87b0965e8cecf88af15f4534
Merged-In: I4ffb183630aadb2d87b0965e8cecf88af15f4534
(cherry picked from commit 9efd606f)
(cherry picked from commit 42c44f36)
parent 756de71e
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -395,6 +395,11 @@ public class ExternalStorageProvider extends DocumentsProvider {
        }
    }

    protected void onDocIdDeleted(String docId) {
        Uri uri = DocumentsContract.buildDocumentUri(AUTHORITY, docId);
        getContext().revokeUriPermission(uri, ~0);
    }

    @Override
    public Cursor queryRoots(String[] projection) throws FileNotFoundException {
        final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
@@ -472,6 +477,7 @@ public class ExternalStorageProvider extends DocumentsProvider {
            throw new IllegalStateException("Failed to rename to " + after);
        }
        final String afterDocId = getDocIdForFile(after);
        onDocIdDeleted(docId);
        if (!TextUtils.equals(docId, afterDocId)) {
            return afterDocId;
        } else {
@@ -492,6 +498,8 @@ public class ExternalStorageProvider extends DocumentsProvider {
            throw new IllegalStateException("Failed to delete " + file);
        }

        onDocIdDeleted(docId);

        if (visibleFile != null) {
            final ContentResolver resolver = getContext().getContentResolver();
            final Uri externalUri = MediaStore.Files.getContentUri("external");
@@ -526,7 +534,11 @@ public class ExternalStorageProvider extends DocumentsProvider {
        if (!before.renameTo(after)) {
            throw new IllegalStateException("Failed to move to " + after);
        }
        return getDocIdForFile(after);

        final String docId = getDocIdForFile(after);
        onDocIdDeleted(sourceDocumentId);

        return docId;
    }

    @Override