Merge "Notify sysui of side swipe gestures that will show the bars transiently" into sc-v2-dev

This commit is contained in:
Winson Chung
2022-01-07 21:28:16 +00:00
committed by Android (Google) Code Review
13 changed files with 129 additions and 66 deletions

View File

@@ -205,8 +205,10 @@ oneway interface IStatusBar
*
* @param displayId the ID of the display to notify.
* @param types the internal insets types of the bars are about to show transiently.
* @param isGestureOnSystemBar whether the gesture to show the transient bar was a gesture on
* one of the bars itself.
*/
void showTransient(int displayId, in int[] types);
void showTransient(int displayId, in int[] types, boolean isGestureOnSystemBar);
/**
* Notifies System UI to abort the transient state of system bars, which prevents the bars being

View File

@@ -228,6 +228,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
private @Behavior int mBehavior;
private boolean mTransientShown;
private boolean mTransientShownFromGestureOnSystemBar;
private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private LightBarController mLightBarController;
private final LightBarController mMainLightBarController;
@@ -872,6 +873,9 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
+ windowStateToString(mNavigationBarWindowState));
pw.println(" mNavigationBarMode="
+ BarTransitions.modeToString(mNavigationBarMode));
pw.println(" mTransientShown=" + mTransientShown);
pw.println(" mTransientShownFromGestureOnSystemBar="
+ mTransientShownFromGestureOnSystemBar);
dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
mNavigationBarView.dump(pw);
}
@@ -990,7 +994,8 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
}
@Override
public void showTransient(int displayId, @InternalInsetsType int[] types) {
public void showTransient(int displayId, @InternalInsetsType int[] types,
boolean isGestureOnSystemBar) {
if (displayId != mDisplayId) {
return;
}
@@ -999,6 +1004,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
}
if (!mTransientShown) {
mTransientShown = true;
mTransientShownFromGestureOnSystemBar = isGestureOnSystemBar;
handleTransientChanged();
}
}
@@ -1017,12 +1023,14 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
private void clearTransient() {
if (mTransientShown) {
mTransientShown = false;
mTransientShownFromGestureOnSystemBar = false;
handleTransientChanged();
}
}
private void handleTransientChanged() {
mNavigationBarView.onTransientStateChanged(mTransientShown);
mNavigationBarView.onTransientStateChanged(mTransientShown,
mTransientShownFromGestureOnSystemBar);
final int barMode = barMode(mTransientShown, mAppearance);
if (updateBarMode(barMode) && mLightBarController != null) {
mLightBarController.onNavigationBarModeChanged(barMode);

View File

@@ -447,12 +447,17 @@ public class NavigationBarView extends FrameLayout implements
mRegionSamplingHelper.setWindowHasBlurs(hasBlurs);
}
void onTransientStateChanged(boolean isTransient) {
void onTransientStateChanged(boolean isTransient, boolean isGestureOnSystemBar) {
mEdgeBackGestureHandler.onNavBarTransientStateChanged(isTransient);
// The visibility of the navigation bar buttons is dependent on the transient state of
// the navigation bar.
if (mNavBarOverlayController.isNavigationBarOverlayEnabled()) {
// Always allow the overlay if in non-gestural nav mode, otherwise, only allow showing
// the overlay if the user is swiping directly over a system bar
boolean allowNavBarOverlay = !QuickStepContract.isGesturalMode(mNavBarMode)
|| isGestureOnSystemBar;
isTransient = isTransient && allowNavBarOverlay;
mNavBarOverlayController.setButtonState(isTransient, /* force */ false);
}
}

View File

@@ -350,7 +350,7 @@ public class TaskbarDelegate implements CommandQueue.Callbacks,
}
@Override
public void showTransient(int displayId, int[] types) {
public void showTransient(int displayId, int[] types, boolean isGestureOnSystemBar) {
if (displayId != mDisplayId) {
return;
}

View File

@@ -343,10 +343,18 @@ public class CommandQueue extends IStatusBar.Stub implements
String packageName) { }
/**
* @see IStatusBar#showTransient(int, int[]).
* @see IStatusBar#showTransient(int, int[], boolean).
*/
default void showTransient(int displayId, @InternalInsetsType int[] types) { }
/**
* @see IStatusBar#showTransient(int, int[], boolean).
*/
default void showTransient(int displayId, @InternalInsetsType int[] types,
boolean isGestureOnSystemBar) {
showTransient(displayId, types);
}
/**
* @see IStatusBar#abortTransient(int, int[]).
*/
@@ -1019,9 +1027,10 @@ public class CommandQueue extends IStatusBar.Stub implements
}
@Override
public void showTransient(int displayId, int[] types) {
public void showTransient(int displayId, int[] types, boolean isGestureOnSystemBar) {
synchronized (mLock) {
mHandler.obtainMessage(MSG_SHOW_TRANSIENT, displayId, 0, types).sendToTarget();
mHandler.obtainMessage(MSG_SHOW_TRANSIENT, displayId, isGestureOnSystemBar ? 1 : 0,
types).sendToTarget();
}
}
@@ -1404,8 +1413,9 @@ public class CommandQueue extends IStatusBar.Stub implements
case MSG_SHOW_TRANSIENT: {
final int displayId = msg.arg1;
final int[] types = (int[]) msg.obj;
final boolean isGestureOnSystemBar = msg.arg2 != 0;
for (int i = 0; i < mCallbacks.size(); i++) {
mCallbacks.get(i).showTransient(displayId, types);
mCallbacks.get(i).showTransient(displayId, types, isGestureOnSystemBar);
}
break;
}

View File

@@ -495,7 +495,8 @@ public class StatusBarCommandQueueCallbacks implements CommandQueue.Callbacks {
}
@Override
public void showTransient(int displayId, @InternalInsetsType int[] types) {
public void showTransient(int displayId, @InternalInsetsType int[] types,
boolean isGestureOnSystemBar) {
if (displayId != mDisplayId) {
return;
}

View File

@@ -151,17 +151,17 @@ public class CommandQueueTest extends SysuiTestCase {
@Test
public void testShowTransient() {
int[] types = new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR};
mCommandQueue.showTransient(DEFAULT_DISPLAY, types);
mCommandQueue.showTransient(DEFAULT_DISPLAY, types, true /* isGestureOnSystemBar */);
waitForIdleSync();
verify(mCallbacks).showTransient(eq(DEFAULT_DISPLAY), eq(types));
verify(mCallbacks).showTransient(eq(DEFAULT_DISPLAY), eq(types), eq(true));
}
@Test
public void testShowTransientForSecondaryDisplay() {
int[] types = new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR};
mCommandQueue.showTransient(SECONDARY_DISPLAY, types);
mCommandQueue.showTransient(SECONDARY_DISPLAY, types, true /* isGestureOnSystemBar */);
waitForIdleSync();
verify(mCallbacks).showTransient(eq(SECONDARY_DISPLAY), eq(types));
verify(mCallbacks).showTransient(eq(SECONDARY_DISPLAY), eq(types), eq(true));
}
@Test

View File

@@ -136,7 +136,8 @@ public interface StatusBarManagerInternal {
@Behavior int behavior, InsetsVisibilities requestedVisibilities, String packageName);
/** @see com.android.internal.statusbar.IStatusBar#showTransient */
void showTransient(int displayId, @InternalInsetsType int[] types);
void showTransient(int displayId, @InternalInsetsType int[] types,
boolean isGestureOnSystemBar);
/** @see com.android.internal.statusbar.IStatusBar#abortTransient */
void abortTransient(int displayId, @InternalInsetsType int[] types);

View File

@@ -540,11 +540,12 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
}
@Override
public void showTransient(int displayId, @InternalInsetsType int[] types) {
public void showTransient(int displayId, @InternalInsetsType int[] types,
boolean isGestureOnSystemBar) {
getUiState(displayId).showTransient(types);
if (mBar != null) {
try {
mBar.showTransient(displayId, types);
mBar.showTransient(displayId, types, isGestureOnSystemBar);
} catch (RemoteException ex) { }
}
}

View File

@@ -429,7 +429,7 @@ public class DisplayPolicy {
WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS)
? getStatusBar() : getNavigationBar();
if (targetBar != null) {
requestTransientBars(targetBar);
requestTransientBars(targetBar, true /* isGestureOnSystemBar */);
}
}
break;
@@ -480,26 +480,25 @@ public class DisplayPolicy {
// TODO(b/181821798) Migrate SystemGesturesPointerEventListener to use window context.
mSystemGestures = new SystemGesturesPointerEventListener(mUiContext, mHandler,
new SystemGesturesPointerEventListener.Callbacks() {
@Override
public void onSwipeFromTop() {
synchronized (mLock) {
if (mStatusBar != null) {
requestTransientBars(mStatusBar);
}
checkAltBarSwipeForTransientBars(ALT_BAR_TOP,
false /* allowForAllPositions */);
final WindowState bar = mStatusBar != null
? mStatusBar
: findAltBarMatchingPosition(ALT_BAR_TOP);
requestTransientBars(bar, true /* isGestureOnSystemBar */);
}
}
@Override
public void onSwipeFromBottom() {
synchronized (mLock) {
if (mNavigationBar != null
&& mNavigationBarPosition == NAV_BAR_BOTTOM) {
requestTransientBars(mNavigationBar);
}
checkAltBarSwipeForTransientBars(ALT_BAR_BOTTOM,
false /* allowForAllPositions */);
final WindowState bar = mNavigationBar != null
&& mNavigationBarPosition == NAV_BAR_BOTTOM
? mNavigationBar
: findAltBarMatchingPosition(ALT_BAR_BOTTOM);
requestTransientBars(bar, true /* isGestureOnSystemBar */);
}
}
@@ -509,13 +508,8 @@ public class DisplayPolicy {
synchronized (mLock) {
mDisplayContent.calculateSystemGestureExclusion(
excludedRegion, null /* outUnrestricted */);
final boolean allowSideSwipe = mNavigationBarAlwaysShowOnSideGesture &&
!mSystemGestures.currentGestureStartedInRegion(excludedRegion);
if (mNavigationBar != null && (mNavigationBarPosition == NAV_BAR_RIGHT
|| allowSideSwipe)) {
requestTransientBars(mNavigationBar);
}
checkAltBarSwipeForTransientBars(ALT_BAR_RIGHT, allowSideSwipe);
requestTransientBarsForSideSwipe(excludedRegion, NAV_BAR_RIGHT,
ALT_BAR_RIGHT);
}
excludedRegion.recycle();
}
@@ -526,17 +520,33 @@ public class DisplayPolicy {
synchronized (mLock) {
mDisplayContent.calculateSystemGestureExclusion(
excludedRegion, null /* outUnrestricted */);
final boolean allowSideSwipe = mNavigationBarAlwaysShowOnSideGesture &&
!mSystemGestures.currentGestureStartedInRegion(excludedRegion);
if (mNavigationBar != null && (mNavigationBarPosition == NAV_BAR_LEFT
|| allowSideSwipe)) {
requestTransientBars(mNavigationBar);
}
checkAltBarSwipeForTransientBars(ALT_BAR_LEFT, allowSideSwipe);
requestTransientBarsForSideSwipe(excludedRegion, NAV_BAR_LEFT,
ALT_BAR_LEFT);
}
excludedRegion.recycle();
}
private void requestTransientBarsForSideSwipe(Region excludedRegion,
int navBarSide, int altBarSide) {
final WindowState barMatchingSide = mNavigationBar != null
&& mNavigationBarPosition == navBarSide
? mNavigationBar
: findAltBarMatchingPosition(altBarSide);
final boolean allowSideSwipe = mNavigationBarAlwaysShowOnSideGesture &&
!mSystemGestures.currentGestureStartedInRegion(excludedRegion);
if (barMatchingSide == null && !allowSideSwipe) {
return;
}
// Request transient bars on the matching bar, or any bar if we always allow
// side swipes to show the bars
final boolean isGestureOnSystemBar = barMatchingSide != null;
final WindowState bar = barMatchingSide != null
? barMatchingSide
: findTransientNavOrAltBar();
requestTransientBars(bar, isGestureOnSystemBar);
}
@Override
public void onFling(int duration) {
if (mService.mPowerManagerInternal != null) {
@@ -686,21 +696,39 @@ public class DisplayPolicy {
mHandler.post(mGestureNavigationSettingsObserver::register);
}
private void checkAltBarSwipeForTransientBars(@WindowManagerPolicy.AltBarPosition int pos,
boolean allowForAllPositions) {
if (mStatusBarAlt != null && (mStatusBarAltPosition == pos || allowForAllPositions)) {
requestTransientBars(mStatusBarAlt);
/**
* Returns the first non-null alt bar window matching the given position.
*/
private WindowState findAltBarMatchingPosition(@WindowManagerPolicy.AltBarPosition int pos) {
if (mStatusBarAlt != null && mStatusBarAltPosition == pos) {
return mStatusBarAlt;
}
if (mNavigationBarAlt != null
&& (mNavigationBarAltPosition == pos || allowForAllPositions)) {
requestTransientBars(mNavigationBarAlt);
if (mNavigationBarAlt != null && mNavigationBarAltPosition == pos) {
return mNavigationBarAlt;
}
if (mClimateBarAlt != null && (mClimateBarAltPosition == pos || allowForAllPositions)) {
requestTransientBars(mClimateBarAlt);
if (mClimateBarAlt != null && mClimateBarAltPosition == pos) {
return mClimateBarAlt;
}
if (mExtraNavBarAlt != null && (mExtraNavBarAltPosition == pos || allowForAllPositions)) {
requestTransientBars(mExtraNavBarAlt);
if (mExtraNavBarAlt != null && mExtraNavBarAltPosition == pos) {
return mExtraNavBarAlt;
}
return null;
}
/**
* Finds the first non-null nav bar to request transient for.
*/
private WindowState findTransientNavOrAltBar() {
if (mNavigationBar != null) {
return mNavigationBar;
}
if (mNavigationBarAlt != null) {
return mNavigationBarAlt;
}
if (mExtraNavBarAlt != null) {
return mExtraNavBarAlt;
}
return null;
}
void systemReady() {
@@ -2622,8 +2650,8 @@ public class DisplayPolicy {
updateSystemBarAttributes();
}
private void requestTransientBars(WindowState swipeTarget) {
if (!mService.mPolicy.isUserSetupComplete()) {
private void requestTransientBars(WindowState swipeTarget, boolean isGestureOnSystemBar) {
if (swipeTarget == null || !mService.mPolicy.isUserSetupComplete()) {
// Swipe-up for navigation bar is disabled during setup
return;
}
@@ -2659,7 +2687,8 @@ public class DisplayPolicy {
if (controlTarget.canShowTransient()) {
// Show transient bars if they are hidden; restore position if they are visible.
mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_SWIPE);
mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_SWIPE,
isGestureOnSystemBar);
controlTarget.showInsets(restorePositionTypes, false);
} else {
// Restore visibilities and positions of system bars.
@@ -2881,7 +2910,8 @@ public class DisplayPolicy {
// we're no longer on the Keyguard and the screen is ready. We can now request the bars.
mPendingPanicGestureUptime = 0;
if (!isNavBarEmpty(disableFlags)) {
mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_PANIC);
mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_PANIC,
true /* isGestureOnSystemBar */);
}
}

View File

@@ -159,7 +159,7 @@ class InsetsPolicy {
return provider != null && provider.hasWindow() && !provider.getSource().isVisible();
}
void showTransient(@InternalInsetsType int[] types) {
void showTransient(@InternalInsetsType int[] types, boolean isGestureOnSystemBar) {
boolean changed = false;
for (int i = types.length - 1; i >= 0; i--) {
final @InternalInsetsType int type = types[i];
@@ -176,8 +176,8 @@ class InsetsPolicy {
StatusBarManagerInternal statusBarManagerInternal =
mPolicy.getStatusBarManagerInternal();
if (statusBarManagerInternal != null) {
statusBarManagerInternal.showTransient(
mDisplayContent.getDisplayId(), mShowingTransientTypes.toArray());
statusBarManagerInternal.showTransient(mDisplayContent.getDisplayId(),
mShowingTransientTypes.toArray(), isGestureOnSystemBar);
}
updateBarControlTarget(mFocusedWin);

View File

@@ -291,7 +291,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
assertFalse(mDisplayContent.getInsetsStateController().getRawInsetsState()
.getSource(ITYPE_NAVIGATION_BAR).isVisible());
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
true /* isGestureOnSystemBar */);
waitUntilWindowAnimatorIdle();
final InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
@@ -319,7 +320,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
doNothing().when(policy).startAnimation(anyBoolean(), any());
policy.updateBarControlTarget(mAppWindow);
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
true /* isGestureOnSystemBar */);
waitUntilWindowAnimatorIdle();
final InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
@@ -351,7 +353,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
doNothing().when(policy).startAnimation(anyBoolean(), any());
policy.updateBarControlTarget(mAppWindow);
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
true /* isGestureOnSystemBar */);
waitUntilWindowAnimatorIdle();
InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
@@ -402,7 +405,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
doNothing().when(policy).startAnimation(anyBoolean(), any());
policy.updateBarControlTarget(app);
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
true /* isGestureOnSystemBar */);
final InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(app);
policy.updateBarControlTarget(app2);

View File

@@ -332,7 +332,8 @@ public class InsetsStateControllerTest extends WindowTestsBase {
assertTrue(rotatedState.getSource(ITYPE_STATUS_BAR).isVisible());
provider.getSource().setVisible(false);
mDisplayContent.getInsetsPolicy().showTransient(new int[] { ITYPE_STATUS_BAR });
mDisplayContent.getInsetsPolicy().showTransient(new int[] { ITYPE_STATUS_BAR },
true /* isGestureOnSystemBar */);
assertTrue(mDisplayContent.getInsetsPolicy().isTransient(ITYPE_STATUS_BAR));
assertFalse(app.getInsetsState().getSource(ITYPE_STATUS_BAR).isVisible());