From 8e5a164e059500f5d98e8394a66bdf0c4541287a Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 23 Feb 2022 13:32:49 -0800 Subject: [PATCH] Removing unnecessary AM.getTasks() call on every touch Bug: 220906427 Test: Verified on device Change-Id: I58ed22c4d6069f10198ec30ec02fa8c2f7c55cbe (cherry picked from commit d2ec834fac0b9a08ddf08fad188206a47b123c5a) --- .../RecentsAnimationDeviceState.java | 6 +-- .../quickstep/TouchInteractionService.java | 40 ++++++++----------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java index 73d14246a0..99a02e15ce 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java @@ -554,15 +554,13 @@ public class RecentsAnimationDeviceState implements /** * @param ev An ACTION_DOWN motion event - * @param task Info for the currently running task * @return whether the given motion event can trigger the assistant over the current task. */ - public boolean canTriggerAssistantAction(MotionEvent ev, ActivityManager.RunningTaskInfo task) { + public boolean canTriggerAssistantAction(MotionEvent ev) { return mAssistantAvailable && !QuickStepContract.isAssistantGestureDisabled(mSystemUiStateFlags) && mRotationTouchHelper.touchInAssistantRegion(ev) - && !isLockToAppActive() - && !isGestureBlockedActivity(task); + && !isLockToAppActive(); } /** diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 1f6a974c23..af8fec23fb 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -37,7 +37,6 @@ import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_N import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_TRACING_ENABLED; import android.annotation.TargetApi; -import android.app.ActivityManager; import android.app.PendingIntent; import android.app.RemoteAction; import android.app.Service; @@ -600,26 +599,14 @@ public class TouchInteractionService extends Service ActiveGestureLog.INSTANCE.addLog("setInputConsumer: " + mConsumer.getName()); mUncheckedConsumer = mConsumer; - } else if (mDeviceState.isUserUnlocked() && mDeviceState.isFullyGesturalNavMode()) { + } else if (mDeviceState.isUserUnlocked() && mDeviceState.isFullyGesturalNavMode() + && mDeviceState.canTriggerAssistantAction(event)) { mGestureState = createGestureState(mGestureState); - ActivityManager.RunningTaskInfo runningTask = mGestureState.getRunningTask(); - if (mDeviceState.canTriggerAssistantAction(event, runningTask)) { - // Do not change mConsumer as if there is an ongoing QuickSwitch gesture, we - // should not interrupt it. QuickSwitch assumes that interruption can only - // happen if the next gesture is also quick switch. - mUncheckedConsumer = new AssistantInputConsumer( - this, - mGestureState, - InputConsumer.NO_OP, mInputMonitorCompat, - mDeviceState, - event); - } else if (mDeviceState.canTriggerOneHandedAction(event)) { - // Consume gesture event for triggering one handed feature. - mUncheckedConsumer = new OneHandedModeInputConsumer(this, mDeviceState, - InputConsumer.NO_OP, mInputMonitorCompat); - } else { - mUncheckedConsumer = InputConsumer.NO_OP; - } + // Do not change mConsumer as if there is an ongoing QuickSwitch gesture, we + // should not interrupt it. QuickSwitch assumes that interruption can only + // happen if the next gesture is also quick switch. + mUncheckedConsumer = tryCreateAssistantInputConsumer( + InputConsumer.NO_OP, mGestureState, event); } else if (mDeviceState.canTriggerOneHandedAction(event)) { // Consume gesture event for triggering one handed feature. mUncheckedConsumer = new OneHandedModeInputConsumer(this, mDeviceState, @@ -666,6 +653,14 @@ public class TouchInteractionService extends Service ProtoTracer.INSTANCE.get(this).scheduleFrameUpdate(); } + private InputConsumer tryCreateAssistantInputConsumer(InputConsumer base, + GestureState gestureState, MotionEvent motionEvent) { + return mDeviceState.isGestureBlockedActivity(gestureState.getRunningTask()) + ? base + : new AssistantInputConsumer(this, gestureState, base, mInputMonitorCompat, + mDeviceState, motionEvent); + } + public GestureState createGestureState(GestureState previousGestureState) { GestureState gestureState = new GestureState(mOverviewComponentObserver, ActiveGestureLog.INSTANCE.generateAndSetLogId()); @@ -711,9 +706,8 @@ public class TouchInteractionService extends Service handleOrientationSetup(base); } if (mDeviceState.isFullyGesturalNavMode()) { - if (mDeviceState.canTriggerAssistantAction(event, newGestureState.getRunningTask())) { - base = new AssistantInputConsumer(this, newGestureState, base, mInputMonitorCompat, - mDeviceState, event); + if (mDeviceState.canTriggerAssistantAction(event)) { + base = tryCreateAssistantInputConsumer(base, newGestureState, event); } // If Taskbar is present, we listen for long press to unstash it.