diff options
| author | 2019-04-15 15:58:11 +0900 | |
|---|---|---|
| committer | 2019-04-19 02:30:06 +0000 | |
| commit | 3e9d510586b8e5aa7d8786d2884a0d1e5c08569c (patch) | |
| tree | 2dfbf7d5236e6163e5f7c93fcc8beadd2276ff47 | |
| parent | 7deafd415b1f32a9e9c8315ddf7938d2d7ae0c2c (diff) | |
Add a flag to cancelDragAndDrop to skip animation
When running cancel animation for drag shadow image, the system cannot
start another drag operation, which is problematic when the system would
start the other drag operation quickly.
Bug: 130313958
Test: Cancel drag operation by calling cancelDragAndDrop
Change-Id: I5d6650a0ce9a4cd80bbdb1beabc9e514349ccadc
6 files changed, 13 insertions, 10 deletions
diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl index d317df05cc6e..b52fdb8399d1 100644 --- a/core/java/android/view/IWindowSession.aidl +++ b/core/java/android/view/IWindowSession.aidl @@ -187,8 +187,10 @@ interface IWindowSession { /** * Cancel the current drag operation. + * skipAnimation is 'true' when it should skip the drag cancel animation which brings the drag + * shadow image back to the drag start position. */ - void cancelDragAndDrop(IBinder dragToken); + void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation); /** * Tell the OS that we've just dragged into a View that is willing to accept the drop diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 10f9d38c3c66..5929c1b4d6e6 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -25456,7 +25456,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } if (mAttachInfo.mDragToken != null) { try { - mAttachInfo.mSession.cancelDragAndDrop(mAttachInfo.mDragToken); + mAttachInfo.mSession.cancelDragAndDrop(mAttachInfo.mDragToken, false); } catch (Exception e) { Log.e(VIEW_LOG_TAG, "Unable to cancel drag", e); } diff --git a/services/core/java/com/android/server/wm/DragDropController.java b/services/core/java/com/android/server/wm/DragDropController.java index 716e4ef2ef82..f8f6334b04dc 100644 --- a/services/core/java/com/android/server/wm/DragDropController.java +++ b/services/core/java/com/android/server/wm/DragDropController.java @@ -236,7 +236,7 @@ class DragDropController { } } - void cancelDragAndDrop(IBinder dragToken) { + void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) { if (DEBUG_DRAG) { Slog.d(TAG_WM, "cancelDragAndDrop"); } @@ -257,7 +257,7 @@ class DragDropController { } mDragState.mDragResult = false; - mDragState.cancelDragLocked(); + mDragState.cancelDragLocked(skipAnimation); } } finally { mCallback.get().postCancelDragAndDrop(); diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java index c4389667a57e..6127303141f4 100644 --- a/services/core/java/com/android/server/wm/DragState.java +++ b/services/core/java/com/android/server/wm/DragState.java @@ -475,15 +475,16 @@ class DragState { closeLocked(); } - void cancelDragLocked() { + void cancelDragLocked(boolean skipAnimation) { if (mAnimator != null) { return; } - if (!mDragInProgress) { - // This can happen if an app invokes Session#cancelDragAndDrop before + if (!mDragInProgress || skipAnimation) { + // mDragInProgress is false if an app invokes Session#cancelDragAndDrop before // Session#performDrag. Reset the drag state without playing the cancel animation // because H.DRAG_START_TIMEOUT may be sent to WindowManagerService, which will cause // DragState#reset() while playing the cancel animation. + // skipAnimation is true when a caller requests to skip the drag cancel animation. closeLocked(); return; } diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java index 22b030dd1620..b33f8c7ad658 100644 --- a/services/core/java/com/android/server/wm/Session.java +++ b/services/core/java/com/android/server/wm/Session.java @@ -283,10 +283,10 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient { } @Override - public void cancelDragAndDrop(IBinder dragToken) { + public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) { final long ident = Binder.clearCallingIdentity(); try { - mDragDropController.cancelDragAndDrop(dragToken); + mDragDropController.cancelDragAndDrop(dragToken, skipAnimation); } finally { Binder.restoreCallingIdentity(ident); } diff --git a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java index 68d8bc078d54..196cc211692c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java @@ -137,7 +137,7 @@ public class DragDropControllerTests extends WindowTestsBase { return; } if (mToken != null) { - mTarget.cancelDragAndDrop(mToken); + mTarget.cancelDragAndDrop(mToken, false); } latch = new CountDownLatch(1); mTarget.setOnClosedCallbackLocked(latch::countDown); |