From a8d0f22b7e839e591a5c894ce962feb66ca42ce3 Mon Sep 17 00:00:00 2001 From: Diego Vela Date: Thu, 19 May 2022 14:18:35 -0700 Subject: [PATCH] Fix no features emitting. Fix no features emitting by emitting if they are present. Ignore emitting features if the current state is not valid. No features are emitted on registration because consumers are not registered to the source. The following tests ar fixed ExtensionWindowLayoutComponent#testDisplayFeatures ExtensionWindowLayoutComponentTest#testSidecarHasSameDisplayFeatures ExtensionWindowLayoutComponentTest#testGetWindowLayoutInfo_windowRecreated_windowLayoutUpdates ExtensionWindowLayoutComponentTest#testGetWindowLayoutInfo_configChanged_windowLayoutUpdates ExtensionWindowLayoutComponentTest#testGetWindowLayoutInfo_windowRecreated_windowLayoutUpdates Bug: 232354881 Test: atest CtsWindowManagerJetpackTestCases:ExtensionWindowLayoutComponent Change-Id: Ia1f7631576bad0bbefdca0fea3308973c5514056 --- .../src/androidx/window/common/CommonFoldingFeature.java | 4 ++-- .../common/DeviceStateManagerFoldingFeatureProducer.java | 3 +++ .../window/extensions/layout/WindowLayoutComponentImpl.java | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libs/WindowManager/Jetpack/src/androidx/window/common/CommonFoldingFeature.java b/libs/WindowManager/Jetpack/src/androidx/window/common/CommonFoldingFeature.java index 921552b6cfbbe..68ff806c6765b 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/common/CommonFoldingFeature.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/common/CommonFoldingFeature.java @@ -199,7 +199,7 @@ public final class CommonFoldingFeature { throw new IllegalArgumentException( "Display feature rectangle cannot have zero width and height simultaneously."); } - this.mRect = rect; + this.mRect = new Rect(rect); } /** Returns the type of the feature. */ @@ -217,7 +217,7 @@ public final class CommonFoldingFeature { /** Returns the bounds of the feature. */ @NonNull public Rect getRect() { - return mRect; + return new Rect(mRect); } @Override diff --git a/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java b/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java index a20e7179daf1a..cc2bb63ca8e1e 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java @@ -166,6 +166,9 @@ public final class DeviceStateManagerFoldingFeatureProducer } private void notifyFoldingFeatureChange(String displayFeaturesString) { + if (!isCurrentStateValid()) { + return; + } if (TextUtils.isEmpty(displayFeaturesString)) { notifyDataChanged(new ArrayList<>()); } else { diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java index 792176b6d029c..cfb32050e32f4 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java @@ -79,6 +79,11 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent { */ public void addWindowLayoutInfoListener(@NonNull Activity activity, @NonNull Consumer consumer) { + mFoldingFeatureProducer.getData((features) -> { + // Get the WindowLayoutInfo from the activity and pass the value to the layoutConsumer. + WindowLayoutInfo newWindowLayout = getWindowLayoutInfo(activity, features); + consumer.accept(newWindowLayout); + }); mWindowLayoutChangeListeners.put(activity, consumer); }