Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44a65980 authored by Tiger Huang's avatar Tiger Huang
Browse files

Refine isLightBarAllowed

The light bar is only allowed if the color-controlling window has
intersection with the system bar.

The app window frame doesn't need to 'contains' the frame of the bar,
because:
1. In split-screen mode, the app window only intersects a part of status
   bar.
2. When navigation bar is at the same side of a display cutout,
   navigation bar would be thicker than the cutout. The app window which
   fits the cutout can only intersect with a part of navigation bar.

Fix: 183696228
Test: atest LetterboxTest LightBarTests DisplayPolicyTests
Change-Id: If17a2050b22e674bb760d6c98305ee69067b11fe
parent 1628ab39
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -1417,14 +1417,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return mLetterboxUiController.isFullyTransparentBarAllowed(rect);
    }

    /**
     * @return {@code true} if there is a letterbox and any part of that letterbox overlaps with
     * the given {@code rect}.
     */
    boolean isLetterboxOverlappingWith(Rect rect) {
        return mLetterboxUiController.isLetterboxOverlappingWith(rect);
    }

    static class Token extends IApplicationToken.Stub {
        private WeakReference<ActivityRecord> weakActivity;
        private final String name;
+16 −36
Original line number Diff line number Diff line
@@ -146,7 +146,6 @@ import android.view.View;
import android.view.ViewDebug;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManagerGlobal;
@@ -2495,12 +2494,10 @@ public class DisplayPolicy {
        mService.getRootTaskBounds(inSplitScreen ? WINDOWING_MODE_SPLIT_SCREEN_SECONDARY
                        : WINDOWING_MODE_FULLSCREEN,
                ACTIVITY_TYPE_UNDEFINED, mNonDockedRootTaskBounds);
        final int fullscreenAppearance = updateLightStatusBarLw(0 /* appearance */,
                mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState,
                mNonDockedRootTaskBounds);
        final int dockedAppearance = updateLightStatusBarLw(0 /* appearance */,
                mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState,
                mDockedRootTaskBounds);
        final int fullscreenAppearance = getStatusBarAppearance(mTopFullscreenOpaqueWindowState,
                mTopFullscreenOpaqueOrDimmingWindowState);
        final int dockedAppearance = getStatusBarAppearance(mTopDockedOpaqueWindowState,
                mTopDockedOpaqueOrDimmingWindowState);
        final int disableFlags = win.getDisableFlags();
        final int opaqueAppearance = updateSystemBarsLw(win, disableFlags);
        final WindowState navColorWin = chooseNavigationColorWindowLw(
@@ -2560,30 +2557,12 @@ public class DisplayPolicy {
        return true;
    }

    private int updateLightStatusBarLw(@Appearance int appearance, WindowState opaque,
            WindowState opaqueOrDimming, Rect rootTaskBounds) {
        final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation();
        final int statusBarHeight = mStatusBarHeightForRotation[displayRotation.getRotation()];
        final boolean rootTaskBoundsContainStatusBar =
                rootTaskBounds.isEmpty() ? false : rootTaskBounds.top < statusBarHeight;
    private int getStatusBarAppearance(WindowState opaque, WindowState opaqueOrDimming) {
        final boolean onKeyguard = isKeyguardShowing() && !isKeyguardOccluded();
        final WindowState statusColorWin = onKeyguard ? mNotificationShade : opaqueOrDimming;
        if (rootTaskBoundsContainStatusBar && statusColorWin != null) {
            if (statusColorWin == opaque || onKeyguard) {
                // If the top fullscreen-or-dimming window is also the top fullscreen, respect
                // its light flag.
                appearance &= ~APPEARANCE_LIGHT_STATUS_BARS;
                appearance |= statusColorWin.mAttrs.insetsFlags.appearance
                        & APPEARANCE_LIGHT_STATUS_BARS;
            } else if (statusColorWin.isDimming()) {
                // Otherwise if it's dimming, clear the light flag.
                appearance &= ~APPEARANCE_LIGHT_STATUS_BARS;
            }
            if (!isLightBarAllowed(statusColorWin, TYPE_STATUS_BAR)) {
                appearance &= ~APPEARANCE_LIGHT_STATUS_BARS;
            }
        }
        return appearance;
        final WindowState colorWin = onKeyguard ? mNotificationShade : opaqueOrDimming;
        return isLightBarAllowed(colorWin, ITYPE_STATUS_BAR) && (colorWin == opaque || onKeyguard)
                ? (colorWin.mAttrs.insetsFlags.appearance & APPEARANCE_LIGHT_STATUS_BARS)
                : 0;
    }

    @VisibleForTesting
@@ -2642,9 +2621,9 @@ public class DisplayPolicy {
                // Clear the light flag for dimming window.
                appearance &= ~APPEARANCE_LIGHT_NAVIGATION_BARS;
            }
            if (!isLightBarAllowed(navColorWin, TYPE_NAVIGATION_BAR)) {
                appearance &= ~APPEARANCE_LIGHT_NAVIGATION_BARS;
        }
        if (!isLightBarAllowed(navColorWin, ITYPE_NAVIGATION_BAR)) {
            appearance &= ~APPEARANCE_LIGHT_NAVIGATION_BARS;
        }
        return appearance;
    }
@@ -2697,11 +2676,12 @@ public class DisplayPolicy {
        return appearance;
    }

    private boolean isLightBarAllowed(WindowState win, int windowType) {
    private boolean isLightBarAllowed(WindowState win, @InternalInsetsType int type) {
        if (win == null) {
            return true;
            return false;
        }
        return !win.isLetterboxedOverlappingWith(getBarContentFrameForWindow(win, windowType));
        final InsetsSource source = win.getInsetsState().peekSource(type);
        return source != null && Rect.intersects(win.getFrame(), source.getFrame());
    }

    private Rect getBarContentFrameForWindow(WindowState win, int windowType) {
+0 −23
Original line number Diff line number Diff line
@@ -149,18 +149,6 @@ public class Letterbox {
        return (emptyCount + noOverlappingCount) == mSurfaces.length;
    }

    /**
     * Returns true if any part of the letterbox overlaps with the given {@code rect}.
     */
    public boolean isOverlappingWith(Rect rect) {
        for (LetterboxSurface surface : mSurfaces) {
            if (surface.isOverlappingWith(rect)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Hides the letterbox.
     *
@@ -339,17 +327,6 @@ public class Letterbox {
            return Math.max(0, mLayoutFrameGlobal.height());
        }

        /**
         * Returns if the given {@code rect} overlaps with this letterbox piece.
         * @param rect the area to check for overlap in global coordinates
         */
        public boolean isOverlappingWith(Rect rect) {
            if (mLayoutFrameGlobal.isEmpty()) {
                return false;
            }
            return Rect.intersects(rect, mLayoutFrameGlobal);
        }

        public void applySurfaceChanges(SurfaceControl.Transaction t) {
            if (!needsApplySurfaceChanges()) {
                // Nothing changed.
+0 −8
Original line number Diff line number Diff line
@@ -112,14 +112,6 @@ final class LetterboxUiController {
        return mLetterbox == null || mLetterbox.notIntersectsOrFullyContains(rect);
    }

    /**
     * @return {@code true} if there is a letterbox and any part of that letterbox overlaps with
     * the given {@code rect}.
     */
    boolean isLetterboxOverlappingWith(Rect rect) {
        return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
    }

    void updateLetterboxSurface(WindowState winHint) {
        final WindowState w = mActivityRecord.findMainWindow();
        if (w != winHint && winHint != null && w != null) {
+0 −4
Original line number Diff line number Diff line
@@ -4001,10 +4001,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return mActivityRecord == null || mActivityRecord.isFullyTransparentBarAllowed(frame);
    }

    public boolean isLetterboxedOverlappingWith(Rect rect) {
        return mActivityRecord != null && mActivityRecord.isLetterboxOverlappingWith(rect);
    }

    boolean isDragResizeChanged() {
        return mDragResizing != computeDragResizing();
    }
Loading