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

Commit 2ab590a4 authored by Tiger Huang's avatar Tiger Huang
Browse files

Dispatch the requested visibility if the client has the control

Otherwise, we would think its visibility needs to be cleared.

This CL:
- reverts parts of eb5a5920,
- prevents sending redundant MSG_DISPATCH_SYSTEM_UI_VISIBILITY, and
- cancels clearing visibility if a new reversed visibility is set.

Fix: 156994866
Test: atest --iterations 100 LayoutTests#testAddingImmersiveWindow
      atest WindowInsetsControllerTests InsetsAnimationControlImplTest
Change-Id: I8b8b7541523c0a94daf336f3be415aa5fa3f33da
parent 235f1db1
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -568,15 +568,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private void updateState(InsetsState newState) {
        mState.setDisplayFrame(newState.getDisplayFrame());
        for (int i = newState.getSourcesCount() - 1; i >= 0; i--) {
            final InsetsSource source = newState.sourceAt(i);
            final int type = source.getType();
            final InsetsSourceConsumer consumer = getSourceConsumer(type);
            consumer.updateSource(source);
            mHost.updateCompatSysUiVisibility(type, source.isVisible(),
                    consumer.getControl() != null);
            InsetsSource source = newState.sourceAt(i);
            getSourceConsumer(source.getType()).updateSource(source);
        }
        for (int i = mState.getSourcesCount() - 1; i >= 0; i--) {
            final InsetsSource source = mState.sourceAt(i);
            InsetsSource source = mState.sourceAt(i);
            if (newState.peekSource(source.getType()) == null) {
                mState.removeSource(source.getType());
            }
@@ -1010,6 +1006,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        updateRequestedState();
    }

    /**
     * @see ViewRootImpl#updateCompatSysUiVisibility(int, boolean, boolean)
     */
    public void updateCompatSysUiVisibility(@InternalInsetsType int type, boolean visible,
            boolean hasControl) {
        mHost.updateCompatSysUiVisibility(type, visible, hasControl);
    }

    /**
     * Called when current window gains focus.
     */
+12 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;

import static android.view.InsetsController.ANIMATION_TYPE_NONE;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.getDefaultVisibility;
import static android.view.InsetsState.toPublicType;

import android.annotation.IntDef;
@@ -82,7 +83,7 @@ public class InsetsSourceConsumer {
        mState = state;
        mTransactionSupplier = transactionSupplier;
        mController = controller;
        mRequestedVisible = InsetsState.getDefaultVisibility(type);
        mRequestedVisible = getDefaultVisibility(type);
    }

    /**
@@ -200,12 +201,20 @@ public class InsetsSourceConsumer {
    }

    boolean applyLocalVisibilityOverride() {
        final InsetsSource source = mState.peekSource(mType);
        final boolean isVisible = source != null ? source.isVisible() : getDefaultVisibility(mType);
        final boolean hasControl = mSourceControl != null;

        // We still need to let the legacy app know the visibility change even if we don't have the
        // control.
        mController.updateCompatSysUiVisibility(
                mType, hasControl ? mRequestedVisible : isVisible, hasControl);

        // If we don't have control, we are not able to change the visibility.
        if (mSourceControl == null) {
        if (!hasControl) {
            return false;
        }
        if (mState.getSource(mType).isVisible() == mRequestedVisible) {
        if (isVisible == mRequestedVisible) {
            return false;
        }
        mState.getSource(mType).setVisible(mRequestedVisible);
+3 −0
Original line number Diff line number Diff line
@@ -1977,6 +1977,7 @@ public final class ViewRootImpl implements ViewParent,
                    (mCompatibleVisibilityInfo.globalVisibility & ~View.SYSTEM_UI_FLAG_LOW_PROFILE)
                            | (mAttachInfo.mSystemUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE);
            if (mDispatchedSystemUiVisibility != mCompatibleVisibilityInfo.globalVisibility) {
                mHandler.removeMessages(MSG_DISPATCH_SYSTEM_UI_VISIBILITY);
                mHandler.sendMessage(mHandler.obtainMessage(
                        MSG_DISPATCH_SYSTEM_UI_VISIBILITY, mCompatibleVisibilityInfo));
            }
@@ -2031,8 +2032,10 @@ public final class ViewRootImpl implements ViewParent,
            }
        } else {
            info.globalVisibility |= systemUiFlag;
            info.localChanges &= ~systemUiFlag;
        }
        if (mDispatchedSystemUiVisibility != info.globalVisibility) {
            mHandler.removeMessages(MSG_DISPATCH_SYSTEM_UI_VISIBILITY);
            mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, info));
        }
    }