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

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

Change-Id: I2f698727952f1d02aa824769b58140a1b981a433
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Tiger Huang
2022-05-30 08:57:37 +00:00
committed by Automerger Merge Worker

View File

@@ -36,6 +36,7 @@ import android.annotation.IntDef;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.graphics.Insets; import android.graphics.Insets;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.ArraySet;
import android.util.Log; import android.util.Log;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
import android.view.InsetsState.InternalInsetsType; import android.view.InsetsState.InternalInsetsType;
@@ -272,11 +273,7 @@ public class InsetsSourceConsumer {
mController.getHost().getInputMethodManager(), null /* icProto */); mController.getHost().getInputMethodManager(), null /* icProto */);
} }
// We still need to let the legacy app know the visibility change even if we don't have the updateCompatSysUiVisibility(hasControl, source, isVisible);
// 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);
// If we don't have control, we are not able to change the visibility. // If we don't have control, we are not able to change the visibility.
if (!hasControl) { if (!hasControl) {
@@ -294,6 +291,36 @@ public class InsetsSourceConsumer {
return true; 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 @VisibleForTesting
public boolean isRequestedVisible() { public boolean isRequestedVisible() {
return mRequestedVisible; return mRequestedVisible;