Merge "Synchronizing invalidating interaction handler with the eventQueue." into ub-launcher3-master
diff --git a/quickstep/src/com/android/quickstep/BaseSwipeInteractionHandler.java b/quickstep/src/com/android/quickstep/BaseSwipeInteractionHandler.java
index 5bf7e4e..b3ebd77 100644
--- a/quickstep/src/com/android/quickstep/BaseSwipeInteractionHandler.java
+++ b/quickstep/src/com/android/quickstep/BaseSwipeInteractionHandler.java
@@ -20,13 +20,11 @@
 import com.android.launcher3.states.InternalStateHandler;
 import com.android.quickstep.TouchConsumer.InteractionType;
 
-import java.util.function.Consumer;
-
 public abstract class BaseSwipeInteractionHandler extends InternalStateHandler {
 
-    protected Consumer<BaseSwipeInteractionHandler> mGestureEndCallback;
+    protected Runnable mGestureEndCallback;
 
-    public void setGestureEndCallback(Consumer<BaseSwipeInteractionHandler> gestureEndCallback) {
+    public void setGestureEndCallback(Runnable gestureEndCallback) {
         mGestureEndCallback = gestureEndCallback;
     }
 
diff --git a/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java b/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java
index ae70474..ff7d434 100644
--- a/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java
+++ b/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java
@@ -347,7 +347,7 @@
     public void reset() {
         mCurrentShift.cancelAnimation();
         if (mGestureEndCallback != null) {
-            mGestureEndCallback.accept(this);
+            mGestureEndCallback.run();
         }
     }
 
diff --git a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
index 604b60b..786ade3 100644
--- a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
+++ b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
@@ -230,6 +230,9 @@
     }
 
     private void notifyGestureStarted() {
+        if (mInteractionHandler == null) {
+            return;
+        }
         // Notify the handler that the gesture has actually started
         mInteractionHandler.onGestureStarted();
 
@@ -275,7 +278,7 @@
         // Preload the plan
         mRecentsModel.loadTasks(mRunningTask.id, null);
         mInteractionHandler = handler;
-        mInteractionHandler.setGestureEndCallback(this::onFinish);
+        mInteractionHandler.setGestureEndCallback(mEventQueue::reset);
     }
 
     private Bitmap getCurrentTaskSnapshot() {
@@ -314,7 +317,7 @@
         // Preload the plan
         mRecentsModel.loadTasks(mRunningTask.id, null);
         mInteractionHandler = handler;
-        handler.setGestureEndCallback(this::onFinish);
+        handler.setGestureEndCallback(mEventQueue::reset);
 
         CountDownLatch drawWaitLock = new CountDownLatch(1);
         handler.setLauncherOnDrawCallback(() -> {
@@ -408,8 +411,8 @@
         // Clean up the old interaction handler
         if (mInteractionHandler != null) {
             final BaseSwipeInteractionHandler handler = mInteractionHandler;
-            mMainThreadExecutor.execute(handler::reset);
             mInteractionHandler = null;
+            mMainThreadExecutor.execute(handler::reset);
         }
     }
 
@@ -450,12 +453,6 @@
         }
     }
 
-    private void onFinish(BaseSwipeInteractionHandler handler) {
-        if (mInteractionHandler == handler) {
-            mInteractionHandler = null;
-        }
-    }
-
     public void switchToMainChoreographer() {
         mEventQueue.setInterimChoreographer(null);
     }
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index ac253c7..a6192c2 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -688,7 +688,7 @@
         mCurrentShift.cancelAnimation();
 
         if (mGestureEndCallback != null) {
-            mGestureEndCallback.accept(this);
+            mGestureEndCallback.run();
         }
 
         clearReference();