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

Commit f34bc398 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Revert "Remove the flag and make openTypedDocument throw FileNotFoundException."

This reverts commit 95149ab6a5442a05f05f448854b6ab386c87f717.

Change-Id: I218aa8059ef674400dac8531a86cd326748c26d5
parent e475d3b2
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -502,6 +502,11 @@ public class CopyService extends IntentService {
        // If the file is virtual, but can be converted to another format, then try to copy it
        // as such format. Also, append an extension for the target mime type (if known).
        if (srcInfo.isVirtualDocument()) {
            if (!srcInfo.isTypedDocument()) {
                // Impossible to copy a file which is virtual, but not typed.
                mFailedFiles.add(srcInfo);
                return false;
            }
            final String[] streamTypes = getContentResolver().getStreamTypes(
                    srcInfo.derivedUri, "*/*");
            if (streamTypes != null && streamTypes.length > 0) {
@@ -511,7 +516,8 @@ public class CopyService extends IntentService {
                dstDisplayName = srcInfo.displayName +
                        (extension != null ? "." + extension : srcInfo.displayName);
            } else {
                // The virtual file is not available as any alternative streamable format.
                // The provider says that it supports typed documents, but doesn't say
                // anything about available formats.
                // TODO: Log failures. b/26192412
                mFailedFiles.add(srcInfo);
                return false;
@@ -634,8 +640,9 @@ public class CopyService extends IntentService {

        boolean success = true;
        try {
            // If the file is virtual, then try to copy it as an alternative format.
            if (srcInfo.isVirtualDocument()) {
            // If the file is virtual, but can be converted to another format, then try to copy it
            // as such format.
            if (srcInfo.isVirtualDocument() && srcInfo.isTypedDocument()) {
                final AssetFileDescriptor srcFileAsAsset =
                        mSrcClient.openTypedAssetFileDescriptor(
                                srcInfo.derivedUri, mimeType, null, canceller);
+4 −0
Original line number Diff line number Diff line
@@ -255,6 +255,10 @@ public class DocumentInfo implements Durable, Parcelable {
        return (flags & Document.FLAG_VIRTUAL_DOCUMENT) != 0;
    }

    public boolean isTypedDocument() {
        return (flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) != 0;
    }

    public int hashCode() {
        return derivedUri.hashCode() + mimeType.hashCode();
    }
+3 −1
Original line number Diff line number Diff line
@@ -311,8 +311,10 @@ public class CopyServiceTest extends ServiceTestCase<CopyService> {

    public void testCopyVirtualNonTypedFile() throws Exception {
        String srcPath = "/non-typed.sth";
        // Empty stream types causes the FLAG_SUPPORTS_TYPED_DOCUMENT to be not set.
        ArrayList<String> streamTypes = new ArrayList<>();
        Uri testFile = mStorage.createVirtualFile(SRC_ROOT, srcPath, "virtual/mime-type",
                null /* streamTypes */, "I love Tokyo!".getBytes());
                streamTypes, "I love Tokyo!".getBytes());

        Intent intent = createCopyIntent(Lists.newArrayList(testFile));
        startService(intent);
+10 −4
Original line number Diff line number Diff line
@@ -316,9 +316,12 @@ public class StubProvider extends DocumentsProvider {
            String documentId, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
            throws FileNotFoundException {
        final StubDocument document = mStorage.get(documentId);
        if (document == null || !document.file.isFile() || document.streamTypes == null) {
        if (document == null || !document.file.isFile()) {
            throw new FileNotFoundException();
        }
        if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) {
            throw new IllegalStateException("Tried to open a non-typed document as typed.");
        }
        for (final String mimeType : document.streamTypes) {
            // Strict compare won't accept wildcards, but that's OK for tests, as DocumentsUI
            // doesn't use them for getStreamTypes nor openTypedDocument.
@@ -346,13 +349,13 @@ public class StubProvider extends DocumentsProvider {
            throw new IllegalArgumentException(
                    "The provided Uri is incorrect, or the file is gone.");
        }
        if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) {
            return null;
        }
        if (!"*/*".equals(mimeTypeFilter)) {
            // Not used by DocumentsUI, so don't bother implementing it.
            throw new UnsupportedOperationException();
        }
        if (document.streamTypes == null) {
            return null;
        }
        return document.streamTypes.toArray(new String[document.streamTypes.size()]);
    }

@@ -625,6 +628,9 @@ public class StubProvider extends DocumentsProvider {
                File file, String mimeType, List<String> streamTypes, StubDocument parent) {
            int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE
                    | Document.FLAG_VIRTUAL_DOCUMENT;
            if (streamTypes.size() > 0) {
                flags |= Document.FLAG_SUPPORTS_TYPED_DOCUMENT;
            }
            return new StubDocument(file, mimeType, streamTypes, flags, parent);
        }