From 0cb9c102249bd118cabe9f2e058f479588e9180b Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Thu, 1 Jun 2023 18:18:11 +0900 Subject: [PATCH] Fix wrong gesture insets size during rotation We use a pre-provided layout params to deal with rotation. However, the cutout in the pre-provided layout params is not calculated based on rotation correctly. Use the minimal insets size in display cutout safe field instead to let the gesture insets to be with the same size in any given location to fix the issue. Besides, the mMinimalInsetsSizeInDisplayCutoutSafe is missing in IPC, fix it by adding correct statements in the parcel related methods. Bug: 285090475 Test: Rotate the device with cutout and there's no flakiness. Change-Id: Iaddf3acf61a80cce356d009d5a3ca7539f1a33a0 --- core/java/android/view/InsetsFrameProvider.java | 13 +++++++++++-- .../systemui/navigationbar/NavigationBar.java | 14 +++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/java/android/view/InsetsFrameProvider.java b/core/java/android/view/InsetsFrameProvider.java index 470c2801d838e..37b6c77e3c74b 100644 --- a/core/java/android/view/InsetsFrameProvider.java +++ b/core/java/android/view/InsetsFrameProvider.java @@ -223,6 +223,10 @@ public class InsetsFrameProvider implements Parcelable { if (mArbitraryRectangle != null) { sb.append(", mArbitraryRectangle=").append(mArbitraryRectangle.toShortString()); } + if (mMinimalInsetsSizeInDisplayCutoutSafe != null) { + sb.append(", mMinimalInsetsSizeInDisplayCutoutSafe=") + .append(mMinimalInsetsSizeInDisplayCutoutSafe); + } sb.append("}"); return sb.toString(); } @@ -248,6 +252,7 @@ public class InsetsFrameProvider implements Parcelable { mInsetsSize = in.readTypedObject(Insets.CREATOR); mInsetsSizeOverrides = in.createTypedArray(InsetsSizeOverride.CREATOR); mArbitraryRectangle = in.readTypedObject(Rect.CREATOR); + mMinimalInsetsSizeInDisplayCutoutSafe = in.readTypedObject(Insets.CREATOR); } @Override @@ -258,6 +263,7 @@ public class InsetsFrameProvider implements Parcelable { out.writeTypedObject(mInsetsSize, flags); out.writeTypedArray(mInsetsSizeOverrides, flags); out.writeTypedObject(mArbitraryRectangle, flags); + out.writeTypedObject(mMinimalInsetsSizeInDisplayCutoutSafe, flags); } public boolean idEquals(InsetsFrameProvider o) { @@ -276,13 +282,16 @@ public class InsetsFrameProvider implements Parcelable { return mId == other.mId && mSource == other.mSource && mFlags == other.mFlags && Objects.equals(mInsetsSize, other.mInsetsSize) && Arrays.equals(mInsetsSizeOverrides, other.mInsetsSizeOverrides) - && Objects.equals(mArbitraryRectangle, other.mArbitraryRectangle); + && Objects.equals(mArbitraryRectangle, other.mArbitraryRectangle) + && Objects.equals(mMinimalInsetsSizeInDisplayCutoutSafe, + other.mMinimalInsetsSizeInDisplayCutoutSafe); } @Override public int hashCode() { return Objects.hash(mId, mSource, mFlags, mInsetsSize, - Arrays.hashCode(mInsetsSizeOverrides), mArbitraryRectangle); + Arrays.hashCode(mInsetsSizeOverrides), mArbitraryRectangle, + mMinimalInsetsSizeInDisplayCutoutSafe); } public static final @NonNull Parcelable.Creator CREATOR = diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java index b0fb349083e6c..682335e0b419a 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java @@ -76,7 +76,6 @@ import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.Log; import android.view.Display; -import android.view.DisplayCutout; import android.view.Gravity; import android.view.HapticFeedbackConstants; import android.view.InsetsFrameProvider; @@ -1730,9 +1729,6 @@ public class NavigationBar extends ViewController implements tappableElementProvider.setInsetsSize(Insets.NONE); } - final DisplayCutout cutout = userContext.getDisplay().getCutout(); - final int safeInsetsLeft = cutout != null ? cutout.getSafeInsetLeft() : 0; - final int safeInsetsRight = cutout != null ? cutout.getSafeInsetRight() : 0; final int gestureHeight = userContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.navigation_bar_gesture_height); final boolean handlingGesture = mEdgeBackGestureHandler.isHandlingGestures(); @@ -1742,19 +1738,23 @@ public class NavigationBar extends ViewController implements mandatoryGestureProvider.setInsetsSize(Insets.of(0, 0, 0, gestureHeight)); } final int gestureInsetsLeft = handlingGesture - ? mEdgeBackGestureHandler.getEdgeWidthLeft() + safeInsetsLeft : 0; + ? mEdgeBackGestureHandler.getEdgeWidthLeft() : 0; final int gestureInsetsRight = handlingGesture - ? mEdgeBackGestureHandler.getEdgeWidthRight() + safeInsetsRight : 0; + ? mEdgeBackGestureHandler.getEdgeWidthRight() : 0; return new InsetsFrameProvider[] { navBarProvider, tappableElementProvider, mandatoryGestureProvider, new InsetsFrameProvider(mInsetsSourceOwner, 0, WindowInsets.Type.systemGestures()) .setSource(InsetsFrameProvider.SOURCE_DISPLAY) - .setInsetsSize(Insets.of(gestureInsetsLeft, 0, 0, 0)), + .setInsetsSize(Insets.of(gestureInsetsLeft, 0, 0, 0)) + .setMinimalInsetsSizeInDisplayCutoutSafe( + Insets.of(gestureInsetsLeft, 0, 0, 0)), new InsetsFrameProvider(mInsetsSourceOwner, 1, WindowInsets.Type.systemGestures()) .setSource(InsetsFrameProvider.SOURCE_DISPLAY) .setInsetsSize(Insets.of(0, 0, gestureInsetsRight, 0)) + .setMinimalInsetsSizeInDisplayCutoutSafe( + Insets.of(0, 0, gestureInsetsRight, 0)) }; }