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

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

Allow delegate input consumer to clear consumer state

- When we have multiple wrapped input consumers, mConsumer will be
  set to the wrapper while the caller can actually be the input
  consumer being delegated to (ie. other activity ic). So we should
  clear the consumer state if the caller is anywhere in the IC
  hierarchy.  This results in a separate issue where mGesture
  could be cleared during onConsumerAboutToBeSwitched() before being
  passed to the new consumer, so make a copy of the previous state
  just for passing to the new consumer.

Bug: 152318829
Change-Id: I4afcef5b18aa772889e9104f3977887893f174ea
parent 75add7ce
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -444,9 +444,12 @@ public class TouchInteractionService extends Service implements PluginListener<O
            GestureState newGestureState;

            if (mDeviceState.isInSwipeUpTouchRegion(event)) {
                // Clone the previous gesture state since onConsumerAboutToBeSwitched might trigger
                // onConsumerInactive and wipe the previous gesture state
                GestureState prevGestureState = new GestureState(mGestureState);
                newGestureState = createGestureState();
                mConsumer.onConsumerAboutToBeSwitched();
                mConsumer = newConsumer(mGestureState, newGestureState, event);
                mConsumer = newConsumer(prevGestureState, newGestureState, event);

                ActiveGestureLog.INSTANCE.addLog("setInputConsumer", mConsumer.getType());
                mUncheckedConsumer = mConsumer;
@@ -686,7 +689,7 @@ public class TouchInteractionService extends Service implements PluginListener<O
     * To be called by the consumer when it's no longer active.
     */
    private void onConsumerInactive(InputConsumer caller) {
        if (mConsumer == caller) {
        if (mConsumer != null && mConsumer.isInConsumerHierarchy(caller)) {
            mConsumer = mUncheckedConsumer = mResetGestureInputConsumer;
            mGestureState = new GestureState();
        }
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,11 @@ public abstract class DelegateInputConsumer implements InputConsumer {
        return mDelegate.isConsumerDetachedFromGesture();
    }

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

    @Override
    public boolean allowInterceptByParent() {
        return mDelegate.allowInterceptByParent() && mState != STATE_ACTIVE;
+11 −0
Original line number Diff line number Diff line
@@ -126,6 +126,17 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL
        mGestureId = gestureId;
    }

    public GestureState(GestureState other) {
        mHomeIntent = other.mHomeIntent;
        mOverviewIntent = other.mOverviewIntent;
        mActivityInterface = other.mActivityInterface;
        mStateCallback = other.mStateCallback;
        mGestureId = other.mGestureId;
        mRunningTask = other.mRunningTask;
        mEndTarget = other.mEndTarget;
        mFinishingRecentsAnimationTaskId = other.mFinishingRecentsAnimationTaskId;
    }

    public GestureState() {
        // Do nothing, only used for initializing the gesture state prior to user unlock
        mHomeIntent = new Intent();
+7 −0
Original line number Diff line number Diff line
@@ -69,6 +69,13 @@ public interface InputConsumer {
        return false;
    }

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

    /**
     * Called by the event queue when the consumer is about to be switched to a new consumer.
     * Consumers should update the state accordingly here before the state is passed to the new