From 02d3a8ad07072a2732e9ff53fe57881279eda3cb Mon Sep 17 00:00:00 2001 From: Yuncheol Heo Date: Wed, 22 Apr 2020 15:46:45 -0700 Subject: [PATCH 1/2] Notify the visibility change to update color views without control. Previously, we've notified it only when we have the control. But to update color views, we should notify it even when we have no control. Bug: 154720832 Test: atest WindowInsetsPolicyTest Test: make sure no regression on b/150195782, b/151425506 Change-Id: I44b88ddc206f36d8ef11dae9c1477739a185ff21 --- core/java/android/view/InsetsSourceConsumer.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index 2dcfd899adf40..58ec9ec11e56f 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -200,6 +200,15 @@ public class InsetsSourceConsumer { } boolean applyLocalVisibilityOverride() { + return applyLocalVisibilityOverride(false /* notifyWithoutControl */); + } + + /** + * @param notifyWithoutControl set it true when the caller wants to notify the visibility + * changes even if the consumer doesn't have the control. + * @return true if it needs to notify the visibility changes to the controller + */ + private boolean applyLocalVisibilityOverride(boolean notifyWithoutControl) { InsetsSource source = mState.peekSource(mType); final boolean isVisible = source != null && source.isVisible(); final boolean hasControl = mSourceControl != null; @@ -211,7 +220,7 @@ public class InsetsSourceConsumer { // If we don't have control, we are not able to change the visibility. if (!hasControl) { - return false; + return notifyWithoutControl; } if (isVisible == mRequestedVisible) { return false; @@ -293,7 +302,9 @@ public class InsetsSourceConsumer { mRequestedVisible = requestedVisible; mIsAnimationPending = false; } - if (applyLocalVisibilityOverride()) { + // We need to notify the visibility changed even if we don't have mSourceControl in order + // to update color views. + if (applyLocalVisibilityOverride(true /* notifyWithoutControl */)) { mController.notifyVisibilityChanged(); } } From 70c4bb900751242bb61ed04db8ef50ebaec169b3 Mon Sep 17 00:00:00 2001 From: Yuncheol Heo Date: Tue, 28 Apr 2020 22:41:22 -0700 Subject: [PATCH 2/2] Add test api getStatus/NavigationBarBackgroundView. Introduces new test api to access the background view of status bar and navigation bar. Bug: 154720832 Test: atest WindowInsetsPolicyTest Change-Id: If38d3f57edfbb2631d4c1e47ed5347a332edacfb --- api/test-current.txt | 5 +++++ core/java/android/view/Window.java | 19 +++++++++++++++++++ .../android/internal/policy/DecorView.java | 8 ++++++++ .../android/internal/policy/PhoneWindow.java | 13 +++++++++++++ 4 files changed, 45 insertions(+) diff --git a/api/test-current.txt b/api/test-current.txt index 44fb63017ace8..377f3762d40d9 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -4966,6 +4966,11 @@ package android.view { method @Nullable public static AutoCloseable startRenderingCommandsCapture(android.view.View, java.util.concurrent.Executor, java.util.concurrent.Callable); } + public abstract class Window { + method @Nullable public android.view.View getNavigationBarBackgroundView(); + method @Nullable public android.view.View getStatusBarBackgroundView(); + } + public interface WindowManager extends android.view.ViewManager { method public default void setShouldShowIme(int, boolean); method public default void setShouldShowSystemDecors(int, boolean); diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index b1536484b5159..446e7aa67bc56 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -26,6 +26,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.StyleRes; import android.annotation.SystemApi; +import android.annotation.TestApi; import android.app.WindowConfiguration; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -1794,6 +1795,24 @@ public abstract class Window { */ public abstract @NonNull View getDecorView(); + /** + * @return the status bar background view or null. + * @hide + */ + @TestApi + public @Nullable View getStatusBarBackgroundView() { + return null; + } + + /** + * @return the navigation bar background view or null. + * @hide + */ + @TestApi + public @Nullable View getNavigationBarBackgroundView() { + return null; + } + /** * Retrieve the current decor view, but only if it has already been created; * otherwise returns null. diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java index 863659d7c4eb3..c6135f2c81d3f 100644 --- a/core/java/com/android/internal/policy/DecorView.java +++ b/core/java/com/android/internal/policy/DecorView.java @@ -324,6 +324,14 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind return mBackgroundFallback.getDrawable(); } + @Nullable View getStatusBarBackgroundView() { + return mStatusColorViewState.view; + } + + @Nullable View getNavigationBarBackgroundView() { + return mNavigationColorViewState.view; + } + @Override public boolean gatherTransparentRegion(Region region) { boolean statusOpaque = gatherTransparentRegion(mStatusColorViewState, region); diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index aa75d40107484..c5729b05c5878 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -38,6 +38,7 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; import android.annotation.NonNull; +import android.annotation.Nullable; import android.app.ActivityManager; import android.app.KeyguardManager; import android.app.SearchManager; @@ -3949,4 +3950,16 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { public void removeScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { getViewRootImpl().removeScrollCaptureCallback(callback); } + + @Override + @Nullable + public View getStatusBarBackgroundView() { + return mDecor != null ? mDecor.getStatusBarBackgroundView() : null; + } + + @Override + @Nullable + public View getNavigationBarBackgroundView() { + return mDecor != null ? mDecor.getNavigationBarBackgroundView() : null; + } }