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

Commit bf030c39 authored by Danny Baumann's avatar Danny Baumann Committed by Steve Kondik
Browse files

Fix race condition in panel expansion handling.

If a call to instantExpand() immediately was followed by a call to
instantCollapse() without a layout pass happening inbetween, the panel
ended up being expanded instead of collapsed.

Change-Id: I5d0f159f3dc2c24c84defc1f5e4279bce8a032a3
parent c07621f6
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -122,6 +122,18 @@ public abstract class PanelView extends FrameLayout {
        }
    };

    private ViewTreeObserver.OnGlobalLayoutListener mInstantExpandLayoutListener =
            new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (mStatusBar.getStatusBarWindow().getHeight() != mStatusBar.getStatusBarHeight()) {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
                setExpandedFraction(1f);
                mInstantExpanding = false;
            }
        }
    };

    protected void onExpandingFinished() {
        endClosing();
        mBar.onExpandingFinished();
@@ -874,18 +886,7 @@ public abstract class PanelView extends FrameLayout {

        // Wait for window manager to pickup the change, so we know the maximum height of the panel
        // then.
        getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (mStatusBar.getStatusBarWindow().getHeight()
                                != mStatusBar.getStatusBarHeight()) {
                            getViewTreeObserver().removeOnGlobalLayoutListener(this);
                            setExpandedFraction(1f);
                            mInstantExpanding = false;
                        }
                    }
                });
        getViewTreeObserver().addOnGlobalLayoutListener(mInstantExpandLayoutListener);

        // Make sure a layout really happens.
        requestLayout();
@@ -894,6 +895,7 @@ public abstract class PanelView extends FrameLayout {
    public void instantCollapse() {
        abortAnimations();
        setExpandedFraction(0f);
        getViewTreeObserver().removeOnGlobalLayoutListener(mInstantExpandLayoutListener);
        if (mExpanding) {
            notifyExpandingFinished();
        }