diff options
| -rw-r--r-- | core/java/android/view/InsetsSourceConsumer.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index d6b75b94b19a..b17e19998a9d 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -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; |