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

Commit c887908f authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Block access to most Android/* directories.

In a scoped storage world, access to "Android/data" style directories
is blocked for privacy reasons.

Bug: 141521616
Test: manual
Change-Id: I0f435204ce2fcb4514e774239ecb1a1ca26d9dff
parent 1e89d231
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Pattern;

/**
 * A helper class for {@link android.provider.DocumentsProvider} to perform file operations on local
@@ -388,8 +389,10 @@ public abstract class FileSystemProvider extends DocumentsProvider {
                resolveProjection(projection), parentDocumentId, parent);
        if (parent.isDirectory()) {
            for (File file : FileUtils.listFilesOrEmpty(parent)) {
                if (!shouldHide(file)) {
                    includeFile(result, null, file);
                }
            }
        } else {
            Log.w(TAG, "parentDocumentId '" + parentDocumentId + "' is not Directory");
        }
@@ -422,6 +425,8 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        pending.add(folder);
        while (!pending.isEmpty() && result.getCount() < 24) {
            final File file = pending.removeFirst();
            if (shouldHide(file)) continue;

            if (file.isDirectory()) {
                for (File child : file.listFiles()) {
                    pending.add(child);
@@ -540,6 +545,7 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        } else {
            file = getFileForDocId(docId);
        }

        final String mimeType = getDocumentType(docId, file);
        row.add(Document.COLUMN_DOCUMENT_ID, docId);
        row.add(Document.COLUMN_MIME_TYPE, mimeType);
@@ -598,6 +604,17 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        return row;
    }

    private static final Pattern PATTERN_HIDDEN_PATH = Pattern.compile(
            "(?i)^/storage/[^/]+/(?:[0-9]+/)?Android/(?:data|obb|sandbox)$");

    /**
     * In a scoped storage world, access to "Android/data" style directories are
     * hidden for privacy reasons.
     */
    protected boolean shouldHide(@NonNull File file) {
        return (PATTERN_HIDDEN_PATH.matcher(file.getAbsolutePath()).matches());
    }

    protected boolean shouldBlockFromTree(@NonNull String docId) {
        return false;
    }