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

Commit c8749149 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by android-build-merger
Browse files

Fix configuration calculation when task is non-fullscreen

am: 82c9dc95

* commit '82c9dc95':
  Fix configuration calculation when task is non-fullscreen
parents edbb3507 82c9dc95
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -631,7 +631,7 @@ public interface WindowManagerPolicy {

    /**
     * Return the display width available after excluding any screen
     * decorations that can never be removed.  That is, system bar or
     * decorations that could never be removed in Honeycomb. That is, system bar or
     * button bar.
     */
    public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
@@ -639,7 +639,7 @@ public interface WindowManagerPolicy {

    /**
     * Return the display height available after excluding any screen
     * decorations that can never be removed.  That is, system bar or
     * decorations that could never be removed in Honeycomb. That is, system bar or
     * button bar.
     */
    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
@@ -1350,4 +1350,16 @@ public interface WindowManagerPolicy {
     */
    public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
            Rect outInsets);

    /**
     * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system
     * bar or button bar. See {@link #getNonDecorDisplayWidth}.
     *
     * @param displayRotation the current display rotation
     * @param displayWidth the current display width
     * @param displayHeight the current display height
     * @param outInsets the insets to return
     */
    public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
            Rect outInsets);
}
+36 −14
Original line number Diff line number Diff line
@@ -243,7 +243,8 @@ final class TaskRecord {

    // Bounds of the Task. null for fullscreen tasks.
    Rect mBounds = null;
    private final Rect mTmpRect = new Rect();
    private final Rect mTmpStableBounds = new Rect();
    private final Rect mTmpNonDecorBounds = new Rect();
    private final Rect mTmpRect2 = new Rect();

    // Last non-fullscreen bounds the task was launched in or resized to.
@@ -1353,12 +1354,7 @@ final class TaskRecord {
            if (stack == null || StackId.persistTaskBounds(stack.mStackId)) {
                mLastNonFullscreenBounds = mBounds;
            }

            // Stable insets need to be subtracted because we also subtract it in the fullscreen
            // configuration.
            mTmpRect.set(bounds);
            subtractStableInsets(mTmpRect, insetBounds != null ? insetBounds : mTmpRect);
            mOverrideConfig = calculateOverrideConfig(mTmpRect);
            mOverrideConfig = calculateOverrideConfig(bounds, insetBounds);
        }

        if (mFullscreen != oldFullscreen) {
@@ -1368,6 +1364,16 @@ final class TaskRecord {
        return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
    }

    private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds) {
        mTmpRect2.set(inInsetBounds);
        mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
        int leftInset = mTmpRect2.left - inInsetBounds.left;
        int topInset = mTmpRect2.top - inInsetBounds.top;
        int rightInset = inInsetBounds.right - mTmpRect2.right;
        int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom;
        inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
    }

    private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds) {
        mTmpRect2.set(inInsetBounds);
        mService.mWindowManager.subtractStableInsets(mTmpRect2);
@@ -1378,23 +1384,39 @@ final class TaskRecord {
        inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
    }

    Configuration calculateOverrideConfig(Rect bounds) {
    private Configuration calculateOverrideConfig(Rect bounds, Rect insetBounds) {
        mTmpNonDecorBounds.set(bounds);
        mTmpStableBounds.set(bounds);
        subtractNonDecorInsets(
                mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds);
        subtractStableInsets(
                mTmpStableBounds, insetBounds != null ? insetBounds : bounds);

        // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
        // i.e. the screen area without the system bars.
        final Configuration serviceConfig = mService.mConfiguration;
        final Configuration config = new Configuration(Configuration.EMPTY);
        // TODO(multidisplay): Update Dp to that of display stack is on.
        final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
        config.screenWidthDp =
                Math.min((int)(bounds.width() / density), serviceConfig.screenWidthDp);
                Math.min((int)(mTmpStableBounds.width() / density), serviceConfig.screenWidthDp);
        config.screenHeightDp =
                Math.min((int)(bounds.height() / density), serviceConfig.screenHeightDp);
        config.smallestScreenWidthDp =
                Math.min(config.screenWidthDp, config.screenHeightDp);
                Math.min((int)(mTmpStableBounds.height() / density), serviceConfig.screenHeightDp);
        config.smallestScreenWidthDp = Math.min(config.screenWidthDp, config.screenHeightDp);

        // TODO: Orientation?
        config.orientation = (config.screenWidthDp <= config.screenHeightDp)
                ? Configuration.ORIENTATION_PORTRAIT
                : Configuration.ORIENTATION_LANDSCAPE;

        // For calculating screen layout, we need to use the non-decor inset screen area for the
        // calculation for compatibility reasons, i.e. screen area without system bars that could
        // never go away in Honeycomb.
        final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
        final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
        final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
        int longSize = Math.max(config.screenWidthDp, config.screenHeightDp);
        int shortSize = Math.min(config.screenWidthDp, config.screenHeightDp);
        final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
        final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
        config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
        return config;
    }
+11 −0
Original line number Diff line number Diff line
@@ -6075,9 +6075,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
            Rect outInsets) {
        outInsets.setEmpty();

        // Navigation bar and status bar.
        getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
        if (mStatusBar != null) {
            outInsets.top = mStatusBarHeight;
        }
    }

    @Override
    public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
            Rect outInsets) {
        outInsets.setEmpty();

        // Only navigation bar
        if (mNavigationBar != null) {
            if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
                outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
+22 −0
Original line number Diff line number Diff line
@@ -10445,6 +10445,11 @@ public class WindowManagerService extends IWindowManager.Stub
        mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, outInsets);
    }

    private void getNonDecorInsetsLocked(Rect outInsets) {
        final DisplayInfo di = getDefaultDisplayInfoLocked();
        mPolicy.getNonDecorInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, outInsets);
    }

    /**
     * Intersects the specified {@code inOutBounds} with the display frame that excludes the stable
     * inset areas.
@@ -10461,6 +10466,23 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    /**
     * Intersects the specified {@code inOutBounds} with the display frame that excludes
     * areas that could never be removed in Honeycomb. See
     * {@link WindowManagerPolicy#getNonDecorInsetsLw}.
     *
     * @param inOutBounds The inOutBounds to subtract the inset areas from.
     */
    public void subtractNonDecorInsets(Rect inOutBounds) {
        synchronized (mWindowMap) {
            getNonDecorInsetsLocked(mTmpRect2);
            final DisplayInfo di = getDefaultDisplayInfoLocked();
            mTmpRect.set(0, 0, di.logicalWidth, di.logicalHeight);
            mTmpRect.inset(mTmpRect2);
            inOutBounds.intersect(mTmpRect);
        }
    }

    private MousePositionTracker mMousePositionTracker = new MousePositionTracker();

    private static class MousePositionTracker implements PointerEventListener {