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

Commit 50d9df22 authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Record latest back gesture occur on which task." into main

parents acfb66a3 cf244b08
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.window;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;

import android.annotation.AnimRes;
import android.annotation.ColorInt;
import android.annotation.IntDef;
@@ -118,6 +120,7 @@ public final class BackNavigationInfo implements Parcelable {
    private final Rect mTouchableRegion;

    private final boolean mAppProgressGenerationAllowed;
    private final int mFocusedTaskId;

    /**
     * Create a new {@link BackNavigationInfo} instance.
@@ -135,7 +138,8 @@ public final class BackNavigationInfo implements Parcelable {
            @Nullable CustomAnimationInfo customAnimationInfo,
            int letterboxColor,
            @Nullable Rect touchableRegion,
            boolean appProgressGenerationAllowed) {
            boolean appProgressGenerationAllowed,
            int focusedTaskId) {
        mType = type;
        mOnBackNavigationDone = onBackNavigationDone;
        mOnBackInvokedCallback = onBackInvokedCallback;
@@ -145,6 +149,7 @@ public final class BackNavigationInfo implements Parcelable {
        mLetterboxColor = letterboxColor;
        mTouchableRegion = new Rect(touchableRegion);
        mAppProgressGenerationAllowed = appProgressGenerationAllowed;
        mFocusedTaskId = focusedTaskId;
    }

    private BackNavigationInfo(@NonNull Parcel in) {
@@ -157,6 +162,7 @@ public final class BackNavigationInfo implements Parcelable {
        mLetterboxColor = in.readInt();
        mTouchableRegion = in.readTypedObject(Rect.CREATOR);
        mAppProgressGenerationAllowed = in.readBoolean();
        mFocusedTaskId = in.readInt();
    }

    /** @hide */
@@ -171,6 +177,7 @@ public final class BackNavigationInfo implements Parcelable {
        dest.writeInt(mLetterboxColor);
        dest.writeTypedObject(mTouchableRegion, flags);
        dest.writeBoolean(mAppProgressGenerationAllowed);
        dest.writeInt(mFocusedTaskId);
    }

    /**
@@ -237,6 +244,14 @@ public final class BackNavigationInfo implements Parcelable {
        return mAppProgressGenerationAllowed;
    }

    /**
     * @return The focused task id when back gesture start.
     * @hide
     */
    public int getFocusedTaskId() {
        return mFocusedTaskId;
    }

    /**
     * Callback to be called when the back preview is finished in order to notify the server that
     * it can clean up the resources created for the animation.
@@ -435,6 +450,7 @@ public final class BackNavigationInfo implements Parcelable {
        private int mLetterboxColor = Color.TRANSPARENT;
        private Rect mTouchableRegion;
        private boolean mAppProgressGenerationAllowed;
        private int mFocusedTaskId = INVALID_TASK_ID;

        /**
         * @see BackNavigationInfo#getType()
@@ -526,6 +542,14 @@ public final class BackNavigationInfo implements Parcelable {
            return this;
        }

        /**
         * @param focusedTaskId The current focused taskId when back gesture start.
         */
        public Builder setFocusedTaskId(int focusedTaskId) {
            mFocusedTaskId = focusedTaskId;
            return this;
        }

        /**
         * Builds and returns an instance of {@link BackNavigationInfo}
         */
@@ -537,7 +561,8 @@ public final class BackNavigationInfo implements Parcelable {
                    mCustomAnimationInfo,
                    mLetterboxColor,
                    mTouchableRegion,
                    mAppProgressGenerationAllowed);
                    mAppProgressGenerationAllowed,
                    mFocusedTaskId);
        }
    }
}
+60 −0
Original line number Diff line number Diff line
@@ -164,6 +164,9 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
     */
    private BackTouchTracker mQueuedTracker = new BackTouchTracker();

    private final FocusTaskTrackerObserver mFocusTaskTrackerObserver =
            new FocusTaskTrackerObserver();

    private final Runnable mAnimationTimeoutRunnable = () -> {
        ProtoLog.w(WM_SHELL_BACK_PREVIEW, "Animation didn't finish in %d ms. Resetting...",
                MAX_ANIMATION_DURATION);
@@ -268,6 +271,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        mBackTransitionHandler = new BackTransitionHandler();
        mTransitions.addHandler(mBackTransitionHandler);
        mHandler = handler;
        mTransitions.registerObserver(mFocusTaskTrackerObserver);
        updateTouchableArea();
    }

@@ -728,6 +732,13 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        }
    }

    /**
     * @return Latest task id which back gesture has occurred on it.
     */
    public int getLatestTriggerBackTask() {
        return mFocusTaskTrackerObserver.mFocusedTaskId;
    }

    /**
     * Sets to true when the back gesture has passed the triggering threshold, false otherwise.
     */
@@ -792,6 +803,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        boolean triggerBack = activeTouchTracker.getTriggerBack();
        ProtoLog.d(WM_SHELL_BACK_PREVIEW, "onGestureFinished() mTriggerBack == %s", triggerBack);

        if (triggerBack) {
            mFocusTaskTrackerObserver.update(mBackNavigationInfo != null
                            ? mBackNavigationInfo.getFocusedTaskId()
                            : INVALID_TASK_ID);
        }
        // Reset gesture states.
        mThresholdCrossed = false;
        mPointersPilfered = false;
@@ -1645,4 +1661,48 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    private static boolean canBeTransitionTarget(TransitionInfo.Change change) {
        return findComponentName(change) != null || findTaskId(change) != INVALID_TASK_ID;
    }

    // Record the latest back gesture happen on which task.
    static class FocusTaskTrackerObserver implements Transitions.TransitionObserver {
        int mFocusedTaskId = INVALID_TASK_ID;
        IBinder mMonitorBinder;

        void update(int focusedTaskId) {
            mFocusedTaskId = focusedTaskId;
        }

        @Override
        public void onTransitionReady(@NonNull IBinder transition, @NonNull TransitionInfo info,
                @NonNull SurfaceControl.Transaction startTransaction,
                @NonNull SurfaceControl.Transaction finishTransaction) {
            if (mFocusedTaskId == INVALID_TASK_ID) {
                return;
            }
            for (int i = info.getChanges().size() - 1; i >= 0; --i) {
                final TransitionInfo.Change c = info.getChanges().get(i);
                if (c.getTaskInfo() != null && c.getTaskInfo().taskId == mFocusedTaskId) {
                    mMonitorBinder = transition;
                    break;
                }
            }
            // Transition happen but the task isn't involved, reset.
            if (mMonitorBinder == null) {
                mFocusedTaskId = INVALID_TASK_ID;
            }
        }

        @Override
        public void onTransitionMerged(@NonNull IBinder merged, @NonNull IBinder playing) {
            if (mMonitorBinder == merged) {
                mMonitorBinder = playing;
            }
        }

        @Override
        public void onTransitionFinished(@NonNull IBinder transition, boolean aborted) {
            if (mMonitorBinder == transition) {
                mFocusedTaskId = INVALID_TASK_ID;
            }
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -201,6 +201,9 @@ class BackNavigationController {
            infoBuilder.setTouchableRegion(window.getFrame());
            infoBuilder.setAppProgressAllowed((window.getAttrs().privateFlags
                    & PRIVATE_FLAG_APP_PROGRESS_GENERATION_ALLOWED) != 0);
            if (currentTask != null) {
                infoBuilder.setFocusedTaskId(currentTask.mTaskId);
            }
            mNavigationMonitor.startMonitor(window, navigationObserver);

            ProtoLog.d(WM_DEBUG_BACK_PREVIEW, "startBackNavigation currentTask=%s, "