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

Commit 0de0a5fa authored by Tiger's avatar Tiger
Browse files

Notify the host when the insets animation running state is changed

This helps the UI toolkit control the frame rate while there is any
insets animation running.

Bug: 300019131
Test: Add local logs to see if notifyInsetsAnimationRunningStateChanged
      is called as expected while playing insets animations.
Change-Id: I01bbacf8379ed165791b797a3e247dd7ac6e5901
parent 7d7d81a1
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -216,6 +216,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        default CompatibilityInfo.Translator getTranslator() {
            return null;
        }

        /**
         * Notifies when the state of running animation is changed. The state is either "running" or
         * "idle".
         *
         * @param running {@code true} if there is any animation running; {@code false} otherwise.
         */
        default void notifyAnimationRunningStateChanged(boolean running) {}
    }

    private static final String TAG = "InsetsController";
@@ -749,6 +757,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    final InsetsAnimationControlRunner runner = new InsetsResizeAnimationRunner(
                            mFrame, state1, mToState, RESIZE_INTERPOLATOR,
                            ANIMATION_DURATION_RESIZE, mTypes, InsetsController.this);
                    if (mRunningAnimations.isEmpty()) {
                        mHost.notifyAnimationRunningStateChanged(true);
                    }
                    mRunningAnimations.add(new RunningAnimation(runner, runner.getAnimationType()));
                }
            };
@@ -1382,6 +1393,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            }
        }
        ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_ANIMATION_RUNNING);
        if (mRunningAnimations.isEmpty()) {
            mHost.notifyAnimationRunningStateChanged(true);
        }
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
                + useInsetsAnimationThread);
@@ -1588,6 +1602,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                break;
            }
        }
        if (mRunningAnimations.isEmpty()) {
            mHost.notifyAnimationRunningStateChanged(false);
        }
        onAnimationStateChanged(removedTypes, false /* running */);
    }

+6 −0
Original line number Diff line number Diff line
@@ -816,6 +816,8 @@ public final class ViewRootImpl implements ViewParent,
    private long mFpsPrevTime = -1;
    private int mFpsNumFrames;

    private boolean mInsetsAnimationRunning;

    /**
     * The resolved pointer icon type requested by this window.
     * A null value indicates the resolved pointer icon has not yet been calculated.
@@ -2179,6 +2181,10 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    void notifyInsetsAnimationRunningStateChanged(boolean running) {
        mInsetsAnimationRunning = running;
    }

    @Override
    public void requestLayout() {
        if (!mHandlingLayoutInLayoutRequest) {
+7 −0
Original line number Diff line number Diff line
@@ -279,6 +279,13 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host {
        return null;
    }

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

    private boolean isVisibleToUser() {
        return mViewRoot.getHostVisibility() == View.VISIBLE;
    }
+7 −0
Original line number Diff line number Diff line
@@ -740,6 +740,8 @@ class InsetsPolicy {
        private final Handler mHandler;
        private final String mName;

        private boolean mInsetsAnimationRunning;

        Host(Handler handler, String name) {
            mHandler = handler;
            mName = name;
@@ -841,5 +843,10 @@ class InsetsPolicy {
        public IBinder getWindowToken() {
            return null;
        }

        @Override
        public void notifyAnimationRunningStateChanged(boolean running) {
            mInsetsAnimationRunning = running;
        }
    }
}