From 9913411b547ae5bf92233499a7a12e8faef6bee7 Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Mon, 14 Sep 2020 16:47:33 +0900 Subject: [PATCH] Remove remaining insets system UI flags in DisplayPolicy This patch is to remove all the remaining insets hidding and immersive flags, including: - SYSTEM_UI_FLAG_HIDE_NAVIGATION - SYSTEM_UI_FLAG_FULLSCREEN - SYSTEM_UI_FLAG_IMMERSIVE - SYSTEM_UI_FLAG_IMMERSIVE_STICKY Translucent and transparent flags are removed and the new appearance flags are used instead. The removed flags are: - View.STATUS_BAR_TRANSPARENT - View.STATUS_BAR_TRANSLUCENT BarController functions got removed, and the necessary channels for informing System UI the insets state change got moved to DisplayPolicy instead. Flags are replaced with the new API's. Some necessary modifications are made to support the new API. layoutNavigationBar and layoutStatusBar will always return false, removed dead code for it. Test: go/wm-smoke Test: atest DisplayPolicyTests Test: atest DisplayPolicyLayoutTests Test: atest DisplayPolicyInsetsTests Bug: 155413635 Change-Id: I74404f2abe5df521e097f7d7b2bb7cc93ea9328c --- .../com/android/server/wm/BarController.java | 340 +--------- .../com/android/server/wm/DisplayContent.java | 30 +- .../com/android/server/wm/DisplayPolicy.java | 612 +++++------------- .../server/wm/StatusBarController.java | 109 ---- .../server/wm/DisplayPolicyLayoutTests.java | 2 +- .../android/server/wm/DisplayPolicyTests.java | 67 +- .../server/wm/DisplayPolicyTestsBase.java | 3 - .../android/server/wm/SizeCompatTests.java | 2 +- 8 files changed, 203 insertions(+), 962 deletions(-) delete mode 100644 services/core/java/com/android/server/wm/StatusBarController.java diff --git a/services/core/java/com/android/server/wm/BarController.java b/services/core/java/com/android/server/wm/BarController.java index 8568d5fc1d649..4a90bbcc66239 100644 --- a/services/core/java/com/android/server/wm/BarController.java +++ b/services/core/java/com/android/server/wm/BarController.java @@ -16,88 +16,19 @@ package com.android.server.wm; -import static com.android.server.wm.BarControllerProto.STATE; -import static com.android.server.wm.BarControllerProto.TRANSIENT_STATE; - import android.annotation.NonNull; -import android.app.StatusBarManager; import android.graphics.Rect; -import android.os.Handler; -import android.os.Message; -import android.os.SystemClock; -import android.util.Slog; -import android.util.proto.ProtoOutputStream; -import android.view.View; -import android.view.ViewRootImpl; -import android.view.WindowManager; - -import com.android.server.LocalServices; -import com.android.server.UiThread; -import com.android.server.statusbar.StatusBarManagerInternal; - -import java.io.PrintWriter; /** * Controls state/behavior specific to a system bar window. */ public class BarController { - private static final boolean DEBUG = false; - - private static final int TRANSIENT_BAR_NONE = 0; - private static final int TRANSIENT_BAR_SHOW_REQUESTED = 1; - private static final int TRANSIENT_BAR_SHOWING = 2; - private static final int TRANSIENT_BAR_HIDING = 3; - - private static final int TRANSLUCENT_ANIMATION_DELAY_MS = 1000; - - private static final int MSG_NAV_BAR_VISIBILITY_CHANGED = 1; - - protected final String mTag; - protected final int mDisplayId; - private final int mTransientFlag; - private final int mUnhideFlag; - private final int mTranslucentFlag; - private final int mTransparentFlag; - private final int mStatusBarManagerId; - private final int mTranslucentWmFlag; private final int mWindowType; - protected final Handler mHandler; - private final Object mServiceAquireLock = new Object(); - private StatusBarManagerInternal mStatusBarInternal; - protected WindowState mWin; - private @StatusBarManager.WindowVisibleState int mState = - StatusBarManager.WINDOW_STATE_SHOWING; - private int mTransientBarState; - private boolean mPendingShow; - private long mLastTranslucent; - private boolean mShowTransparent; - private boolean mSetUnHideFlagWhenNextTransparent; - private boolean mNoAnimationOnNextShow; private final Rect mContentFrame = new Rect(); - private OnBarVisibilityChangedListener mVisibilityChangeListener; - - BarController(String tag, int displayId, int transientFlag, int unhideFlag, int translucentFlag, - int statusBarManagerId, int windowType, int translucentWmFlag, int transparentFlag) { - mTag = "BarController." + tag; - mDisplayId = displayId; - mTransientFlag = transientFlag; - mUnhideFlag = unhideFlag; - mTranslucentFlag = translucentFlag; - mStatusBarManagerId = statusBarManagerId; + BarController(int windowType) { mWindowType = windowType; - mTranslucentWmFlag = translucentWmFlag; - mTransparentFlag = transparentFlag; - mHandler = new BarHandler(); - } - - void setWindow(WindowState win) { - if (ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL) { - // BarController gets replaced with InsetsPolicy in the full insets mode. - return; - } - mWin = win; } /** @@ -109,67 +40,6 @@ public class BarController { mContentFrame.set(frame); } - void setShowTransparent(boolean transparent) { - if (transparent != mShowTransparent) { - mShowTransparent = transparent; - mSetUnHideFlagWhenNextTransparent = transparent; - mNoAnimationOnNextShow = true; - } - } - - void showTransient() { - if (mWin != null) { - setTransientBarState(TRANSIENT_BAR_SHOW_REQUESTED); - } - } - - boolean isTransientShowing() { - return mTransientBarState == TRANSIENT_BAR_SHOWING; - } - - boolean isTransientShowRequested() { - return mTransientBarState == TRANSIENT_BAR_SHOW_REQUESTED; - } - - boolean wasRecentlyTranslucent() { - return (SystemClock.uptimeMillis() - mLastTranslucent) < TRANSLUCENT_ANIMATION_DELAY_MS; - } - - void adjustSystemUiVisibilityLw(int oldVis, int vis) { - if (mWin != null && mTransientBarState == TRANSIENT_BAR_SHOWING - && (vis & mTransientFlag) == 0) { - // sysui requests hide - setTransientBarState(TRANSIENT_BAR_HIDING); - setBarShowingLw(false); - } else if (mWin != null && (oldVis & mUnhideFlag) != 0 && (vis & mUnhideFlag) == 0) { - // sysui ready to unhide - setBarShowingLw(true); - } - } - - int applyTranslucentFlagLw(WindowState win, int vis, int oldVis) { - if (mWin != null) { - if (win != null) { - int fl = PolicyControl.getWindowFlags(win, null); - if ((fl & mTranslucentWmFlag) != 0) { - vis |= mTranslucentFlag; - } else { - vis &= ~mTranslucentFlag; - } - if ((fl & WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 - && isTransparentAllowed(win)) { - vis |= mTransparentFlag; - } else { - vis &= ~mTransparentFlag; - } - } else { - vis = (vis & ~mTranslucentFlag) | (oldVis & mTranslucentFlag); - vis = (vis & ~mTransparentFlag) | (oldVis & mTransparentFlag); - } - } - return vis; - } - private Rect getContentFrame(@NonNull WindowState win) { final Rect rotatedContentFrame = win.mToken.getFixedRotationBarContentFrame(mWindowType); return rotatedContentFrame != null ? rotatedContentFrame : mContentFrame; @@ -188,212 +58,4 @@ public class BarController { } return win.letterboxNotIntersectsOrFullyContains(getContentFrame(win)); } - - boolean setBarShowingLw(final boolean show) { - if (mWin == null) return false; - if (show && mTransientBarState == TRANSIENT_BAR_HIDING) { - mPendingShow = true; - return false; - } - final boolean wasVis = mWin.isVisibleLw(); - final boolean wasAnim = mWin.isAnimatingLw(); - final boolean skipAnim = skipAnimation(); - final boolean change = show ? mWin.showLw(!mNoAnimationOnNextShow && !skipAnim) - : mWin.hideLw(!mNoAnimationOnNextShow && !skipAnim); - mNoAnimationOnNextShow = false; - final int state = computeStateLw(wasVis, wasAnim, mWin, change); - final boolean stateChanged = updateStateLw(state); - - if (change && (mVisibilityChangeListener != null)) { - mHandler.obtainMessage(MSG_NAV_BAR_VISIBILITY_CHANGED, show ? 1 : 0, 0).sendToTarget(); - } - - return change || stateChanged; - } - - void setOnBarVisibilityChangedListener(OnBarVisibilityChangedListener listener, - boolean invokeWithState) { - mVisibilityChangeListener = listener; - if (invokeWithState) { - // Optionally report the initial window state for initialization purposes - mHandler.obtainMessage(MSG_NAV_BAR_VISIBILITY_CHANGED, - (mState == StatusBarManager.WINDOW_STATE_SHOWING) ? 1 : 0, 0).sendToTarget(); - } - } - - protected boolean skipAnimation() { - return !mWin.isDrawn(); - } - - private @StatusBarManager.WindowVisibleState int computeStateLw( - boolean wasVis, boolean wasAnim, WindowState win, boolean change) { - if (win.isDrawn()) { - final boolean vis = win.isVisibleLw(); - final boolean anim = win.isAnimatingLw(); - if (mState == StatusBarManager.WINDOW_STATE_HIDING && !change && !vis) { - return StatusBarManager.WINDOW_STATE_HIDDEN; - } else if (mState == StatusBarManager.WINDOW_STATE_HIDDEN && vis) { - return StatusBarManager.WINDOW_STATE_SHOWING; - } else if (change) { - if (wasVis && vis && !wasAnim && anim) { - return StatusBarManager.WINDOW_STATE_HIDING; - } else { - return StatusBarManager.WINDOW_STATE_SHOWING; - } - } - } - return mState; - } - - private boolean updateStateLw(@StatusBarManager.WindowVisibleState final int state) { - if (mWin != null && state != mState) { - mState = state; - if (DEBUG) Slog.d(mTag, "mState: " + StatusBarManager.windowStateToString(state)); - mHandler.post(new Runnable() { - @Override - public void run() { - StatusBarManagerInternal statusbar = getStatusBarInternal(); - if (statusbar != null) { - statusbar.setWindowState(mDisplayId, mStatusBarManagerId, state); - } - } - }); - return true; - } - return false; - } - - boolean checkHiddenLw() { - if (mWin != null && mWin.isDrawn()) { - if (!mWin.isVisibleLw() && !mWin.isAnimatingLw()) { - updateStateLw(StatusBarManager.WINDOW_STATE_HIDDEN); - } - if (mTransientBarState == TRANSIENT_BAR_HIDING && !mWin.isVisibleLw()) { - // Finished animating out, clean up and reset style - setTransientBarState(TRANSIENT_BAR_NONE); - if (mPendingShow) { - setBarShowingLw(true); - mPendingShow = false; - } - return true; - } - } - return false; - } - - boolean checkShowTransientBarLw() { - if (mTransientBarState == TRANSIENT_BAR_SHOWING) { - if (DEBUG) Slog.d(mTag, "Not showing transient bar, already shown"); - return false; - } else if (mTransientBarState == TRANSIENT_BAR_SHOW_REQUESTED) { - if (DEBUG) Slog.d(mTag, "Not showing transient bar, already requested"); - return false; - } else if (mWin == null) { - if (DEBUG) Slog.d(mTag, "Not showing transient bar, bar doesn't exist"); - return false; - } else if (mWin.isDisplayed()) { - if (DEBUG) Slog.d(mTag, "Not showing transient bar, bar already visible"); - return false; - } else { - return true; - } - } - - int updateVisibilityLw(boolean transientAllowed, int oldVis, int vis) { - if (mWin == null) return vis; - if (isTransientShowing() || isTransientShowRequested()) { // transient bar requested - if (transientAllowed) { - vis |= mTransientFlag; - if ((oldVis & mTransientFlag) == 0) { - vis |= mUnhideFlag; // tell sysui we're ready to unhide - } - setTransientBarState(TRANSIENT_BAR_SHOWING); // request accepted - } else { - setTransientBarState(TRANSIENT_BAR_NONE); // request denied - } - } - if (mShowTransparent) { - vis |= mTransparentFlag; - if (mSetUnHideFlagWhenNextTransparent) { - vis |= mUnhideFlag; - mSetUnHideFlagWhenNextTransparent = false; - } - } - if (mTransientBarState != TRANSIENT_BAR_NONE) { - vis |= mTransientFlag; // ignore clear requests until transition completes - vis &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE; // never show transient bars in low profile - } - if ((vis & mTranslucentFlag) != 0 || (oldVis & mTranslucentFlag) != 0 - || ((vis | oldVis) & mTransparentFlag) != 0) { - mLastTranslucent = SystemClock.uptimeMillis(); - } - return vis; - } - - private void setTransientBarState(int state) { - if (mWin != null && state != mTransientBarState) { - if (mTransientBarState == TRANSIENT_BAR_SHOWING || state == TRANSIENT_BAR_SHOWING) { - mLastTranslucent = SystemClock.uptimeMillis(); - } - mTransientBarState = state; - if (DEBUG) Slog.d(mTag, "mTransientBarState: " + transientBarStateToString(state)); - } - } - - protected StatusBarManagerInternal getStatusBarInternal() { - synchronized (mServiceAquireLock) { - if (mStatusBarInternal == null) { - mStatusBarInternal = LocalServices.getService(StatusBarManagerInternal.class); - } - return mStatusBarInternal; - } - } - - private static String transientBarStateToString(int state) { - if (state == TRANSIENT_BAR_HIDING) return "TRANSIENT_BAR_HIDING"; - if (state == TRANSIENT_BAR_SHOWING) return "TRANSIENT_BAR_SHOWING"; - if (state == TRANSIENT_BAR_SHOW_REQUESTED) return "TRANSIENT_BAR_SHOW_REQUESTED"; - if (state == TRANSIENT_BAR_NONE) return "TRANSIENT_BAR_NONE"; - throw new IllegalArgumentException("Unknown state " + state); - } - - void dumpDebug(ProtoOutputStream proto, long fieldId) { - final long token = proto.start(fieldId); - proto.write(STATE, mState); - proto.write(TRANSIENT_STATE, mTransientBarState); - proto.end(token); - } - - void dump(PrintWriter pw, String prefix) { - if (mWin != null) { - pw.print(prefix); pw.println(mTag); - pw.print(prefix); pw.print(" "); pw.print("mState"); pw.print('='); - pw.println(StatusBarManager.windowStateToString(mState)); - pw.print(prefix); pw.print(" "); pw.print("mTransientBar"); pw.print('='); - pw.println(transientBarStateToString(mTransientBarState)); - pw.print(prefix); pw.print(" mContentFrame="); pw.println(mContentFrame); - } - } - - private class BarHandler extends Handler { - BarHandler() { - super(UiThread.getHandler().getLooper()); - } - - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_NAV_BAR_VISIBILITY_CHANGED: - final boolean visible = msg.arg1 != 0; - if (mVisibilityChangeListener != null) { - mVisibilityChangeListener.onBarVisibilityChanged(visible); - } - break; - } - } - } - - interface OnBarVisibilityChangedListener { - void onBarVisibilityChanged(boolean visible); - } } diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 5efe10736a755..d22107802f5f5 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -191,7 +191,6 @@ import android.view.SurfaceControl; import android.view.SurfaceControl.Transaction; import android.view.SurfaceSession; import android.view.View; -import android.view.ViewRootImpl; import android.view.WindowInsets; import android.view.WindowManager; import android.view.WindowManagerPolicyConstants.PointerEventListener; @@ -3743,7 +3742,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp void statusBarVisibilityChanged(int visibility) { mLastStatusBarVisibility = visibility; - visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility); updateStatusBarVisibilityLocked(visibility); } @@ -3768,32 +3766,16 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp void updateSystemUiVisibility(int visibility, int globalDiff) { forAllWindows(w -> { - try { - final int curValue = w.mSystemUiVisibility; - final int diff = (curValue ^ visibility) & globalDiff; - final int newValue = (curValue & ~diff) | (visibility & diff); - if (newValue != curValue) { - w.mSeq++; - w.mSystemUiVisibility = newValue; - } - if ((newValue != curValue || w.mAttrs.hasSystemUiListeners) - && ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL) { - w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, - visibility, newValue, diff); - } - } catch (RemoteException e) { - // so sorry + final int curValue = w.mSystemUiVisibility; + final int diff = (curValue ^ visibility) & globalDiff; + final int newValue = (curValue & ~diff) | (visibility & diff); + if (newValue != curValue) { + w.mSeq++; + w.mSystemUiVisibility = newValue; } }, true /* traverseTopToBottom */); } - void reevaluateStatusBarVisibility() { - int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility); - if (updateStatusBarVisibilityLocked(visibility)) { - mWmService.mWindowPlacerLocked.requestTraversal(); - } - } - void onWindowFreezeTimeout() { Slog.w(TAG_WM, "Window freeze timeout expired."); mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 779f6b2d30cc2..572c9b3060478 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -57,8 +57,6 @@ import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; -import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; -import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; @@ -66,13 +64,11 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_BA import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; -import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; -import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; @@ -134,14 +130,13 @@ import android.graphics.Region; import android.hardware.input.InputManager; import android.hardware.power.Boost; import android.os.Handler; +import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; import android.util.ArraySet; -import android.util.IntArray; -import android.util.Pair; import android.util.PrintWriterPrinter; import android.util.Slog; import android.util.SparseArray; @@ -199,7 +194,6 @@ import java.util.function.Consumer; */ public class DisplayPolicy { private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayPolicy" : TAG_WM; - private static final boolean DEBUG = false; private static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false; @@ -221,18 +215,6 @@ public class DisplayPolicy { /** Use the transit animation in style resource (see {@link #selectAnimation}). */ static final int ANIMATION_STYLEABLE = 0; - /** - * These are the system UI flags that, when changing, can cause the layout - * of the screen to change. - */ - private static final int SYSTEM_UI_CHANGING_LAYOUT = - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.STATUS_BAR_TRANSLUCENT - | View.NAVIGATION_BAR_TRANSLUCENT - | View.STATUS_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}; @@ -327,21 +309,10 @@ public class DisplayPolicy { private boolean mLastImmersiveMode; - private final StatusBarController mStatusBarController; - + private StatusBarManagerInternal mStatusBarInternal; + private final BarController mStatusBarController; private final BarController mNavigationBarController; - private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener = - new BarController.OnBarVisibilityChangedListener() { - @Override - public void onBarVisibilityChanged(boolean visible) { - if (mAccessibilityManager == null) { - return; - } - mAccessibilityManager.notifyAccessibilityButtonVisibilityChanged(visible); - } - }; - // The windows we were told about in focusChanged. private WindowState mFocusedWindow; private WindowState mLastFocusedWindow; @@ -353,15 +324,8 @@ public class DisplayPolicy { private boolean mLastNavVisible; private boolean mLastNavTranslucent; private boolean mLastNavAllowedHidden; - private boolean mLastNotificationShadeForcesShowingNavigation; - int mLastSystemUiFlags; - // Bits that we are in the process of clearing, so we want to prevent - // them from being set by applications until everything has been updated - // to have them clear. - private int mResettingSystemUiFlags = 0; - // Bits that we are currently always keeping cleared. - private int mForceClearedSystemUiFlags = 0; + private int mLastDisableFlags; private int mLastAppearance; private int mLastFullscreenAppearance; private int mLastDockedAppearance; @@ -430,6 +394,8 @@ public class DisplayPolicy { private final GestureNavigationSettingsObserver mGestureNavigationSettingsObserver; + private final WindowManagerInternal.AppTransitionListener mAppTransitionListener; + private class PolicyHandler extends Handler { PolicyHandler(Looper looper) { @@ -472,16 +438,9 @@ public class DisplayPolicy { mLock = service.getWindowManagerLock(); final int displayId = displayContent.getDisplayId(); - mStatusBarController = new StatusBarController(displayId); - mNavigationBarController = new BarController("NavigationBar", - displayId, - View.NAVIGATION_BAR_TRANSIENT, - View.NAVIGATION_BAR_UNHIDE, - View.NAVIGATION_BAR_TRANSLUCENT, - StatusBarManager.WINDOW_NAVIGATION_BAR, - TYPE_NAVIGATION_BAR, - FLAG_TRANSLUCENT_NAVIGATION, - View.NAVIGATION_BAR_TRANSPARENT); + + mStatusBarController = new BarController(TYPE_STATUS_BAR); + mNavigationBarController = new BarController(TYPE_NAVIGATION_BAR); final Resources r = mContext.getResources(); mCarDockEnablesAccelerometer = r.getBoolean(R.bool.config_carDockEnablesAccelerometer); @@ -612,8 +571,58 @@ public class DisplayPolicy { } }); displayContent.registerPointerEventListener(mSystemGestures); - displayContent.mAppTransition.registerListenerLocked( - mStatusBarController.getAppTransitionListener()); + mAppTransitionListener = new WindowManagerInternal.AppTransitionListener() { + + private Runnable mAppTransitionPending = () -> { + StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); + if (statusBar != null) { + statusBar.appTransitionPending(displayId); + } + }; + + private Runnable mAppTransitionCancelled = () -> { + StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); + if (statusBar != null) { + statusBar.appTransitionCancelled(displayId); + } + }; + + private Runnable mAppTransitionFinished = () -> { + StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); + if (statusBar != null) { + statusBar.appTransitionFinished(displayId); + } + }; + + @Override + public void onAppTransitionPendingLocked() { + mHandler.post(mAppTransitionPending); + } + + @Override + public int onAppTransitionStartingLocked(int transit, long duration, + long statusBarAnimationStartTime, long statusBarAnimationDuration) { + mHandler.post(() -> { + StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); + if (statusBar != null) { + statusBar.appTransitionStarting(mContext.getDisplayId(), + statusBarAnimationStartTime, statusBarAnimationDuration); + } + }); + return 0; + } + + @Override + public void onAppTransitionCancelledLocked(int transit) { + mHandler.post(mAppTransitionCancelled); + } + + @Override + public void onAppTransitionFinishedLocked(IBinder token) { + mHandler.post(mAppTransitionFinished); + } + }; + displayContent.mAppTransition.registerListenerLocked(mAppTransitionListener); mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext, looper, mService.mVrModeEnabled); @@ -1066,7 +1075,6 @@ public class DisplayPolicy { break; case TYPE_STATUS_BAR: mStatusBar = win; - mStatusBarController.setWindow(win); final TriConsumer frameProvider = (displayFrames, windowState, rect) -> { rect.bottom = rect.top + getStatusBarHeight(displayFrames); @@ -1077,9 +1085,6 @@ public class DisplayPolicy { break; case TYPE_NAVIGATION_BAR: mNavigationBar = win; - mNavigationBarController.setWindow(win); - mNavigationBarController.setOnBarVisibilityChangedListener( - mNavBarVisibilityListener, true); mDisplayContent.setInsetProvider(ITYPE_NAVIGATION_BAR, win, (displayFrames, windowState, inOutFrame) -> { @@ -1135,12 +1140,10 @@ public class DisplayPolicy { switch (insetsType) { case ITYPE_STATUS_BAR: mStatusBarAlt = win; - mStatusBarController.setWindow(mStatusBarAlt); mStatusBarAltPosition = getAltBarPosition(attrs); break; case ITYPE_NAVIGATION_BAR: mNavigationBarAlt = win; - mNavigationBarController.setWindow(mNavigationBarAlt); mNavigationBarAltPosition = getAltBarPosition(attrs); break; } @@ -1210,12 +1213,10 @@ public class DisplayPolicy { if (mStatusBar == win || mStatusBarAlt == win) { mStatusBar = null; mStatusBarAlt = null; - mStatusBarController.setWindow(null); mDisplayContent.setInsetProvider(ITYPE_STATUS_BAR, null, null); } else if (mNavigationBar == win || mNavigationBarAlt == win) { mNavigationBar = null; mNavigationBarAlt = null; - mNavigationBarController.setWindow(null); mDisplayContent.setInsetProvider(ITYPE_NAVIGATION_BAR, null, null); } else if (mNotificationShade == win) { mNotificationShade = null; @@ -1235,7 +1236,7 @@ public class DisplayPolicy { } @VisibleForTesting - StatusBarController getStatusBarController() { + BarController getStatusBarController() { return mStatusBarController; } @@ -1367,25 +1368,6 @@ public class DisplayPolicy { return ANIMATION_STYLEABLE; } - /** - * Called when a new system UI visibility is being reported, allowing - * the policy to adjust what is actually reported. - * @param visibility The raw visibility reported by the status bar. - * @return The new desired visibility. - */ - public int adjustSystemUiVisibilityLw(int visibility) { - mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); - mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); - - // Reset any bits in mForceClearingStatusBarVisibility that - // are now clear. - mResettingSystemUiFlags &= visibility; - // Clear any bits in the new visibility that are currently being - // force cleared, before reporting it. - return visibility & ~mResettingSystemUiFlags - & ~mForceClearedSystemUiFlags; - } - /** * @return true if the system bars are forced to stay visible */ @@ -1481,16 +1463,6 @@ public class DisplayPolicy { return mForceShowSystemBars; } - private final Runnable mClearHideNavigationFlag = new Runnable() { - @Override - public void run() { - synchronized (mLock) { - mForceClearedSystemUiFlags &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; - mDisplayContent.reevaluateStatusBarVisibility(); - } - } - }; - /** * Input handler used while nav bar is hidden. Captures any touch on the screen, * to determine when the nav bar should be shown and prevent applications from @@ -1515,32 +1487,6 @@ public class DisplayPolicy { return; } showSystemBars(); - // Any user activity always causes us to show the - // navigation controls, if they had been hidden. - // We also clear the low profile and only content - // flags so that tapping on the screen will atomically - // restore all currently hidden screen decorations. - int newVal = mResettingSystemUiFlags - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LOW_PROFILE - | View.SYSTEM_UI_FLAG_FULLSCREEN; - if (mResettingSystemUiFlags != newVal) { - mResettingSystemUiFlags = newVal; - changed = true; - } - // We don't allow the system's nav bar to be hidden - // again for 1 second, to prevent applications from - // spamming us and keeping it from being shown. - newVal = mForceClearedSystemUiFlags - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; - if (mForceClearedSystemUiFlags != newVal) { - mForceClearedSystemUiFlags = newVal; - changed = true; - mHandler.postDelayed(mClearHideNavigationFlag, 1000); - } - if (changed) { - mDisplayContent.reevaluateStatusBarVisibility(); - } } } } @@ -1594,12 +1540,12 @@ public class DisplayPolicy { contentFrame -> layoutNavigationBar(displayFrames, mDisplayContent.getConfiguration().uiMode, mLastNavVisible, mLastNavTranslucent, mLastNavAllowedHidden, - mLastNotificationShadeForcesShowingNavigation, contentFrame)); + contentFrame)); } if (mStatusBar != null) { simulateLayoutDecorWindow(mStatusBar, displayFrames, insetsState, simulatedWindowFrames, barContentFrames, - contentFrame -> layoutStatusBar(displayFrames, mLastSystemUiFlags, + contentFrame -> layoutStatusBar(displayFrames, mLastAppearance, contentFrame)); } layoutScreenDecorWindows(displayFrames, simulatedWindowFrames); @@ -1621,25 +1567,17 @@ public class DisplayPolicy { // For purposes of putting out fake window up to steal focus, we will // drive nav being hidden only by whether it is requested. - final int sysui = mLastSystemUiFlags; + final int appearance = mLastAppearance; final int behavior = mLastBehavior; final InsetsSourceProvider provider = mDisplayContent.getInsetsStateController().peekSourceProvider(ITYPE_NAVIGATION_BAR); boolean navVisible = provider != null ? provider.isClientVisible() : InsetsState.getDefaultVisibility(ITYPE_NAVIGATION_BAR); - boolean navTranslucent = (sysui - & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; - boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0 - || (behavior & BEHAVIOR_SHOW_BARS_BY_SWIPE) != 0; - boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0 - || (behavior & BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) != 0; + boolean navTranslucent = (appearance & APPEARANCE_OPAQUE_NAVIGATION_BARS) == 0; + boolean immersive = (behavior & BEHAVIOR_SHOW_BARS_BY_SWIPE) != 0; + boolean immersiveSticky = (behavior & BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) != 0; boolean navAllowedHidden = immersive || immersiveSticky; navTranslucent &= !immersiveSticky; // transient trumps translucent - boolean isKeyguardShowing = isKeyguardShowing() && !isKeyguardOccluded(); - boolean notificationShadeForcesShowingNavigation = - !isKeyguardShowing && mNotificationShade != null - && (mNotificationShade.getAttrs().privateFlags - & PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION) != 0; updateHideNavInputEventReceiver(); @@ -1647,21 +1585,15 @@ public class DisplayPolicy { // be hidden (because of the screen aspect ratio), then take that into account. navVisible |= !canHideNavigationBar(); - boolean updateSysUiVisibility = layoutNavigationBar(displayFrames, uiMode, navVisible, - navTranslucent, navAllowedHidden, notificationShadeForcesShowingNavigation, - null /* simulatedContentFrame */); + layoutNavigationBar(displayFrames, uiMode, navVisible, + navTranslucent, navAllowedHidden, null /* simulatedContentFrame */); if (DEBUG_LAYOUT) Slog.i(TAG, "mDock rect:" + displayFrames.mDock); - updateSysUiVisibility |= layoutStatusBar(displayFrames, sysui, - null /* simulatedContentFrame */); - if (updateSysUiVisibility) { - updateSystemUiVisibilityLw(); - } + layoutStatusBar(displayFrames, appearance, null /* simulatedContentFrame */); layoutScreenDecorWindows(displayFrames, null /* simulatedFrames */); postAdjustDisplayFrames(displayFrames); mLastNavVisible = navVisible; mLastNavTranslucent = navTranslucent; mLastNavAllowedHidden = navAllowedHidden; - mLastNotificationShadeForcesShowingNavigation = notificationShadeForcesShowingNavigation; } void updateHideNavInputEventReceiver() { @@ -1825,11 +1757,11 @@ public class DisplayPolicy { displayFrames.mContent.set(dockFrame); } - private boolean layoutStatusBar(DisplayFrames displayFrames, int sysui, + private void layoutStatusBar(DisplayFrames displayFrames, int appearance, Rect simulatedContentFrame) { // decide where the status bar goes ahead of time if (mStatusBar == null) { - return false; + return; } // apply any status bar insets getRotatedWindowBounds(displayFrames, mStatusBar, sTmpStatusFrame); @@ -1860,10 +1792,9 @@ public class DisplayPolicy { mStatusBarController.setContentFrame(sTmpRect); } - boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0 - || mDisplayContent.getInsetsPolicy().isTransient(ITYPE_STATUS_BAR); - boolean statusBarTranslucent = (sysui - & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; + boolean statusBarTransient = + mDisplayContent.getInsetsPolicy().isTransient(ITYPE_STATUS_BAR); + boolean statusBarTranslucent = (appearance & APPEARANCE_OPAQUE_STATUS_BARS) == 0; // If the status bar is hidden, we don't want to cause windows behind it to scroll. if (mStatusBar.isVisibleLw() && !statusBarTransient) { @@ -1879,8 +1810,7 @@ public class DisplayPolicy { "dock=%s content=%s cur=%s", dockFrame.toString(), displayFrames.mContent.toString(), displayFrames.mCurrent.toString())); - if (!statusBarTranslucent && !mStatusBarController.wasRecentlyTranslucent() - && !mStatusBar.isAnimatingLw()) { + if (!statusBarTranslucent && !mStatusBar.isAnimatingLw()) { // If the opaque status bar is currently requested to be visible, and not in the // process of animating on or off, then we can tell the app that it is covered by @@ -1888,18 +1818,17 @@ public class DisplayPolicy { displayFrames.mSystem.top = displayFrames.mStable.top; } } - return mStatusBarController.checkHiddenLw(); } - private boolean layoutNavigationBar(DisplayFrames displayFrames, int uiMode, boolean navVisible, - boolean navTranslucent, boolean navAllowedHidden, - boolean statusBarForcesShowingNavigation, Rect simulatedContentFrame) { + private void layoutNavigationBar(DisplayFrames displayFrames, int uiMode, boolean navVisible, + boolean navTranslucent, boolean navAllowedHidden, Rect simulatedContentFrame) { if (mNavigationBar == null) { - return false; + return; } final Rect navigationFrame = sTmpNavFrame; - boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); + boolean navBarTransient = + mDisplayContent.getInsetsPolicy().isTransient(ITYPE_NAVIGATION_BAR); // Force the navigation bar to its appropriate place and size. We need to do this directly, // instead of relying on it to bubble up from the nav bar, because this needs to change // atomically with screen rotations. @@ -1924,18 +1853,11 @@ public class DisplayPolicy { - getNavigationBarHeight(rotation, uiMode); navigationFrame.top = topNavBar; displayFrames.mStable.bottom = displayFrames.mStableFullscreen.bottom = top; - if (transientNavBarShowing) { - mNavigationBarController.setBarShowingLw(true); - } else if (navVisible) { - mNavigationBarController.setBarShowingLw(true); + if (navVisible && !navBarTransient) { dockFrame.bottom = displayFrames.mRestricted.bottom = top; - } else { - // We currently want to hide the navigation UI - unless we expanded the status bar. - mNavigationBarController.setBarShowingLw(statusBarForcesShowingNavigation); } if (navVisible && !navTranslucent && !navAllowedHidden - && !mNavigationBar.isAnimatingLw() - && !mNavigationBarController.wasRecentlyTranslucent()) { + && !mNavigationBar.isAnimatingLw()) { // If the opaque nav bar is currently requested to be visible and not in the process // of animating on or off, then we can tell the app that it is covered by it. displayFrames.mSystem.bottom = top; @@ -1946,18 +1868,11 @@ public class DisplayPolicy { - getNavigationBarWidth(rotation, uiMode); navigationFrame.left = left; displayFrames.mStable.right = displayFrames.mStableFullscreen.right = left; - if (transientNavBarShowing) { - mNavigationBarController.setBarShowingLw(true); - } else if (navVisible) { - mNavigationBarController.setBarShowingLw(true); + if (navVisible && !navBarTransient) { dockFrame.right = displayFrames.mRestricted.right = left; - } else { - // We currently want to hide the navigation UI - unless we expanded the status bar. - mNavigationBarController.setBarShowingLw(statusBarForcesShowingNavigation); } if (navVisible && !navTranslucent && !navAllowedHidden - && !mNavigationBar.isAnimatingLw() - && !mNavigationBarController.wasRecentlyTranslucent()) { + && !mNavigationBar.isAnimatingLw()) { // If the nav bar is currently requested to be visible, and not in the process of // animating on or off, then we can tell the app that it is covered by it. displayFrames.mSystem.right = left; @@ -1968,18 +1883,11 @@ public class DisplayPolicy { + getNavigationBarWidth(rotation, uiMode); navigationFrame.right = right; displayFrames.mStable.left = displayFrames.mStableFullscreen.left = right; - if (transientNavBarShowing) { - mNavigationBarController.setBarShowingLw(true); - } else if (navVisible) { - mNavigationBarController.setBarShowingLw(true); + if (navVisible && !navBarTransient) { dockFrame.left = displayFrames.mRestricted.left = right; - } else { - // We currently want to hide the navigation UI - unless we expanded the status bar. - mNavigationBarController.setBarShowingLw(statusBarForcesShowingNavigation); } if (navVisible && !navTranslucent && !navAllowedHidden - && !mNavigationBar.isAnimatingLw() - && !mNavigationBarController.wasRecentlyTranslucent()) { + && !mNavigationBar.isAnimatingLw()) { // If the nav bar is currently requested to be visible, and not in the process of // animating on or off, then we can tell the app that it is covered by it. displayFrames.mSystem.left = right; @@ -2008,7 +1916,6 @@ public class DisplayPolicy { } if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + navigationFrame); - return mNavigationBarController.checkHiddenLw(); } private boolean canReceiveInput(WindowState win) { @@ -2059,9 +1966,6 @@ public class DisplayPolicy { dcf.setEmpty(); windowFrames.setParentFrameWasClippedByDisplayCutout(false); - final boolean hasNavBar = hasNavigationBar() && mNavigationBar != null - && mNavigationBar.isVisibleLw(); - final int adjust = sim & SOFT_INPUT_MASK_ADJUST; final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) == FLAG_LAYOUT_IN_SCREEN; @@ -2407,53 +2311,27 @@ public class DisplayPolicy { + " top=" + mTopFullscreenOpaqueWindowState); final boolean forceShowStatusBar = (getStatusBar().getAttrs().privateFlags & PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR) != 0; - final boolean notificationShadeForcesShowingNavigation = - mNotificationShade != null - && (mNotificationShade.getAttrs().privateFlags - & PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION) != 0; boolean topAppHidesStatusBar = topAppHidesStatusBar(); if (mForceStatusBar || forceShowStatusBar) { if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); - if (mStatusBarController.setBarShowingLw(true)) { - changes |= FINISH_LAYOUT_REDO_LAYOUT; - } // Maintain fullscreen layout until incoming animation is complete. topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); - // Transient status bar is not allowed if notification shade is expecting the - // navigation keys from the user. - if (notificationShadeForcesShowingNavigation - && mStatusBarController.isTransientShowing()) { - mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, - mLastSystemUiFlags, mLastSystemUiFlags); - } } else if (mTopFullscreenOpaqueWindowState != null) { topIsFullscreen = topAppHidesStatusBar; // The subtle difference between the window for mTopFullscreenOpaqueWindowState // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the // case though. - if (mStatusBarController.isTransientShowing()) { - if (mStatusBarController.setBarShowingLw(true)) { - changes |= FINISH_LAYOUT_REDO_LAYOUT; - } - } else if (topIsFullscreen && !mDisplayContent.getDefaultTaskDisplayArea() + if (!topIsFullscreen || mDisplayContent.getDefaultTaskDisplayArea() .isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) { - if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); - if (mStatusBarController.setBarShowingLw(false)) { - changes |= FINISH_LAYOUT_REDO_LAYOUT; - } else { - if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); - } - } else { - if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); - if (mStatusBarController.setBarShowingLw(true)) { - changes |= FINISH_LAYOUT_REDO_LAYOUT; - } topAppHidesStatusBar = false; } } - mStatusBarController.setTopAppHidesStatusBar(topAppHidesStatusBar); + StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); + if (statusBar != null) { + statusBar.setTopAppHidesStatusBar(topAppHidesStatusBar); + } } if (mTopIsFullscreen != topIsFullscreen) { @@ -2464,7 +2342,7 @@ public class DisplayPolicy { mTopIsFullscreen = topIsFullscreen; } - if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) { + if (updateSystemUiVisibilityLw()) { // If the navigation bar has been hidden or shown, we need to do another // layout pass to update that window. changes |= FINISH_LAYOUT_REDO_LAYOUT; @@ -2497,7 +2375,6 @@ public class DisplayPolicy { Slog.d(TAG, "attr: " + attrs + " request: " + request); } return (fl & LayoutParams.FLAG_FULLSCREEN) != 0 - || (sysui & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0 || (request != null && !request.isVisible()); } @@ -2910,7 +2787,7 @@ public class DisplayPolicy { if (mDisplayContent.isDefaultDisplay) { mService.mPolicy.onDefaultDisplayFocusChangedLw(newFocus); } - if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) { + if (updateSystemUiVisibilityLw()) { // If the navigation bar has been hidden or shown, we need to do another // layout pass to update that window. return FINISH_LAYOUT_REDO_LAYOUT; @@ -2977,17 +2854,20 @@ public class DisplayPolicy { } void resetSystemUiVisibilityLw() { - mLastSystemUiFlags = 0; + mLastDisableFlags = 0; updateSystemUiVisibilityLw(); } - int updateSystemUiVisibilityLw() { + /** + * @return {@code true} if the update may affect the layout. + */ + boolean updateSystemUiVisibilityLw() { // If there is no window focused, there will be nobody to handle the events // anyway, so just hang on in whatever state we're in until things settle down. WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; if (winCandidate == null) { - return 0; + return false; } // The immersive mode confirmation should never affect the system bar visibility, otherwise @@ -3003,7 +2883,7 @@ public class DisplayPolicy { : lastFocusCanReceiveKeys ? mLastFocusedWindow : mTopFullscreenOpaqueWindowState; if (winCandidate == null) { - return 0; + return false; } } final WindowState win = winCandidate; @@ -3011,17 +2891,9 @@ public class DisplayPolicy { mDisplayContent.getInsetsPolicy().updateBarControlTarget(win); - int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) - & ~mResettingSystemUiFlags - & ~mForceClearedSystemUiFlags; - if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { - tmpVisibility - &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); - } - - final int fullscreenAppearance = updateLightStatusBarAppearanceLw(0 /* vis */, + final int fullscreenAppearance = updateLightStatusBarLw(0 /* vis */, mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); - final int dockedAppearance = updateLightStatusBarAppearanceLw(0 /* vis */, + final int dockedAppearance = updateLightStatusBarLw(0 /* vis */, mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); final boolean inSplitScreen = mService.mRoot.getDefaultTaskDisplayArea().isSplitScreenModeActivated(); @@ -3034,32 +2906,24 @@ public class DisplayPolicy { mService.getStackBounds(inSplitScreen ? WINDOWING_MODE_SPLIT_SCREEN_SECONDARY : WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_UNDEFINED, mNonDockedStackBounds); - final Pair result = - updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); - final int visibility = result.first; - final WindowState navColorWin = result.second; + final int disableFlags = win.getSystemUiVisibility() & StatusBarManager.DISABLE_MASK; + final int opaqueAppearance = updateSystemBarsLw(win, disableFlags); + final WindowState navColorWin = chooseNavigationColorWindowLw( + mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState, + mDisplayContent.mInputMethodWindow, mNavigationBarPosition); final boolean isNavbarColorManagedByIme = navColorWin != null && navColorWin == mDisplayContent.mInputMethodWindow; - final int opaqueAppearance = InsetsFlags.getAppearance(visibility) - & (APPEARANCE_OPAQUE_STATUS_BARS | APPEARANCE_OPAQUE_NAVIGATION_BARS); - final int appearance = updateLightNavigationBarAppearanceLw( + final int appearance = updateLightNavigationBarLw( win.mAttrs.insetsFlags.appearance, mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState, mDisplayContent.mInputMethodWindow, navColorWin) | opaqueAppearance; - final int diff = visibility ^ mLastSystemUiFlags; - final InsetsPolicy insetsPolicy = getInsetsPolicy(); - final boolean isFullscreen = (visibility & (View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)) != 0 - || (PolicyControl.getWindowFlags(win, win.mAttrs) & FLAG_FULLSCREEN) != 0 - || (getStatusBar() != null && insetsPolicy.isHidden(ITYPE_STATUS_BAR)) - || (getNavigationBar() != null && insetsPolicy.isHidden( - ITYPE_NAVIGATION_BAR)); + final InsetsState requestedInsets = win.getRequestedInsetsState(); final int behavior = win.mAttrs.insetsFlags.behavior; - final boolean isImmersive = (visibility & (View.SYSTEM_UI_FLAG_IMMERSIVE - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)) != 0 - || behavior == BEHAVIOR_SHOW_BARS_BY_SWIPE + final boolean isImmersive = behavior == BEHAVIOR_SHOW_BARS_BY_SWIPE || behavior == BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; - if (diff == 0 + final boolean isFullscreen = !requestedInsets.getSourceOrDefaultVisibility(ITYPE_STATUS_BAR) + || !requestedInsets.getSourceOrDefaultVisibility(ITYPE_NAVIGATION_BAR); + if (mLastDisableFlags == disableFlags && mLastAppearance == appearance && mLastFullscreenAppearance == fullscreenAppearance && mLastDockedAppearance == dockedAppearance @@ -3068,14 +2932,10 @@ public class DisplayPolicy { && mLastFocusIsImmersive == isImmersive && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) && mLastDockedStackBounds.equals(mDockedStackBounds)) { - return 0; + return false; } - // Obtains which types should show transient and which types should abort transient. - // If there is no transient state change, this pair will contain two empty arrays. - final Pair transientState = getTransientState(visibility, mLastSystemUiFlags); - - mLastSystemUiFlags = visibility; + mLastDisableFlags = disableFlags; mLastAppearance = appearance; mLastFullscreenAppearance = fullscreenAppearance; mLastDockedAppearance = dockedAppearance; @@ -3097,50 +2957,17 @@ public class DisplayPolicy { StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); if (statusBar != null) { final int displayId = getDisplayId(); - statusBar.setDisableFlags(displayId, visibility & StatusBarManager.DISABLE_MASK, - cause); - if (transientState.first.length > 0) { - statusBar.showTransient(displayId, transientState.first); - } - if (transientState.second.length > 0) { - statusBar.abortTransient(displayId, transientState.second); - } + statusBar.setDisableFlags(displayId, disableFlags, cause); statusBar.onSystemBarAppearanceChanged(displayId, appearance, appearanceRegions, isNavbarColorManagedByIme); statusBar.topAppWindowChanged(displayId, isFullscreen, isImmersive); - // TODO(b/118118435): Remove this after removing system UI visibilities. - synchronized (mLock) { - mDisplayContent.statusBarVisibilityChanged( - visibility & ~(View.STATUS_BAR_UNHIDE | View.NAVIGATION_BAR_UNHIDE)); - } } }); - return diff; + return true; } - private static Pair getTransientState(int vis, int oldVis) { - final IntArray typesToShow = new IntArray(0); - final IntArray typesToAbort = new IntArray(0); - updateTransientState(vis, oldVis, View.STATUS_BAR_TRANSIENT, ITYPE_STATUS_BAR, typesToShow, - typesToAbort); - updateTransientState(vis, oldVis, View.NAVIGATION_BAR_TRANSIENT, - ITYPE_NAVIGATION_BAR, typesToShow, typesToAbort); - return Pair.create(typesToShow.toArray(), typesToAbort.toArray()); - } - - private static void updateTransientState(int vis, int oldVis, int transientFlag, - @InternalInsetsType int type, IntArray typesToShow, IntArray typesToAbort) { - final boolean wasTransient = (oldVis & transientFlag) != 0; - final boolean isTransient = (vis & transientFlag) != 0; - if (!wasTransient && isTransient) { - typesToShow.add(type); - } else if (wasTransient && !isTransient) { - typesToAbort.add(type); - } - } - - private int updateLightStatusBarAppearanceLw(@Appearance int appearance, WindowState opaque, + private int updateLightStatusBarLw(@Appearance int appearance, WindowState opaque, WindowState opaqueOrDimming) { final boolean onKeyguard = isKeyguardShowing() && !isKeyguardOccluded(); final WindowState statusColorWin = onKeyguard ? mNotificationShade : opaqueOrDimming; @@ -3207,24 +3034,7 @@ public class DisplayPolicy { } @VisibleForTesting - static int updateLightNavigationBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming, - WindowState imeWindow, WindowState navColorWin) { - - if (navColorWin != null) { - if (navColorWin == imeWindow || navColorWin == opaque) { - // Respect the light flag. - vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; - vis |= PolicyControl.getSystemUiVisibility(navColorWin, null) - & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; - } else if (navColorWin == opaqueOrDimming && navColorWin.isDimming()) { - // Clear the light flag for dimming window. - vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; - } - } - return vis; - } - - private int updateLightNavigationBarAppearanceLw(int appearance, WindowState opaque, + int updateLightNavigationBarLw(int appearance, WindowState opaque, WindowState opaqueOrDimming, WindowState imeWindow, WindowState navColorWin) { if (navColorWin != null) { @@ -3244,7 +3054,7 @@ public class DisplayPolicy { return appearance; } - private Pair updateSystemBarsLw(WindowState win, int oldVis, int vis) { + private int updateSystemBarsLw(WindowState win, int disableFlags) { final boolean dockedStackVisible = mDisplayContent.getDefaultTaskDisplayArea() .isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); final boolean freeformStackVisible = mDisplayContent.getDefaultTaskDisplayArea() @@ -3257,115 +3067,46 @@ public class DisplayPolicy { mForceShowSystemBars = dockedStackVisible || win.inFreeformWindowingMode() || resizing; final boolean forceOpaqueStatusBar = mForceShowSystemBars && !isKeyguardShowing(); - // apply translucent bar vis flags - WindowState fullscreenTransWin = isKeyguardShowing() && !isKeyguardOccluded() - ? mNotificationShade - : mTopFullscreenOpaqueWindowState; - vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); - vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); - int dockedVis = mStatusBarController.applyTranslucentFlagLw( - mTopDockedOpaqueWindowState, 0, 0); - dockedVis = mNavigationBarController.applyTranslucentFlagLw( - mTopDockedOpaqueWindowState, dockedVis, 0); - final boolean fullscreenDrawsStatusBarBackground = - drawsStatusBarBackground(vis, mTopFullscreenOpaqueWindowState); + drawsStatusBarBackground(mTopFullscreenOpaqueWindowState); final boolean dockedDrawsStatusBarBackground = - drawsStatusBarBackground(dockedVis, mTopDockedOpaqueWindowState); + drawsStatusBarBackground(mTopDockedOpaqueWindowState); final boolean fullscreenDrawsNavBarBackground = - drawsNavigationBarBackground(vis, mTopFullscreenOpaqueWindowState); + drawsNavigationBarBackground(mTopFullscreenOpaqueWindowState); final boolean dockedDrawsNavigationBarBackground = - drawsNavigationBarBackground(dockedVis, mTopDockedOpaqueWindowState); + drawsNavigationBarBackground(mTopDockedOpaqueWindowState); - // prevent status bar interaction from clearing certain flags - int type = win.getAttrs().type; - boolean notificationShadeHasFocus = type == TYPE_NOTIFICATION_SHADE; - if (notificationShadeHasFocus && !isKeyguardShowing()) { - int flags = View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_IMMERSIVE - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - if (isKeyguardOccluded()) { - flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; - } - vis = (vis & ~flags) | (oldVis & flags); - } + int appearance = APPEARANCE_OPAQUE_NAVIGATION_BARS | APPEARANCE_OPAQUE_STATUS_BARS; if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { - vis |= View.STATUS_BAR_TRANSPARENT; - vis &= ~View.STATUS_BAR_TRANSLUCENT; - } else if (forceOpaqueStatusBar) { - vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); + appearance &= ~APPEARANCE_OPAQUE_STATUS_BARS; } - vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing, - fullscreenDrawsNavBarBackground, dockedDrawsNavigationBarBackground); + appearance = configureNavBarOpacity(appearance, dockedStackVisible, + freeformStackVisible, resizing, fullscreenDrawsNavBarBackground, + dockedDrawsNavigationBarBackground); - // update status bar - boolean immersiveSticky = - (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; - final boolean hideStatusBarWM = - mTopFullscreenOpaqueWindowState != null - && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) - & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; - final boolean hideStatusBarSysui = - (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; - final boolean hideNavBarSysui = (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 - // We shouldn't rely on the system UI visibilities anymore because the window can - // use the new API (e.g., WindowInsetsController.hide) to hide navigation bar. - // TODO(b/149813814): clean up the system UI flag usages in this function. - || !win.getRequestedInsetsState().getSourceOrDefaultVisibility( + final InsetsState requestedInsetsState = win.getRequestedInsetsState(); + final boolean requestHideNavBar = !requestedInsetsState.getSourceOrDefaultVisibility( ITYPE_NAVIGATION_BAR); - final boolean transientStatusBarAllowed = getStatusBar() != null - && (notificationShadeHasFocus || (!mForceShowSystemBars - && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); - - final boolean transientNavBarAllowed = mNavigationBar != null - && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; - final long now = SystemClock.uptimeMillis(); final boolean pendingPanic = mPendingPanicGestureUptime != 0 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; final DisplayPolicy defaultDisplayPolicy = mService.getDefaultDisplayContentLocked().getDisplayPolicy(); - if (pendingPanic && hideNavBarSysui && win != mNotificationShade + if (pendingPanic && requestHideNavBar && win != mNotificationShade && getInsetsPolicy().isHidden(ITYPE_NAVIGATION_BAR) // TODO (b/111955725): Show keyguard presentation on all external displays && defaultDisplayPolicy.isKeyguardDrawComplete()) { // The user performed the panic gesture recently, we're about to hide the bars, // we're no longer on the Keyguard and the screen is ready. We can now request the bars. mPendingPanicGestureUptime = 0; - if (!isNavBarEmpty(vis)) { + if (!isNavBarEmpty(disableFlags)) { mDisplayContent.getInsetsPolicy().showTransient(SHOW_TYPES_FOR_PANIC); } } - final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() - && !transientStatusBarAllowed && hideStatusBarSysui; - final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() - && !transientNavBarAllowed; - if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { - // clear the clearable flags instead - clearClearableFlagsLw(); - vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; - } - - final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; - immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; - final boolean navAllowedHidden = immersive || immersiveSticky; - - if (hideNavBarSysui && !navAllowedHidden - && mService.mPolicy.getWindowLayerLw(win) - > mService.mPolicy.getWindowLayerFromTypeLw(TYPE_INPUT_CONSUMER)) { - // We can't hide the navbar from this window otherwise the input consumer would not get - // the input events. - vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); - } - - vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); - // update navigation bar boolean oldImmersiveMode = mLastImmersiveMode; boolean newImmersiveMode = isImmersiveMode(win); @@ -3374,23 +3115,13 @@ public class DisplayPolicy { final String pkg = win.getOwningPackage(); mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, mService.mPolicy.isUserSetupComplete(), - isNavBarEmpty(win.getSystemUiVisibility())); + isNavBarEmpty(disableFlags)); } - vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); - - final WindowState navColorWin = chooseNavigationColorWindowLw( - mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState, - mDisplayContent.mInputMethodWindow, mNavigationBarPosition); - vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState, - mTopFullscreenOpaqueOrDimmingWindowState, - mDisplayContent.mInputMethodWindow, navColorWin); - - return Pair.create(vis, navColorWin); + return appearance; } - private boolean drawsBarBackground(int vis, WindowState win, BarController controller, - int translucentFlag) { + private boolean drawsBarBackground(WindowState win, BarController controller) { if (!controller.isTransparentAllowed(win)) { return false; } @@ -3403,73 +3134,59 @@ public class DisplayPolicy { final boolean forceDrawsSystemBars = (win.getAttrs().privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0; - return forceDrawsSystemBars || drawsSystemBars && (vis & translucentFlag) == 0; + return forceDrawsSystemBars || drawsSystemBars; } - private boolean drawsStatusBarBackground(int vis, WindowState win) { - return drawsBarBackground(vis, win, mStatusBarController, FLAG_TRANSLUCENT_STATUS); + private boolean drawsStatusBarBackground(WindowState win) { + return drawsBarBackground(win, mStatusBarController); } - private boolean drawsNavigationBarBackground(int vis, WindowState win) { - return drawsBarBackground(vis, win, mNavigationBarController, FLAG_TRANSLUCENT_NAVIGATION); + private boolean drawsNavigationBarBackground(WindowState win) { + return drawsBarBackground(win, mNavigationBarController); } /** * @return the current visibility flags with the nav-bar opacity related flags toggled based * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. */ - private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, + private int configureNavBarOpacity(int appearance, boolean dockedStackVisible, boolean freeformStackVisible, boolean isDockedDividerResizing, boolean fullscreenDrawsBackground, boolean dockedDrawsNavigationBarBackground) { if (mNavBarOpacityMode == NAV_BAR_FORCE_TRANSPARENT) { if (fullscreenDrawsBackground && dockedDrawsNavigationBarBackground) { - visibility = setNavBarTransparentFlag(visibility); + appearance = clearNavBarOpaqueFlag(appearance); } else if (dockedStackVisible) { - visibility = setNavBarOpaqueFlag(visibility); + appearance = setNavBarOpaqueFlag(appearance); } } else if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { if (mIsFreeformWindowOverlappingWithNavBar) { - visibility = setNavBarTranslucentFlag(visibility); + appearance = clearNavBarOpaqueFlag(appearance); } else { - visibility = setNavBarOpaqueFlag(visibility); + appearance = setNavBarOpaqueFlag(appearance); } } else if (fullscreenDrawsBackground) { - visibility = setNavBarTransparentFlag(visibility); + appearance = clearNavBarOpaqueFlag(appearance); } } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { if (isDockedDividerResizing) { - visibility = setNavBarOpaqueFlag(visibility); + appearance = setNavBarOpaqueFlag(appearance); } else if (freeformStackVisible) { - visibility = setNavBarTranslucentFlag(visibility); + appearance = clearNavBarOpaqueFlag(appearance); } else { - visibility = setNavBarOpaqueFlag(visibility); + appearance = setNavBarOpaqueFlag(appearance); } } - return visibility; + return appearance; } - private int setNavBarOpaqueFlag(int visibility) { - return visibility & ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); + private int setNavBarOpaqueFlag(int appearance) { + return appearance | APPEARANCE_OPAQUE_NAVIGATION_BARS; } - private int setNavBarTranslucentFlag(int visibility) { - visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; - return visibility | View.NAVIGATION_BAR_TRANSLUCENT; - } - - private int setNavBarTransparentFlag(int visibility) { - visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; - return visibility | View.NAVIGATION_BAR_TRANSPARENT; - } - - private void clearClearableFlagsLw() { - int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; - if (newVal != mResettingSystemUiFlags) { - mResettingSystemUiFlags = newVal; - mDisplayContent.reevaluateStatusBarVisibility(); - } + private int clearNavBarOpaqueFlag(int appearance) { + return appearance & ~APPEARANCE_OPAQUE_NAVIGATION_BARS; } private boolean isImmersiveMode(WindowState win) { @@ -3520,7 +3237,7 @@ public class DisplayPolicy { // taken over the whole screen. boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(isScreenOn, SystemClock.elapsedRealtime(), isImmersiveMode(mSystemUiControllingWindow), - isNavBarEmpty(mLastSystemUiFlags)); + isNavBarEmpty(mLastDisableFlags)); if (panic) { mHandler.post(mHiddenNavPanic); } @@ -3579,14 +3296,9 @@ public class DisplayPolicy { pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); pw.print(prefix); pw.print("mHdmiPlugged="); pw.println(mHdmiPlugged); - if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 - || mForceClearedSystemUiFlags != 0) { - pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); - pw.print(Integer.toHexString(mLastSystemUiFlags)); - pw.print(" mResettingSystemUiFlags=0x"); - pw.print(Integer.toHexString(mResettingSystemUiFlags)); - pw.print(" mForceClearedSystemUiFlags=0x"); - pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); + if (mLastDisableFlags != 0) { + pw.print(prefix); pw.print("mLastDisableFlags=0x"); + pw.print(Integer.toHexString(mLastDisableFlags)); } pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream); pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); @@ -3635,8 +3347,6 @@ public class DisplayPolicy { pw.print(prefix); pw.print("mRemoteInsetsControllerControlsSystemBars"); pw.print(mDisplayContent.getInsetsPolicy().getRemoteInsetsControllerControlsSystemBars()); pw.print(" mAllowLockscreenWhenOn="); pw.println(mAllowLockscreenWhenOn); - mStatusBarController.dump(pw, prefix); - mNavigationBarController.dump(pw, prefix); pw.print(prefix); pw.println("Looper state:"); mHandler.getLooper().dump(new PrintWriterPrinter(pw), prefix + " "); diff --git a/services/core/java/com/android/server/wm/StatusBarController.java b/services/core/java/com/android/server/wm/StatusBarController.java deleted file mode 100644 index 3564e0bce5f58..0000000000000 --- a/services/core/java/com/android/server/wm/StatusBarController.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wm; - -import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; -import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; - -import static com.android.server.wm.WindowManagerInternal.AppTransitionListener; - -import android.app.StatusBarManager; -import android.os.IBinder; -import android.view.View; - -import com.android.server.statusbar.StatusBarManagerInternal; - -/** - * Implements status bar specific behavior. - */ -public class StatusBarController extends BarController { - - private final AppTransitionListener mAppTransitionListener = new AppTransitionListener() { - - private Runnable mAppTransitionPending = () -> { - StatusBarManagerInternal statusBar = getStatusBarInternal(); - if (statusBar != null) { - statusBar.appTransitionPending(mDisplayId); - } - }; - - private Runnable mAppTransitionCancelled = () -> { - StatusBarManagerInternal statusBar = getStatusBarInternal(); - if (statusBar != null) { - statusBar.appTransitionCancelled(mDisplayId); - } - }; - - private Runnable mAppTransitionFinished = () -> { - StatusBarManagerInternal statusBar = getStatusBarInternal(); - if (statusBar != null) { - statusBar.appTransitionFinished(mDisplayId); - } - }; - - @Override - public void onAppTransitionPendingLocked() { - mHandler.post(mAppTransitionPending); - } - - @Override - public int onAppTransitionStartingLocked(int transit, long duration, - long statusBarAnimationStartTime, long statusBarAnimationDuration) { - mHandler.post(() -> { - StatusBarManagerInternal statusBar = getStatusBarInternal(); - if (statusBar != null) { - statusBar.appTransitionStarting(mDisplayId, - statusBarAnimationStartTime, statusBarAnimationDuration); - } - }); - return 0; - } - - @Override - public void onAppTransitionCancelledLocked(int transit) { - mHandler.post(mAppTransitionCancelled); - } - - @Override - public void onAppTransitionFinishedLocked(IBinder token) { - mHandler.post(mAppTransitionFinished); - } - }; - - StatusBarController(int displayId) { - super("StatusBar", - displayId, - View.STATUS_BAR_TRANSIENT, - View.STATUS_BAR_UNHIDE, - View.STATUS_BAR_TRANSLUCENT, - StatusBarManager.WINDOW_STATUS_BAR, - TYPE_STATUS_BAR, - FLAG_TRANSLUCENT_STATUS, - View.STATUS_BAR_TRANSPARENT); - } - - void setTopAppHidesStatusBar(boolean hidesStatusBar) { - StatusBarManagerInternal statusBar = getStatusBarInternal(); - if (statusBar != null) { - statusBar.setTopAppHidesStatusBar(hidesStatusBar); - } - } - - AppTransitionListener getAppTransitionListener() { - return mAppTransitionListener; - } -} diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java index 94e40413f9f8b..951118125f6ee 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java @@ -124,7 +124,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { spyOn(mNavBarWindow); // Disabling this call for most tests since it can override the systemUiFlags when called. - doReturn(0).when(mDisplayPolicy).updateSystemUiVisibilityLw(); + doReturn(false).when(mDisplayPolicy).updateSystemUiVisibilityLw(); updateDisplayFrames(); } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java index b77d21c0f711c..a55423a7baf6a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java @@ -19,9 +19,9 @@ package com.android.server.wm; import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.Surface.ROTATION_0; -import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; +import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE; import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH; import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; @@ -78,8 +78,7 @@ public class DisplayPolicyTests extends WindowTestsBase { attrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; attrs.format = PixelFormat.OPAQUE; - attrs.systemUiVisibility = attrs.subtreeSystemUiVisibility = win.mSystemUiVisibility = - hasLightNavBar ? SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0; + attrs.insetsFlags.appearance = hasLightNavBar ? APPEARANCE_LIGHT_NAVIGATION_BARS : 0; return win; } @@ -103,8 +102,7 @@ public class DisplayPolicyTests extends WindowTestsBase { attrs.flags = FLAG_NOT_FOCUSABLE | FLAG_LAYOUT_IN_SCREEN | (drawNavBar ? FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS : 0); attrs.format = PixelFormat.TRANSPARENT; - attrs.systemUiVisibility = attrs.subtreeSystemUiVisibility = win.mSystemUiVisibility = - hasLightNavBar ? SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0; + attrs.insetsFlags.appearance = hasLightNavBar ? APPEARANCE_LIGHT_NAVIGATION_BARS : 0; win.mHasSurface = visible; return win; } @@ -163,6 +161,7 @@ public class DisplayPolicyTests extends WindowTestsBase { @Test public void testUpdateLightNavigationBarLw() { + DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy(); final WindowState opaqueDarkNavBar = createOpaqueFullscreen(false); final WindowState opaqueLightNavBar = createOpaqueFullscreen(true); @@ -171,50 +170,50 @@ public class DisplayPolicyTests extends WindowTestsBase { final WindowState imeDrawDarkNavBar = createInputMethodWindow(true, true, false); final WindowState imeDrawLightNavBar = createInputMethodWindow(true, true, true); - assertEquals(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, - DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, null, null, + assertEquals(APPEARANCE_LIGHT_NAVIGATION_BARS, + displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, null, null, null, null)); - // Opaque top fullscreen window overrides SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR flag. - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( + // Opaque top fullscreen window overrides APPEARANCE_LIGHT_NAVIGATION_BARS flag. + assertEquals(0, displayPolicy.updateLightNavigationBarLw( 0, opaqueDarkNavBar, opaqueDarkNavBar, null, opaqueDarkNavBar)); - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, opaqueDarkNavBar, opaqueDarkNavBar, null, + assertEquals(0, displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, opaqueDarkNavBar, opaqueDarkNavBar, null, opaqueDarkNavBar)); - assertEquals(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, - DisplayPolicy.updateLightNavigationBarLw(0, opaqueLightNavBar, + assertEquals(APPEARANCE_LIGHT_NAVIGATION_BARS, + displayPolicy.updateLightNavigationBarLw(0, opaqueLightNavBar, opaqueLightNavBar, null, opaqueLightNavBar)); - assertEquals(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, - DisplayPolicy.updateLightNavigationBarLw(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, + assertEquals(APPEARANCE_LIGHT_NAVIGATION_BARS, + displayPolicy.updateLightNavigationBarLw(APPEARANCE_LIGHT_NAVIGATION_BARS, opaqueLightNavBar, opaqueLightNavBar, null, opaqueLightNavBar)); - // Dimming window clears SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR. - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( + // Dimming window clears APPEARANCE_LIGHT_NAVIGATION_BARS. + assertEquals(0, displayPolicy.updateLightNavigationBarLw( 0, opaqueDarkNavBar, dimming, null, dimming)); - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( + assertEquals(0, displayPolicy.updateLightNavigationBarLw( 0, opaqueLightNavBar, dimming, null, dimming)); - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, opaqueDarkNavBar, dimming, null, dimming)); - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, opaqueLightNavBar, dimming, null, dimming)); - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, opaqueLightNavBar, dimming, imeDrawLightNavBar, + assertEquals(0, displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, opaqueDarkNavBar, dimming, null, dimming)); + assertEquals(0, displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, opaqueLightNavBar, dimming, null, dimming)); + assertEquals(0, displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, opaqueLightNavBar, dimming, imeDrawLightNavBar, dimming)); - // IME window clears SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, null, null, imeDrawDarkNavBar, + // IME window clears APPEARANCE_LIGHT_NAVIGATION_BARS + assertEquals(0, displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, null, null, imeDrawDarkNavBar, imeDrawDarkNavBar)); - // Even if the top fullscreen has SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, IME window wins. - assertEquals(0, DisplayPolicy.updateLightNavigationBarLw( - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, opaqueLightNavBar, opaqueLightNavBar, + // Even if the top fullscreen has APPEARANCE_LIGHT_NAVIGATION_BARS, IME window wins. + assertEquals(0, displayPolicy.updateLightNavigationBarLw( + APPEARANCE_LIGHT_NAVIGATION_BARS, opaqueLightNavBar, opaqueLightNavBar, imeDrawDarkNavBar, imeDrawDarkNavBar)); - // IME window should be able to use SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR. - assertEquals(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, - DisplayPolicy.updateLightNavigationBarLw(0, opaqueDarkNavBar, + // IME window should be able to use APPEARANCE_LIGHT_NAVIGATION_BARS. + assertEquals(APPEARANCE_LIGHT_NAVIGATION_BARS, + displayPolicy.updateLightNavigationBarLw(0, opaqueDarkNavBar, opaqueDarkNavBar, imeDrawLightNavBar, imeDrawLightNavBar)); } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java index af8cb02a86fe7..94ffcdab4fa72 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java @@ -45,7 +45,6 @@ import android.util.Pair; import android.view.DisplayCutout; import android.view.DisplayInfo; import android.view.Gravity; -import android.view.View; import android.view.WindowManagerGlobal; import com.android.internal.R; @@ -99,11 +98,9 @@ public class DisplayPolicyTestsBase extends WindowTestsBase { mStatusBarWindow.mAttrs.gravity = Gravity.TOP; addWindow(mStatusBarWindow); - mDisplayPolicy.mLastSystemUiFlags |= View.STATUS_BAR_TRANSPARENT; mNavBarWindow.mAttrs.gravity = Gravity.BOTTOM; addWindow(mNavBarWindow); - mDisplayPolicy.mLastSystemUiFlags |= View.NAVIGATION_BAR_TRANSPARENT; // Update source frame and visibility of insets providers. mDisplayContent.getInsetsStateController().onPostLayout(); diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index edcf0d4f55011..f1540731da8be 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -566,7 +566,7 @@ public class SizeCompatTests extends WindowTestsBase { assertEquals(new Rect(mActivity.getBounds().left, 0, dh - mActivity.getBounds().right, 0), mActivity.getLetterboxInsets()); - final StatusBarController statusBarController = + final BarController statusBarController = mActivity.mDisplayContent.getDisplayPolicy().getStatusBarController(); // The activity doesn't fill the display, so the letterbox of the rotated activity is // overlapped with the rotated content frame of status bar. Hence the status bar shouldn't