Don't show status bar while swiping on visible taskbar

If the swipe target is visible navigation bar, don't show status bar.

The existing logic apply the rule above only when the swipe target is
the traditional navigation bar (with window type TYPE_NAVIGATION_BAR),
but this CL applies to the target which provides Type.navigationBars.

Fix: 263251179
Test: Swipe on visible taskbar and see if status bar becomes visible in
      an app (Window Insets Controller) which only hides status bar.
Change-Id: I966fd87b5a02169ef8b7c7b952ac0abed1110d65
This commit is contained in:
Tiger
2023-02-17 17:37:55 +08:00
parent e835a95134
commit a281e3e237
2 changed files with 14 additions and 17 deletions

View File

@@ -1940,7 +1940,8 @@ public class DisplayPolicy {
final @InsetsType int restorePositionTypes = (Type.statusBars() | Type.navigationBars())
& controlTarget.getRequestedVisibleTypes();
if (swipeTarget == mNavigationBar
final InsetsSourceProvider sp = swipeTarget.getControllableInsetProvider();
if (sp != null && sp.getSource().getType() == Type.navigationBars()
&& (restorePositionTypes & Type.navigationBars()) != 0) {
// Don't show status bar when swiping on already visible navigation bar.
// But restore the position of navigation bar if it has been moved by the control

View File

@@ -26,6 +26,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.WindowInsets.Type.navigationBars;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
@@ -46,13 +47,7 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.graphics.PixelFormat;
@@ -367,23 +362,24 @@ public class DisplayPolicyTests extends WindowTestsBase {
assertEquals(attrs.height - 10, navBarSource.getFrame().height());
}
@SetupWindows(addWindows = { W_ACTIVITY, W_NAVIGATION_BAR })
@Test
public void testCanSystemBarsBeShownByUser() {
((TestWindowManagerPolicy) mWm.mPolicy).mIsUserSetupComplete = true;
mAppWindow.mAttrs.insetsFlags.behavior = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
mAppWindow.setRequestedVisibleTypes(0, navigationBars());
final DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy();
final WindowState windowState = mock(WindowState.class);
final InsetsSourceProvider provider = mock(InsetsSourceProvider.class);
final InsetsControlTarget controlTarget = mock(InsetsControlTarget.class);
when(provider.getControlTarget()).thenReturn(controlTarget);
when(windowState.getControllableInsetProvider()).thenReturn(provider);
when(controlTarget.isRequestedVisible(anyInt())).thenReturn(true);
displayPolicy.addWindowLw(mNavBarWindow, mNavBarWindow.mAttrs);
final InsetsSourceProvider navBarProvider = mNavBarWindow.getControllableInsetProvider();
navBarProvider.updateControlForTarget(mAppWindow, false);
navBarProvider.getSource().setVisible(false);
displayPolicy.setCanSystemBarsBeShownByUser(false);
displayPolicy.requestTransientBars(windowState, true);
verify(controlTarget, never()).showInsets(anyInt(), anyBoolean(), any() /* statsToken */);
displayPolicy.requestTransientBars(mNavBarWindow, true);
assertFalse(mDisplayContent.getInsetsPolicy().isTransient(navigationBars()));
displayPolicy.setCanSystemBarsBeShownByUser(true);
displayPolicy.requestTransientBars(windowState, true);
verify(controlTarget).showInsets(anyInt(), anyBoolean(), any() /* statsToken */);
displayPolicy.requestTransientBars(mNavBarWindow, true);
assertTrue(mDisplayContent.getInsetsPolicy().isTransient(navigationBars()));
}
}