Loading services/core/java/com/android/server/wm/DragDropController.java +0 −29 Original line number Diff line number Diff line Loading @@ -28,11 +28,9 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import android.annotation.NonNull; import android.content.ClipData; import android.content.Context; import android.hardware.display.DisplayTopology; import android.hardware.input.InputManagerGlobal; import android.os.Binder; import android.os.Handler; import android.os.HandlerExecutor; import android.os.IBinder; import android.os.Looper; import android.os.Message; Loading @@ -51,7 +49,6 @@ import android.window.IGlobalDragListener; import android.window.IUnhandledDragCallback; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.hidden_from_bootclasspath.com.android.window.flags.Flags; import com.android.server.wm.WindowManagerInternal.IDragDropCallback; import java.util.Objects; Loading @@ -59,7 +56,6 @@ import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; /** * Managing drag and drop operations initiated by View#startDragAndDrop. Loading Loading @@ -87,8 +83,6 @@ class DragDropController { private WindowManagerService mService; private final Handler mHandler; private final Consumer<DisplayTopology> mDisplayTopologyListener = this::handleDisplayTopologyChange; // The global drag listener for handling cross-window drags private IGlobalDragListener mGlobalDragListener; Loading @@ -114,17 +108,6 @@ class DragDropController { DragDropController(WindowManagerService service, Looper looper) { mService = service; mHandler = new DragHandler(service, looper); if (Flags.enableConnectedDisplaysDnd()) { mService.mDisplayManager.registerTopologyListener( new HandlerExecutor(mService.mH), mDisplayTopologyListener); } } @VisibleForTesting void cleanupListeners() { if (Flags.enableConnectedDisplaysDnd()) { mService.mDisplayManager.unregisterTopologyListener(mDisplayTopologyListener); } } @VisibleForTesting Loading Loading @@ -498,18 +481,6 @@ class DragDropController { } } private void handleDisplayTopologyChange(DisplayTopology unused) { synchronized (mService.mGlobalLock) { if (mDragState == null) { return; } if (DEBUG_DRAG) { Slog.d(TAG_WM, "DisplayTopology changed, cancelling DragAndDrop"); } cancelDragAndDrop(mDragState.mToken, true /* skipAnimation */); } } /** * Handles motion events. * @param keepHandling Whether if the drag operation is continuing or this is the last motion Loading services/tests/wmtests/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -101,7 +101,6 @@ android_test { "testng", "truth", "wmtests-support", "display_flags_lib", ], libs: [ Loading services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java +18 −63 Original line number Diff line number Diff line Loading @@ -32,12 +32,10 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; import static com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_TOPOLOGY; import static com.android.server.wm.DragDropController.MSG_UNHANDLED_DROP_LISTENER_TIMEOUT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; Loading @@ -58,7 +56,6 @@ import android.content.Intent; import android.content.pm.ShortcutServiceInternal; import android.graphics.PixelFormat; import android.graphics.Rect; import android.hardware.display.VirtualDisplay; import android.os.Binder; import android.os.Handler; import android.os.IBinder; Loading @@ -69,7 +66,6 @@ import android.os.RemoteException; import android.os.UserHandle; import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.RequiresFlagsEnabled; import android.view.DragEvent; import android.view.InputChannel; import android.view.SurfaceControl; Loading @@ -83,14 +79,12 @@ import androidx.test.filters.SmallTest; import com.android.server.LocalServices; import com.android.server.pm.UserManagerInternal; import com.android.server.wm.utils.VirtualDisplayTestRule; import com.android.window.flags.Flags; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; Loading @@ -111,8 +105,6 @@ import java.util.function.Consumer; @Presubmit @RunWith(WindowTestRunner.class) public class DragDropControllerTests extends WindowTestsBase { @Rule public VirtualDisplayTestRule mVirtualDisplayTestRule = new VirtualDisplayTestRule(); private static final int TIMEOUT_MS = 3000; private static final int TEST_UID = 12345; private static final int TEST_PROFILE_UID = 12345 * UserHandle.PER_USER_RANGE; Loading Loading @@ -228,17 +220,13 @@ public class DragDropControllerTests extends WindowTestsBase { @After public void tearDown() throws Exception { // Besides TestDragDropController, WMService also creates another DragDropController in // test, and since listeners are added on instantiation, it has to be cleared here as well. mTarget.cleanupListeners(); mWm.mDragDropController.cleanupListeners(); final CountDownLatch latch; if (!mTarget.dragDropActiveLocked()) { return; } if (mToken != null) { mTarget.cancelDragAndDrop(mToken, false); } final CountDownLatch latch; latch = new CountDownLatch(1); mTarget.setOnClosedCallbackLocked(latch::countDown); if (mTarget.mIsAccessibilityDrag) { Loading Loading @@ -349,13 +337,12 @@ public class DragDropControllerTests extends WindowTestsBase { // Verify the drop event is only sent for the global intercept window assertTrue(nonLocalWindowDragEvents.isEmpty()); assertNotEquals(ACTION_DROP, localWindowDragEvents.getLast().getAction()); assertEquals(ACTION_DROP, globalInterceptWindowDragEvents.getLast().getAction()); assertTrue(last(localWindowDragEvents).getAction() != ACTION_DROP); assertTrue(last(globalInterceptWindowDragEvents).getAction() == ACTION_DROP); // Verify that item extras were not sent with the drop event assertNull(localWindowDragEvents.getLast().getClipData()); assertFalse(globalInterceptWindowDragEvents.getLast().getClipData() assertNull(last(localWindowDragEvents).getClipData()); assertFalse(last(globalInterceptWindowDragEvents).getClipData() .willParcelWithActivityInfo()); }); } Loading Loading @@ -397,7 +384,7 @@ public class DragDropControllerTests extends WindowTestsBase { } @Test public void testDragEventCoordinatesOverlappingWindows() { public void testDragEventCoordinates() { int dragStartX = mWindow.getBounds().centerX(); int dragStartY = mWindow.getBounds().centerY(); int startOffsetPx = 10; Loading Loading @@ -442,7 +429,7 @@ public class DragDropControllerTests extends WindowTestsBase { // Verify only window2 received the DROP event and coords are sent as-is. assertEquals(1, dragEvents.size()); assertEquals(2, dragEvents2.size()); final DragEvent dropEvent = dragEvents2.getLast(); final DragEvent dropEvent = last(dragEvents2); assertEquals(ACTION_DROP, dropEvent.getAction()); assertEquals(dropCoordsPx, dropEvent.getX(), 0.0 /* delta */); assertEquals(dropCoordsPx, dropEvent.getY(), 0.0 /* delta */); Loading @@ -450,10 +437,10 @@ public class DragDropControllerTests extends WindowTestsBase { mTarget.reportDropResult(iwindow2, true); // Verify both windows received ACTION_DRAG_ENDED event. assertEquals(ACTION_DRAG_ENDED, dragEvents.getLast().getAction()); assertEquals(window2.getDisplayId(), dragEvents.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, dragEvents2.getLast().getAction()); assertEquals(window2.getDisplayId(), dragEvents2.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents).getAction()); assertEquals(window2.getDisplayId(), last(dragEvents).getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents2).getAction()); assertEquals(window2.getDisplayId(), last(dragEvents2).getDisplayId()); } finally { mTarget.continueDragStateClose(); } Loading Loading @@ -506,7 +493,7 @@ public class DragDropControllerTests extends WindowTestsBase { // Verify only window2 received the DROP event and coords are sent as-is assertEquals(1, dragEvents.size()); assertEquals(2, dragEvents2.size()); final DragEvent dropEvent = dragEvents2.getLast(); final DragEvent dropEvent = last(dragEvents2); assertEquals(ACTION_DROP, dropEvent.getAction()); assertEquals(dropCoordsPx, dropEvent.getX(), 0.0 /* delta */); assertEquals(dropCoordsPx, dropEvent.getY(), 0.0 /* delta */); Loading @@ -514,12 +501,10 @@ public class DragDropControllerTests extends WindowTestsBase { mTarget.reportDropResult(iwindow2, true); // Verify both windows received ACTION_DRAG_ENDED event. assertEquals(ACTION_DRAG_ENDED, dragEvents.getLast().getAction()); assertEquals(testDisplay.getDisplayId(), dragEvents.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, dragEvents2.getLast().getAction()); assertEquals(testDisplay.getDisplayId(), dragEvents2.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents).getAction()); assertEquals(testDisplay.getDisplayId(), last(dragEvents).getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents2).getAction()); assertEquals(testDisplay.getDisplayId(), last(dragEvents2).getDisplayId()); } finally { mTarget.continueDragStateClose(); } Loading Loading @@ -576,30 +561,8 @@ public class DragDropControllerTests extends WindowTestsBase { }); } @Test @RequiresFlagsEnabled(FLAG_DISPLAY_TOPOLOGY) @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_DND) public void testDragCancelledOnTopologyChange() { VirtualDisplay virtualDisplay = createVirtualDisplay(); // Necessary for now since DragState.sendDragStartedLocked() will recycle drag events // immediately after dispatching, which is a problem when using mockito arguments captor // because it returns and modifies the same drag event. TestIWindow iwindow = (TestIWindow) mWindow.mClient; final ArrayList<DragEvent> dragEvents = new ArrayList<>(); iwindow.setDragEventJournal(dragEvents); startDrag(0, 0, View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ, ClipData.newPlainText("label", "text"), (surface) -> { final CountDownLatch latch = new CountDownLatch(1); mTarget.setOnClosedCallbackLocked(latch::countDown); // Release virtual display to trigger drag-and-drop cancellation. virtualDisplay.release(); assertTrue(awaitInWmLock(() -> latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS))); assertEquals(2, dragEvents.size()); assertEquals(ACTION_DRAG_ENDED, dragEvents.getLast().getAction()); }); private DragEvent last(ArrayList<DragEvent> list) { return list.get(list.size() - 1); } @Test Loading Loading @@ -979,12 +942,4 @@ public class DragDropControllerTests extends WindowTestsBase { assertNotNull(mToken); r.run(); } private VirtualDisplay createVirtualDisplay() { final int width = 800; final int height = 600; final String name = getClass().getSimpleName() + "_VirtualDisplay"; return mVirtualDisplayTestRule.createDisplayManagerAttachedVirtualDisplay(name, width, height); } } Loading
services/core/java/com/android/server/wm/DragDropController.java +0 −29 Original line number Diff line number Diff line Loading @@ -28,11 +28,9 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import android.annotation.NonNull; import android.content.ClipData; import android.content.Context; import android.hardware.display.DisplayTopology; import android.hardware.input.InputManagerGlobal; import android.os.Binder; import android.os.Handler; import android.os.HandlerExecutor; import android.os.IBinder; import android.os.Looper; import android.os.Message; Loading @@ -51,7 +49,6 @@ import android.window.IGlobalDragListener; import android.window.IUnhandledDragCallback; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.hidden_from_bootclasspath.com.android.window.flags.Flags; import com.android.server.wm.WindowManagerInternal.IDragDropCallback; import java.util.Objects; Loading @@ -59,7 +56,6 @@ import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; /** * Managing drag and drop operations initiated by View#startDragAndDrop. Loading Loading @@ -87,8 +83,6 @@ class DragDropController { private WindowManagerService mService; private final Handler mHandler; private final Consumer<DisplayTopology> mDisplayTopologyListener = this::handleDisplayTopologyChange; // The global drag listener for handling cross-window drags private IGlobalDragListener mGlobalDragListener; Loading @@ -114,17 +108,6 @@ class DragDropController { DragDropController(WindowManagerService service, Looper looper) { mService = service; mHandler = new DragHandler(service, looper); if (Flags.enableConnectedDisplaysDnd()) { mService.mDisplayManager.registerTopologyListener( new HandlerExecutor(mService.mH), mDisplayTopologyListener); } } @VisibleForTesting void cleanupListeners() { if (Flags.enableConnectedDisplaysDnd()) { mService.mDisplayManager.unregisterTopologyListener(mDisplayTopologyListener); } } @VisibleForTesting Loading Loading @@ -498,18 +481,6 @@ class DragDropController { } } private void handleDisplayTopologyChange(DisplayTopology unused) { synchronized (mService.mGlobalLock) { if (mDragState == null) { return; } if (DEBUG_DRAG) { Slog.d(TAG_WM, "DisplayTopology changed, cancelling DragAndDrop"); } cancelDragAndDrop(mDragState.mToken, true /* skipAnimation */); } } /** * Handles motion events. * @param keepHandling Whether if the drag operation is continuing or this is the last motion Loading
services/tests/wmtests/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -101,7 +101,6 @@ android_test { "testng", "truth", "wmtests-support", "display_flags_lib", ], libs: [ Loading
services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java +18 −63 Original line number Diff line number Diff line Loading @@ -32,12 +32,10 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; import static com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_TOPOLOGY; import static com.android.server.wm.DragDropController.MSG_UNHANDLED_DROP_LISTENER_TIMEOUT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; Loading @@ -58,7 +56,6 @@ import android.content.Intent; import android.content.pm.ShortcutServiceInternal; import android.graphics.PixelFormat; import android.graphics.Rect; import android.hardware.display.VirtualDisplay; import android.os.Binder; import android.os.Handler; import android.os.IBinder; Loading @@ -69,7 +66,6 @@ import android.os.RemoteException; import android.os.UserHandle; import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.RequiresFlagsEnabled; import android.view.DragEvent; import android.view.InputChannel; import android.view.SurfaceControl; Loading @@ -83,14 +79,12 @@ import androidx.test.filters.SmallTest; import com.android.server.LocalServices; import com.android.server.pm.UserManagerInternal; import com.android.server.wm.utils.VirtualDisplayTestRule; import com.android.window.flags.Flags; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; Loading @@ -111,8 +105,6 @@ import java.util.function.Consumer; @Presubmit @RunWith(WindowTestRunner.class) public class DragDropControllerTests extends WindowTestsBase { @Rule public VirtualDisplayTestRule mVirtualDisplayTestRule = new VirtualDisplayTestRule(); private static final int TIMEOUT_MS = 3000; private static final int TEST_UID = 12345; private static final int TEST_PROFILE_UID = 12345 * UserHandle.PER_USER_RANGE; Loading Loading @@ -228,17 +220,13 @@ public class DragDropControllerTests extends WindowTestsBase { @After public void tearDown() throws Exception { // Besides TestDragDropController, WMService also creates another DragDropController in // test, and since listeners are added on instantiation, it has to be cleared here as well. mTarget.cleanupListeners(); mWm.mDragDropController.cleanupListeners(); final CountDownLatch latch; if (!mTarget.dragDropActiveLocked()) { return; } if (mToken != null) { mTarget.cancelDragAndDrop(mToken, false); } final CountDownLatch latch; latch = new CountDownLatch(1); mTarget.setOnClosedCallbackLocked(latch::countDown); if (mTarget.mIsAccessibilityDrag) { Loading Loading @@ -349,13 +337,12 @@ public class DragDropControllerTests extends WindowTestsBase { // Verify the drop event is only sent for the global intercept window assertTrue(nonLocalWindowDragEvents.isEmpty()); assertNotEquals(ACTION_DROP, localWindowDragEvents.getLast().getAction()); assertEquals(ACTION_DROP, globalInterceptWindowDragEvents.getLast().getAction()); assertTrue(last(localWindowDragEvents).getAction() != ACTION_DROP); assertTrue(last(globalInterceptWindowDragEvents).getAction() == ACTION_DROP); // Verify that item extras were not sent with the drop event assertNull(localWindowDragEvents.getLast().getClipData()); assertFalse(globalInterceptWindowDragEvents.getLast().getClipData() assertNull(last(localWindowDragEvents).getClipData()); assertFalse(last(globalInterceptWindowDragEvents).getClipData() .willParcelWithActivityInfo()); }); } Loading Loading @@ -397,7 +384,7 @@ public class DragDropControllerTests extends WindowTestsBase { } @Test public void testDragEventCoordinatesOverlappingWindows() { public void testDragEventCoordinates() { int dragStartX = mWindow.getBounds().centerX(); int dragStartY = mWindow.getBounds().centerY(); int startOffsetPx = 10; Loading Loading @@ -442,7 +429,7 @@ public class DragDropControllerTests extends WindowTestsBase { // Verify only window2 received the DROP event and coords are sent as-is. assertEquals(1, dragEvents.size()); assertEquals(2, dragEvents2.size()); final DragEvent dropEvent = dragEvents2.getLast(); final DragEvent dropEvent = last(dragEvents2); assertEquals(ACTION_DROP, dropEvent.getAction()); assertEquals(dropCoordsPx, dropEvent.getX(), 0.0 /* delta */); assertEquals(dropCoordsPx, dropEvent.getY(), 0.0 /* delta */); Loading @@ -450,10 +437,10 @@ public class DragDropControllerTests extends WindowTestsBase { mTarget.reportDropResult(iwindow2, true); // Verify both windows received ACTION_DRAG_ENDED event. assertEquals(ACTION_DRAG_ENDED, dragEvents.getLast().getAction()); assertEquals(window2.getDisplayId(), dragEvents.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, dragEvents2.getLast().getAction()); assertEquals(window2.getDisplayId(), dragEvents2.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents).getAction()); assertEquals(window2.getDisplayId(), last(dragEvents).getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents2).getAction()); assertEquals(window2.getDisplayId(), last(dragEvents2).getDisplayId()); } finally { mTarget.continueDragStateClose(); } Loading Loading @@ -506,7 +493,7 @@ public class DragDropControllerTests extends WindowTestsBase { // Verify only window2 received the DROP event and coords are sent as-is assertEquals(1, dragEvents.size()); assertEquals(2, dragEvents2.size()); final DragEvent dropEvent = dragEvents2.getLast(); final DragEvent dropEvent = last(dragEvents2); assertEquals(ACTION_DROP, dropEvent.getAction()); assertEquals(dropCoordsPx, dropEvent.getX(), 0.0 /* delta */); assertEquals(dropCoordsPx, dropEvent.getY(), 0.0 /* delta */); Loading @@ -514,12 +501,10 @@ public class DragDropControllerTests extends WindowTestsBase { mTarget.reportDropResult(iwindow2, true); // Verify both windows received ACTION_DRAG_ENDED event. assertEquals(ACTION_DRAG_ENDED, dragEvents.getLast().getAction()); assertEquals(testDisplay.getDisplayId(), dragEvents.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, dragEvents2.getLast().getAction()); assertEquals(testDisplay.getDisplayId(), dragEvents2.getLast().getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents).getAction()); assertEquals(testDisplay.getDisplayId(), last(dragEvents).getDisplayId()); assertEquals(ACTION_DRAG_ENDED, last(dragEvents2).getAction()); assertEquals(testDisplay.getDisplayId(), last(dragEvents2).getDisplayId()); } finally { mTarget.continueDragStateClose(); } Loading Loading @@ -576,30 +561,8 @@ public class DragDropControllerTests extends WindowTestsBase { }); } @Test @RequiresFlagsEnabled(FLAG_DISPLAY_TOPOLOGY) @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_DND) public void testDragCancelledOnTopologyChange() { VirtualDisplay virtualDisplay = createVirtualDisplay(); // Necessary for now since DragState.sendDragStartedLocked() will recycle drag events // immediately after dispatching, which is a problem when using mockito arguments captor // because it returns and modifies the same drag event. TestIWindow iwindow = (TestIWindow) mWindow.mClient; final ArrayList<DragEvent> dragEvents = new ArrayList<>(); iwindow.setDragEventJournal(dragEvents); startDrag(0, 0, View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ, ClipData.newPlainText("label", "text"), (surface) -> { final CountDownLatch latch = new CountDownLatch(1); mTarget.setOnClosedCallbackLocked(latch::countDown); // Release virtual display to trigger drag-and-drop cancellation. virtualDisplay.release(); assertTrue(awaitInWmLock(() -> latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS))); assertEquals(2, dragEvents.size()); assertEquals(ACTION_DRAG_ENDED, dragEvents.getLast().getAction()); }); private DragEvent last(ArrayList<DragEvent> list) { return list.get(list.size() - 1); } @Test Loading Loading @@ -979,12 +942,4 @@ public class DragDropControllerTests extends WindowTestsBase { assertNotNull(mToken); r.run(); } private VirtualDisplay createVirtualDisplay() { final int width = 800; final int height = 600; final String name = getClass().getSimpleName() + "_VirtualDisplay"; return mVirtualDisplayTestRule.createDisplayManagerAttachedVirtualDisplay(name, width, height); } }