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

Commit 7e2ebfcd authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Update surface position while there is no surface animation playing" into main

parents c4e021c4 743129f5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -256,6 +256,11 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        }
    }

    @Override
    public boolean willUpdateSurface() {
        return !mFinished && !mCancelled;
    }

    @Override
    public @AnimationType int getAnimationType() {
        return mAnimationType;
+6 −0
Original line number Diff line number Diff line
@@ -54,6 +54,12 @@ public interface InsetsAnimationControlRunner {
     */
    void updateSurfacePosition(SparseArray<InsetsSourceControl> controls);

    /**
     * Returns {@code true} if this runner will keep playing the animation and updating the surface.
     * {@code false} otherwise.
     */
    boolean willUpdateSurface();

    /**
     * Cancels the animation.
     */
+12 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro
        }
    };

    private SurfaceParamsApplier mSurfaceParamsApplier = new SurfaceParamsApplier() {
    private final SurfaceParamsApplier mSurfaceParamsApplier = new SurfaceParamsApplier() {

        private final float[] mTmpFloat9 = new float[9];

@@ -168,6 +168,17 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro
        }
    }

    @Override
    @UiThread
    public boolean willUpdateSurface() {
        synchronized (mControl) {
            // This is called from the UI thread, however, applyChangeInsets would be called on the
            // animation thread, so we need this critical section to ensure this is not called
            // during applyChangeInsets. See: scheduleApplyChangeInsets.
            return mControl.willUpdateSurface();
        }
    }

    @Override
    @UiThread
    public void cancel() {
+36 −20
Original line number Diff line number Diff line
@@ -1747,9 +1747,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        mTypesBeingCancelled |= types;
        try {
            for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
                InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner;
                if ((control.getTypes() & types) != 0) {
                    cancelAnimation(control, true /* invokeCallback */);
                final InsetsAnimationControlRunner runner = mRunningAnimations.get(i).runner;
                if ((runner.getTypes() & types) != 0) {
                    cancelAnimation(runner, true /* invokeCallback */);
                }
            }
            if ((types & ime()) != 0) {
@@ -1807,10 +1807,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    void notifyControlRevoked(InsetsSourceConsumer consumer) {
        final @InsetsType int type = consumer.getType();
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner;
            control.notifyControlRevoked(type);
            if (control.getControllingTypes() == 0) {
                cancelAnimation(control, true /* invokeCallback */);
            final InsetsAnimationControlRunner runner = mRunningAnimations.get(i).runner;
            runner.notifyControlRevoked(type);
            if (runner.getControllingTypes() == 0) {
                cancelAnimation(runner, true /* invokeCallback */);
            }
        }
        if (type == ime()) {
@@ -1823,38 +1823,38 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
    }

    private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) {
    private void cancelAnimation(InsetsAnimationControlRunner runner, boolean invokeCallback) {
        if (invokeCallback) {
            ImeTracker.forLogging().onCancelled(control.getStatsToken(),
            ImeTracker.forLogging().onCancelled(runner.getStatsToken(),
                    ImeTracker.PHASE_CLIENT_ANIMATION_CANCEL);
            control.cancel();
            runner.cancel();
        } else {
            // Succeeds if invokeCallback is false (i.e. when called from notifyFinished).
            ImeTracker.forLogging().onProgress(control.getStatsToken(),
            ImeTracker.forLogging().onProgress(runner.getStatsToken(),
                    ImeTracker.PHASE_CLIENT_ANIMATION_CANCEL);
        }
        if (DEBUG) {
            Log.d(TAG, TextUtils.formatSimple(
                    "cancelAnimation of types: %d, animType: %d, host: %s",
                    control.getTypes(), control.getAnimationType(), mHost.getRootViewTitle()));
                    runner.getTypes(), runner.getAnimationType(), mHost.getRootViewTitle()));
        }
        @InsetsType int removedTypes = 0;
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            RunningAnimation runningAnimation = mRunningAnimations.get(i);
            if (runningAnimation.runner == control) {
            if (runningAnimation.runner == runner) {
                mRunningAnimations.remove(i);
                removedTypes = control.getTypes();
                removedTypes = runner.getTypes();
                if (invokeCallback) {
                    dispatchAnimationEnd(runningAnimation.runner.getAnimation());
                } else {
                    if (Flags.refactorInsetsController()) {
                        if ((removedTypes & ime()) != 0
                                && control.getAnimationType() == ANIMATION_TYPE_HIDE) {
                                && runner.getAnimationType() == ANIMATION_TYPE_HIDE) {
                            if (mHost != null) {
                                // if the (hide) animation is cancelled, the
                                // requestedVisibleTypes should be reported at this point.
                                reportRequestedVisibleTypes(!Flags.reportAnimatingInsetsTypes()
                                        ? control.getStatsToken() : null);
                                        ? runner.getStatsToken() : null);
                                mHost.getInputMethodManager().removeImeSurface(
                                        mHost.getWindowToken());
                            }
@@ -1869,9 +1869,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            if (mHost != null) {
                final boolean dispatchStatsToken =
                        Flags.reportAnimatingInsetsTypes() && (removedTypes & ime()) != 0
                                && control.getAnimationType() == ANIMATION_TYPE_HIDE;
                                && runner.getAnimationType() == ANIMATION_TYPE_HIDE;
                mHost.updateAnimatingTypes(mAnimatingTypes,
                        dispatchStatsToken ? control.getStatsToken() : null);
                        dispatchStatsToken ? runner.getStatsToken() : null);
            }
        }

@@ -1959,14 +1959,30 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    @VisibleForTesting(visibility = PACKAGE)
    public @AnimationType int getAnimationType(@InsetsType int type) {
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner;
            if (control.controlsType(type)) {
            final InsetsAnimationControlRunner runner = mRunningAnimations.get(i).runner;
            if (runner.controlsType(type)) {
                return mRunningAnimations.get(i).type;
            }
        }
        return ANIMATION_TYPE_NONE;
    }

    /**
     * Returns {@code true} if there is an animation which controls the given {@link InsetsType} and
     * the runner is still playing the surface animation.
     *
     * @see InsetsAnimationControlRunner#willUpdateSurface()
     */
    boolean hasSurfaceAnimation(@InsetsType int type) {
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            final InsetsAnimationControlRunner runner = mRunningAnimations.get(i).runner;
            if (runner.controlsType(type) && runner.willUpdateSurface()) {
                return true;
            }
        }
        return false;
    }

    @VisibleForTesting(visibility = PACKAGE)
    public void setRequestedVisibleTypes(@InsetsType int visibleTypes, @InsetsType int mask) {
        final @InsetsType int requestedVisibleTypes =
+5 −0
Original line number Diff line number Diff line
@@ -232,6 +232,11 @@ public class InsetsResizeAnimationRunner implements InsetsAnimationControlRunner
    public void updateSurfacePosition(SparseArray<InsetsSourceControl> controls) {
    }

    @Override
    public boolean willUpdateSurface() {
        return false;
    }

    @Override
    public boolean hasZeroInsetsIme() {
        return false;
Loading