Merge "Introducee maxBounds in WindowConfiguration"

This commit is contained in:
Charles Chen
2020-05-12 10:42:47 +00:00
committed by Android (Google) Code Review
3 changed files with 99 additions and 10 deletions

View File

@@ -20,11 +20,13 @@ import static android.app.ActivityThread.isSystem;
import static android.app.WindowConfigurationProto.ACTIVITY_TYPE; import static android.app.WindowConfigurationProto.ACTIVITY_TYPE;
import static android.app.WindowConfigurationProto.APP_BOUNDS; import static android.app.WindowConfigurationProto.APP_BOUNDS;
import static android.app.WindowConfigurationProto.BOUNDS; import static android.app.WindowConfigurationProto.BOUNDS;
import static android.app.WindowConfigurationProto.MAX_BOUNDS;
import static android.app.WindowConfigurationProto.WINDOWING_MODE; import static android.app.WindowConfigurationProto.WINDOWING_MODE;
import static android.view.Surface.rotationToString; import static android.view.Surface.rotationToString;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.Configuration; import android.content.res.Configuration;
@@ -35,8 +37,10 @@ import android.util.proto.ProtoInputStream;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
import android.util.proto.WireTypeMismatchException; import android.util.proto.WireTypeMismatchException;
import android.view.DisplayInfo; import android.view.DisplayInfo;
import android.view.WindowManager;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
/** /**
* Class that contains windowing configuration/state for other objects that contain windows directly * 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; 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 * 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 * 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. /** Bit that indicates that the {@link #mAppBounds} changed.
* @hide */ * @hide */
public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 1; 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. /** Bit that indicates that the {@link #mWindowingMode} changed.
* @hide */ * @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. /** Bit that indicates that the {@link #mActivityType} changed.
* @hide */ * @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. /** Bit that indicates that the {@link #mAlwaysOnTop} changed.
* @hide */ * @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. /** Bit that indicates that the {@link #mRotation} changed.
* @hide */ * @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. /** Bit that indicates that the {@link #mDisplayWindowingMode} changed.
* @hide */ * @hide */
public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 6; public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 7;
/** @hide */ /** @hide */
@IntDef(flag = true, prefix = { "WINDOW_CONFIG_" }, value = { @IntDef(flag = true, prefix = { "WINDOW_CONFIG_" }, value = {
WINDOW_CONFIG_BOUNDS, WINDOW_CONFIG_BOUNDS,
WINDOW_CONFIG_APP_BOUNDS, WINDOW_CONFIG_APP_BOUNDS,
WINDOW_CONFIG_MAX_BOUNDS,
WINDOW_CONFIG_WINDOWING_MODE, WINDOW_CONFIG_WINDOWING_MODE,
WINDOW_CONFIG_ACTIVITY_TYPE, WINDOW_CONFIG_ACTIVITY_TYPE,
WINDOW_CONFIG_ALWAYS_ON_TOP, WINDOW_CONFIG_ALWAYS_ON_TOP,
@@ -228,6 +242,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(mBounds, flags); dest.writeParcelable(mBounds, flags);
dest.writeParcelable(mAppBounds, flags); dest.writeParcelable(mAppBounds, flags);
dest.writeParcelable(mMaxBounds, flags);
dest.writeInt(mWindowingMode); dest.writeInt(mWindowingMode);
dest.writeInt(mActivityType); dest.writeInt(mActivityType);
dest.writeInt(mAlwaysOnTop); dest.writeInt(mAlwaysOnTop);
@@ -238,6 +253,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
private void readFromParcel(Parcel source) { private void readFromParcel(Parcel source) {
mBounds = source.readParcelable(Rect.class.getClassLoader()); mBounds = source.readParcelable(Rect.class.getClassLoader());
mAppBounds = source.readParcelable(Rect.class.getClassLoader()); mAppBounds = source.readParcelable(Rect.class.getClassLoader());
mMaxBounds = source.readParcelable(Rect.class.getClassLoader());
mWindowingMode = source.readInt(); mWindowingMode = source.readInt();
mActivityType = source.readInt(); mActivityType = source.readInt();
mAlwaysOnTop = 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); 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. * Sets whether this window should be always on top.
@@ -328,6 +364,14 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
return mBounds; return mBounds;
} }
/**
* @see #setMaxBounds(Rect)
* @hide
*/
public Rect getMaxBounds() {
return mMaxBounds;
}
public int getRotation() { public int getRotation() {
return mRotation; return mRotation;
} }
@@ -381,6 +425,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
public void setTo(WindowConfiguration other) { public void setTo(WindowConfiguration other) {
setBounds(other.mBounds); setBounds(other.mBounds);
setAppBounds(other.mAppBounds); setAppBounds(other.mAppBounds);
setMaxBounds(other.mMaxBounds);
setWindowingMode(other.mWindowingMode); setWindowingMode(other.mWindowingMode);
setActivityType(other.mActivityType); setActivityType(other.mActivityType);
setAlwaysOnTop(other.mAlwaysOnTop); setAlwaysOnTop(other.mAlwaysOnTop);
@@ -398,6 +443,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
public void setToDefaults() { public void setToDefaults() {
setAppBounds(null); setAppBounds(null);
setBounds(null); setBounds(null);
setMaxBounds(null);
setWindowingMode(WINDOWING_MODE_UNDEFINED); setWindowingMode(WINDOWING_MODE_UNDEFINED);
setActivityType(ACTIVITY_TYPE_UNDEFINED); setActivityType(ACTIVITY_TYPE_UNDEFINED);
setAlwaysOnTop(ALWAYS_ON_TOP_UNDEFINED); setAlwaysOnTop(ALWAYS_ON_TOP_UNDEFINED);
@@ -424,6 +470,10 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
changed |= WINDOW_CONFIG_APP_BOUNDS; changed |= WINDOW_CONFIG_APP_BOUNDS;
setAppBounds(delta.mAppBounds); 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 if (delta.mWindowingMode != WINDOWING_MODE_UNDEFINED
&& mWindowingMode != delta.mWindowingMode) { && mWindowingMode != delta.mWindowingMode) {
changed |= WINDOW_CONFIG_WINDOWING_MODE; changed |= WINDOW_CONFIG_WINDOWING_MODE;
@@ -462,6 +512,9 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
if ((mask & WINDOW_CONFIG_APP_BOUNDS) != 0) { if ((mask & WINDOW_CONFIG_APP_BOUNDS) != 0) {
setAppBounds(delta.mAppBounds); setAppBounds(delta.mAppBounds);
} }
if ((mask & WINDOW_CONFIG_MAX_BOUNDS) != 0) {
setMaxBounds(delta.mMaxBounds);
}
if ((mask & WINDOW_CONFIG_WINDOWING_MODE) != 0) { if ((mask & WINDOW_CONFIG_WINDOWING_MODE) != 0) {
setWindowingMode(delta.mWindowingMode); setWindowingMode(delta.mWindowingMode);
} }
@@ -504,6 +557,10 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
changes |= WINDOW_CONFIG_APP_BOUNDS; changes |= WINDOW_CONFIG_APP_BOUNDS;
} }
if (!mMaxBounds.equals(other.mMaxBounds)) {
changes |= WINDOW_CONFIG_MAX_BOUNDS;
}
if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED) if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED)
&& mWindowingMode != other.mWindowingMode) { && mWindowingMode != other.mWindowingMode) {
changes |= WINDOW_CONFIG_WINDOWING_MODE; changes |= WINDOW_CONFIG_WINDOWING_MODE;
@@ -550,6 +607,15 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
if (n != 0) return n; 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; n = mBounds.left - that.mBounds.left;
if (n != 0) return n; if (n != 0) return n;
n = mBounds.top - that.mBounds.top; n = mBounds.top - that.mBounds.top;
@@ -589,11 +655,9 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
@Override @Override
public int hashCode() { public int hashCode() {
int result = 0; int result = 0;
if (mAppBounds != null) { result = 31 * result + Objects.hashCode(mAppBounds);
result = 31 * result + mAppBounds.hashCode(); result = 31 * result + Objects.hashCode(mBounds);
} result = 31 * result + Objects.hashCode(mMaxBounds);
result = 31 * result + mBounds.hashCode();
result = 31 * result + mWindowingMode; result = 31 * result + mWindowingMode;
result = 31 * result + mActivityType; result = 31 * result + mActivityType;
result = 31 * result + mAlwaysOnTop; result = 31 * result + mAlwaysOnTop;
@@ -607,6 +671,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
public String toString() { public String toString() {
return "{ mBounds=" + mBounds return "{ mBounds=" + mBounds
+ " mAppBounds=" + mAppBounds + " mAppBounds=" + mAppBounds
+ " mMaxBounds=" + mMaxBounds
+ " mWindowingMode=" + windowingModeToString(mWindowingMode) + " mWindowingMode=" + windowingModeToString(mWindowingMode)
+ " mDisplayWindowingMode=" + windowingModeToString(mDisplayWindowingMode) + " mDisplayWindowingMode=" + windowingModeToString(mDisplayWindowingMode)
+ " mActivityType=" + activityTypeToString(mActivityType) + " mActivityType=" + activityTypeToString(mActivityType)
@@ -634,6 +699,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
if (mBounds != null) { if (mBounds != null) {
mBounds.dumpDebug(protoOutputStream, BOUNDS); mBounds.dumpDebug(protoOutputStream, BOUNDS);
} }
mMaxBounds.dumpDebug(protoOutputStream, MAX_BOUNDS);
protoOutputStream.end(token); protoOutputStream.end(token);
} }
@@ -659,6 +725,10 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
mBounds = new Rect(); mBounds = new Rect();
mBounds.readFromProto(proto, BOUNDS); mBounds.readFromProto(proto, BOUNDS);
break; break;
case (int) MAX_BOUNDS:
mMaxBounds = new Rect();
mMaxBounds.readFromProto(proto, MAX_BOUNDS);
break;
case (int) WINDOWING_MODE: case (int) WINDOWING_MODE:
mWindowingMode = proto.readInt(WINDOWING_MODE); mWindowingMode = proto.readInt(WINDOWING_MODE);
break; break;

View File

@@ -30,4 +30,5 @@ message WindowConfigurationProto {
optional int32 windowing_mode = 2; optional int32 windowing_mode = 2;
optional int32 activity_type = 3; optional int32 activity_type = 3;
optional .android.graphics.RectProto bounds = 4; optional .android.graphics.RectProto bounds = 4;
optional .android.graphics.RectProto max_bounds = 5;
} }

View File

@@ -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_ALWAYS_ON_TOP;
import static android.app.WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS; import static android.app.WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS;
import static android.app.WindowConfiguration.WINDOW_CONFIG_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_ROTATION;
import static android.app.WindowConfiguration.WINDOW_CONFIG_WINDOWING_MODE; import static android.app.WindowConfiguration.WINDOW_CONFIG_WINDOWING_MODE;
import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION; import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
@@ -78,11 +79,14 @@ public class WindowConfigurationTests extends WindowTestsBase {
final WindowConfiguration winConfig3 = config3.windowConfiguration; final WindowConfiguration winConfig3 = config3.windowConfiguration;
final Configuration config4 = new Configuration(); final Configuration config4 = new Configuration();
final WindowConfiguration winConfig4 = config4.windowConfiguration; final WindowConfiguration winConfig4 = config4.windowConfiguration;
final Configuration config5 = new Configuration();
final WindowConfiguration winConfig5 = config5.windowConfiguration;
winConfig1.setAppBounds(0, 1, 1, 0); winConfig1.setAppBounds(0, 1, 1, 0);
winConfig2.setAppBounds(1, 2, 2, 1); winConfig2.setAppBounds(1, 2, 2, 1);
winConfig3.setAppBounds(winConfig1.getAppBounds()); winConfig3.setAppBounds(winConfig1.getAppBounds());
winConfig4.setRotation(Surface.ROTATION_90); winConfig4.setRotation(Surface.ROTATION_90);
winConfig5.setAppBounds(winConfig1.getAppBounds());
assertEquals(CONFIG_WINDOW_CONFIGURATION, config1.diff(config2)); assertEquals(CONFIG_WINDOW_CONFIGURATION, config1.diff(config2));
assertEquals(0, config1.diffPublicOnly(config2)); assertEquals(0, config1.diffPublicOnly(config2));
@@ -104,6 +108,13 @@ public class WindowConfigurationTests extends WindowTestsBase {
assertEquals(0, config1.diff(config3)); assertEquals(0, config1.diff(config3));
assertEquals(0, config1.diffPublicOnly(config3)); assertEquals(0, config1.diffPublicOnly(config3));
assertEquals(0, winConfig1.diff(winConfig3, false /* compareUndefined */)); 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)}. */ /** Tests {@link android.app.WindowConfiguration#compareTo(WindowConfiguration)}. */
@@ -115,6 +126,7 @@ public class WindowConfigurationTests extends WindowTestsBase {
final Configuration config1 = new Configuration(); final Configuration config1 = new Configuration();
final WindowConfiguration winConfig1 = config1.windowConfiguration; final WindowConfiguration winConfig1 = config1.windowConfiguration;
winConfig1.setAppBounds(1, 2, 3, 4); winConfig1.setAppBounds(1, 2, 3, 4);
winConfig1.setMaxBounds(1, 2, 3, 4);
final Configuration config2 = new Configuration(config1); final Configuration config2 = new Configuration(config1);
final WindowConfiguration winConfig2 = config2.windowConfiguration; final WindowConfiguration winConfig2 = config2.windowConfiguration;
@@ -150,6 +162,12 @@ public class WindowConfigurationTests extends WindowTestsBase {
assertNotEquals(0, winConfig1.compareTo(winConfig2)); assertNotEquals(0, winConfig1.compareTo(winConfig2));
winConfig2.setRotation(winConfig1.getRotation()); 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, blankConfig.compareTo(config1));
assertEquals(1, blankWinConfig.compareTo(winConfig1)); assertEquals(1, blankWinConfig.compareTo(winConfig1));
} }