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

Commit 78c1a423 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Cancelling touch interaction on multi-touch event

If the second touch happens outside the swipe region, for eg when the user
is using a different gesture like pinch-to-zoom, do not capture the
input events

Bug: 132916535
Change-Id: I59df3831b96689586a2a684bf11805d42f1cb1d9
parent c9986f59
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -476,7 +476,7 @@ public class TouchInteractionService extends Service implements
            if ((mSystemUiStateFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0) {
                base = new AccessibilityInputConsumer(this, mISystemUiProxy,
                        (mSystemUiStateFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0, base,
                        mInputMonitorCompat);
                        mInputMonitorCompat, mSwipeTouchRegion);
            }
        }
        return base;
@@ -527,7 +527,7 @@ public class TouchInteractionService extends Service implements
        return new OtherActivityInputConsumer(this, runningTaskInfo, mRecentsModel,
                mOverviewComponentObserver.getOverviewIntent(), activityControl,
                shouldDefer, mOverviewCallbacks, mInputConsumer, this::onConsumerInactive,
                mSwipeSharedState, mInputMonitorCompat);
                mSwipeSharedState, mInputMonitorCompat, mSwipeTouchRegion);
    }

    /**
+8 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.view.MotionEvent.ACTION_POINTER_UP;
import static android.view.MotionEvent.ACTION_UP;

import android.content.Context;
import android.graphics.RectF;
import android.os.RemoteException;
import android.util.Log;
import android.view.Display;
@@ -46,6 +47,7 @@ public class AccessibilityInputConsumer extends DelegateInputConsumer {
    private final VelocityTracker mVelocityTracker;
    private final MotionPauseDetector mMotionPauseDetector;
    private final boolean mAllowLongClick;
    private final RectF mSwipeTouchRegion;

    private final float mMinGestureDistance;
    private final float mMinFlingVelocity;
@@ -55,13 +57,15 @@ public class AccessibilityInputConsumer extends DelegateInputConsumer {
    private float mTotalY;

    public AccessibilityInputConsumer(Context context, ISystemUiProxy systemUiProxy,
            boolean allowLongClick, InputConsumer delegate, InputMonitorCompat inputMonitor) {
            boolean allowLongClick, InputConsumer delegate, InputMonitorCompat inputMonitor,
            RectF swipeTouchRegion) {
        super(delegate, inputMonitor);
        mSystemUiProxy = systemUiProxy;
        mVelocityTracker = VelocityTracker.obtain();
        mMinGestureDistance = context.getResources()
                .getDimension(R.dimen.accessibility_gesture_min_swipe_distance);
        mMinFlingVelocity = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();
        mSwipeTouchRegion = swipeTouchRegion;

        mMotionPauseDetector = new MotionPauseDetector(context);
        mAllowLongClick = allowLongClick;
@@ -98,10 +102,11 @@ public class AccessibilityInputConsumer extends DelegateInputConsumer {
            }
            case ACTION_POINTER_DOWN: {
                if (mState == STATE_INACTIVE) {
                    if (mDelegate.allowInterceptByParent()) {
                    int pointerIndex = ev.getActionIndex();
                    if (mSwipeTouchRegion.contains(ev.getX(pointerIndex), ev.getY(pointerIndex))
                            && mDelegate.allowInterceptByParent()) {
                        setActive(ev);

                        int pointerIndex = ev.getActionIndex();
                        mActivePointerId = ev.getPointerId(pointerIndex);
                        mDownY = ev.getY(pointerIndex);
                    } else {
+9 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.quickstep.inputconsumers;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_POINTER_UP;
import static android.view.MotionEvent.ACTION_UP;

import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction.UPLEFT;
import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction.UPRIGHT;
import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch.FLING;
@@ -38,6 +40,7 @@ import android.os.SystemClock;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;

import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.R;
import com.android.launcher3.anim.Interpolators;
@@ -117,6 +120,12 @@ public class AssistantTouchConsumer extends DelegateInputConsumer
                mTimeFraction = 0;
                break;
            }
            case ACTION_POINTER_DOWN: {
                if (mState != STATE_ACTIVE) {
                    mState = STATE_DELEGATE_ACTIVE;
                    break;
                }
            }
            case ACTION_POINTER_UP: {
                int ptrIdx = ev.getActionIndex();
                int ptrId = ev.getPointerId(ptrIdx);
+23 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.quickstep.inputconsumers;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_POINTER_UP;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.MotionEvent.INVALID_POINTER_ID;
@@ -36,6 +37,7 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
@@ -90,6 +92,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
    private final SwipeSharedState mSwipeSharedState;
    private final InputMonitorCompat mInputMonitorCompat;
    private final SysUINavigationMode.Mode mMode;
    private final RectF mSwipeTouchRegion;

    private final int mDisplayRotation;

@@ -127,7 +130,8 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
            boolean isDeferredDownTarget, OverviewCallbacks overviewCallbacks,
            InputConsumerController inputConsumer,
            Consumer<OtherActivityInputConsumer> onCompleteCallback,
            SwipeSharedState swipeSharedState, InputMonitorCompat inputMonitorCompat) {
            SwipeSharedState swipeSharedState, InputMonitorCompat inputMonitorCompat,
            RectF swipeTouchRegion) {
        super(base);

        mMainThreadHandler = new Handler(Looper.getMainLooper());
@@ -135,6 +139,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
        mRecentsModel = recentsModel;
        mHomeIntent = homeIntent;
        mMode = SysUINavigationMode.getMode(base);
        mSwipeTouchRegion = swipeTouchRegion;

        mMotionPauseDetector = new MotionPauseDetector(base);
        mMotionPauseMinDisplacement = base.getResources().getDimension(
@@ -204,6 +209,19 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
                RaceConditionTracker.onEvent(DOWN_EVT, EXIT);
                break;
            }
            case ACTION_POINTER_DOWN: {
                if (!mPassedTouchSlop) {
                    // Cancel interaction in case of multi-touch interaction
                    int ptrIdx = ev.getActionIndex();
                    if (!mSwipeTouchRegion.contains(ev.getX(ptrIdx), ev.getY(ptrIdx))) {
                        int action = ev.getAction();
                        ev.setAction(ACTION_CANCEL);
                        finishTouchTracking(ev);
                        ev.setAction(action);
                    }
                }
                break;
            }
            case ACTION_POINTER_UP: {
                int ptrIdx = ev.getActionIndex();
                int ptrId = ev.getPointerId(ptrIdx);
@@ -273,13 +291,8 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
                break;
            }
            case ACTION_CANCEL:
                // TODO: Should be different than ACTION_UP
            case ACTION_UP: {
                RaceConditionTracker.onEvent(UP_EVT, ENTER);
                TraceHelper.endSection("TouchInt");

                finishTouchTracking(ev);
                RaceConditionTracker.onEvent(UP_EVT, EXIT);
                break;
            }
        }
@@ -342,6 +355,9 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
     * the animation can still be running.
     */
    private void finishTouchTracking(MotionEvent ev) {
        RaceConditionTracker.onEvent(UP_EVT, ENTER);
        TraceHelper.endSection("TouchInt");

        if (mPassedDragSlop && mInteractionHandler != null) {
            if (ev.getActionMasked() == ACTION_CANCEL) {
                mInteractionHandler.onGestureCancelled();
@@ -374,6 +390,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mMotionPauseDetector.clear();
        RaceConditionTracker.onEvent(UP_EVT, EXIT);
    }

    @Override