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

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

Merge "Add support for copying virtual files in DocumentsUI."

parents e4d6af9c 03bd4645
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.PendingIntent;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
@@ -592,9 +593,26 @@ public class CopyService extends IntentService {

        IOException copyError = null;
        try {
            // 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 String[] streamTypes = mSrcClient.getStreamTypes(srcInfo.derivedUri, "*/*");
                if (streamTypes.length > 0) {
                    // Pick the first streamable format.
                    final AssetFileDescriptor srcFileAsAsset =
                            mSrcClient.openTypedAssetFileDescriptor(
                                    srcInfo.derivedUri, streamTypes[0], null, canceller);
                    srcFile = srcFileAsAsset.getParcelFileDescriptor();
                    src = new AssetFileDescriptor.AutoCloseInputStream(srcFileAsAsset);
                } else {
                    // TODO: Log failures. b/26192412
                    mFailedFiles.add(srcInfo);
                }
            } else {
                srcFile = mSrcClient.openFile(srcInfo.derivedUri, "r", canceller);
            dstFile = mDstClient.openFile(dstInfo.derivedUri, "w", canceller);
                src = new ParcelFileDescriptor.AutoCloseInputStream(srcFile);
            }
            dstFile = mDstClient.openFile(dstInfo.derivedUri, "w", canceller);
            dst = new ParcelFileDescriptor.AutoCloseOutputStream(dstFile);

            byte[] buffer = new byte[8192];
+8 −0
Original line number Diff line number Diff line
@@ -251,6 +251,14 @@ public class DocumentInfo implements Durable, Parcelable {
        return isDirectory() || isArchive();
    }

    public boolean isVirtualDocument() {
        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();
    }