From 2d6b7b0af1b2ba930e267a403af6e4c581ac9ad8 Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Mon, 6 Jun 2022 08:03:52 +0000 Subject: [PATCH] Fix CrossAppDragAndDropTests failed Currently, InputDispatcher could report the invalid drop target when receving an unexpected cancel or the drag window has gone. In other hand,`View.cancelDragAndDrop` could directly cancel the current drag state cause `reportDropWindow` access the invalid state. We should check the valid drag state when called `reportDropWindow`. Test: atest DragDropControllerTests CrossAppDragAndDropTests Bug: 234889646 Change-Id: Ibe9c94d2ff4471bfc5ff32d62e4701ef9a0d75d0 --- .../core/java/com/android/server/wm/DragDropController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/core/java/com/android/server/wm/DragDropController.java b/services/core/java/com/android/server/wm/DragDropController.java index 4ce0581530035..aa8ebf763beca 100644 --- a/services/core/java/com/android/server/wm/DragDropController.java +++ b/services/core/java/com/android/server/wm/DragDropController.java @@ -342,6 +342,11 @@ class DragDropController { } void reportDropWindow(IBinder token, float x, float y) { + if (mDragState == null) { + Slog.w(TAG_WM, "Drag state is closed."); + return; + } + synchronized (mService.mGlobalLock) { mDragState.reportDropWindowLock(token, x, y); }