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

Commit a726df92 authored by Winson Chung's avatar Winson Chung
Browse files

Fix issue with delegate consumers being overwritten

- Whenever the delegate consumer sets itself as active, it will cancel
  the base consumers which can cause onConsumerInactive() which will
  clear the active consumer.  Instead, we should only clear the active
  consumer, and in the case where isConsumerDetachedFromGesture() is
  checked, only check the active consumer before resetting.

  ie.
  base ic (detached) -> on touch up (do nothing) -> onConsumerInactive (active == base) -> reset
  base ic (detached), wrapped ic (active) -> onConsumerInactive (active != base) -> on touch up (active == wrapped) -> reset
  base ic (detached, active), wrapped ic -> on touch up (do nothing) -> onConsumerInactive (active == base) -> reset
  base ic (not detached) -> on touch up (active == base) -> reset
  base ic (not detached), wrapped ic (active) -> onConsumerInactive (active != base) -> on touch up (active == wrapped) -> reset
  base ic (not detached, active), wrapped ic -> on touch up (active == base) -> reset

Change-Id: I2d623c501d9c9799dadcf2005f34e1e0062c113f
parent 59431db5
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -481,14 +481,14 @@ public class TouchInteractionService extends Service implements PluginListener<O
        }

        ActiveGestureLog.INSTANCE.addLog("onMotionEvent", event.getActionMasked());
        boolean cleanUpConsumer = (action == ACTION_UP || action == ACTION_CANCEL)
                && mConsumer != null
                && !mConsumer.getActiveConsumerInHierarchy().isConsumerDetachedFromGesture();
        mUncheckedConsumer.onMotionEvent(event);

        if (action == ACTION_UP || action == ACTION_CANCEL) {
            if (mConsumer != null && !mConsumer.isConsumerDetachedFromGesture()) {
                onConsumerInactive(mConsumer);
        if (cleanUpConsumer) {
            reset();
        }
        }

        TraceHelper.INSTANCE.endFlagsOverride(traceToken);
    }

@@ -686,14 +686,20 @@ public class TouchInteractionService extends Service implements PluginListener<O
    }

    /**
     * To be called by the consumer when it's no longer active.
     * To be called by the consumer when it's no longer active. This can be called by any consumer
     * in the hierarchy at any point during the gesture (ie. if a delegate consumer starts
     * intercepting touches, the base consumer can try to call this).
     */
    private void onConsumerInactive(InputConsumer caller) {
        if (mConsumer != null && mConsumer.isInConsumerHierarchy(caller)) {
        if (mConsumer != null && mConsumer.getActiveConsumerInHierarchy() == caller) {
            reset();
        }
    }

    private void reset() {
        mConsumer = mUncheckedConsumer = mResetGestureInputConsumer;
        mGestureState = new GestureState();
    }
    }

    private void preloadOverview(boolean fromInit) {
        if (!mDeviceState.isUserUnlocked()) {
+5 −7
Original line number Diff line number Diff line
@@ -25,13 +25,11 @@ public abstract class DelegateInputConsumer implements InputConsumer {
    }

    @Override
    public boolean isConsumerDetachedFromGesture() {
        return mDelegate.isConsumerDetachedFromGesture();
    public InputConsumer getActiveConsumerInHierarchy() {
        if (mState == STATE_ACTIVE) {
            return this;
        }

    @Override
    public boolean isInConsumerHierarchy(InputConsumer candidate) {
        return this == candidate || mDelegate.isInConsumerHierarchy(candidate);
        return mDelegate.getActiveConsumerInHierarchy();
    }

    @Override
+3 −3
Original line number Diff line number Diff line
@@ -70,10 +70,10 @@ public interface InputConsumer {
    }

    /**
     * Returns true if the given input consumer is in the hierarchy of this input consumer.
     * Returns the active input consumer is in the hierarchy of this input consumer.
     */
    default boolean isInConsumerHierarchy(InputConsumer candidate) {
        return this == candidate;
    default InputConsumer getActiveConsumerInHierarchy() {
        return this;
    }

    /**