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

Commit 8edec67e authored by Garfield Tan's avatar Garfield Tan Committed by android-build-merger
Browse files

Save the op type before fetching root document.

am: 3b987ccd

Change-Id: If2b6f9c8e6d8c6f1e9cdd1b7658cf63dba912e2e
parents d8e41dd8 3b987ccd
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -367,26 +367,38 @@ public interface DragAndDropManager {
                return false;
            }

            // Calculate the op type now just in case user releases Ctrl key while we're obtaining
            // root document in the background.
            final @OpType int opType = calculateOpType(clipData, destRoot);
            action.getRootDocument(
                    destRoot,
                    TimeoutTask.DEFAULT_TIMEOUT,
                    (DocumentInfo doc) -> {
                        dropOnRootDocument(clipData, localState, destRoot, doc, callback);
                        dropOnRootDocument(clipData, localState, destRoot, doc, opType, callback);
                    });

            return true;
        }

        private void dropOnRootDocument(ClipData clipData, Object localState, RootInfo destRoot,
                @Nullable DocumentInfo destRootDoc, FileOperations.Callback callback) {
        private void dropOnRootDocument(
                ClipData clipData,
                Object localState,
                RootInfo destRoot,
                @Nullable DocumentInfo destRootDoc,
                @OpType int opType,
                FileOperations.Callback callback) {
            if (destRootDoc == null) {
                callback.onOperationResult(
                        FileOperations.Callback.STATUS_FAILED,
                        calculateOpType(clipData, destRoot),
                        opType,
                        0);
            } else {
                dropChecked(
                        clipData, localState, new DocumentStack(destRoot, destRootDoc), callback);
                        clipData,
                        localState,
                        new DocumentStack(destRoot, destRootDoc),
                        opType,
                        callback);
            }
        }

@@ -398,12 +410,17 @@ public interface DragAndDropManager {
                return false;
            }

            dropChecked(clipData, localState, dstStack, callback);
            dropChecked(
                    clipData,
                    localState,
                    dstStack,
                    calculateOpType(clipData, dstStack.getRoot()),
                    callback);
            return true;
        }

        private void dropChecked(ClipData clipData, Object localState, DocumentStack dstStack,
                FileOperations.Callback callback) {
                @OpType int opType, FileOperations.Callback callback) {

            // Recognize multi-window drag and drop based on the fact that localState is not
            // carried between processes. It will stop working when the localsState behavior
@@ -414,11 +431,7 @@ public interface DragAndDropManager {
                    localState == null ? Metrics.USER_ACTION_DRAG_N_DROP_MULTI_WINDOW
                            : Metrics.USER_ACTION_DRAG_N_DROP);

            mClipper.copyFromClipData(
                    dstStack,
                    clipData,
                    calculateOpType(clipData, dstStack.getRoot()),
                    callback);
            mClipper.copyFromClipData(dstStack, clipData, opType, callback);
        }

        @Override
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import java.util.function.Consumer;

public class TestActionHandler extends AbstractActionHandler<TestActivity> {

    private final TestEnv mEnv;

    public final TestEventHandler<DocumentDetails> open = new TestEventHandler<>();
    public boolean mDeleteHappened;

@@ -48,6 +50,8 @@ public class TestActionHandler extends AbstractActionHandler<TestActivity> {
                env.searchViewManager,
                (String authority) -> null,
                env.injector);

        mEnv = env;
    }

    @Override
@@ -77,6 +81,8 @@ public class TestActionHandler extends AbstractActionHandler<TestActivity> {

    @Override
    public void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback) {
        mEnv.mExecutor.submit(() -> {
            callback.accept(nextRootDocument);
        });
    }
}
+40 −5
Original line number Diff line number Diff line
@@ -562,7 +562,7 @@ public class DragAndDropManagerTests {
    }

    @Test
    public void testDrop_Fails_NotGetRootDoc() {
    public void testDrop_Fails_NotGetRootDoc() throws Exception {
        mManager.startDrag(
                mStartDragView,
                TestEnv.FOLDER_0,
@@ -577,11 +577,12 @@ public class DragAndDropManagerTests {
        mManager.drop(
                mClipData, mManager, TestProvidersAccess.DOWNLOADS, mActions, mCallback);

        mEnv.beforeAsserts();
        mCallbackListener.assertLastArgument(FileOperations.Callback.STATUS_FAILED);
    }

    @Test
    public void testDrop_DifferentRoot_DropOnRoot() {
    public void testDrop_Copies_DifferentRoot_DropOnRoot() throws Exception {
        mActions.nextRootDocument = TestEnv.FOLDER_1;

        mManager.startDrag(
@@ -598,6 +599,7 @@ public class DragAndDropManagerTests {
        mManager.drop(
                mClipData, mManager, TestProvidersAccess.DOWNLOADS, mActions, mCallback);

        mEnv.beforeAsserts();
        final DocumentStack expect =
                new DocumentStack(TestProvidersAccess.DOWNLOADS, TestEnv.FOLDER_1);
        mClipper.copy.assertLastArgument(Pair.create(expect, mClipData));
@@ -605,7 +607,7 @@ public class DragAndDropManagerTests {
    }

    @Test
    public void testDrop_SameRoot_DropOnRoot() {
    public void testDrop_Moves_SameRoot_DropOnRoot() throws Exception {
        mActions.nextRootDocument = TestEnv.FOLDER_1;

        mManager.startDrag(
@@ -622,12 +624,45 @@ public class DragAndDropManagerTests {
        mManager.drop(
                mClipData, mManager, TestProvidersAccess.DOWNLOADS, mActions, mCallback);

        mEnv.beforeAsserts();
        final DocumentStack expect =
                new DocumentStack(TestProvidersAccess.DOWNLOADS, TestEnv.FOLDER_1);
        mClipper.copy.assertLastArgument(Pair.create(expect, mClipData));
        mClipper.opType.assertLastArgument(FileOperationService.OPERATION_MOVE);
    }

    @Test
    public void testDrop_Copies_SameRoot_DropOnRoot_ReleasesCtrlBeforeGettingRootDocument()
            throws Exception{
        mActions.nextRootDocument = TestEnv.FOLDER_1;

        mManager.startDrag(
                mStartDragView,
                TestEnv.FOLDER_0,
                Arrays.asList(TestEnv.FILE_APK, TestEnv.FILE_JPG),
                TestProvidersAccess.DOWNLOADS,
                Arrays.asList(TestEnv.FOLDER_0.derivedUri, TestEnv.FILE_APK.derivedUri,
                        TestEnv.FILE_JPG.derivedUri),
                mIconHelper);

        KeyEvent event = KeyEvents.createLeftCtrlKey(KeyEvent.ACTION_DOWN);
        mManager.onKeyEvent(event);

        mManager.updateState(mUpdateShadowView, TestProvidersAccess.DOWNLOADS, TestEnv.FOLDER_1);

        mManager.drop(
                mClipData, mManager, TestProvidersAccess.DOWNLOADS, mActions, mCallback);

        event = KeyEvents.createLeftCtrlKey(KeyEvent.ACTION_UP);
        mManager.onKeyEvent(event);

        mEnv.beforeAsserts();
        final DocumentStack expect =
                new DocumentStack(TestProvidersAccess.DOWNLOADS, TestEnv.FOLDER_1);
        mClipper.copy.assertLastArgument(Pair.create(expect, mClipData));
        mClipper.opType.assertLastArgument(FileOperationService.OPERATION_COPY);
    }

    @Test
    public void testDrop_Rejects_RootNotSupportCreate_DropOnDocument() {
        mManager.startDrag(
@@ -647,7 +682,7 @@ public class DragAndDropManagerTests {
    }

    @Test
    public void testDrop_DifferentRoot_DropOnDocument() {
    public void testDrop_Copies_DifferentRoot_DropOnDocument() {
        mManager.startDrag(
                mStartDragView,
                TestEnv.FOLDER_0,
@@ -668,7 +703,7 @@ public class DragAndDropManagerTests {
    }

    @Test
    public void testDrop_SameRoot_DropOnDocument() {
    public void testDrop_Moves_SameRoot_DropOnDocument() {
        mManager.startDrag(
                mStartDragView,
                TestEnv.FOLDER_0,