Merge "Refine system bar position restoring" into rvc-qpr-dev

This commit is contained in:
Tiger Huang
2020-08-19 11:57:15 +00:00
committed by Android (Google) Code Review
6 changed files with 37 additions and 27 deletions

View File

@@ -60,6 +60,8 @@ import java.util.StringJoiner;
*/ */
public class InsetsState implements Parcelable { public class InsetsState implements Parcelable {
public static final InsetsState EMPTY = new InsetsState();
/** /**
* Internal representation of inset source types. This is different from the public API in * Internal representation of inset source types. This is different from the public API in
* {@link WindowInsets.Type} as one type from the public API might indicate multiple windows * {@link WindowInsets.Type} as one type from the public API might indicate multiple windows

View File

@@ -246,6 +246,9 @@ public class DisplayPolicy {
| View.STATUS_BAR_TRANSPARENT | View.STATUS_BAR_TRANSPARENT
| View.NAVIGATION_BAR_TRANSPARENT; | View.NAVIGATION_BAR_TRANSPARENT;
private static final int[] SHOW_TYPES_FOR_SWIPE = {ITYPE_NAVIGATION_BAR, ITYPE_STATUS_BAR};
private static final int[] SHOW_TYPES_FOR_PANIC = {ITYPE_NAVIGATION_BAR};
private final WindowManagerService mService; private final WindowManagerService mService;
private final Context mContext; private final Context mContext;
private final Context mUiContext; private final Context mUiContext;
@@ -3330,8 +3333,15 @@ public class DisplayPolicy {
return; return;
} }
final InsetsState requestedState = controlTarget.getRequestedInsetsState();
final @InsetsType int restorePositionTypes =
(requestedState.getSourceOrDefaultVisibility(ITYPE_NAVIGATION_BAR)
? Type.navigationBars() : 0)
| (requestedState.getSourceOrDefaultVisibility(ITYPE_STATUS_BAR)
? Type.statusBars() : 0);
if (swipeTarget == mNavigationBar if (swipeTarget == mNavigationBar
&& !getInsetsPolicy().isHidden(ITYPE_NAVIGATION_BAR)) { && (restorePositionTypes & Type.navigationBars()) != 0) {
// Don't show status bar when swiping on already visible navigation bar. // 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 // But restore the position of navigation bar if it has been moved by the control
// target. // target.
@@ -3339,14 +3349,13 @@ public class DisplayPolicy {
return; return;
} }
int insetsTypesToShow = Type.systemBars();
if (controlTarget.canShowTransient()) { if (controlTarget.canShowTransient()) {
insetsTypesToShow &= ~mDisplayContent.getInsetsPolicy().showTransient(IntArray.wrap( // Show transient bars if they are hidden; restore position if they are visible.
new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR})); mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_SWIPE);
} controlTarget.showInsets(restorePositionTypes, false);
if (insetsTypesToShow != 0) { } else {
controlTarget.showInsets(insetsTypesToShow, false); // Restore visibilities and positions of system bars.
controlTarget.showInsets(Type.statusBars() | Type.navigationBars(), false);
} }
} else { } else {
boolean sb = mStatusBarController.checkShowTransientBarLw(); boolean sb = mStatusBarController.checkShowTransientBarLw();
@@ -3923,8 +3932,7 @@ public class DisplayPolicy {
mPendingPanicGestureUptime = SystemClock.uptimeMillis(); mPendingPanicGestureUptime = SystemClock.uptimeMillis();
if (!isNavBarEmpty(mLastSystemUiFlags)) { if (!isNavBarEmpty(mLastSystemUiFlags)) {
mNavigationBarController.showTransient(); mNavigationBarController.showTransient();
mDisplayContent.getInsetsPolicy().showTransient(IntArray.wrap( mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_PANIC);
new int[] {ITYPE_NAVIGATION_BAR}));
} }
} }
} }

View File

@@ -17,6 +17,7 @@
package com.android.server.wm; package com.android.server.wm;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.view.InsetsState;
import android.view.WindowInsets.Type.InsetsType; import android.view.WindowInsets.Type.InsetsType;
/** /**
@@ -37,6 +38,13 @@ interface InsetsControlTarget {
return null; return null;
} }
/**
* @return The requested {@link InsetsState} of this target.
*/
default InsetsState getRequestedInsetsState() {
return InsetsState.EMPTY;
}
/** /**
* Instructs the control target to show inset sources. * Instructs the control target to show inset sources.
* *

View File

@@ -42,7 +42,6 @@ import android.view.InsetsState.InternalInsetsType;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.SyncRtSurfaceTransactionApplier; import android.view.SyncRtSurfaceTransactionApplier;
import android.view.ViewRootImpl; import android.view.ViewRootImpl;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsAnimation; import android.view.WindowInsetsAnimation;
import android.view.WindowInsetsAnimation.Bounds; import android.view.WindowInsetsAnimation.Bounds;
import android.view.WindowInsetsAnimationControlListener; import android.view.WindowInsetsAnimationControlListener;
@@ -154,15 +153,13 @@ class InsetsPolicy {
return provider != null && provider.hasWindow() && !provider.getSource().isVisible(); return provider != null && provider.hasWindow() && !provider.getSource().isVisible();
} }
@InsetsType int showTransient(IntArray types) { void showTransient(@InternalInsetsType int[] types) {
@InsetsType int showingTransientTypes = 0;
boolean changed = false; boolean changed = false;
for (int i = types.size() - 1; i >= 0; i--) { for (int i = types.length - 1; i >= 0; i--) {
final int type = types.get(i); final @InternalInsetsType int type = types[i];
if (!isHidden(type)) { if (!isHidden(type)) {
continue; continue;
} }
showingTransientTypes |= InsetsState.toPublicType(type);
if (mShowingTransientTypes.indexOf(type) != -1) { if (mShowingTransientTypes.indexOf(type) != -1) {
continue; continue;
} }
@@ -190,7 +187,6 @@ class InsetsPolicy {
} }
}); });
} }
return showingTransientTypes;
} }
void hideTransient() { void hideTransient() {

View File

@@ -725,7 +725,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
* @return The insets state as requested by the client, i.e. the dispatched insets state * @return The insets state as requested by the client, i.e. the dispatched insets state
* for which the visibilities are overridden with what the client requested. * for which the visibilities are overridden with what the client requested.
*/ */
InsetsState getRequestedInsetsState() { @Override
public InsetsState getRequestedInsetsState() {
return mRequestedInsetsState; return mRequestedInsetsState;
} }

View File

@@ -43,7 +43,6 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit;
import android.util.IntArray;
import android.view.InsetsSourceControl; import android.view.InsetsSourceControl;
import android.view.InsetsState; import android.view.InsetsState;
import android.view.test.InsetsModeSession; import android.view.test.InsetsModeSession;
@@ -241,8 +240,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
}).when(policy).startAnimation(anyBoolean(), any(), any()); }).when(policy).startAnimation(anyBoolean(), any(), any());
policy.updateBarControlTarget(mAppWindow); policy.updateBarControlTarget(mAppWindow);
policy.showTransient( policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
IntArray.wrap(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR}));
waitUntilWindowAnimatorIdle(); waitUntilWindowAnimatorIdle();
final InsetsSourceControl[] controls = final InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow); mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
@@ -269,8 +267,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
doNothing().when(policy).startAnimation(anyBoolean(), any(), any()); doNothing().when(policy).startAnimation(anyBoolean(), any(), any());
policy.updateBarControlTarget(mAppWindow); policy.updateBarControlTarget(mAppWindow);
policy.showTransient( policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
IntArray.wrap(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR}));
waitUntilWindowAnimatorIdle(); waitUntilWindowAnimatorIdle();
final InsetsSourceControl[] controls = final InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow); mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
@@ -298,8 +295,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
doNothing().when(policy).startAnimation(anyBoolean(), any(), any()); doNothing().when(policy).startAnimation(anyBoolean(), any(), any());
policy.updateBarControlTarget(mAppWindow); policy.updateBarControlTarget(mAppWindow);
policy.showTransient( policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
IntArray.wrap(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR}));
waitUntilWindowAnimatorIdle(); waitUntilWindowAnimatorIdle();
InsetsSourceControl[] controls = InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow); mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
@@ -337,8 +333,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
doNothing().when(policy).startAnimation(anyBoolean(), any(), any()); doNothing().when(policy).startAnimation(anyBoolean(), any(), any());
policy.updateBarControlTarget(app); policy.updateBarControlTarget(app);
policy.showTransient( policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR});
IntArray.wrap(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR}));
final InsetsSourceControl[] controls = final InsetsSourceControl[] controls =
mDisplayContent.getInsetsStateController().getControlsForDispatch(app); mDisplayContent.getInsetsStateController().getControlsForDispatch(app);
policy.updateBarControlTarget(app2); policy.updateBarControlTarget(app2);