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

Commit c957e68e authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Android (Google) Code Review
Browse files

Merge "Add fallback handling for gesture nav mode switch and launcher...

Merge "Add fallback handling for gesture nav mode switch and launcher destroyed mid-gesture" into main
parents bb2e9732 0b15d982
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -152,8 +152,6 @@ import com.android.window.flags.Flags;
import com.android.wm.shell.common.TransactionPool;
import com.android.wm.shell.startingsurface.SplashScreenExitAnimationUtils;

import kotlin.Unit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -163,6 +161,8 @@ import java.util.Optional;
import java.util.OptionalInt;
import java.util.function.Consumer;

import kotlin.Unit;

/**
 * Handles the navigation gestures when Launcher is the default home activity.
 */
@@ -2423,34 +2423,42 @@ public abstract class AbsSwipeUpHandler<T extends RecentsViewContainer,
        if (mRecentsAnimationController == null) {
            return;
        }
        final Runnable onFinishComplete = () -> {
            ActiveGestureLog.INSTANCE.addLog(new ActiveGestureLog.CompoundString(
                    "AbsSwipeUpHandler.onTasksAppeared: ")
                    .append("force finish recents animation complete; clearing state callback."));
            mStateCallback.setStateOnUiThread(STATE_GESTURE_CANCELLED | STATE_HANDLER_INVALIDATED);
        };
        ActiveGestureLog.CompoundString forceFinishReason = new ActiveGestureLog.CompoundString(
                "Forcefully finishing recents animation: ");
        if (!mStateCallback.hasStates(STATE_GESTURE_COMPLETED)
                && !hasStartedTaskBefore(appearedTaskTargets)) {
            // This is a special case, if a task is started mid-gesture that wasn't a part of a
            // previous quickswitch task launch, then cancel the animation back to the app
            RemoteAnimationTarget appearedTaskTarget = appearedTaskTargets[0];
            TaskInfo taskInfo = appearedTaskTarget.taskInfo;
            ActiveGestureLog.INSTANCE.addLog(
                    new ActiveGestureLog.CompoundString("Unexpected task appeared")
                            .append(" id=")
            ActiveGestureLog.INSTANCE.addLog(forceFinishReason
                            .append("Unexpected task appeared id=")
                            .append(taskInfo.taskId)
                            .append(" pkg=")
                            .append(taskInfo.baseIntent.getComponent().getPackageName()));
            finishRecentsAnimationOnTasksAppeared(null /* onFinishComplete */);
            finishRecentsAnimationOnTasksAppeared(onFinishComplete);
            return;
        }
        ActiveGestureLog.CompoundString handleTaskFailureReason =
                new ActiveGestureLog.CompoundString("handleTaskAppeared check failed: ");
        if (!handleTaskAppeared(appearedTaskTargets, handleTaskFailureReason)) {
            ActiveGestureLog.INSTANCE.addLog(handleTaskFailureReason);
            finishRecentsAnimationOnTasksAppeared(null /* onFinishComplete */);
            ActiveGestureLog.INSTANCE.addLog(forceFinishReason.append(handleTaskFailureReason));
            finishRecentsAnimationOnTasksAppeared(onFinishComplete);
            return;
        }
        RemoteAnimationTarget[] taskTargets = Arrays.stream(appearedTaskTargets)
                .filter(mGestureState.mLastStartedTaskIdPredicate)
                .toArray(RemoteAnimationTarget[]::new);
        if (taskTargets.length == 0) {
            ActiveGestureLog.INSTANCE.addLog("No appeared task matching started task id");
            finishRecentsAnimationOnTasksAppeared(null /* onFinishComplete */);
            ActiveGestureLog.INSTANCE.addLog(
                    forceFinishReason.append("No appeared task matching started task id"));
            finishRecentsAnimationOnTasksAppeared(onFinishComplete);
            return;
        }
        RemoteAnimationTarget taskTarget = taskTargets[0];
@@ -2458,13 +2466,13 @@ public abstract class AbsSwipeUpHandler<T extends RecentsViewContainer,
                ? null : mRecentsView.getTaskViewByTaskId(taskTarget.taskId);
        if (taskView == null || taskView.getTaskContainers().stream().noneMatch(
                TaskContainer::getShouldShowSplashView)) {
            ActiveGestureLog.INSTANCE.addLog("Splash not needed");
            finishRecentsAnimationOnTasksAppeared(null /* onFinishComplete */);
            ActiveGestureLog.INSTANCE.addLog(forceFinishReason.append("Splash not needed"));
            finishRecentsAnimationOnTasksAppeared(onFinishComplete);
            return;
        }
        if (mContainer == null) {
            ActiveGestureLog.INSTANCE.addLog("Activity destroyed");
            finishRecentsAnimationOnTasksAppeared(null /* onFinishComplete */);
            ActiveGestureLog.INSTANCE.addLog(forceFinishReason.append("Activity destroyed"));
            finishRecentsAnimationOnTasksAppeared(onFinishComplete);
            return;
        }
        animateSplashScreenExit(mContainer, appearedTaskTargets, taskTargets);
+4 −0
Original line number Diff line number Diff line
@@ -302,6 +302,10 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
        return mNavBarPosition;
    }

    public NavigationMode getMode() {
        return mMode;
    }

    /**
     * @return whether the current nav mode is fully gestural.
     */
+28 −7
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_DOWN;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_MOVE;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_UP;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.NAVIGATION_MODE_SWITCHED;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.RECENTS_ANIMATION_START_PENDING;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYSUI_PROXY;
@@ -70,7 +71,6 @@ import android.hardware.input.InputManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.util.ArraySet;
@@ -102,6 +102,7 @@ import com.android.launcher3.testing.shared.ResourceUtils;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.LockedUserState;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.PluginManagerWrapper;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.ScreenOnTracker;
@@ -622,6 +623,8 @@ public class TouchInteractionService extends Service {
    private InputManager mInputManager;
    private final Set<Integer> mTrackpadsConnected = new ArraySet<>();

    private NavigationMode mGestureStartNavMode = null;

    @Override
    public void onCreate() {
        super.onCreate();
@@ -836,14 +839,26 @@ public class TouchInteractionService extends Service {
        TestLogging.recordMotionEvent(
                TestProtocol.SEQUENCE_TIS, "TouchInteractionService.onInputEvent", event);

        boolean isUserUnlocked = LockedUserState.get(this).isUserUnlocked();
        if (!isUserUnlocked || (mDeviceState.isButtonNavMode()
                && !isTrackpadMotionEvent(event))) {
        if (!LockedUserState.get(this).isUserUnlocked()) {
            ActiveGestureLog.INSTANCE.addLog(new CompoundString("TIS.onInputEvent: ")
                    .append("Cannot process input event: user is locked"));
            return;
        }

        NavigationMode currentNavMode = mDeviceState.getMode();
        if (mGestureStartNavMode != null && mGestureStartNavMode != currentNavMode) {
            ActiveGestureLog.INSTANCE.addLog(new CompoundString("TIS.onInputEvent: ")
                            .append("Navigation mode switched mid-gesture (")
                            .append(mGestureStartNavMode.name())
                            .append(" -> ")
                            .append(currentNavMode.name())
                            .append("); cancelling gesture."),
                    NAVIGATION_MODE_SWITCHED);
            event.setAction(ACTION_CANCEL);
        } else if (mDeviceState.isButtonNavMode() && !isTrackpadMotionEvent(event)) {
            ActiveGestureLog.INSTANCE.addLog(new CompoundString("TIS.onInputEvent: ")
                    .append("Cannot process input event: ")
                    .append(!isUserUnlocked
                            ? "user is locked"
                            : "using 3-button nav and event is not a trackpad event"));
                    .append("using 3-button nav and event is not a trackpad event"));
            return;
        }

@@ -870,6 +885,12 @@ public class TouchInteractionService extends Service {
            }
        }

        if (action == ACTION_DOWN || isHoverActionWithoutConsumer) {
            mGestureStartNavMode = currentNavMode;
        } else if (action == ACTION_UP || action == ACTION_CANCEL) {
            mGestureStartNavMode = null;
        }

        SafeCloseable traceToken = TraceHelper.INSTANCE.allowIpcs("TIS.onInputEvent");

        CompoundString reasonString = action == ACTION_DOWN
+8 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public class ActiveGestureErrorDetector {
        SCROLLER_ANIMATION_ABORTED, TASK_APPEARED, EXPECTING_TASK_APPEARED,
        FLAG_USING_OTHER_ACTIVITY_INPUT_CONSUMER, LAUNCHER_DESTROYED, RECENT_TASKS_MISSING,
        INVALID_VELOCITY_ON_SWIPE_UP, RECENTS_ANIMATION_START_PENDING,
        QUICK_SWITCH_FROM_HOME_FALLBACK, QUICK_SWITCH_FROM_HOME_FAILED,
        QUICK_SWITCH_FROM_HOME_FALLBACK, QUICK_SWITCH_FROM_HOME_FAILED, NAVIGATION_MODE_SWITCHED,

        /**
         * These GestureEvents are specifically associated to state flags that get set in
@@ -299,6 +299,13 @@ public class ActiveGestureErrorDetector {
                                    + "the current page index and index 0 were missing.",
                            writer);
                    break;
                case NAVIGATION_MODE_SWITCHED:
                    errorDetected |= printErrorIfTrue(
                            true,
                            prefix,
                            /* errorMessage= */ "Navigation mode switched mid-gesture.",
                            writer);
                    break;
                case EXPECTING_TASK_APPEARED:
                case MOTION_DOWN:
                case SET_END_TARGET: