From 63a95a2795ed35be7e92314730caa9ce1b8a998c Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Tue, 4 Jan 2022 22:48:15 +0800 Subject: [PATCH] Fix insets animations being skipped when the host view was invisible In case the insets animation frame will not be scheduled by render thread when the host window was not visible to user, added ViewRootInsetsControllerHost#isVisibleToUser to check when invoking applySurfaceParams to schedule the next frame, if the host was not visible means we don't have to synchronize with the window host and just apply the surface transaction on the UI thread directly. Fix: 206992027 Test: manual as steps 1) Receive any incoming message 2) Tap on inline reply to show the keyboard 3) Tap on the voice input button on the keyboard 4) when permission dialogue prompts on the screen, expecting both notification shade panel collpse animation and IME hiding animation are working fine without any stucked frame. Change-Id: I266587d5a3f136149d116214e2a49de92466ec2e --- core/java/android/view/InsetsController.java | 4 ++-- core/java/android/view/ViewRootInsetsControllerHost.java | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index a4841f6f0d95..7b6a0d64f980 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -1310,8 +1310,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) { - if (DEBUG) Log.d(TAG, String.format("cancelAnimation of types: %d, animType: %d", - control.getTypes(), control.getAnimationType())); + if (DEBUG) Log.d(TAG, String.format("cancelAnimation of types: %d, animType: %d, host: %s", + control.getTypes(), control.getAnimationType(), mHost.getRootViewTitle())); if (invokeCallback) { control.cancel(); } diff --git a/core/java/android/view/ViewRootInsetsControllerHost.java b/core/java/android/view/ViewRootInsetsControllerHost.java index 4387701f7a24..d960ba1489ca 100644 --- a/core/java/android/view/ViewRootInsetsControllerHost.java +++ b/core/java/android/view/ViewRootInsetsControllerHost.java @@ -125,10 +125,11 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host { if (mApplier == null) { mApplier = new SyncRtSurfaceTransactionApplier(mViewRoot.mView); } - if (mViewRoot.mView.isHardwareAccelerated()) { + if (mViewRoot.mView.isHardwareAccelerated() && isVisibleToUser()) { mApplier.scheduleApply(params); } else { - // Window doesn't support hardware acceleration, no synchronization for now. + // Synchronization requires hardware acceleration for now. + // If the window isn't visible, drawing is paused and the applier won't run. // TODO(b/149342281): use mViewRoot.mSurface.getNextFrameNumber() to sync on every // frame instead. final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); @@ -269,4 +270,8 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host { } return null; } + + private boolean isVisibleToUser() { + return mViewRoot.getHostVisibility() == View.VISIBLE; + } }