Merge "Fix RecentTasksList change id incrementing" into ub-launcher3-master
diff --git a/quickstep/libs/sysui_shared.jar b/quickstep/libs/sysui_shared.jar
index 5ec699c..8c58e3e 100644
--- a/quickstep/libs/sysui_shared.jar
+++ b/quickstep/libs/sysui_shared.jar
Binary files differ
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/InputConsumer.java
similarity index 69%
rename from quickstep/recents_ui_overrides/src/com/android/quickstep/TouchConsumer.java
rename to quickstep/recents_ui_overrides/src/com/android/quickstep/InputConsumer.java
index 12ae7b6..8dfb9ab 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchConsumer.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/InputConsumer.java
@@ -17,15 +17,13 @@
 
 import android.annotation.TargetApi;
 import android.os.Build;
+import android.view.InputEvent;
+import android.view.KeyEvent;
 import android.view.MotionEvent;
 
-import java.util.function.Consumer;
-
 @TargetApi(Build.VERSION_CODES.O)
-@FunctionalInterface
-public interface TouchConsumer extends Consumer<MotionEvent> {
-
-    TouchConsumer NO_OP = (ev) -> {};
+public interface InputConsumer {
+    InputConsumer NO_OP = new InputConsumer() { };
 
     default boolean isActive() {
         return false;
@@ -35,4 +33,16 @@
      * Called by the event queue when the consumer is about to be switched to a new consumer.
      */
     default void onConsumerAboutToBeSwitched() { }
+
+    default void onMotionEvent(MotionEvent ev) { }
+
+    default void onKeyEvent(KeyEvent ev) { }
+
+    default void onInputEvent(InputEvent ev) {
+        if (ev instanceof MotionEvent) {
+            onMotionEvent((MotionEvent) ev);
+        } else {
+            onKeyEvent((KeyEvent) ev);
+        }
+    }
 }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityInputConsumer.java
similarity index 96%
rename from quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityTouchConsumer.java
rename to quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityInputConsumer.java
index 012e670..67bfeaa 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityTouchConsumer.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityInputConsumer.java
@@ -64,13 +64,13 @@
 import java.util.function.Consumer;
 
 /**
- * Touch consumer for handling events originating from an activity other than Launcher
+ * Input consumer for handling events originating from an activity other than Launcher
  */
 @TargetApi(Build.VERSION_CODES.P)
-public class OtherActivityTouchConsumer extends ContextWrapper implements TouchConsumer {
+public class OtherActivityInputConsumer extends ContextWrapper implements InputConsumer {
 
-    public static final String DOWN_EVT = "OtherActivityTouchConsumer.DOWN";
-    private static final String UP_EVT = "OtherActivityTouchConsumer.UP";
+    public static final String DOWN_EVT = "OtherActivityInputConsumer.DOWN";
+    private static final String UP_EVT = "OtherActivityInputConsumer.UP";
 
     private final CachedEventDispatcher mRecentsViewDispatcher = new CachedEventDispatcher();
     private final RunningTaskInfo mRunningTask;
@@ -85,7 +85,7 @@
     private final int mDisplayRotation;
     private final Rect mStableInsets = new Rect();
 
-    private final Consumer<OtherActivityTouchConsumer> mOnCompleteCallback;
+    private final Consumer<OtherActivityInputConsumer> mOnCompleteCallback;
     private final MotionPauseDetector mMotionPauseDetector;
     private VelocityTracker mVelocityTracker;
 
@@ -113,11 +113,11 @@
                 true /* restoreHomeStackPosition */);
     };
 
-    public OtherActivityTouchConsumer(Context base, RunningTaskInfo runningTaskInfo,
+    public OtherActivityInputConsumer(Context base, RunningTaskInfo runningTaskInfo,
             RecentsModel recentsModel, Intent homeIntent, ActivityControlHelper activityControl,
             boolean isDeferredDownTarget, OverviewCallbacks overviewCallbacks,
             TaskOverlayFactory taskOverlayFactory, InputConsumerController inputConsumer,
-            Consumer<OtherActivityTouchConsumer> onCompleteCallback,
+            Consumer<OtherActivityInputConsumer> onCompleteCallback,
             SwipeSharedState swipeSharedState) {
         super(base);
 
@@ -148,7 +148,7 @@
     }
 
     @Override
-    public void accept(MotionEvent ev) {
+    public void onMotionEvent(MotionEvent ev) {
         if (mVelocityTracker == null) {
             return;
         }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewTouchConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewInputConsumer.java
similarity index 86%
rename from quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewTouchConsumer.java
rename to quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewInputConsumer.java
index 4da52e1..28c4db4 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewTouchConsumer.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewInputConsumer.java
@@ -20,10 +20,12 @@
 import static android.view.MotionEvent.ACTION_MOVE;
 import static android.view.MotionEvent.ACTION_UP;
 
+import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
 import static com.android.quickstep.TouchInteractionService.TOUCH_INTERACTION_LOG;
 import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;
 
 import android.graphics.PointF;
+import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.ViewConfiguration;
 
@@ -33,10 +35,10 @@
 import com.android.systemui.shared.system.ActivityManagerWrapper;
 
 /**
- * Touch consumer for handling touch on the recents/Launcher activity.
+ * Input consumer for handling touch on the recents/Launcher activity.
  */
-public class OverviewTouchConsumer<T extends BaseDraggingActivity>
-        implements TouchConsumer {
+public class OverviewInputConsumer<T extends BaseDraggingActivity>
+        implements InputConsumer {
 
     private final CachedEventDispatcher mCachedEventDispatcher = new CachedEventDispatcher();
     private final T mActivity;
@@ -50,7 +52,7 @@
     private boolean mTrackingStarted = false;
     private boolean mInvalidated = false;
 
-    OverviewTouchConsumer(T activity, boolean startingInActivityBounds) {
+    OverviewInputConsumer(T activity, boolean startingInActivityBounds) {
         mActivity = activity;
         mTarget = activity.getDragLayer();
         mTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
@@ -58,7 +60,7 @@
     }
 
     @Override
-    public void accept(MotionEvent ev) {
+    public void onMotionEvent(MotionEvent ev) {
         if (mInvalidated) {
             return;
         }
@@ -96,11 +98,18 @@
 
             // Set an empty consumer to that all the cached events are cleared
             if (!mCachedEventDispatcher.hasConsumer()) {
-                mCachedEventDispatcher.setConsumer(NO_OP);
+                mCachedEventDispatcher.setConsumer(motionEvent -> { });
             }
         }
     }
 
+    @Override
+    public void onKeyEvent(KeyEvent ev) {
+        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
+            mActivity.dispatchKeyEvent(ev);
+        }
+    }
+
     private void startTouchTracking(MotionEvent ev, boolean updateLocationOffset,
             boolean closeActiveWindows) {
         if (updateLocationOffset) {
@@ -135,12 +144,12 @@
         ev.setEdgeFlags(flags);
     }
 
-    public static TouchConsumer newInstance(ActivityControlHelper activityHelper,
+    public static InputConsumer newInstance(ActivityControlHelper activityHelper,
             boolean startingInActivityBounds) {
         BaseDraggingActivity activity = activityHelper.getCreatedActivity();
         if (activity == null) {
-            return TouchConsumer.NO_OP;
+            return InputConsumer.NO_OP;
         }
-        return new OverviewTouchConsumer(activity, startingInActivityBounds);
+        return new OverviewInputConsumer(activity, startingInActivityBounds);
     }
 }
\ No newline at end of file
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java
index 5e7c1a1..f0bc223 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java
@@ -19,6 +19,8 @@
 import static android.view.MotionEvent.ACTION_DOWN;
 import static android.view.MotionEvent.ACTION_UP;
 
+import android.view.InputEvent;
+import android.view.KeyEvent;
 import android.view.MotionEvent;
 
 import com.android.launcher3.util.Preconditions;
@@ -43,18 +45,18 @@
 
     private boolean mWindowThresholdCrossed = false;
 
-    private final InputConsumerController mInputConsumer;
-    private final Supplier<TouchConsumer> mTouchProxySupplier;
+    private final InputConsumerController mInputConsumerController;
+    private final Supplier<InputConsumer> mInputProxySupplier;
 
-    private TouchConsumer mTouchConsumer;
+    private InputConsumer mInputConsumer;
     private boolean mTouchInProgress;
 
     private boolean mFinishPending;
 
-    public RecentsAnimationWrapper(InputConsumerController inputConsumer,
-            Supplier<TouchConsumer> touchProxySupplier) {
-        mInputConsumer = inputConsumer;
-        mTouchProxySupplier = touchProxySupplier;
+    public RecentsAnimationWrapper(InputConsumerController inputConsumerController,
+            Supplier<InputConsumer> inputProxySupplier) {
+        mInputConsumerController = inputConsumerController;
+        mInputProxySupplier = inputProxySupplier;
     }
 
     @UiThread
@@ -132,15 +134,30 @@
         }
     }
 
-    public void enableTouchProxy() {
-        mInputConsumer.setTouchListener(this::onInputConsumerTouch);
+    public void enableInputProxy() {
+        mInputConsumerController.setInputListener(this::onInputConsumerEvent);
     }
 
-    private boolean onInputConsumerTouch(MotionEvent ev) {
+    private boolean onInputConsumerEvent(InputEvent ev) {
+        if (ev instanceof MotionEvent) {
+            onInputConsumerMotionEvent((MotionEvent) ev);
+        } else if (ev instanceof KeyEvent) {
+            if (mInputConsumer == null) {
+                mInputConsumer = mInputProxySupplier.get();
+            }
+            mInputConsumer.onKeyEvent((KeyEvent) ev);
+            return true;
+        }
+        return false;
+    }
+
+    private boolean onInputConsumerMotionEvent(MotionEvent ev) {
         int action = ev.getAction();
         if (action == ACTION_DOWN) {
             mTouchInProgress = true;
-            mTouchConsumer = mTouchProxySupplier.get();
+            if (mInputConsumer == null) {
+                mInputConsumer = mInputProxySupplier.get();
+            }
         } else if (action == ACTION_CANCEL || action == ACTION_UP) {
             // Finish any pending actions
             mTouchInProgress = false;
@@ -149,8 +166,8 @@
                 finishAndClear(true /* toRecents */, null);
             }
         }
-        if (mTouchConsumer != null) {
-            mTouchConsumer.accept(ev);
+        if (mInputConsumer != null) {
+            mInputConsumer.onMotionEvent(ev);
         }
 
         return true;
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java
index b542701..4b660d4 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java
@@ -42,7 +42,7 @@
         getCurrentLog().add("[" + mDateFormat.format(mCalendar.getTime()) + "]");
     }
 
-    public void setTouchConsumer(TouchConsumer consumer) {
+    public void setInputConsumer(InputConsumer consumer) {
         getCurrentLog().add("tc=" + consumer.getClass().getSimpleName());
     }
 
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
index 0ccd141..ddf3ad5 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
@@ -159,7 +159,7 @@
     private InputConsumerController mInputConsumer;
     private SwipeSharedState mSwipeSharedState;
 
-    private TouchConsumer mConsumer = TouchConsumer.NO_OP;
+    private InputConsumer mConsumer = InputConsumer.NO_OP;
     private Choreographer mMainChoreographer;
 
     private InputEventReceiver mInputEventReceiver;
@@ -226,34 +226,34 @@
             boolean useSharedState = mConsumer.isActive();
             mConsumer.onConsumerAboutToBeSwitched();
             mConsumer = newConsumer(useSharedState, event);
-            TOUCH_INTERACTION_LOG.setTouchConsumer(mConsumer);
+            TOUCH_INTERACTION_LOG.setInputConsumer(mConsumer);
         }
         TOUCH_INTERACTION_LOG.addMotionEvent(event);
 
-        mConsumer.accept(event);
+        mConsumer.onMotionEvent(event);
     }
 
-    private TouchConsumer newConsumer(boolean useSharedState, MotionEvent event) {
+    private InputConsumer newConsumer(boolean useSharedState, MotionEvent event) {
         RunningTaskInfo runningTaskInfo = mAM.getRunningTask(0);
         if (!useSharedState) {
             mSwipeSharedState.clearAllState();
         }
 
         if (runningTaskInfo == null && !mSwipeSharedState.goingToLauncher) {
-            return TouchConsumer.NO_OP;
+            return InputConsumer.NO_OP;
         } else if (mSwipeSharedState.goingToLauncher ||
                 mOverviewComponentObserver.getActivityControlHelper().isResumed()) {
-            return OverviewTouchConsumer.newInstance(
+            return OverviewInputConsumer.newInstance(
                     mOverviewComponentObserver.getActivityControlHelper(), false);
         } else if (ENABLE_QUICKSTEP_LIVE_TILE.get() &&
                 mOverviewComponentObserver.getActivityControlHelper().isInLiveTileMode()) {
-            return OverviewTouchConsumer.newInstance(
+            return OverviewInputConsumer.newInstance(
                     mOverviewComponentObserver.getActivityControlHelper(), false);
         } else {
             ActivityControlHelper activityControl =
                     mOverviewComponentObserver.getActivityControlHelper();
             boolean shouldDefer = activityControl.deferStartingActivity(mActiveNavBarRegion, event);
-            return new OtherActivityTouchConsumer(this, runningTaskInfo, mRecentsModel,
+            return new OtherActivityInputConsumer(this, runningTaskInfo, mRecentsModel,
                     mOverviewComponentObserver.getOverviewIntent(), activityControl,
                     shouldDefer, mOverviewCallbacks, mTaskOverlayFactory, mInputConsumer,
                     this::onConsumerInactive, mSwipeSharedState);
@@ -263,9 +263,9 @@
     /**
      * To be called by the consumer when it's no longer active.
      */
-    private void onConsumerInactive(TouchConsumer caller) {
+    private void onConsumerInactive(InputConsumer caller) {
         if (mConsumer == caller) {
-            mConsumer = TouchConsumer.NO_OP;
+            mConsumer = InputConsumer.NO_OP;
         }
     }
 
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
index f578149..4d0136e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -56,7 +56,6 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.os.SystemClock;
-import android.util.Log;
 import android.view.HapticFeedbackConstants;
 import android.view.MotionEvent;
 import android.view.View;
@@ -274,7 +273,7 @@
                 .createActivityInitListener(this::onActivityInit);
         mContinuingLastGesture = continuingLastGesture;
         mRecentsAnimationWrapper = new RecentsAnimationWrapper(inputConsumer,
-                this::createNewTouchProxyHandler);
+                this::createNewInputProxyHandler);
         mClipAnimationHelper = new ClipAnimationHelper(context);
         mTransformParams = new ClipAnimationHelper.TransformParams();
 
@@ -719,7 +718,7 @@
     }
 
     @UiThread
-    private TouchConsumer createNewTouchProxyHandler() {
+    private InputConsumer createNewInputProxyHandler() {
         mCurrentShift.finishAnimation();
         if (mLauncherTransitionController != null) {
             mLauncherTransitionController.getAnimationPlayer().end();
@@ -729,7 +728,7 @@
             setTargetAlphaProvider(WindowTransformSwipeHandler::getHiddenTargetAlpha);
         }
 
-        return OverviewTouchConsumer.newInstance(mActivityControlHelper, true);
+        return OverviewInputConsumer.newInstance(mActivityControlHelper, true);
     }
 
     @UiThread
@@ -823,7 +822,7 @@
             setShelfState(ShelfAnimState.CANCEL, LINEAR, 0);
             duration = Math.max(MIN_OVERSHOOT_DURATION, duration);
         } else if (endTarget == RECENTS) {
-            mRecentsAnimationWrapper.enableTouchProxy();
+            mRecentsAnimationWrapper.enableInputProxy();
             if (mRecentsView != null) {
                 duration = Math.max(duration, mRecentsView.getScroller().getDuration());
             }
diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
index c243968..fe789aa 100644
--- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
+++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
@@ -63,11 +63,11 @@
     public void testPressHome() {
         runTest(enterEvt(Launcher.ON_CREATE_EVT),
                 exitEvt(Launcher.ON_CREATE_EVT),
-                enterEvt(OtherActivityTouchConsumer.DOWN_EVT),
-                exitEvt(OtherActivityTouchConsumer.DOWN_EVT));
+                enterEvt(OtherActivityInputConsumer.DOWN_EVT),
+                exitEvt(OtherActivityInputConsumer.DOWN_EVT));
 
-        runTest(enterEvt(OtherActivityTouchConsumer.DOWN_EVT),
-                exitEvt(OtherActivityTouchConsumer.DOWN_EVT),
+        runTest(enterEvt(OtherActivityInputConsumer.DOWN_EVT),
+                exitEvt(OtherActivityInputConsumer.DOWN_EVT),
                 enterEvt(Launcher.ON_CREATE_EVT),
                 exitEvt(Launcher.ON_CREATE_EVT));
     }