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

Commit 95d9c251 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Add first-class support for virtual files in SAF.

Bug: 20820363
Change-Id: Ic509a6003a99997126f129a836fdd8c0e843108f
parent 64a702b1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -172,6 +172,11 @@ public class DocumentsActivity extends BaseActivity {
                    Intent.EXTRA_ALLOW_MULTIPLE, false);
        }

        if (state.action == ACTION_OPEN || state.action == ACTION_GET_CONTENT
                || state.action == ACTION_CREATE) {
            state.openableOnly = intent.hasCategory(Intent.CATEGORY_OPENABLE);
        }

        if (state.action == ACTION_PICK_COPY_DESTINATION) {
            state.directoryCopy = intent.getBooleanExtra(
                    Shared.EXTRA_DIRECTORY_COPY, false);
+3 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class State implements android.os.Parcelable {
    public boolean stackTouched;
    public boolean restored;
    public boolean directoryCopy;
    public boolean openableOnly;
    /** Transfer mode for file copy/move operations. */
    public int transferMode;

@@ -119,6 +120,7 @@ public class State implements android.os.Parcelable {
        out.writeMap(dirState);
        out.writeList(selectedDocumentsForCopy);
        out.writeList(excludedAuthorities);
        out.writeInt(openableOnly ? 1 : 0);
    }

    public static final Creator<State> CREATOR = new Creator<State>() {
@@ -142,6 +144,7 @@ public class State implements android.os.Parcelable {
            in.readMap(state.dirState, null);
            in.readList(state.selectedDocumentsForCopy, null);
            in.readList(state.excludedAuthorities, null);
            state.openableOnly = in.readInt() != 0;
            return state;
        }

+1 −2
Original line number Diff line number Diff line
@@ -660,8 +660,7 @@ public class DirectoryFragment extends Fragment {
                checkNotNull(cursor, "Cursor cannot be null.");
                final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
                final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
                return mTuner.canSelectType(docMimeType)
                        && mTuner.isDocumentEnabled(docMimeType, docFlags);
                return mTuner.canSelectType(docMimeType, docFlags);
            }
            return true;
        }
+29 −16
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public abstract class FragmentTuner {
    // Subtly different from isDocumentEnabled. The reason may be illuminated as follows.
    // A folder is enabled such that it may be double clicked, even in settings
    // when the folder itself cannot be selected. This may also be true of container types.
    public boolean canSelectType(String docMimeType) {
    public boolean canSelectType(String docMimeType, int docFlags) {
        return true;
    }

@@ -85,32 +85,45 @@ public abstract class FragmentTuner {
        }

        @Override
        public boolean canSelectType(String docMimeType) {
            switch (mState.action) {
                case ACTION_OPEN:
                case ACTION_CREATE:
                case ACTION_GET_CONTENT:
                    return !isDirectory(docMimeType);
                case ACTION_OPEN_TREE:
        public boolean canSelectType(String docMimeType, int docFlags) {
            if (!isDocumentEnabled(docMimeType, docFlags)) {
                return false;
            }

            if (isDirectory(docMimeType)) {
                return false;
            }

            if (mState.action == ACTION_OPEN_TREE) {
                // In this case nothing *ever* is selectable...the expected user behavior is
                // they navigate *into* a folder, then click a confirmation button indicating
                // that the current directory is the directory they are picking.
                return false;
            }

            return true;
        }

        @Override
        public boolean isDocumentEnabled(String docMimeType, int docFlags) {
            // Directories are always enabled
            // Directories are always enabled.
            if (isDirectory(docMimeType)) {
                return true;
            }

            // Read-only files are disabled when creating
            if (mState.action == ACTION_CREATE && (docFlags & Document.FLAG_SUPPORTS_WRITE) == 0) {
            switch (mState.action) {
                case ACTION_CREATE:
                    // Read-only files are disabled when creating.
                    if ((docFlags & Document.FLAG_SUPPORTS_WRITE) == 0) {
                        return false;
                    }
                case ACTION_OPEN:
                case ACTION_GET_CONTENT:
                    final boolean isVirtual = (docFlags & Document.FLAG_VIRTUAL_DOCUMENT) != 0;
                    if (isVirtual && mState.openableOnly) {
                        return false;
                    }
            }

            return MimePredicate.mimeMatches(mState.acceptMimes, docMimeType);
        }