Merge "Fix regression in app drag target windows" into sc-dev am: 90f649445f am: 3856b08bc7
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14637477 Change-Id: Ia28af169c191ef33f54552d8dae6af696ea9bdf0
This commit is contained in:
@@ -497,9 +497,10 @@ class DragState {
|
|||||||
if (targetWin == null) {
|
if (targetWin == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!interceptsGlobalDrag && containsAppExtras) {
|
final boolean isLocalWindow = mLocalWin == targetWin.mClient.asBinder();
|
||||||
// App-drags can only go to windows that can intercept global drag, and not to normal
|
if (!isLocalWindow && !interceptsGlobalDrag && containsAppExtras) {
|
||||||
// app windows
|
// App-drags can only go to local windows or windows that can intercept global drag, and
|
||||||
|
// not to other app windows
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!targetWin.isPotentialDragTarget(interceptsGlobalDrag)) {
|
if (!targetWin.isPotentialDragTarget(interceptsGlobalDrag)) {
|
||||||
@@ -507,7 +508,7 @@ class DragState {
|
|||||||
}
|
}
|
||||||
if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0 || !targetWindowSupportsGlobalDrag(targetWin)) {
|
if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0 || !targetWindowSupportsGlobalDrag(targetWin)) {
|
||||||
// Drag is limited to the current window.
|
// Drag is limited to the current window.
|
||||||
if (mLocalWin != targetWin.mClient.asBinder()) {
|
if (!isLocalWindow) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,25 +239,31 @@ public class DragDropControllerTests extends WindowTestsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInterceptGlobalDragDropIgnoresOtherWindows() {
|
public void testPrivateInterceptGlobalDragDropIgnoresNonLocalWindows() {
|
||||||
|
WindowState nonLocalWindow = createDropTargetWindow("App drag test window", 0);
|
||||||
WindowState globalInterceptWindow = createDropTargetWindow("Global drag test window", 0);
|
WindowState globalInterceptWindow = createDropTargetWindow("Global drag test window", 0);
|
||||||
globalInterceptWindow.mAttrs.privateFlags |= PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP;
|
globalInterceptWindow.mAttrs.privateFlags |= PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP;
|
||||||
|
|
||||||
// Necessary for now since DragState.sendDragStartedLocked() will recycle drag events
|
// Necessary for now since DragState.sendDragStartedLocked() will recycle drag events
|
||||||
// immediately after dispatching, which is a problem when using mockito arguments captor
|
// immediately after dispatching, which is a problem when using mockito arguments captor
|
||||||
// because it returns and modifies the same drag event
|
// because it returns and modifies the same drag event
|
||||||
TestIWindow iwindow = (TestIWindow) mWindow.mClient;
|
TestIWindow localIWindow = (TestIWindow) mWindow.mClient;
|
||||||
final ArrayList<DragEvent> dragEvents = new ArrayList<>();
|
final ArrayList<DragEvent> localWindowDragEvents = new ArrayList<>();
|
||||||
iwindow.setDragEventJournal(dragEvents);
|
localIWindow.setDragEventJournal(localWindowDragEvents);
|
||||||
|
TestIWindow nonLocalIWindow = (TestIWindow) nonLocalWindow.mClient;
|
||||||
|
final ArrayList<DragEvent> nonLocalWindowDragEvents = new ArrayList<>();
|
||||||
|
nonLocalIWindow.setDragEventJournal(nonLocalWindowDragEvents);
|
||||||
TestIWindow globalInterceptIWindow = (TestIWindow) globalInterceptWindow.mClient;
|
TestIWindow globalInterceptIWindow = (TestIWindow) globalInterceptWindow.mClient;
|
||||||
final ArrayList<DragEvent> globalInterceptWindowDragEvents = new ArrayList<>();
|
final ArrayList<DragEvent> globalInterceptWindowDragEvents = new ArrayList<>();
|
||||||
globalInterceptIWindow.setDragEventJournal(globalInterceptWindowDragEvents);
|
globalInterceptIWindow.setDragEventJournal(globalInterceptWindowDragEvents);
|
||||||
|
|
||||||
startDrag(View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ,
|
startDrag(View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ,
|
||||||
createClipDataForActivity(null, mock(UserHandle.class)), () -> {
|
createClipDataForActivity(null, mock(UserHandle.class)), () -> {
|
||||||
// Verify the start-drag event is sent for the intercept window but not the
|
// Verify the start-drag event is sent for the local and global intercept window
|
||||||
// other window
|
// but not the other window
|
||||||
assertTrue(dragEvents.isEmpty());
|
assertTrue(nonLocalWindowDragEvents.isEmpty());
|
||||||
|
assertTrue(localWindowDragEvents.get(0).getAction()
|
||||||
|
== ACTION_DRAG_STARTED);
|
||||||
assertTrue(globalInterceptWindowDragEvents.get(0).getAction()
|
assertTrue(globalInterceptWindowDragEvents.get(0).getAction()
|
||||||
== ACTION_DRAG_STARTED);
|
== ACTION_DRAG_STARTED);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user