From 55581522eaf0dbb4356824d3bb8dc460110e70cc Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Sat, 17 Apr 2021 02:37:23 +0800 Subject: [PATCH] Stop processing if the new control equals the current one InsetsSourceConsumer#setControl compares the identities between the new control and current one. If they are the same, the function stops processing. However, the instance of the control returned from relayout will always be different, which makes setControl process more than expected. This CL overrides InsetsSourceControl#equals, and use it to decide if we should do further processing in setControl. Bug: 185193241 Fix: 185460364 Test: steps in the bug Change-Id: If347df353202ef441b57dabccfd0ef254ec72477 --- .../android/view/InsetsSourceConsumer.java | 7 ++++- .../android/view/InsetsSourceControl.java | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index 8e50fed7f3923..c2c8d63af7e60 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -46,6 +46,7 @@ import com.android.internal.annotations.VisibleForTesting; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Objects; import java.util.function.Supplier; /** @@ -120,7 +121,11 @@ public class InsetsSourceConsumer { ImeTracing.getInstance().triggerClientDump("InsetsSourceConsumer#setControl", mController.getHost().getInputMethodManager(), null /* icProto */); } - if (mSourceControl == control) { + if (Objects.equals(mSourceControl, control)) { + if (mSourceControl != null && mSourceControl != control) { + mSourceControl.release(SurfaceControl::release); + mSourceControl = control; + } return; } SurfaceControl oldLeash = mSourceControl != null ? mSourceControl.getLeash() : null; diff --git a/core/java/android/view/InsetsSourceControl.java b/core/java/android/view/InsetsSourceControl.java index 9256beff0e4f1..85ff93bcc5e17 100644 --- a/core/java/android/view/InsetsSourceControl.java +++ b/core/java/android/view/InsetsSourceControl.java @@ -152,6 +152,34 @@ public class InsetsSourceControl implements Parcelable { } } + @Override + public boolean equals(@Nullable Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final InsetsSourceControl that = (InsetsSourceControl) o; + final SurfaceControl thatLeash = that.mLeash; + return mType == that.mType + && ((mLeash == thatLeash) + || (mLeash != null && thatLeash != null && mLeash.isSameSurface(thatLeash))) + && mSurfacePosition.equals(that.mSurfacePosition) + && mInsetsHint.equals(that.mInsetsHint) + && mSkipAnimationOnce == that.mSkipAnimationOnce; + } + + @Override + public int hashCode() { + int result = mType; + result = 31 * result + (mLeash != null ? mLeash.hashCode() : 0); + result = 31 * result + mSurfacePosition.hashCode(); + result = 31 * result + mInsetsHint.hashCode(); + result = 31 * result + (mSkipAnimationOnce ? 1 : 0); + return result; + } + public void dump(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("InsetsSourceControl type="); pw.print(InsetsState.typeToString(mType));