From 40b4880d7ae0d74856287b18d7d7f07a9263f2dd Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 8 Sep 2022 15:40:49 +0800 Subject: [PATCH 1/2] Apply synced relayout if we have FLAG_WINDOW_VISIBILITY_CHANGED The client needs to call relayout to get the valid surface if - mFirst, - mViewVisibility != viewVisibility, - mNewSurfaceNeeded, or - mAppVisibilityChanged. We didn't cover mNewSurfaceNeeded or mAppVisibilityChanged previously. All of them are covered by FLAG_WINDOW_VISIBILITY_CHANGED. Bug: 244521023 Bug: 161810301 Test: 1. Enable LOCAL_LAYOUT 2. Open Camera and double press the power button. See if the preview screen of Camera become blank. Change-Id: I37fb8ffc9063b72bf3abba5d29fc2f750e7fc64f --- core/java/android/view/ViewRootImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index ec6b4acd6aff5..108d177d566d8 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -8085,7 +8085,8 @@ public final class ViewRootImpl implements ViewParent, final int measuredWidth = mView.getMeasuredWidth(); final int measuredHeight = mView.getMeasuredHeight(); final boolean relayoutAsync; - if (LOCAL_LAYOUT && !mFirst && viewVisibility == mViewVisibility + if (LOCAL_LAYOUT + && (mViewFrameInfo.flags & FrameInfo.FLAG_WINDOW_VISIBILITY_CHANGED) == 0 && mWindowAttributes.type != TYPE_APPLICATION_STARTING && mSyncSeqId <= mLastSyncSeqId && winConfigFromAm.diff(winConfigFromWm, false /* compareUndefined */) == 0) { From f3b99eee95a41e1da05745998a6af9a2224b73ed Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 15 Sep 2022 15:02:40 +0800 Subject: [PATCH 2/2] Don't perform config change if relayoutAsync mPendingMergedConfiguration wouldn't be updated if we didn't call IWindowSession#relayout. Bug: 244003094 Test: atest ToggleDarkThemeMicrobenchmark#testToggle Change-Id: Ibc2f40dd986136d9b54f3a7f491f7517489e05af --- core/java/android/view/ViewRootImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 108d177d566d8..e4caa385bc9b5 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -3064,7 +3064,8 @@ public final class ViewRootImpl implements ViewParent, // WindowManagerService has reported back a frame from a configuration not yet // handled by the client. In this case, we need to accept the configuration so we // do not lay out and draw with the wrong configuration. - if (!mPendingMergedConfiguration.equals(mLastReportedMergedConfiguration)) { + if (mRelayoutRequested + && !mPendingMergedConfiguration.equals(mLastReportedMergedConfiguration)) { if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " + mPendingMergedConfiguration.getMergedConfiguration()); performConfigurationChange(new MergedConfiguration(mPendingMergedConfiguration),