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

Commit 947da49a authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by Android (Google) Code Review
Browse files

Merge "Clean up sharing virtual files."

parents 0d35785b 699acefa
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class Model {
    /**
     * Filter that passes (returns true) all non-partial files and non-archived files.
     */
    public static final Predicate<Cursor> NO_PARTIAL_NOR_ARCHIVED_FILE_FILTER = (Cursor c) -> {
    public static final Predicate<Cursor> SHARABLE_FILE_FILTER = (Cursor c) -> {
        int flags = getCursorInt(c, Document.COLUMN_FLAGS);
        String authority = getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY);
        return (flags & Document.FLAG_PARTIAL) == 0
@@ -232,29 +232,42 @@ public class Model {
        final int size = (selection != null) ? selection.size() : 0;

        final List<DocumentInfo> docs =  new ArrayList<>(size);
        DocumentInfo doc;
        for (String modelId: selection) {
            loadDocument(docs, modelId, filter);
            doc = loadDocument(modelId, filter);
            if (doc != null) {
                docs.add(doc);
            }
        }
        return docs;
    }

    public boolean hasDocuments(Selection selection, Predicate<Cursor> filter) {
        for (String modelId: selection) {
            if (loadDocument(modelId, filter) != null) {
                return true;
            }
        }
        return false;
    }

    /**
     * @param docs
     * @return DocumentInfo, or null. If filter returns false, null will be returned.
     */
    private void loadDocument(
            List<DocumentInfo> docs, String modelId, Predicate<Cursor> filter) {
    private @Nullable DocumentInfo loadDocument(String modelId, Predicate<Cursor> filter) {
        final Cursor cursor = getItem(modelId);

        if (cursor == null) {
            Log.w(TAG, "Unable to obtain document for modelId: " + modelId);
            return null;
        }

        if (filter.test(cursor)) {
            docs.add(DocumentInfo.fromDirectoryCursor(cursor));
        } else {
            if (VERBOSE) Log.v(TAG, "Filtered document from results: " + modelId);
            return DocumentInfo.fromDirectoryCursor(cursor);
        }

        if (VERBOSE) Log.v(TAG, "Filtered out document from results: " + modelId);
        return null;
    }

    public Uri getItemUri(String modelId) {
+3 −5
Original line number Diff line number Diff line
@@ -290,10 +290,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs =
                mScope.model.loadDocuments(selection, Model.NO_PARTIAL_NOR_ARCHIVED_FILE_FILTER);

        List<DocumentInfo> virtualDocs =
                mScope.model.loadDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER);
                mScope.model.loadDocuments(selection, Model.SHARABLE_FILE_FILTER);

        Intent intent;

@@ -323,7 +320,8 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa

        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        if (virtualDocs.size() > 0) {

        if (mScope.model.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) {
            intent.addCategory(Intent.CATEGORY_TYPED_OPENABLE);
        }