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

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

Merge "Add gesture nav error state tracking and logging" into tm-qpr-dev

parents 924852fe 038922a6
Loading
Loading
Loading
Loading
+45 −8
Original line number Original line Diff line number Diff line
@@ -46,6 +46,10 @@ import static com.android.quickstep.GestureState.STATE_END_TARGET_SET;
import static com.android.quickstep.GestureState.STATE_RECENTS_ANIMATION_CANCELED;
import static com.android.quickstep.GestureState.STATE_RECENTS_ANIMATION_CANCELED;
import static com.android.quickstep.GestureState.STATE_RECENTS_SCROLLING_FINISHED;
import static com.android.quickstep.GestureState.STATE_RECENTS_SCROLLING_FINISHED;
import static com.android.quickstep.MultiStateCallback.DEBUG_STATES;
import static com.android.quickstep.MultiStateCallback.DEBUG_STATES;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.CANCEL_RECENTS_ANIMATION;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.FINISH_RECENTS_ANIMATION;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.ON_SETTLED_ON_END_TARGET;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.START_RECENTS_ANIMATION;
import static com.android.quickstep.util.VibratorWrapper.OVERVIEW_HAPTIC;
import static com.android.quickstep.util.VibratorWrapper.OVERVIEW_HAPTIC;
import static com.android.quickstep.views.RecentsView.UPDATE_SYSUI_FLAGS_THRESHOLD;
import static com.android.quickstep.views.RecentsView.UPDATE_SYSUI_FLAGS_THRESHOLD;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;
@@ -100,6 +104,7 @@ import com.android.launcher3.util.WindowBounds;
import com.android.quickstep.BaseActivityInterface.AnimationFactory;
import com.android.quickstep.BaseActivityInterface.AnimationFactory;
import com.android.quickstep.GestureState.GestureEndTarget;
import com.android.quickstep.GestureState.GestureEndTarget;
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
import com.android.quickstep.util.ActiveGestureErrorDetector;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.AnimatorControllerWithResistance;
import com.android.quickstep.util.AnimatorControllerWithResistance;
@@ -320,8 +325,21 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        initStateCallbacks();
        initStateCallbacks();
    }
    }


    @Nullable
    private static ActiveGestureErrorDetector.GestureEvent getTrackedEventForState(int stateFlag) {
        if (stateFlag == STATE_GESTURE_STARTED) {
            return ActiveGestureErrorDetector.GestureEvent.STATE_GESTURE_STARTED;
        } else if (stateFlag == STATE_GESTURE_COMPLETED) {
            return ActiveGestureErrorDetector.GestureEvent.STATE_GESTURE_COMPLETED;
        } else if (stateFlag == STATE_GESTURE_CANCELLED) {
            return ActiveGestureErrorDetector.GestureEvent.STATE_GESTURE_CANCELLED;
        }
        return null;
    }

    private void initStateCallbacks() {
    private void initStateCallbacks() {
        mStateCallback = new MultiStateCallback(STATE_NAMES.toArray(new String[0]));
        mStateCallback = new MultiStateCallback(
                STATE_NAMES.toArray(new String[0]), AbsSwipeUpHandler::getTrackedEventForState);


        mStateCallback.runOnceAtState(STATE_LAUNCHER_PRESENT | STATE_GESTURE_STARTED,
        mStateCallback.runOnceAtState(STATE_LAUNCHER_PRESENT | STATE_GESTURE_STARTED,
                this::onLauncherPresentAndGestureStarted);
                this::onLauncherPresentAndGestureStarted);
@@ -800,7 +818,10 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    public void onRecentsAnimationStart(RecentsAnimationController controller,
    public void onRecentsAnimationStart(RecentsAnimationController controller,
            RecentsAnimationTargets targets) {
            RecentsAnimationTargets targets) {
        super.onRecentsAnimationStart(controller, targets);
        super.onRecentsAnimationStart(controller, targets);
        ActiveGestureLog.INSTANCE.addLog("startRecentsAnimationCallback", targets.apps.length);
        ActiveGestureLog.INSTANCE.addLog(
                /* event= */ "startRecentsAnimationCallback",
                /* extras= */ targets.apps.length,
                /* gestureEvent= */ START_RECENTS_ANIMATION);
        mRemoteTargetHandles = mTargetGluer.assignTargetsForSplitScreen(mContext, targets);
        mRemoteTargetHandles = mTargetGluer.assignTargetsForSplitScreen(mContext, targets);
        mRecentsAnimationController = controller;
        mRecentsAnimationController = controller;
        mRecentsAnimationTargets = targets;
        mRecentsAnimationTargets = targets;
@@ -843,7 +864,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,


    @Override
    @Override
    public void onRecentsAnimationCanceled(HashMap<Integer, ThumbnailData> thumbnailDatas) {
    public void onRecentsAnimationCanceled(HashMap<Integer, ThumbnailData> thumbnailDatas) {
        ActiveGestureLog.INSTANCE.addLog("cancelRecentsAnimation");
        ActiveGestureLog.INSTANCE.addLog(
                /* event= */ "cancelRecentsAnimation",
                /* gestureEvent= */ CANCEL_RECENTS_ANIMATION);
        mActivityInitListener.unregister();
        mActivityInitListener.unregister();
        // Cache the recents animation controller so we can defer its cleanup to after having
        // Cache the recents animation controller so we can defer its cleanup to after having
        // properly cleaned up the screenshot without accidentally using it.
        // properly cleaned up the screenshot without accidentally using it.
@@ -1010,7 +1033,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
                }
                }
                break;
                break;
        }
        }
        ActiveGestureLog.INSTANCE.addLog("onSettledOnEndTarget " + endTarget);
        ActiveGestureLog.INSTANCE.addLog(
                /* event= */ "onSettledOnEndTarget " + endTarget,
                /* gestureEvent= */ ON_SETTLED_ON_END_TARGET);
    }
    }


    /** @return Whether this was the task we were waiting to appear, and thus handled it. */
    /** @return Whether this was the task we were waiting to appear, and thus handled it. */
@@ -1587,7 +1612,10 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    private void resumeLastTask() {
    private void resumeLastTask() {
        if (mRecentsAnimationController != null) {
        if (mRecentsAnimationController != null) {
            mRecentsAnimationController.finish(false /* toRecents */, null);
            mRecentsAnimationController.finish(false /* toRecents */, null);
            ActiveGestureLog.INSTANCE.addLog("finishRecentsAnimation", false);
            ActiveGestureLog.INSTANCE.addLog(
                    /* event= */ "finishRecentsAnimation",
                    /* extras= */ false,
                    /* gestureEvent= */ FINISH_RECENTS_ANIMATION);
        }
        }
        doLogGesture(LAST_TASK, null);
        doLogGesture(LAST_TASK, null);
        reset();
        reset();
@@ -1791,7 +1819,10 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            mRecentsAnimationController.finish(true /* toRecents */,
            mRecentsAnimationController.finish(true /* toRecents */,
                    () -> mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED));
                    () -> mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED));
        }
        }
        ActiveGestureLog.INSTANCE.addLog("finishRecentsAnimation", true);
        ActiveGestureLog.INSTANCE.addLog(
                /* event= */ "finishRecentsAnimation",
                /* extras= */ true,
                /* gestureEvent= */ FINISH_RECENTS_ANIMATION);
    }
    }


    private void finishCurrentTransitionToHome() {
    private void finishCurrentTransitionToHome() {
@@ -1803,7 +1834,10 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            finishRecentsControllerToHome(
            finishRecentsControllerToHome(
                    () -> mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED));
                    () -> mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED));
        }
        }
        ActiveGestureLog.INSTANCE.addLog("finishRecentsAnimation", true);
        ActiveGestureLog.INSTANCE.addLog(
                /* event= */ "finishRecentsAnimation",
                /* extras= */ true,
                /* gestureEvent= */ FINISH_RECENTS_ANIMATION);
        doLogGesture(HOME, mRecentsView == null ? null : mRecentsView.getCurrentPageTaskView());
        doLogGesture(HOME, mRecentsView == null ? null : mRecentsView.getCurrentPageTaskView());
    }
    }


@@ -1991,7 +2025,10 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
                mRecentsAnimationController.finish(false /* toRecents */,
                mRecentsAnimationController.finish(false /* toRecents */,
                        null /* onFinishComplete */);
                        null /* onFinishComplete */);
                mActivityInterface.onLaunchTaskSuccess();
                mActivityInterface.onLaunchTaskSuccess();
                ActiveGestureLog.INSTANCE.addLog("finishRecentsAnimation", false);
                ActiveGestureLog.INSTANCE.addLog(
                        /* event= */ "finishRecentsAnimation",
                        /* extras= */ false,
                        /* gestureEvent= */ FINISH_RECENTS_ANIMATION);
            }
            }
        }
        }
    }
    }
+19 −3
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKG
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
import static com.android.quickstep.MultiStateCallback.DEBUG_STATES;
import static com.android.quickstep.MultiStateCallback.DEBUG_STATES;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.SET_END_TARGET;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.TargetApi;
import android.annotation.TargetApi;
@@ -30,6 +31,7 @@ import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.tracing.GestureStateProto;
import com.android.launcher3.tracing.GestureStateProto;
import com.android.launcher3.tracing.SwipeHandlerProto;
import com.android.launcher3.tracing.SwipeHandlerProto;
import com.android.quickstep.TopTaskTracker.CachedTaskInfo;
import com.android.quickstep.TopTaskTracker.CachedTaskInfo;
import com.android.quickstep.util.ActiveGestureErrorDetector;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
@@ -153,7 +155,8 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL
        mHomeIntent = componentObserver.getHomeIntent();
        mHomeIntent = componentObserver.getHomeIntent();
        mOverviewIntent = componentObserver.getOverviewIntent();
        mOverviewIntent = componentObserver.getOverviewIntent();
        mActivityInterface = componentObserver.getActivityInterface();
        mActivityInterface = componentObserver.getActivityInterface();
        mStateCallback = new MultiStateCallback(STATE_NAMES.toArray(new String[0]));
        mStateCallback = new MultiStateCallback(
                STATE_NAMES.toArray(new String[0]), GestureState::getTrackedEventForState);
        mGestureId = gestureId;
        mGestureId = gestureId;
    }
    }


@@ -175,10 +178,21 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL
        mHomeIntent = new Intent();
        mHomeIntent = new Intent();
        mOverviewIntent = new Intent();
        mOverviewIntent = new Intent();
        mActivityInterface = null;
        mActivityInterface = null;
        mStateCallback = new MultiStateCallback(STATE_NAMES.toArray(new String[0]));
        mStateCallback = new MultiStateCallback(
                STATE_NAMES.toArray(new String[0]), GestureState::getTrackedEventForState);
        mGestureId = -1;
        mGestureId = -1;
    }
    }


    @Nullable
    private static ActiveGestureErrorDetector.GestureEvent getTrackedEventForState(int stateFlag) {
        if (stateFlag == STATE_END_TARGET_ANIMATION_FINISHED) {
            return ActiveGestureErrorDetector.GestureEvent.STATE_END_TARGET_ANIMATION_FINISHED;
        } else if (stateFlag == STATE_RECENTS_SCROLLING_FINISHED) {
            return ActiveGestureErrorDetector.GestureEvent.STATE_RECENTS_SCROLLING_FINISHED;
        }
        return null;
    }

    /**
    /**
     * @return whether the gesture state has the provided {@param stateMask} flags set.
     * @return whether the gesture state has the provided {@param stateMask} flags set.
     */
     */
@@ -311,7 +325,9 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL
    public void setEndTarget(GestureEndTarget target, boolean isAtomic) {
    public void setEndTarget(GestureEndTarget target, boolean isAtomic) {
        mEndTarget = target;
        mEndTarget = target;
        mStateCallback.setState(STATE_END_TARGET_SET);
        mStateCallback.setState(STATE_END_TARGET_SET);
        ActiveGestureLog.INSTANCE.addLog("setEndTarget " + mEndTarget);
        ActiveGestureLog.INSTANCE.addLog(
                /* event= */ "setEndTarget " + mEndTarget,
                /* gestureEvent= */ SET_END_TARGET);
        if (isAtomic) {
        if (isAtomic) {
            mStateCallback.setState(STATE_END_TARGET_ANIMATION_FINISHED);
            mStateCallback.setState(STATE_END_TARGET_ANIMATION_FINISHED);
        }
        }
+37 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,12 @@ import android.os.Looper;
import android.util.Log;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.FeatureFlags;
import com.android.quickstep.util.ActiveGestureErrorDetector;
import com.android.quickstep.util.ActiveGestureLog;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.LinkedList;
@@ -41,17 +46,29 @@ public class MultiStateCallback {
    private final SparseArray<ArrayList<Consumer<Boolean>>> mStateChangeListeners =
    private final SparseArray<ArrayList<Consumer<Boolean>>> mStateChangeListeners =
            new SparseArray<>();
            new SparseArray<>();


    @NonNull private final TrackedEventsMapper mTrackedEventsMapper;

    private final String[] mStateNames;
    private final String[] mStateNames;


    private int mState = 0;
    private int mState = 0;


    public MultiStateCallback(String[] stateNames) {
    public MultiStateCallback(String[] stateNames) {
        this(stateNames, stateFlag -> null);
    }

    public MultiStateCallback(
            String[] stateNames,
            @NonNull TrackedEventsMapper trackedEventsMapper) {
        mStateNames = DEBUG_STATES ? stateNames : null;
        mStateNames = DEBUG_STATES ? stateNames : null;
        mTrackedEventsMapper = trackedEventsMapper;
    }
    }


    /**
    /**
     * Adds the provided state flags to the global state on the UI thread and executes any callbacks
     * Adds the provided state flags to the global state on the UI thread and executes any callbacks
     * as a result.
     * as a result.
     *
     * Also tracks the provided gesture events for error detection. Each provided event must be
     * associated with one provided state flag.
     */
     */
    public void setStateOnUiThread(int stateFlag) {
    public void setStateOnUiThread(int stateFlag) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
@@ -69,7 +86,9 @@ public class MultiStateCallback {
            Log.d(TAG, "[" + System.identityHashCode(this) + "] Adding "
            Log.d(TAG, "[" + System.identityHashCode(this) + "] Adding "
                    + convertToFlagNames(stateFlag) + " to " + convertToFlagNames(mState));
                    + convertToFlagNames(stateFlag) + " to " + convertToFlagNames(mState));
        }
        }

        if (FeatureFlags.ENABLE_GESTURE_ERROR_DETECTION.get()) {
            trackGestureEvents(stateFlag);
        }
        final int oldState = mState;
        final int oldState = mState;
        mState = mState | stateFlag;
        mState = mState | stateFlag;


@@ -87,6 +106,20 @@ public class MultiStateCallback {
        notifyStateChangeListeners(oldState);
        notifyStateChangeListeners(oldState);
    }
    }


    private void trackGestureEvents(int stateFlags) {
        for (int index = 0; (stateFlags >> index) != 0; index++) {
            if ((stateFlags & (1 << index)) == 0) {
                continue;
            }
            ActiveGestureErrorDetector.GestureEvent gestureEvent =
                    mTrackedEventsMapper.getTrackedEventForState(1 << index);
            if (gestureEvent == null) {
                continue;
            }
            ActiveGestureLog.INSTANCE.trackEvent(gestureEvent);
        }
    }

    /**
    /**
     * Adds the provided state flags to the global state and executes any change handlers
     * Adds the provided state flags to the global state and executes any change handlers
     * as a result.
     * as a result.
@@ -174,4 +207,7 @@ public class MultiStateCallback {
        return joiner.toString();
        return joiner.toString();
    }
    }


    public interface TrackedEventsMapper {
        @Nullable ActiveGestureErrorDetector.GestureEvent getTrackedEventForState(int stateflag);
    }
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.quickstep;
package com.android.quickstep;


import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.CANCEL_RECENTS_ANIMATION;


import android.graphics.Rect;
import android.graphics.Rect;
import android.util.ArraySet;
import android.util.ArraySet;
@@ -27,6 +28,7 @@ import androidx.annotation.UiThread;


import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Preconditions;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
@@ -122,6 +124,9 @@ public class RecentsAnimationCallbacks implements
    @Override
    @Override
    public final void onAnimationCanceled(HashMap<Integer, ThumbnailData> thumbnailDatas) {
    public final void onAnimationCanceled(HashMap<Integer, ThumbnailData> thumbnailDatas) {
        Utilities.postAsyncCallback(MAIN_EXECUTOR.getHandler(), () -> {
        Utilities.postAsyncCallback(MAIN_EXECUTOR.getHandler(), () -> {
            ActiveGestureLog.INSTANCE.addLog(
                    /* event= */ "onRecentsAnimationCancelled",
                    /* gestureEvent= */ CANCEL_RECENTS_ANIMATION);
            for (RecentsAnimationListener listener : getListeners()) {
            for (RecentsAnimationListener listener : getListeners()) {
                listener.onRecentsAnimationCanceled(thumbnailDatas);
                listener.onRecentsAnimationCanceled(thumbnailDatas);
            }
            }
@@ -132,6 +137,7 @@ public class RecentsAnimationCallbacks implements
    @Override
    @Override
    public void onTasksAppeared(RemoteAnimationTargetCompat[] apps) {
    public void onTasksAppeared(RemoteAnimationTargetCompat[] apps) {
        Utilities.postAsyncCallback(MAIN_EXECUTOR.getHandler(), () -> {
        Utilities.postAsyncCallback(MAIN_EXECUTOR.getHandler(), () -> {
            ActiveGestureLog.INSTANCE.addLog("onTasksAppeared");
            for (RecentsAnimationListener listener : getListeners()) {
            for (RecentsAnimationListener listener : getListeners()) {
                listener.onTasksAppeared(apps);
                listener.onTasksAppeared(apps);
            }
            }
+5 −2
Original line number Original line Diff line number Diff line
@@ -580,12 +580,15 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
                && ((mSystemUiStateFlags & SYSUI_STATE_IME_SHOWING) != 0);
                && ((mSystemUiStateFlags & SYSUI_STATE_IME_SHOWING) != 0);
    }
    }


    public String getSystemUiStateString() {
        return  QuickStepContract.getSystemUiStateString(mSystemUiStateFlags);
    }

    public void dump(PrintWriter pw) {
    public void dump(PrintWriter pw) {
        pw.println("DeviceState:");
        pw.println("DeviceState:");
        pw.println("  canStartSystemGesture=" + canStartSystemGesture());
        pw.println("  canStartSystemGesture=" + canStartSystemGesture());
        pw.println("  systemUiFlags=" + mSystemUiStateFlags);
        pw.println("  systemUiFlags=" + mSystemUiStateFlags);
        pw.println("  systemUiFlagsDesc="
        pw.println("  systemUiFlagsDesc=" + getSystemUiStateString());
                + QuickStepContract.getSystemUiStateString(mSystemUiStateFlags));
        pw.println("  assistantAvailable=" + mAssistantAvailable);
        pw.println("  assistantAvailable=" + mAssistantAvailable);
        pw.println("  assistantDisabled="
        pw.println("  assistantDisabled="
                + QuickStepContract.isAssistantGestureDisabled(mSystemUiStateFlags));
                + QuickStepContract.isAssistantGestureDisabled(mSystemUiStateFlags));
Loading