diff options
| author | Tiger Huang <tigerhuang@google.com> | 2021-06-24 13:40:22 +0800 |
|---|---|---|
| committer | Tiger Huang <tigerhuang@google.com> | 2021-06-24 09:42:32 +0000 |
| commit | c7746aa3deb9deffcab5a50b80ffec4a08740982 (patch) | |
| tree | e07ead0074e411f3f4847001fcc10256817bcd92 /core/java | |
| parent | 9515d87dbbdf530abfac876f0547fee27b188d0e (diff) | |
Release leashes of insets controls if they are not needed
Previously, leashes would be only released by GC in some cases, but the
timing could be late. This CL proactively release them as long as they
are not needed. The cases were:
1. The leashes in DisplayImeController. It didn't release leashes while
receiving a new one.
2. The leashes returned from addWindow/relayoutWindow. The leashes would
be copied to prevent others from releasing them before writeToParcel.
The copied leashes could be redundant after writeToParcel.
3. The leashes held by the client whose window is removed. If a window
is removed, the server won't invoke mClient.insetsControlChanged, so
the client would never get notified about losing control to release
the leashes. This could happen if the window doesn't have an exiting
animation.
Fix: 175851610
Test: Steps in the bug.
Test: Show and dismiss a dialog which doesn't have FLAG_ALT_FOCUSABLE_IM
or any window animation. Repeat this thousands of times. And see
if there are many insets leashes as offscreen layers in `dumpsys
SurfaceFlinger`
Change-Id: I5eb774ac071154a8d7205dbd1ab4a5f8eca215c3
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/InsetsSourceControl.java | 11 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 15 |
2 files changed, 22 insertions, 4 deletions
diff --git a/core/java/android/view/InsetsSourceControl.java b/core/java/android/view/InsetsSourceControl.java index 85ff93bcc5e1..1506ee4c2c7a 100644 --- a/core/java/android/view/InsetsSourceControl.java +++ b/core/java/android/view/InsetsSourceControl.java @@ -48,6 +48,7 @@ public class InsetsSourceControl implements Parcelable { private Insets mInsetsHint; private boolean mSkipAnimationOnce; + private int mParcelableFlags; public InsetsSourceControl(@InternalInsetsType int type, @Nullable SurfaceControl leash, Point surfacePosition, Insets insetsHint) { @@ -132,6 +133,10 @@ public class InsetsSourceControl implements Parcelable { return result; } + public void setParcelableFlags(int parcelableFlags) { + mParcelableFlags = parcelableFlags; + } + @Override public int describeContents() { return 0; @@ -140,9 +145,9 @@ public class InsetsSourceControl implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mType); - dest.writeTypedObject(mLeash, 0 /* parcelableFlags */); - dest.writeTypedObject(mSurfacePosition, 0 /* parcelableFlags */); - dest.writeTypedObject(mInsetsHint, 0 /* parcelableFlags */); + dest.writeTypedObject(mLeash, mParcelableFlags); + dest.writeTypedObject(mSurfacePosition, mParcelableFlags); + dest.writeTypedObject(mInsetsHint, mParcelableFlags); dest.writeBoolean(mSkipAnimationOnce); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index d42e0c367763..a6464e75795c 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -5269,7 +5269,16 @@ public final class ViewRootImpl implements ViewParent, // b) When loosing control, controller can restore server state by taking last // dispatched state as truth. mInsetsController.onStateChanged((InsetsState) args.arg1); - mInsetsController.onControlsChanged((InsetsSourceControl[]) args.arg2); + InsetsSourceControl[] controls = (InsetsSourceControl[]) args.arg2; + if (mAdded) { + mInsetsController.onControlsChanged(controls); + } else if (controls != null) { + for (InsetsSourceControl control : controls) { + if (control != null) { + control.release(SurfaceControl::release); + } + } + } args.recycle(); break; } @@ -8107,6 +8116,10 @@ public final class ViewRootImpl implements ViewParent, } } + // If our window is removed, we might not get notified about losing control. + // Invoking this can release the leashes as soon as possible instead of relying on GC. + mInsetsController.onControlsChanged(null); + mAdded = false; } WindowManagerGlobal.getInstance().doRemoveView(this); |
