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

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

Merge "Do not allow to move virtual files using conversion."

parents 60965d22 87156dc8
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.os.RemoteException;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.util.Log;

import com.android.documentsui.R;
import com.android.documentsui.model.DocumentInfo;
@@ -92,6 +93,15 @@ final class MoveJob extends CopyJob {
            }
        }

        // Moving virtual files by bytes is not supported. This is because, it would involve
        // conversion, and the source file should not be deleted in such case (as it's a different
        // file).
        if (src.isVirtualDocument()) {
            Log.w(TAG, "Cannot move virtual files byte by byte.");
            onFileFailed(src);
            return false;
        }

        // If we couldn't do an optimized copy...we fall back to vanilla byte copy.
        boolean copied = byteCopyDocument(src, dest);

+14 −3
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.documentsui.services;

import static com.google.common.collect.Lists.newArrayList;

import android.net.Uri;
import android.test.suitebuilder.annotation.MediumTest;

import com.android.documentsui.model.DocumentInfo;
@@ -33,15 +36,23 @@ public class MoveJobTest extends AbstractCopyJobTest<MoveJob> {
    }

    public void testMoveVirtualTypedFile() throws Exception {
        runCopyVirtualTypedFileTest();
        Uri testFile = mDocs.createVirtualFile(
                mSrcRoot, "/virtual.sth", "virtual/mime-type",
                FRUITY_BYTES, "application/pdf", "text/html");
        createJob(newArrayList(testFile)).run();

        mDocs.assertChildCount(mSrcRoot, 0);
        mJobListener.waitForFinished();

        // Should have failed, source not deleted. Moving by bytes for virtual files
        // is not supported.
        mDocs.assertChildCount(mDestRoot, 0);
        mDocs.assertChildCount(mSrcRoot, 1);
    }

    public void testMoveVirtualNonTypedFile() throws Exception {
        runCopyVirtualNonTypedFileTest();

        // should have failed, source not deleted
        // Should have failed, source not deleted.
        mDocs.assertChildCount(mSrcRoot, 1);
    }