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

Commit ee3aa546 authored by Tiger Huang's avatar Tiger Huang Committed by Automerger Merge Worker
Browse files

Merge "Only update the compat system UI visibility if the source is valid"...

Merge "Only update the compat system UI visibility if the source is valid" into tm-dev am: 1fab4540 am: 1a2b3de8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18583184



Change-Id: Iacbf6be2ba274e4542a09ba6f882dde9f1bdb15c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 496b062d 1a2b3de8
Loading
Loading
Loading
Loading
+32 −5
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.annotation.IntDef;
import android.annotation.Nullable;
import android.graphics.Insets;
import android.graphics.Rect;
import android.util.ArraySet;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsState.InternalInsetsType;
@@ -272,11 +273,7 @@ public class InsetsSourceConsumer {
                    mController.getHost().getInputMethodManager(), null /* icProto */);
        }

        // We still need to let the legacy app know the visibility change even if we don't have the
        // control. If we don't have the source, we don't change the requested visibility for making
        // the callback behavior compatible.
        mController.updateCompatSysUiVisibility(
                mType, (hasControl || source == null) ? mRequestedVisible : isVisible, hasControl);
        updateCompatSysUiVisibility(hasControl, source, isVisible);

        // If we don't have control, we are not able to change the visibility.
        if (!hasControl) {
@@ -294,6 +291,36 @@ public class InsetsSourceConsumer {
        return true;
    }

    private void updateCompatSysUiVisibility(boolean hasControl, InsetsSource source,
            boolean visible) {
        final @InsetsType int publicType = InsetsState.toPublicType(mType);
        if (publicType != WindowInsets.Type.statusBars()
                && publicType != WindowInsets.Type.navigationBars()) {
            // System UI visibility only controls status bars and navigation bars.
            return;
        }
        final boolean compatVisible;
        if (hasControl) {
            compatVisible = mRequestedVisible;
        } else if (source != null && !source.getFrame().isEmpty()) {
            compatVisible = visible;
        } else {
            final ArraySet<Integer> types = InsetsState.toInternalType(publicType);
            for (int i = types.size() - 1; i >= 0; i--) {
                final InsetsSource s = mState.peekSource(types.valueAt(i));
                if (s != null && !s.getFrame().isEmpty()) {
                    // The compat system UI visibility would be updated by another consumer which
                    // handles the same public insets type.
                    return;
                }
            }
            // No one provides the public type. Use the requested visibility for making the callback
            // behavior compatible.
            compatVisible = mRequestedVisible;
        }
        mController.updateCompatSysUiVisibility(mType, compatVisible, hasControl);
    }

    @VisibleForTesting
    public boolean isRequestedVisible() {
        return mRequestedVisible;