diff options
| author | 2023-11-28 21:50:51 +0800 | |
|---|---|---|
| committer | 2023-11-28 21:50:51 +0800 | |
| commit | 0de0a5fae0ae057888c4625ce6efba6860b6442f (patch) | |
| tree | a69d74a441d40ec8c3f22e99e3268d257f200b6f | |
| parent | 7d7d81a1440673a7d848eb0014e3f72a02cbfe4c (diff) | |
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
4 files changed, 37 insertions, 0 deletions
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 90663c7ad38e..147c15bea076 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -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 */); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 7a6c2929c706..b1076277ee2d 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -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) { diff --git a/core/java/android/view/ViewRootInsetsControllerHost.java b/core/java/android/view/ViewRootInsetsControllerHost.java index a2708eead171..40730e8de849 100644 --- a/core/java/android/view/ViewRootInsetsControllerHost.java +++ b/core/java/android/view/ViewRootInsetsControllerHost.java @@ -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; } diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index e6bbd52807bd..c089d107d07d 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -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; + } } } |