Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32f91ab9 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Proxying touch events from RecentsTouchConsumer to Launcher

While swipe-up animation is running, the user can quickly start
another touch gesture. In that case we keep the recents transtion active
and proxy all touch events to launcher.

Bug: 110901700
Change-Id: Ie3b448dfea00473082dc9143423d3596504a3fcc
parent 0a40a187
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.uioverrides;

import static com.android.launcher3.AbstractFloatingView.TYPE_ACCESSIBLE;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
@@ -109,7 +110,7 @@ public class PortraitStatesTouchController extends AbstractStateChangeTouchContr
                return false;
            }
        }
        if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
        if (AbstractFloatingView.getTopOpenViewWithType(mLauncher, TYPE_ACCESSIBLE) != null) {
            return false;
        }
        return true;
+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.uioverrides;

import static com.android.launcher3.AbstractFloatingView.TYPE_ACCESSIBLE;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;

@@ -79,7 +80,7 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
            // If we are already animating from a previous state, we can intercept.
            return true;
        }
        if (AbstractFloatingView.getTopOpenView(mActivity) != null) {
        if (AbstractFloatingView.getTopOpenViewWithType(mActivity, TYPE_ACCESSIBLE) != null) {
            return false;
        }
        return isRecentsInteractive();
+0 −8
Original line number Diff line number Diff line
@@ -169,12 +169,4 @@ public class LongSwipeHelper {

        callback.run();
    }

    public float getTargetAlpha(RemoteAnimationTargetCompat app, Float expectedAlpha) {
        if (!(app.isNotInRecents
                || app.activityType == RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME)) {
            return 0;
        }
        return expectedAlpha;
    }
}
+102 −8
Original line number Diff line number Diff line
@@ -15,14 +15,23 @@
 */
package com.android.quickstep;

import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;

import android.view.MotionEvent;

import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.util.UiThreadHelper;
import com.android.quickstep.util.RemoteAnimationTargetSet;
import com.android.systemui.shared.system.InputConsumerController;
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;

/**
 * Wrapper around RecentsAnimationController to help with some synchronization
@@ -43,6 +52,27 @@ public class RecentsAnimationWrapper {
    private final ExecutorService mExecutorService =
            new LooperExecutor(UiThreadHelper.getBackgroundLooper());

    private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
    private InputConsumerController mInputConsumer =
            InputConsumerController.getRecentsAnimationInputConsumer();
    private final Supplier<TouchConsumer> mTouchProxySupplier;

    private boolean mInputConsumerUnregistered;
    private boolean mTouchProxyEnabled;

    private TouchConsumer mTouchConsumer;
    private boolean mTouchInProgress;
    private boolean mInputConsumerUnregisterPending;

    private boolean mFinishPending;

    public RecentsAnimationWrapper(Supplier<TouchConsumer> touchProxySupplier) {
        // Register the input consumer on the UI thread, to ensure that it runs after any pending
        // unregister calls
        mTouchProxySupplier = touchProxySupplier;
        mMainThreadExecutor.execute(mInputConsumer::registerInputConsumer);
    }

    public synchronized void setController(
            RecentsAnimationControllerCompat controller, RemoteAnimationTargetSet targetSet) {
        TraceHelper.partitionSection("RecentsController", "Set controller " + controller);
@@ -77,19 +107,35 @@ public class RecentsAnimationWrapper {
     *                         on the background thread.
     */
    public void finish(boolean toHome, Runnable onFinishComplete) {
        mExecutorService.submit(() -> {
        if (!toHome) {
            mExecutorService.submit(() -> finishBg(false, onFinishComplete));
        }

        mMainThreadExecutor.execute(() -> {
            if (mTouchInProgress) {
                mFinishPending = true;
                // Execute the callback
                if (onFinishComplete != null) {
                    onFinishComplete.run();
                }
            } else {
                mExecutorService.submit(() -> finishBg(true, onFinishComplete));
            }
        });
    }

    protected void finishBg(boolean toHome, Runnable onFinishComplete) {
        RecentsAnimationControllerCompat controller = mController;
        mController = null;
            TraceHelper.endSection("RecentsController",
                    "Finish " + controller + ", toHome=" + toHome);
        TraceHelper.endSection("RecentsController", "Finish " + controller + ", toHome=" + toHome);
        if (controller != null) {
            controller.setInputConsumerEnabled(false);
            controller.finish(toHome);

            if (onFinishComplete != null) {
                onFinishComplete.run();
            }
        }
        });
    }

    public void enableInputConsumer() {
@@ -106,6 +152,54 @@ public class RecentsAnimationWrapper {
        }
    }

    public void unregisterInputConsumer() {
        mMainThreadExecutor.execute(this::unregisterInputConsumerUi);
    }

    private void unregisterInputConsumerUi() {
        if (mTouchProxyEnabled && mTouchInProgress) {
            mInputConsumerUnregisterPending = true;
        } else {
            mInputConsumerUnregistered = true;
            mInputConsumer.unregisterInputConsumer();
        }
    }

    public void enableTouchProxy() {
        mMainThreadExecutor.execute(this::enableTouchProxyUi);
    }

    private void enableTouchProxyUi() {
        if (!mInputConsumerUnregistered) {
            mTouchProxyEnabled = true;
            mInputConsumer.setTouchListener(this::onInputConsumerTouch);
        }
    }

    private boolean onInputConsumerTouch(MotionEvent ev) {
        int action = ev.getAction();
        if (action == ACTION_DOWN) {
            mTouchInProgress = true;
            mTouchConsumer = mTouchProxySupplier.get();
        } else if (action == ACTION_CANCEL || action == ACTION_UP) {
            // Finish any pending actions
            mTouchInProgress = false;
            if (mInputConsumerUnregisterPending) {
                mInputConsumerUnregisterPending = false;
                mInputConsumer.unregisterInputConsumer();
            }
            if (mFinishPending) {
                mFinishPending = false;
                mExecutorService.submit(() -> finishBg(true, null));
            }
        }
        if (mTouchConsumer != null) {
            mTouchConsumer.accept(ev);
        }

        return true;
    }

    public void setAnimationTargetsBehindSystemBars(boolean behindSystemBars) {
        if (mBehindSystemBars == behindSystemBars) {
            return;
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import java.util.function.Consumer;
@FunctionalInterface
public interface TouchConsumer extends Consumer<MotionEvent> {

    TouchConsumer NO_OP = (ev) -> {};

    @IntDef(flag = true, value = {
            INTERACTION_NORMAL,
            INTERACTION_QUICK_SCRUB
Loading