Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed48db3d authored by Rob Carr's avatar Rob Carr
Browse files

InsetSourceConsumer: Ensure we release Leash when finished.

SurfaceControl resources may be heavy weight, and so we explicitly
release them when finished. Specifically, we need to fix this to
keep the CloseGuard from complaining in strict-mode.

Bug: 150805473
Test: Existing tests pass
Change-Id: Ie3c609f79a953374a4d336465676cdc312679f93
parent 062f7a09
Loading
Loading
Loading
Loading
+18 −15
Original line number Original line Diff line number Diff line
@@ -87,6 +87,7 @@ public class InsetsSourceConsumer {
        if (mSourceControl == control) {
        if (mSourceControl == control) {
            return;
            return;
        }
        }
        final InsetsSourceControl lastControl = mSourceControl;
        mSourceControl = control;
        mSourceControl = control;


        // We are loosing control
        // We are loosing control
@@ -97,26 +98,28 @@ public class InsetsSourceConsumer {
            mState.getSource(getType()).setVisible(
            mState.getSource(getType()).setVisible(
                    mController.getLastDispatchedState().getSource(getType()).isVisible());
                    mController.getLastDispatchedState().getSource(getType()).isVisible());
            applyLocalVisibilityOverride();
            applyLocalVisibilityOverride();
            return;
        } else {
        }
            // We are gaining control, and need to run an animation since previous state

            // didn't match
        // We are gaining control, and need to run an animation since previous state didn't match
            if (mRequestedVisible != mState.getSource(mType).isVisible()) {
            if (mRequestedVisible != mState.getSource(mType).isVisible()) {
                if (mRequestedVisible) {
                if (mRequestedVisible) {
                    showTypes[0] |= toPublicType(getType());
                    showTypes[0] |= toPublicType(getType());
                } else {
                } else {
                    hideTypes[0] |= toPublicType(getType());
                    hideTypes[0] |= toPublicType(getType());
                }
                }
            return;
            } else {
        }
              // We are gaining control, but don't need to run an animation.

              // However make sure that the leash visibility is still up to date.
        // We are gaining control, but don't need to run an animation. However make sure that the
        // leash visibility is still up to date.
              if (applyLocalVisibilityOverride()) {
              if (applyLocalVisibilityOverride()) {
                  mController.notifyVisibilityChanged();
                  mController.notifyVisibilityChanged();
              }
              }
              applyHiddenToControl();
              applyHiddenToControl();
            }
            }
        }
        if (lastControl != null) {
            lastControl.release();
        }
    }


    @VisibleForTesting
    @VisibleForTesting
    public InsetsSourceControl getControl() {
    public InsetsSourceControl getControl() {
+6 −0
Original line number Original line Diff line number Diff line
@@ -94,6 +94,12 @@ public class InsetsSourceControl implements Parcelable {
        dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
        dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
    }
    }


    public void release() {
        if (mLeash != null) {
            mLeash.release();
        }
    }

    public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
    public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
            = new Creator<InsetsSourceControl>() {
            = new Creator<InsetsSourceControl>() {
        public InsetsSourceControl createFromParcel(Parcel in) {
        public InsetsSourceControl createFromParcel(Parcel in) {