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

Commit 805bc242 authored by Charles Chen's avatar Charles Chen Committed by Android (Google) Code Review
Browse files

Merge "Introducee maxBounds in WindowConfiguration"

parents 5b198db8 32f14f03
Loading
Loading
Loading
Loading
+80 −10
Original line number Diff line number Diff line
@@ -20,11 +20,13 @@ import static android.app.ActivityThread.isSystem;
import static android.app.WindowConfigurationProto.ACTIVITY_TYPE;
import static android.app.WindowConfigurationProto.APP_BOUNDS;
import static android.app.WindowConfigurationProto.BOUNDS;
import static android.app.WindowConfigurationProto.MAX_BOUNDS;
import static android.app.WindowConfigurationProto.WINDOWING_MODE;
import static android.view.Surface.rotationToString;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.Configuration;
@@ -35,8 +37,10 @@ import android.util.proto.ProtoInputStream;
import android.util.proto.ProtoOutputStream;
import android.util.proto.WireTypeMismatchException;
import android.view.DisplayInfo;
import android.view.WindowManager;

import java.io.IOException;
import java.util.Objects;

/**
 * Class that contains windowing configuration/state for other objects that contain windows directly
@@ -63,6 +67,12 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
     */
    private Rect mAppBounds;

    /**
     * The maximum {@link Rect} bounds that an app can expect. It is used to report value of
     * {@link WindowManager#getMaximumWindowMetrics()}.
     */
    private Rect mMaxBounds = new Rect();

    /**
     * The current rotation of this window container relative to the default
     * orientation of the display it is on (regardless of how deep in the hierarchy
@@ -179,26 +189,30 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    /** Bit that indicates that the {@link #mAppBounds} changed.
     * @hide */
    public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 1;
    /** Bit that indicates that the {@link #mMaxBounds} changed.
     * @hide */
    public static final int WINDOW_CONFIG_MAX_BOUNDS = 1 << 2;
    /** Bit that indicates that the {@link #mWindowingMode} changed.
     * @hide */
    public static final int WINDOW_CONFIG_WINDOWING_MODE = 1 << 2;
    public static final int WINDOW_CONFIG_WINDOWING_MODE = 1 << 3;
    /** Bit that indicates that the {@link #mActivityType} changed.
     * @hide */
    public static final int WINDOW_CONFIG_ACTIVITY_TYPE = 1 << 3;
    public static final int WINDOW_CONFIG_ACTIVITY_TYPE = 1 << 4;
    /** Bit that indicates that the {@link #mAlwaysOnTop} changed.
     * @hide */
    public static final int WINDOW_CONFIG_ALWAYS_ON_TOP = 1 << 4;
    public static final int WINDOW_CONFIG_ALWAYS_ON_TOP = 1 << 5;
    /** Bit that indicates that the {@link #mRotation} changed.
     * @hide */
    public static final int WINDOW_CONFIG_ROTATION = 1 << 5;
    public static final int WINDOW_CONFIG_ROTATION = 1 << 6;
    /** Bit that indicates that the {@link #mDisplayWindowingMode} changed.
     * @hide */
    public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 6;
    public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 7;

    /** @hide */
    @IntDef(flag = true, prefix = { "WINDOW_CONFIG_" }, value = {
            WINDOW_CONFIG_BOUNDS,
            WINDOW_CONFIG_APP_BOUNDS,
            WINDOW_CONFIG_MAX_BOUNDS,
            WINDOW_CONFIG_WINDOWING_MODE,
            WINDOW_CONFIG_ACTIVITY_TYPE,
            WINDOW_CONFIG_ALWAYS_ON_TOP,
@@ -228,6 +242,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mBounds, flags);
        dest.writeParcelable(mAppBounds, flags);
        dest.writeParcelable(mMaxBounds, flags);
        dest.writeInt(mWindowingMode);
        dest.writeInt(mActivityType);
        dest.writeInt(mAlwaysOnTop);
@@ -238,6 +253,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    private void readFromParcel(Parcel source) {
        mBounds = source.readParcelable(Rect.class.getClassLoader());
        mAppBounds = source.readParcelable(Rect.class.getClassLoader());
        mMaxBounds = source.readParcelable(Rect.class.getClassLoader());
        mWindowingMode = source.readInt();
        mActivityType = source.readInt();
        mAlwaysOnTop = source.readInt();
@@ -290,7 +306,27 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        setAppBounds(rect.left, rect.top, rect.right, rect.bottom);
    }

    /**
     * Sets the maximum bounds to the provided {@link Rect}.
     * @param rect the new bounds value.
     * @see #getMaxBounds()
     * @hide
     */
    public void setMaxBounds(@Nullable Rect rect) {
        if (rect == null) {
            mMaxBounds.setEmpty();
            return;
        }
        mMaxBounds.set(rect);
    }

    /**
     * @see #setMaxBounds(Rect)
     * @hide
     */
    public void setMaxBounds(int left, int top, int right, int bottom) {
        mMaxBounds.set(left, top, right, bottom);
    }

    /**
     * Sets whether this window should be always on top.
@@ -328,6 +364,14 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        return mBounds;
    }

    /**
     * @see #setMaxBounds(Rect)
     * @hide
     */
    public Rect getMaxBounds() {
        return mMaxBounds;
    }

    public int getRotation() {
        return mRotation;
    }
@@ -381,6 +425,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    public void setTo(WindowConfiguration other) {
        setBounds(other.mBounds);
        setAppBounds(other.mAppBounds);
        setMaxBounds(other.mMaxBounds);
        setWindowingMode(other.mWindowingMode);
        setActivityType(other.mActivityType);
        setAlwaysOnTop(other.mAlwaysOnTop);
@@ -398,6 +443,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    public void setToDefaults() {
        setAppBounds(null);
        setBounds(null);
        setMaxBounds(null);
        setWindowingMode(WINDOWING_MODE_UNDEFINED);
        setActivityType(ACTIVITY_TYPE_UNDEFINED);
        setAlwaysOnTop(ALWAYS_ON_TOP_UNDEFINED);
@@ -424,6 +470,10 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
            changed |= WINDOW_CONFIG_APP_BOUNDS;
            setAppBounds(delta.mAppBounds);
        }
        if (!delta.mMaxBounds.isEmpty() && !delta.mMaxBounds.equals(mMaxBounds)) {
            changed |= WINDOW_CONFIG_MAX_BOUNDS;
            setMaxBounds(delta.mMaxBounds);
        }
        if (delta.mWindowingMode != WINDOWING_MODE_UNDEFINED
                && mWindowingMode != delta.mWindowingMode) {
            changed |= WINDOW_CONFIG_WINDOWING_MODE;
@@ -462,6 +512,9 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        if ((mask & WINDOW_CONFIG_APP_BOUNDS) != 0) {
            setAppBounds(delta.mAppBounds);
        }
        if ((mask & WINDOW_CONFIG_MAX_BOUNDS) != 0) {
            setMaxBounds(delta.mMaxBounds);
        }
        if ((mask & WINDOW_CONFIG_WINDOWING_MODE) != 0) {
            setWindowingMode(delta.mWindowingMode);
        }
@@ -504,6 +557,10 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
            changes |= WINDOW_CONFIG_APP_BOUNDS;
        }

        if (!mMaxBounds.equals(other.mMaxBounds)) {
            changes |= WINDOW_CONFIG_MAX_BOUNDS;
        }

        if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED)
                && mWindowingMode != other.mWindowingMode) {
            changes |= WINDOW_CONFIG_WINDOWING_MODE;
@@ -550,6 +607,15 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
            if (n != 0) return n;
        }

        n = mMaxBounds.left - that.mMaxBounds.left;
        if (n != 0) return n;
        n = mMaxBounds.top - that.mMaxBounds.top;
        if (n != 0) return n;
        n = mMaxBounds.right - that.mMaxBounds.right;
        if (n != 0) return n;
        n = mMaxBounds.bottom - that.mMaxBounds.bottom;
        if (n != 0) return n;

        n = mBounds.left - that.mBounds.left;
        if (n != 0) return n;
        n = mBounds.top - that.mBounds.top;
@@ -589,11 +655,9 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    @Override
    public int hashCode() {
        int result = 0;
        if (mAppBounds != null) {
            result = 31 * result + mAppBounds.hashCode();
        }
        result = 31 * result + mBounds.hashCode();

        result = 31 * result + Objects.hashCode(mAppBounds);
        result = 31 * result + Objects.hashCode(mBounds);
        result = 31 * result + Objects.hashCode(mMaxBounds);
        result = 31 * result + mWindowingMode;
        result = 31 * result + mActivityType;
        result = 31 * result + mAlwaysOnTop;
@@ -607,6 +671,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    public String toString() {
        return "{ mBounds=" + mBounds
                + " mAppBounds=" + mAppBounds
                + " mMaxBounds=" + mMaxBounds
                + " mWindowingMode=" + windowingModeToString(mWindowingMode)
                + " mDisplayWindowingMode=" + windowingModeToString(mDisplayWindowingMode)
                + " mActivityType=" + activityTypeToString(mActivityType)
@@ -634,6 +699,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        if (mBounds != null) {
            mBounds.dumpDebug(protoOutputStream, BOUNDS);
        }
        mMaxBounds.dumpDebug(protoOutputStream, MAX_BOUNDS);
        protoOutputStream.end(token);
    }

@@ -659,6 +725,10 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
                        mBounds = new Rect();
                        mBounds.readFromProto(proto, BOUNDS);
                        break;
                    case (int) MAX_BOUNDS:
                        mMaxBounds = new Rect();
                        mMaxBounds.readFromProto(proto, MAX_BOUNDS);
                        break;
                    case (int) WINDOWING_MODE:
                        mWindowingMode = proto.readInt(WINDOWING_MODE);
                        break;
+1 −0
Original line number Diff line number Diff line
@@ -30,4 +30,5 @@ message WindowConfigurationProto {
    optional int32 windowing_mode = 2;
    optional int32 activity_type = 3;
    optional .android.graphics.RectProto bounds = 4;
    optional .android.graphics.RectProto max_bounds = 5;
}
+18 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOW_CONFIG_ALWAYS_ON_TOP;
import static android.app.WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS;
import static android.app.WindowConfiguration.WINDOW_CONFIG_BOUNDS;
import static android.app.WindowConfiguration.WINDOW_CONFIG_MAX_BOUNDS;
import static android.app.WindowConfiguration.WINDOW_CONFIG_ROTATION;
import static android.app.WindowConfiguration.WINDOW_CONFIG_WINDOWING_MODE;
import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
@@ -78,11 +79,14 @@ public class WindowConfigurationTests extends WindowTestsBase {
        final WindowConfiguration winConfig3 = config3.windowConfiguration;
        final Configuration config4 = new Configuration();
        final WindowConfiguration winConfig4 = config4.windowConfiguration;
        final Configuration config5 = new Configuration();
        final WindowConfiguration winConfig5 = config5.windowConfiguration;

        winConfig1.setAppBounds(0, 1, 1, 0);
        winConfig2.setAppBounds(1, 2, 2, 1);
        winConfig3.setAppBounds(winConfig1.getAppBounds());
        winConfig4.setRotation(Surface.ROTATION_90);
        winConfig5.setAppBounds(winConfig1.getAppBounds());

        assertEquals(CONFIG_WINDOW_CONFIGURATION, config1.diff(config2));
        assertEquals(0, config1.diffPublicOnly(config2));
@@ -104,6 +108,13 @@ public class WindowConfigurationTests extends WindowTestsBase {
        assertEquals(0, config1.diff(config3));
        assertEquals(0, config1.diffPublicOnly(config3));
        assertEquals(0, winConfig1.diff(winConfig3, false /* compareUndefined */));

        winConfig1.setMaxBounds(1, 1, 1, 1);
        winConfig5.setMaxBounds(2, 2, 2, 2);
        assertEquals(WINDOW_CONFIG_MAX_BOUNDS,
                winConfig1.diff(winConfig5, false /* compareUndefined */));
        assertEquals(CONFIG_WINDOW_CONFIGURATION, config1.diff(config5));
        assertEquals(0, config1.diffPublicOnly(config5));
    }

    /** Tests {@link android.app.WindowConfiguration#compareTo(WindowConfiguration)}. */
@@ -115,6 +126,7 @@ public class WindowConfigurationTests extends WindowTestsBase {
        final Configuration config1 = new Configuration();
        final WindowConfiguration winConfig1 = config1.windowConfiguration;
        winConfig1.setAppBounds(1, 2, 3, 4);
        winConfig1.setMaxBounds(1, 2, 3, 4);

        final Configuration config2 = new Configuration(config1);
        final WindowConfiguration winConfig2 = config2.windowConfiguration;
@@ -150,6 +162,12 @@ public class WindowConfigurationTests extends WindowTestsBase {
        assertNotEquals(0, winConfig1.compareTo(winConfig2));
        winConfig2.setRotation(winConfig1.getRotation());

        // Different max bounds
        winConfig2.setMaxBounds(0, 2, 3, 4);
        assertNotEquals(0, config1.compareTo(config2));
        assertNotEquals(0, winConfig1.compareTo(winConfig2));
        winConfig2.setMaxBounds(winConfig1.getMaxBounds());

        assertEquals(1, blankConfig.compareTo(config1));
        assertEquals(1, blankWinConfig.compareTo(winConfig1));
    }