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

Commit 68d02e9a authored by Charles Chen's avatar Charles Chen
Browse files

Add DisplayArea support for WM#getMaximumWindowMetrics

Set max bounds whenenver bounds change in DisplayContent and DisplayArea

Bug: 151414021
Test: atest ConfigurationContainerTests#testSetMaxBoundsByHierarchy
Test: atest ConfigurationContainerTests#testSetBoundsNotOverrideMaxBounds
Test: atest DisplayAreaTest#testSetMaxBounds
Test: atest DisplayAreaOrganizerTest

Change-Id: I88be4f165cf8958eec0128e196368a630b2492aa
parent e8e0cac6
Loading
Loading
Loading
Loading
+12 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.app.KeyguardManager;
import android.app.KeyguardManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.CompatibilityInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources;
@@ -1157,9 +1158,19 @@ public final class Display {
     * </p><p>
     * </p><p>
     * The real size may be smaller than the physical size of the screen when the
     * The real size may be smaller than the physical size of the screen when the
     * window manager is emulating a smaller display (using adb shell wm size).
     * window manager is emulating a smaller display (using adb shell wm size).
     * </p>
     * </p><p>
     * In general, {@link #getRealSize(Point)} and {@link WindowManager#getMaximumWindowMetrics()}
     * report the same bounds except that certain areas of the display may not be available to
     * windows created in the {@link WindowManager}'s {@link Context}.
     *
     * For example, imagine a device which has a multi-task mode that limits windows to half of the
     * screen. In this case, {@link WindowManager#getMaximumWindowMetrics()} reports the
     * bounds of the screen half where the window is located, while {@link #getRealSize(Point)}
     * still reports the bounds of the whole display.
     *
     *
     * @param outSize Set to the real size of the display.
     * @param outSize Set to the real size of the display.
     *
     * @see WindowManager#getMaximumWindowMetrics()
     */
     */
    public void getRealSize(Point outSize) {
    public void getRealSize(Point outSize) {
        synchronized (this) {
        synchronized (this) {
+11 −1
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Region;
import android.os.IBinder;
import android.os.IBinder;
@@ -473,9 +474,18 @@ public interface WindowManager extends ViewManager {
     *
     *
     * Note that this might still be smaller than the size of the physical display if certain areas
     * Note that this might still be smaller than the size of the physical display if certain areas
     * of the display are not available to windows created in this {@link Context}.
     * of the display are not available to windows created in this {@link Context}.
     * <p>
     * For example, given that there's a device which have a multi-task mode to limit activities
     * to a half screen. In this case, {@link #getMaximumWindowMetrics()} reports the bounds of
     * the half screen which the activity is located, while {@link Display#getRealSize(Point)} still
     * reports the bounds of the whole physical display.
     *
     *
     * @see #getMaximumWindowMetrics()
     * Despite this, {@link #getMaximumWindowMetrics()} and {@link Display#getRealSize(Point)}
     * reports the same bounds in general.
     *
     * @see #getCurrentWindowMetrics()
     * @see WindowMetrics
     * @see WindowMetrics
     * @see Display#getRealSize(Point)
     */
     */
    default @NonNull WindowMetrics getMaximumWindowMetrics() {
    default @NonNull WindowMetrics getMaximumWindowMetrics() {
        throw new UnsupportedOperationException();
        throw new UnsupportedOperationException();
+7 −9
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ import android.app.ResourcesManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.graphics.Insets;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Region;
import android.os.Bundle;
import android.os.Bundle;
@@ -233,17 +232,16 @@ public final class WindowManagerImpl implements WindowManager {


    @Override
    @Override
    public WindowMetrics getMaximumWindowMetrics() {
    public WindowMetrics getMaximumWindowMetrics() {
        final Rect maxBounds = getMaximumBounds();
        final Context context = mParentWindow != null ? mParentWindow.getContext() : mContext;
        final Rect maxBounds = getMaximumBounds(context);

        return new WindowMetrics(maxBounds, computeWindowInsets(maxBounds));
        return new WindowMetrics(maxBounds, computeWindowInsets(maxBounds));
    }
    }


    private Rect getMaximumBounds() {
    private static Rect getMaximumBounds(Context context) {
        // TODO(b/128338354): Current maximum bound is display size, but it should be displayArea
        synchronized (ResourcesManager.getInstance()) {
        //  bound after displayArea feature is finished.
            return context.getResources().getConfiguration().windowConfiguration.getMaxBounds();
        final Display display = mContext.getDisplayNoVerify();
        }
        final Point displaySize = new Point();
        display.getRealSize(displaySize);
        return new Rect(0, 0, displaySize.x, displaySize.y);
    }
    }


    // TODO(b/150095967): Set window type to LayoutParams
    // TODO(b/150095967): Set window type to LayoutParams
+71 −10
Original line number Original line Diff line number Diff line
@@ -93,9 +93,17 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
    private final Rect mTmpRect = new Rect();
    private final Rect mTmpRect = new Rect();


    static final int BOUNDS_CHANGE_NONE = 0;
    static final int BOUNDS_CHANGE_NONE = 0;
    // Return value from {@link setBounds} indicating the position of the override bounds changed.

    /**
     * Return value from {@link #setBounds(Rect)} indicating the position of the override bounds
     * changed.
     */
    static final int BOUNDS_CHANGE_POSITION = 1;
    static final int BOUNDS_CHANGE_POSITION = 1;
    // Return value from {@link setBounds} indicating the size of the override bounds changed.

    /**
     * Return value from {@link #setBounds(Rect)} indicating the size of the override bounds
     * changed.
     */
    static final int BOUNDS_CHANGE_SIZE = 1 << 1;
    static final int BOUNDS_CHANGE_SIZE = 1 << 1;


    /**
    /**
@@ -226,6 +234,11 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        return equivalentBounds(getRequestedOverrideBounds(),  bounds);
        return equivalentBounds(getRequestedOverrideBounds(),  bounds);
    }
    }


    /** Similar to {@link #equivalentRequestedOverrideBounds(Rect)}, but compares max bounds. */
    public boolean equivalentRequestedOverrideMaxBounds(Rect bounds) {
        return equivalentBounds(getRequestedOverrideMaxBounds(),  bounds);
    }

    /**
    /**
     * Returns whether the two bounds are equal to each other or are a combination of null or empty.
     * Returns whether the two bounds are equal to each other or are a combination of null or empty.
     */
     */
@@ -238,7 +251,6 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
    /**
    /**
     * Returns the effective bounds of this container, inheriting the first non-empty bounds set in
     * Returns the effective bounds of this container, inheriting the first non-empty bounds set in
     * its ancestral hierarchy, including itself.
     * its ancestral hierarchy, including itself.
     * @return
     */
     */
    public Rect getBounds() {
    public Rect getBounds() {
        mReturnBounds.set(getConfiguration().windowConfiguration.getBounds());
        mReturnBounds.set(getConfiguration().windowConfiguration.getBounds());
@@ -249,6 +261,12 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        outBounds.set(getBounds());
        outBounds.set(getBounds());
    }
    }


    /** Similar to {@link #getBounds()}, but reports the max bounds. */
    public Rect getMaxBounds() {
        mReturnBounds.set(getConfiguration().windowConfiguration.getMaxBounds());
        return mReturnBounds;
    }

    /**
    /**
     * Sets {@code out} to the top-left corner of the bounds as returned by {@link #getBounds()}.
     * Sets {@code out} to the top-left corner of the bounds as returned by {@link #getBounds()}.
     */
     */
@@ -273,6 +291,13 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        return mReturnBounds;
        return mReturnBounds;
    }
    }


    /** Similar to {@link #getRequestedOverrideBounds()}, but returns the max bounds. */
    public Rect getRequestedOverrideMaxBounds() {
        mReturnBounds.set(getRequestedOverrideConfiguration().windowConfiguration.getMaxBounds());

        return mReturnBounds;
    }

    /**
    /**
     * Returns {@code true} if the {@link WindowConfiguration} in the requested override
     * Returns {@code true} if the {@link WindowConfiguration} in the requested override
     * {@link Configuration} specifies bounds.
     * {@link Configuration} specifies bounds.
@@ -283,7 +308,7 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {


    /**
    /**
     * Sets the passed in {@link Rect} to the current bounds.
     * Sets the passed in {@link Rect} to the current bounds.
     * @see {@link #getRequestedOverrideBounds()}.
     * @see #getRequestedOverrideBounds()
     */
     */
    public void getRequestedOverrideBounds(Rect outBounds) {
    public void getRequestedOverrideBounds(Rect outBounds) {
        outBounds.set(getRequestedOverrideBounds());
        outBounds.set(getRequestedOverrideBounds());
@@ -295,19 +320,25 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
     * {@link #getRequestedOverrideBounds()}. If
     * {@link #getRequestedOverrideBounds()}. If
     * an empty {@link Rect} or null is specified, this container will be considered to match its
     * an empty {@link Rect} or null is specified, this container will be considered to match its
     * parent bounds {@see #matchParentBounds} and will inherit bounds from its parent.
     * parent bounds {@see #matchParentBounds} and will inherit bounds from its parent.
     *
     * @param bounds The bounds defining the container size.
     * @param bounds The bounds defining the container size.
     *
     * @return a bitmask representing the types of changes made to the bounds.
     * @return a bitmask representing the types of changes made to the bounds.
     */
     */
    public int setBounds(Rect bounds) {
    public int setBounds(Rect bounds) {
        int boundsChange = diffRequestedOverrideBounds(bounds);
        int boundsChange = diffRequestedOverrideBounds(bounds);
        final boolean overrideMaxBounds = providesMaxBounds()
                && diffRequestedOverrideMaxBounds(bounds) != BOUNDS_CHANGE_NONE;


        if (boundsChange == BOUNDS_CHANGE_NONE) {
        if (boundsChange == BOUNDS_CHANGE_NONE && !overrideMaxBounds) {
            return boundsChange;
            return boundsChange;
        }
        }



        mRequestsTmpConfig.setTo(getRequestedOverrideConfiguration());
        mRequestsTmpConfig.setTo(getRequestedOverrideConfiguration());
        mRequestsTmpConfig.windowConfiguration.setBounds(bounds);
        mRequestsTmpConfig.windowConfiguration.setBounds(bounds);
        if (overrideMaxBounds) {
            mRequestsTmpConfig.windowConfiguration.setMaxBounds(bounds);
        }
        onRequestedOverrideConfigurationChanged(mRequestsTmpConfig);
        onRequestedOverrideConfigurationChanged(mRequestsTmpConfig);


        return boundsChange;
        return boundsChange;
@@ -318,6 +349,40 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        return setBounds(mTmpRect);
        return setBounds(mTmpRect);
    }
    }


    /**
     * Returns {@code true} if this {@link ConfigurationContainer} provides the maximum bounds to
     * its child {@link ConfigurationContainer}s. Returns {@code false}, otherwise.
     * <p>
     * The maximum bounds is how large a window can be expanded. Currently only
     * {@link DisplayContent} and {@link DisplayArea} effect this property.
     * </p>
     */
    protected boolean providesMaxBounds() {
        return false;
    }

    int diffRequestedOverrideMaxBounds(Rect bounds) {
        if (equivalentRequestedOverrideMaxBounds(bounds)) {
            return BOUNDS_CHANGE_NONE;
        }

        int boundsChange = BOUNDS_CHANGE_NONE;

        final Rect existingBounds = getRequestedOverrideMaxBounds();

        if (bounds == null || existingBounds.left != bounds.left
                || existingBounds.top != bounds.top) {
            boundsChange |= BOUNDS_CHANGE_POSITION;
        }

        if (bounds == null || existingBounds.width() != bounds.width()
                || existingBounds.height() != bounds.height()) {
            boundsChange |= BOUNDS_CHANGE_SIZE;
        }

        return boundsChange;
    }

    int diffRequestedOverrideBounds(Rect bounds) {
    int diffRequestedOverrideBounds(Rect bounds) {
        if (equivalentRequestedOverrideBounds(bounds)) {
        if (equivalentRequestedOverrideBounds(bounds)) {
            return BOUNDS_CHANGE_NONE;
            return BOUNDS_CHANGE_NONE;
@@ -340,10 +405,6 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        return boundsChange;
        return boundsChange;
    }
    }


    boolean hasOverrideConfiguration() {
        return mHasOverrideConfiguration;
    }

    public WindowConfiguration getWindowConfiguration() {
    public WindowConfiguration getWindowConfiguration() {
        return mFullConfiguration.windowConfiguration;
        return mFullConfiguration.windowConfiguration;
    }
    }
+5 −0
Original line number Original line Diff line number Diff line
@@ -349,6 +349,11 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
        return info;
        return info;
    }
    }


    @Override
    public boolean providesMaxBounds() {
        return true;
    }

    /**
    /**
     * DisplayArea that contains WindowTokens, and orders them according to their type.
     * DisplayArea that contains WindowTokens, and orders them according to their type.
     */
     */
Loading