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
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 496a3d8..61fe6cb 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
@@ -444,9 +444,12 @@
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 @@
* 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();
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/DelegateInputConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/DelegateInputConsumer.java
index a87e7eb..c684900 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/DelegateInputConsumer.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/DelegateInputConsumer.java
@@ -30,6 +30,11 @@
}
@Override
+ public boolean isInConsumerHierarchy(InputConsumer candidate) {
+ return this == candidate || mDelegate.isInConsumerHierarchy(candidate);
+ }
+
+ @Override
public boolean allowInterceptByParent() {
return mDelegate.allowInterceptByParent() && mState != STATE_ACTIVE;
}
diff --git a/quickstep/src/com/android/quickstep/GestureState.java b/quickstep/src/com/android/quickstep/GestureState.java
index f7e40ca..5224f83 100644
--- a/quickstep/src/com/android/quickstep/GestureState.java
+++ b/quickstep/src/com/android/quickstep/GestureState.java
@@ -126,6 +126,17 @@
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();
diff --git a/quickstep/src/com/android/quickstep/InputConsumer.java b/quickstep/src/com/android/quickstep/InputConsumer.java
index 8efaeb9..818d836 100644
--- a/quickstep/src/com/android/quickstep/InputConsumer.java
+++ b/quickstep/src/com/android/quickstep/InputConsumer.java
@@ -70,6 +70,13 @@
}
/**
+ * 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
* consumer.