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

Commit 470a3dbc authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Add support for copying virtual files in DocumentsUI.

Bug: 26147488
Change-Id: I09cf010de7267fbdba6e3fcd0f300b0ecce19d10
parent 29d1ddd4
Loading
Loading
Loading
Loading
+20 −2
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.PendingIntent;
import android.content.ContentProviderClient;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.Cursor;
import android.net.Uri;
import android.net.Uri;
@@ -592,9 +593,26 @@ public class CopyService extends IntentService {


        IOException copyError = null;
        IOException copyError = null;
        try {
        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);
                srcFile = mSrcClient.openFile(srcInfo.derivedUri, "r", canceller);
            dstFile = mDstClient.openFile(dstInfo.derivedUri, "w", canceller);
                src = new ParcelFileDescriptor.AutoCloseInputStream(srcFile);
                src = new ParcelFileDescriptor.AutoCloseInputStream(srcFile);
            }
            dstFile = mDstClient.openFile(dstInfo.derivedUri, "w", canceller);
            dst = new ParcelFileDescriptor.AutoCloseOutputStream(dstFile);
            dst = new ParcelFileDescriptor.AutoCloseOutputStream(dstFile);


            byte[] buffer = new byte[8192];
            byte[] buffer = new byte[8192];
+8 −0
Original line number Original line Diff line number Diff line
@@ -251,6 +251,14 @@ public class DocumentInfo implements Durable, Parcelable {
        return isDirectory() || isArchive();
        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() {
    public int hashCode() {
        return derivedUri.hashCode() + mimeType.hashCode();
        return derivedUri.hashCode() + mimeType.hashCode();
    }
    }