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

Commit 1c073391 authored by Felix Stern's avatar Felix Stern
Browse files

Adding animatingInsetsTypes to InsetsControlTarget

During a hide or show animation, the system might need to know, which insets types are animating.
This CL is a preparation to set the requestedVisibleTypes at the beginning at the hide animation, but avoiding resetting the leash to early.

Fix: 393049691
Flag: android.view.inputmethod.report_animating_insets_types
Test: atest android.view.InsetsControllerTest#testAnimatingTypes
Change-Id: I19643d6cfbf819d207746372264f86cc6768b0df
parent 64cf3ae5
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -788,6 +788,12 @@ interface IWindowManager
    void updateDisplayWindowRequestedVisibleTypes(int displayId, int visibleTypes, int mask,
            in @nullable ImeTracker.Token statsToken);

    /**
     * Updates the currently animating insets types of a remote process.
     */
    @EnforcePermission("MANAGE_APP_TOKENS")
    void updateDisplayWindowAnimatingTypes(int displayId, int animatingTypes);

    /**
     * Called to get the expected window insets.
     *
+9 −10
Original line number Diff line number Diff line
@@ -271,6 +271,15 @@ interface IWindowSession {
    oneway void updateRequestedVisibleTypes(IWindow window, int requestedVisibleTypes,
            in @nullable ImeTracker.Token imeStatsToken);

    /**
     * Notifies WindowState what insets types are currently running within the Window.
     * see {@link com.android.server.wm.WindowState#mInsetsAnimationRunning).
     *
     * @param window The window that is insets animaiton is running.
     * @param animatingTypes Indicates the currently animating insets types.
     */
    oneway void updateAnimatingTypes(IWindow window, int animatingTypes);

    /**
     * Called when the system gesture exclusion has changed.
     */
@@ -372,14 +381,4 @@ interface IWindowSession {
     */
    oneway void notifyImeWindowVisibilityChangedFromClient(IWindow window, boolean visible,
            in ImeTracker.Token statsToken);

    /**
     * Notifies WindowState whether inset animations are currently running within the Window.
     * This value is used by the server to vote for refresh rate.
     * see {@link com.android.server.wm.WindowState#mInsetsAnimationRunning).
     *
     * @param window The window that is insets animaiton is running.
     * @param running Indicates the insets animation state.
     */
    oneway void notifyInsetsAnimationRunningStateChanged(IWindow window, boolean running);
}
+17 −20
Original line number Diff line number Diff line
@@ -211,12 +211,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }

        /**
         * Notifies when the state of running animation is changed. The state is either "running" or
         * "idle".
         * Notifies when the insets types of running animation have changed. The animatingTypes
         * contain all types, which have an ongoing animation.
         *
         * @param running {@code true} if there is any animation running; {@code false} otherwise.
         * @param animatingTypes the {@link InsetsType}s that are currently animating
         */
        default void notifyAnimationRunningStateChanged(boolean running) {}
        default void updateAnimatingTypes(@InsetsType int animatingTypes) {}

        /** @see ViewRootImpl#isHandlingPointerEvent */
        default boolean isHandlingPointerEvent() {
@@ -665,6 +665,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    /** Set of inset types which are requested visible which are reported to the host */
    private @InsetsType int mReportedRequestedVisibleTypes = WindowInsets.Type.defaultVisible();

    /** Set of insets types which are currently animating */
    private @InsetsType int mAnimatingTypes = 0;

    /** Set of inset types that we have controls of */
    private @InsetsType int mControllableTypes;

@@ -745,9 +748,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                            mFrame, mFromState, mToState, RESIZE_INTERPOLATOR,
                            ANIMATION_DURATION_RESIZE, mTypes, InsetsController.this);
                    if (mRunningAnimations.isEmpty()) {
                        mHost.notifyAnimationRunningStateChanged(true);
                        mHost.updateAnimatingTypes(runner.getTypes());
                    }
                    mRunningAnimations.add(new RunningAnimation(runner, runner.getAnimationType()));
                    mAnimatingTypes |= runner.getTypes();
                }
            };

@@ -1564,9 +1568,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            }
        }
        ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_ANIMATION_RUNNING);
        if (mRunningAnimations.isEmpty()) {
            mHost.notifyAnimationRunningStateChanged(true);
        }
        mAnimatingTypes |= runner.getTypes();
        mHost.updateAnimatingTypes(mAnimatingTypes);
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
                + useInsetsAnimationThread);
@@ -1831,7 +1834,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    dispatchAnimationEnd(runningAnimation.runner.getAnimation());
                } else {
                    if (Flags.refactorInsetsController()) {
                        if (removedTypes == ime()
                        if ((removedTypes & ime()) != 0
                                && control.getAnimationType() == ANIMATION_TYPE_HIDE) {
                            if (mHost != null) {
                                // if the (hide) animation is cancelled, the
@@ -1846,9 +1849,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                break;
            }
        }
        if (mRunningAnimations.isEmpty()) {
            mHost.notifyAnimationRunningStateChanged(false);
        if (removedTypes > 0) {
            mAnimatingTypes &= ~removedTypes;
            mHost.updateAnimatingTypes(mAnimatingTypes);
        }

        onAnimationStateChanged(removedTypes, false /* running */);
    }

@@ -1973,14 +1978,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        return animatingTypes;
    }

    private @InsetsType int computeAnimatingTypes() {
        int animatingTypes = 0;
        for (int i = 0; i < mRunningAnimations.size(); i++) {
            animatingTypes |= mRunningAnimations.get(i).runner.getTypes();
        }
        return animatingTypes;
    }

    /**
     * Called when finishing setting requested visible types or finishing setting controls.
     *
@@ -1993,7 +1990,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            // report its requested visibility at the end of the animation, otherwise we would
            // lose the leash, and it would disappear during the animation
            // TODO(b/326377046) revisit this part and see if we can make it more general
            typesToReport = mRequestedVisibleTypes | (computeAnimatingTypes() & ime());
            typesToReport = mRequestedVisibleTypes | (mAnimatingTypes & ime());
        } else {
            typesToReport = mRequestedVisibleTypes;
        }
+4 −3
Original line number Diff line number Diff line
@@ -2540,11 +2540,12 @@ public final class ViewRootImpl implements ViewParent,
    }
    /**
     * Notify the when the running state of a insets animation changed.
     * Notify the when the animating insets types have changed.
     */
    @VisibleForTesting
    public void notifyInsetsAnimationRunningStateChanged(boolean running) {
    public void updateAnimatingTypes(@InsetsType int animatingTypes) {
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
            boolean running = animatingTypes != 0;
            if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) {
                Trace.instant(Trace.TRACE_TAG_VIEW,
                        TextUtils.formatSimple("notifyInsetsAnimationRunningStateChanged(%s)",
@@ -2552,7 +2553,7 @@ public final class ViewRootImpl implements ViewParent,
            }
            mInsetsAnimationRunning = running;
            try {
                mWindowSession.notifyInsetsAnimationRunningStateChanged(mWindow, running);
                mWindowSession.updateAnimatingTypes(mWindow, animatingTypes);
            } catch (RemoteException e) {
            }
        }
+7 −7
Original line number Diff line number Diff line
@@ -170,6 +170,13 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host {
        }
    }

    @Override
    public void updateAnimatingTypes(@WindowInsets.Type.InsetsType int animatingTypes) {
        if (mViewRoot != null) {
            mViewRoot.updateAnimatingTypes(animatingTypes);
        }
    }

    @Override
    public boolean hasAnimationCallbacks() {
        if (mViewRoot.mView == null) {
@@ -274,13 +281,6 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host {
        return null;
    }

    @Override
    public void notifyAnimationRunningStateChanged(boolean running) {
        if (mViewRoot != null) {
            mViewRoot.notifyInsetsAnimationRunningStateChanged(running);
        }
    }

    @Override
    public boolean isHandlingPointerEvent() {
        return mViewRoot != null && mViewRoot.isHandlingPointerEvent();
Loading