From 9af4098658c9840fe713a71668efa6074aef9bfc Mon Sep 17 00:00:00 2001 From: Diego Vela Date: Fri, 8 Apr 2022 16:06:35 -0700 Subject: [PATCH] Fix crash when unfolding a device. Fix a crash when unfolding a device with reference implementation. There is a crash because we get a callback before changes propagate. Bug: 218980376 Test: manual - open the fold samples with config changing app. fold and unfold the device. Change-Id: I3c99058e47e29b18a30921bc23b14182e970ac65 --- .../layout/WindowLayoutComponentImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 2f7d958434a3b..a6f638822d10a 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java @@ -200,12 +200,23 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent { rotateRectToDisplayRotation(displayId, featureRect); transformToWindowSpaceRect(activity, featureRect); - features.add(new FoldingFeature(featureRect, baseFeature.getType(), state)); + if (!isRectZero(featureRect)) { + // TODO(b/228641877) Remove guarding if when fixed. + features.add(new FoldingFeature(featureRect, baseFeature.getType(), state)); + } } } return features; } + /** + * Returns {@link true} if a {@link Rect} has zero width and zero height, + * {@code false} otherwise. + */ + private boolean isRectZero(Rect rect) { + return rect.width() == 0 && rect.height() == 0; + } + private final class NotifyOnConfigurationChanged extends EmptyLifecycleCallbacksAdapter { @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {