Merge "Create per-app treatment for overriding minimum aspect ratio" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0b3f22b216
@@ -730,6 +730,11 @@ package android.content.pm {
|
||||
method public static boolean isTranslucentOrFloating(android.content.res.TypedArray);
|
||||
field public static final long FORCE_NON_RESIZE_APP = 181136395L; // 0xacbec0bL
|
||||
field public static final long FORCE_RESIZE_APP = 174042936L; // 0xa5faf38L
|
||||
field public static final long OVERRIDE_MIN_ASPECT_RATIO = 174042980L; // 0xa5faf64L
|
||||
field public static final long OVERRIDE_MIN_ASPECT_RATIO_LARGE = 180326787L; // 0xabf9183L
|
||||
field public static final float OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE = 1.7777778f;
|
||||
field public static final long OVERRIDE_MIN_ASPECT_RATIO_MEDIUM = 180326845L; // 0xabf91bdL
|
||||
field public static final float OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE = 1.5f;
|
||||
field public static final int RESIZE_MODE_RESIZEABLE = 2; // 0x2
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ public class LaunchActivityItem extends ClientTransactionItem {
|
||||
return other == null;
|
||||
}
|
||||
return other != null && mInfo.flags == other.flags
|
||||
&& mInfo.maxAspectRatio == other.maxAspectRatio
|
||||
&& mInfo.getMaxAspectRatio() == other.getMaxAspectRatio()
|
||||
&& Objects.equals(mInfo.launchToken, other.launchToken)
|
||||
&& Objects.equals(mInfo.getComponentName(), other.getComponentName());
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.annotation.TestApi;
|
||||
import android.app.compat.CompatChanges;
|
||||
import android.compat.annotation.ChangeId;
|
||||
import android.compat.annotation.Disabled;
|
||||
import android.compat.annotation.Overridable;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
@@ -254,7 +255,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
* @See {@link android.R.attr#maxAspectRatio}.
|
||||
* @hide
|
||||
*/
|
||||
public float maxAspectRatio;
|
||||
private float mMaxAspectRatio;
|
||||
|
||||
/**
|
||||
* Value indicating the minimum aspect ratio the activity supports.
|
||||
@@ -263,7 +264,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
* @See {@link android.R.attr#minAspectRatio}.
|
||||
* @hide
|
||||
*/
|
||||
public float minAspectRatio;
|
||||
private float mMinAspectRatio;
|
||||
|
||||
/**
|
||||
* Indicates that the activity works well with size changes like display changing size.
|
||||
@@ -947,6 +948,57 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface SizeChangesSupportMode {}
|
||||
|
||||
/**
|
||||
* This change id is the gatekeeper for all treatments that force a given min aspect ratio.
|
||||
* Enabling this change will allow the following min aspect ratio treatments to be applied:
|
||||
* OVERRIDE_MIN_ASPECT_RATIO_MEDIUM
|
||||
* OVERRIDE_MIN_ASPECT_RATIO_LARGE
|
||||
*
|
||||
* If OVERRIDE_MIN_ASPECT_RATIO is applied, the min aspect ratio given in the app's
|
||||
* manifest will be overridden to the largest enabled aspect ratio treatment unless the app's
|
||||
* manifest value is higher.
|
||||
* @hide
|
||||
*/
|
||||
@ChangeId
|
||||
@Overridable
|
||||
@Disabled
|
||||
@TestApi
|
||||
public static final long OVERRIDE_MIN_ASPECT_RATIO = 174042980L; // buganizer id
|
||||
|
||||
/**
|
||||
* This change id sets the activity's min aspect ratio to a medium value as defined by
|
||||
* OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE.
|
||||
*
|
||||
* This treatment only takes effect if OVERRIDE_MIN_ASPECT_RATIO is also enabled.
|
||||
* @hide
|
||||
*/
|
||||
@ChangeId
|
||||
@Overridable
|
||||
@Disabled
|
||||
@TestApi
|
||||
public static final long OVERRIDE_MIN_ASPECT_RATIO_MEDIUM = 180326845L; // buganizer id
|
||||
|
||||
/** @hide Medium override aspect ratio, currently 3:2. */
|
||||
@TestApi
|
||||
public static final float OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE = 3 / 2f;
|
||||
|
||||
/**
|
||||
* This change id sets the activity's min aspect ratio to a large value as defined by
|
||||
* OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE.
|
||||
*
|
||||
* This treatment only takes effect if OVERRIDE_MIN_ASPECT_RATIO is also enabled.
|
||||
* @hide
|
||||
*/
|
||||
@ChangeId
|
||||
@Overridable
|
||||
@Disabled
|
||||
@TestApi
|
||||
public static final long OVERRIDE_MIN_ASPECT_RATIO_LARGE = 180326787L; // buganizer id
|
||||
|
||||
/** @hide Large override aspect ratio, currently 16:9 */
|
||||
@TestApi
|
||||
public static final float OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE = 16 / 9f;
|
||||
|
||||
/**
|
||||
* Convert Java change bits to native.
|
||||
*
|
||||
@@ -1118,8 +1170,8 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
requestedVrComponent = orig.requestedVrComponent;
|
||||
rotationAnimation = orig.rotationAnimation;
|
||||
colorMode = orig.colorMode;
|
||||
maxAspectRatio = orig.maxAspectRatio;
|
||||
minAspectRatio = orig.minAspectRatio;
|
||||
mMaxAspectRatio = orig.mMaxAspectRatio;
|
||||
mMinAspectRatio = orig.mMinAspectRatio;
|
||||
supportsSizeChanges = orig.supportsSizeChanges;
|
||||
attributionTags = orig.attributionTags;
|
||||
}
|
||||
@@ -1149,7 +1201,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
* @hide
|
||||
*/
|
||||
public boolean hasFixedAspectRatio() {
|
||||
return maxAspectRatio != 0 || minAspectRatio != 0;
|
||||
return getMaxAspectRatio() != 0 || getMinAspectRatio() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1261,6 +1313,58 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
return SIZE_CHANGES_UNSUPPORTED_METADATA;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void setMaxAspectRatio(float maxAspectRatio) {
|
||||
this.mMaxAspectRatio = maxAspectRatio;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public float getMaxAspectRatio() {
|
||||
return mMaxAspectRatio;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void setMinAspectRatio(float minAspectRatio) {
|
||||
this.mMinAspectRatio = minAspectRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the min aspect ratio of this activity.
|
||||
*
|
||||
* This takes into account the minimum aspect ratio as defined in the app's manifest and
|
||||
* possible overrides as per OVERRIDE_MIN_ASPECT_RATIO.
|
||||
*
|
||||
* In the rare cases where the manifest minimum aspect ratio is required, use
|
||||
* {@code getManifestMinAspectRatio}.
|
||||
* @hide
|
||||
*/
|
||||
public float getMinAspectRatio() {
|
||||
if (applicationInfo == null || !CompatChanges.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO,
|
||||
applicationInfo.packageName,
|
||||
UserHandle.getUserHandleForUid(applicationInfo.uid))) {
|
||||
return mMinAspectRatio;
|
||||
}
|
||||
|
||||
if (CompatChanges.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_LARGE,
|
||||
applicationInfo.packageName,
|
||||
UserHandle.getUserHandleForUid(applicationInfo.uid))) {
|
||||
return Math.max(OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE, mMinAspectRatio);
|
||||
}
|
||||
|
||||
if (CompatChanges.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_MEDIUM,
|
||||
applicationInfo.packageName,
|
||||
UserHandle.getUserHandleForUid(applicationInfo.uid))) {
|
||||
return Math.max(OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE, mMinAspectRatio);
|
||||
}
|
||||
|
||||
return mMinAspectRatio;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public float getManifestMinAspectRatio() {
|
||||
return mMinAspectRatio;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@UnsupportedAppUsage
|
||||
public static boolean isResizeableMode(int mode) {
|
||||
@@ -1360,11 +1464,14 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
if (requestedVrComponent != null) {
|
||||
pw.println(prefix + "requestedVrComponent=" + requestedVrComponent);
|
||||
}
|
||||
if (maxAspectRatio != 0) {
|
||||
pw.println(prefix + "maxAspectRatio=" + maxAspectRatio);
|
||||
if (getMaxAspectRatio() != 0) {
|
||||
pw.println(prefix + "maxAspectRatio=" + getMaxAspectRatio());
|
||||
}
|
||||
if (minAspectRatio != 0) {
|
||||
pw.println(prefix + "minAspectRatio=" + minAspectRatio);
|
||||
if (getMinAspectRatio() != 0) {
|
||||
pw.println(prefix + "minAspectRatio=" + getMinAspectRatio());
|
||||
if (getManifestMinAspectRatio() != getMinAspectRatio()) {
|
||||
pw.println(prefix + "getManifestMinAspectRatio=" + getManifestMinAspectRatio());
|
||||
}
|
||||
}
|
||||
if (supportsSizeChanges) {
|
||||
pw.println(prefix + "supportsSizeChanges=true");
|
||||
@@ -1420,8 +1527,8 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
dest.writeString8(requestedVrComponent);
|
||||
dest.writeInt(rotationAnimation);
|
||||
dest.writeInt(colorMode);
|
||||
dest.writeFloat(maxAspectRatio);
|
||||
dest.writeFloat(minAspectRatio);
|
||||
dest.writeFloat(mMaxAspectRatio);
|
||||
dest.writeFloat(mMinAspectRatio);
|
||||
dest.writeBoolean(supportsSizeChanges);
|
||||
dest.writeString8Array(attributionTags);
|
||||
}
|
||||
@@ -1540,8 +1647,8 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
|
||||
requestedVrComponent = source.readString8();
|
||||
rotationAnimation = source.readInt();
|
||||
colorMode = source.readInt();
|
||||
maxAspectRatio = source.readFloat();
|
||||
minAspectRatio = source.readFloat();
|
||||
mMaxAspectRatio = source.readFloat();
|
||||
mMinAspectRatio = source.readFloat();
|
||||
supportsSizeChanges = source.readBoolean();
|
||||
attributionTags = source.createString8Array();
|
||||
}
|
||||
|
||||
@@ -4890,8 +4890,8 @@ public class PackageParser {
|
||||
info.maxRecents = target.info.maxRecents;
|
||||
info.windowLayout = target.info.windowLayout;
|
||||
info.resizeMode = target.info.resizeMode;
|
||||
info.maxAspectRatio = target.info.maxAspectRatio;
|
||||
info.minAspectRatio = target.info.minAspectRatio;
|
||||
info.setMaxAspectRatio(target.info.getMaxAspectRatio());
|
||||
info.setMinAspectRatio(target.info.getManifestMinAspectRatio());
|
||||
info.supportsSizeChanges = target.info.supportsSizeChanges;
|
||||
info.requestedVrComponent = target.info.requestedVrComponent;
|
||||
|
||||
@@ -8157,7 +8157,7 @@ public class PackageParser {
|
||||
return;
|
||||
}
|
||||
|
||||
info.maxAspectRatio = maxAspectRatio;
|
||||
info.setMaxAspectRatio(maxAspectRatio);
|
||||
mHasMaxAspectRatio = true;
|
||||
}
|
||||
|
||||
@@ -8173,7 +8173,7 @@ public class PackageParser {
|
||||
return;
|
||||
}
|
||||
|
||||
info.minAspectRatio = minAspectRatio;
|
||||
info.setMinAspectRatio(minAspectRatio);
|
||||
mHasMinAspectRatio = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -474,9 +474,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
ai.screenOrientation = a.getScreenOrientation();
|
||||
ai.resizeMode = a.getResizeMode();
|
||||
Float maxAspectRatio = a.getMaxAspectRatio();
|
||||
ai.maxAspectRatio = maxAspectRatio != null ? maxAspectRatio : 0f;
|
||||
ai.setMaxAspectRatio(maxAspectRatio != null ? maxAspectRatio : 0f);
|
||||
Float minAspectRatio = a.getMinAspectRatio();
|
||||
ai.minAspectRatio = minAspectRatio != null ? minAspectRatio : 0f;
|
||||
ai.setMinAspectRatio(minAspectRatio != null ? minAspectRatio : 0f);
|
||||
ai.supportsSizeChanges = a.getSupportsSizeChanges();
|
||||
ai.requestedVrComponent = a.getRequestedVrComponent();
|
||||
ai.rotationAnimation = a.getRotationAnimation();
|
||||
|
||||
@@ -133,7 +133,7 @@ public class ObjectPoolTests {
|
||||
int ident = 57;
|
||||
ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.flags = 42;
|
||||
activityInfo.maxAspectRatio = 2.4f;
|
||||
activityInfo.setMaxAspectRatio(2.4f);
|
||||
activityInfo.launchToken = "token";
|
||||
activityInfo.applicationInfo = new ApplicationInfo();
|
||||
activityInfo.packageName = "packageName";
|
||||
|
||||
@@ -182,7 +182,7 @@ public class TransactionParcelTests {
|
||||
int ident = 57;
|
||||
ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.flags = 42;
|
||||
activityInfo.maxAspectRatio = 2.4f;
|
||||
activityInfo.setMaxAspectRatio(2.4f);
|
||||
activityInfo.launchToken = "token";
|
||||
activityInfo.applicationInfo = new ApplicationInfo();
|
||||
activityInfo.packageName = "packageName";
|
||||
|
||||
@@ -1081,11 +1081,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
pw.println(prefix + "supportsEnterPipOnTaskSwitch: "
|
||||
+ supportsEnterPipOnTaskSwitch);
|
||||
}
|
||||
if (info.maxAspectRatio != 0) {
|
||||
pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio);
|
||||
if (info.getMaxAspectRatio() != 0) {
|
||||
pw.println(prefix + "maxAspectRatio=" + info.getMaxAspectRatio());
|
||||
}
|
||||
if (info.minAspectRatio != 0) {
|
||||
pw.println(prefix + "minAspectRatio=" + info.minAspectRatio);
|
||||
if (info.getMinAspectRatio() != 0) {
|
||||
pw.println(prefix + "minAspectRatio=" + info.getMinAspectRatio());
|
||||
}
|
||||
if (info.getMinAspectRatio() != info.getManifestMinAspectRatio()) {
|
||||
// Log the fact that we've overridden the min aspect ratio from the manifest
|
||||
pw.println(prefix + "manifestMinAspectRatio="
|
||||
+ info.getManifestMinAspectRatio());
|
||||
}
|
||||
pw.println(prefix + "supportsSizeChanges="
|
||||
+ ActivityInfo.sizeChangesSupportModeToString(info.supportsSizeChanges()));
|
||||
@@ -7055,8 +7060,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
|
||||
// Adjust the fixed orientation letterbox bounds to fit the app request aspect ratio in
|
||||
// order to use the extra available space.
|
||||
final float maxAspectRatio = info.maxAspectRatio;
|
||||
final float minAspectRatio = info.minAspectRatio;
|
||||
final float maxAspectRatio = info.getMaxAspectRatio();
|
||||
final float minAspectRatio = info.getMinAspectRatio();
|
||||
if (aspect > maxAspectRatio && maxAspectRatio != 0) {
|
||||
aspect = maxAspectRatio;
|
||||
} else if (aspect < minAspectRatio) {
|
||||
@@ -7293,21 +7298,21 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
|
||||
// The rest of the condition is that only one side is smaller than the container, but it
|
||||
// still needs to exclude the cases where the size is limited by the fixed aspect ratio.
|
||||
if (info.maxAspectRatio > 0) {
|
||||
if (info.getMaxAspectRatio() > 0) {
|
||||
final float aspectRatio = (0.5f + Math.max(appWidth, appHeight))
|
||||
/ Math.min(appWidth, appHeight);
|
||||
if (aspectRatio >= info.maxAspectRatio) {
|
||||
if (aspectRatio >= info.getMaxAspectRatio()) {
|
||||
// The current size has reached the max aspect ratio.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (info.minAspectRatio > 0) {
|
||||
if (info.getMinAspectRatio() > 0) {
|
||||
// The activity should have at least the min aspect ratio, so this checks if the
|
||||
// container still has available space to provide larger aspect ratio.
|
||||
final float containerAspectRatio =
|
||||
(0.5f + Math.max(containerAppWidth, containerAppHeight))
|
||||
/ Math.min(containerAppWidth, containerAppHeight);
|
||||
if (containerAspectRatio <= info.minAspectRatio) {
|
||||
if (containerAspectRatio <= info.getMinAspectRatio()) {
|
||||
// The long side has reached the parent.
|
||||
return false;
|
||||
}
|
||||
@@ -7474,9 +7479,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
// TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
|
||||
private void applyAspectRatio(Rect outBounds, Rect containingAppBounds,
|
||||
Rect containingBounds) {
|
||||
final float maxAspectRatio = info.maxAspectRatio;
|
||||
final float maxAspectRatio = info.getMaxAspectRatio();
|
||||
final Task rootTask = getRootTask();
|
||||
final float minAspectRatio = info.minAspectRatio;
|
||||
final float minAspectRatio = info.getMinAspectRatio();
|
||||
|
||||
if (task == null || rootTask == null
|
||||
|| (inMultiWindowMode() && !shouldCreateCompatDisplayInsets())
|
||||
|
||||
@@ -161,7 +161,8 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
|
||||
final Rect displayBounds = mActivity.mDisplayContent.getWindowConfiguration().getBounds();
|
||||
final float aspectRatio = 1.2f;
|
||||
mActivity.info.minAspectRatio = mActivity.info.maxAspectRatio = aspectRatio;
|
||||
mActivity.info.setMaxAspectRatio(aspectRatio);
|
||||
mActivity.info.setMinAspectRatio(aspectRatio);
|
||||
prepareUnresizable(mActivity, -1f, SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds();
|
||||
|
||||
@@ -779,6 +780,139 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
assertTrue(activity.shouldCreateCompatDisplayInsets());
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
|
||||
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
|
||||
public void testOverrideMinAspectRatioMedium() {
|
||||
setUpDisplaySizeWithApp(1000, 1200);
|
||||
|
||||
// Create a size compat activity on the same task.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm)
|
||||
.setTask(mTask)
|
||||
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
.setComponent(ComponentName.createRelative(mContext,
|
||||
SizeCompatTests.class.getName()))
|
||||
.setUid(android.os.Process.myUid())
|
||||
.build();
|
||||
|
||||
// The per-package override forces the activity into a 3:2 aspect ratio
|
||||
assertEquals(1200, activity.getBounds().height());
|
||||
assertEquals(1200 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE,
|
||||
activity.getBounds().width(), 0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
|
||||
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
|
||||
public void testOverrideMinAspectRatioLowerThanManifest() {
|
||||
setUpDisplaySizeWithApp(1400, 1600);
|
||||
|
||||
// Create a size compat activity on the same task.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm)
|
||||
.setTask(mTask)
|
||||
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
.setComponent(ComponentName.createRelative(mContext,
|
||||
SizeCompatTests.class.getName()))
|
||||
.setMinAspectRatio(2f)
|
||||
.setUid(android.os.Process.myUid())
|
||||
.build();
|
||||
|
||||
// The per-package override should have no effect, because the manifest aspect ratio is
|
||||
// larger (2:1)
|
||||
assertEquals(1600, activity.getBounds().height());
|
||||
assertEquals(800, activity.getBounds().width());
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
|
||||
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE})
|
||||
public void testOverrideMinAspectRatioLargerThanManifest() {
|
||||
setUpDisplaySizeWithApp(1400, 1600);
|
||||
|
||||
// Create a size compat activity on the same task.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm)
|
||||
.setTask(mTask)
|
||||
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
.setComponent(ComponentName.createRelative(mContext,
|
||||
SizeCompatTests.class.getName()))
|
||||
.setMinAspectRatio(1.1f)
|
||||
.setUid(android.os.Process.myUid())
|
||||
.build();
|
||||
|
||||
// The per-package override should have no effect, because the manifest aspect ratio is
|
||||
// larger (2:1)
|
||||
assertEquals(1600, activity.getBounds().height());
|
||||
assertEquals(1600 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE,
|
||||
activity.getBounds().width(), 0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
|
||||
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE})
|
||||
public void testOverrideMinAspectRatioLarge() {
|
||||
setUpDisplaySizeWithApp(1500, 1600);
|
||||
|
||||
// Create a size compat activity on the same task.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm)
|
||||
.setTask(mTask)
|
||||
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
.setComponent(ComponentName.createRelative(mContext,
|
||||
SizeCompatTests.class.getName()))
|
||||
.setUid(android.os.Process.myUid())
|
||||
.build();
|
||||
|
||||
// The per-package override forces the activity into a 16:9 aspect ratio
|
||||
assertEquals(1600, activity.getBounds().height());
|
||||
assertEquals(1600 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE,
|
||||
activity.getBounds().width(), 0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
|
||||
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM,
|
||||
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE})
|
||||
public void testOverrideMinAspectRatio_Both() {
|
||||
// If multiple override aspect ratios are set, we should use the largest one
|
||||
|
||||
setUpDisplaySizeWithApp(1400, 1600);
|
||||
|
||||
// Create a size compat activity on the same task.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm)
|
||||
.setTask(mTask)
|
||||
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
.setComponent(ComponentName.createRelative(mContext,
|
||||
SizeCompatTests.class.getName()))
|
||||
.setUid(android.os.Process.myUid())
|
||||
.build();
|
||||
|
||||
// The per-package override forces the activity into a 16:9 aspect ratio
|
||||
assertEquals(1600, activity.getBounds().height());
|
||||
assertEquals(1600 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE,
|
||||
activity.getBounds().width(), 0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
|
||||
public void testOverrideMinAspectRatioWithoutGlobalOverride() {
|
||||
// In this test, only OVERRIDE_MIN_ASPECT_RATIO_1_5 is set, which has no effect without
|
||||
// OVERRIDE_MIN_ASPECT_RATIO being also set.
|
||||
|
||||
setUpDisplaySizeWithApp(1000, 1200);
|
||||
|
||||
// Create a size compat activity on the same task.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm)
|
||||
.setTask(mTask)
|
||||
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
.setComponent(ComponentName.createRelative(mContext,
|
||||
SizeCompatTests.class.getName()))
|
||||
.setUid(android.os.Process.myUid())
|
||||
.build();
|
||||
|
||||
// The per-package override should have no effect
|
||||
assertEquals(1200, activity.getBounds().height());
|
||||
assertEquals(1000, activity.getBounds().width());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchWithFixedRotationTransform() {
|
||||
final int dw = 1000;
|
||||
@@ -872,7 +1006,7 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
// Portrait fixed app with min aspect ratio higher that aspect ratio override for fixed
|
||||
// orientation letterbox.
|
||||
mActivity.mWmService.setFixedOrientationLetterboxAspectRatio(1.1f);
|
||||
mActivity.info.minAspectRatio = 3;
|
||||
mActivity.info.setMinAspectRatio(3);
|
||||
prepareUnresizable(mActivity, /* maxAspect= */ 0, SCREEN_ORIENTATION_PORTRAIT);
|
||||
|
||||
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
|
||||
@@ -889,7 +1023,8 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
|
||||
// Activity bounds should respect minimum aspect ratio for activity.
|
||||
assertEquals(displayBounds.height(), activityBounds.height());
|
||||
assertEquals((int) Math.rint(displayBounds.height() / mActivity.info.minAspectRatio),
|
||||
assertEquals((int) Math.rint(displayBounds.height()
|
||||
/ mActivity.info.getManifestMinAspectRatio()),
|
||||
activityBounds.width());
|
||||
}
|
||||
|
||||
@@ -918,7 +1053,8 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
|
||||
// Activity bounds should respect maximum aspect ratio for activity.
|
||||
assertEquals(displayBounds.height(), activityBounds.height());
|
||||
assertEquals((int) Math.rint(displayBounds.height() / mActivity.info.maxAspectRatio),
|
||||
assertEquals((int) Math.rint(displayBounds.height()
|
||||
/ mActivity.info.getMaxAspectRatio()),
|
||||
activityBounds.width());
|
||||
}
|
||||
|
||||
@@ -1098,7 +1234,8 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
|
||||
assertFalse(newActivity.inSizeCompatMode());
|
||||
assertEquals(displayBounds.height(), newActivityBounds.height());
|
||||
assertEquals((long) Math.rint(newActivityBounds.height() / newActivity.info.maxAspectRatio),
|
||||
assertEquals((long) Math.rint(newActivityBounds.height()
|
||||
/ newActivity.info.getMaxAspectRatio()),
|
||||
newActivityBounds.width());
|
||||
}
|
||||
|
||||
@@ -1347,7 +1484,7 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
: RESIZE_MODE_RESIZEABLE;
|
||||
activity.mVisibleRequested = true;
|
||||
if (maxAspect >= 0) {
|
||||
activity.info.maxAspectRatio = maxAspect;
|
||||
activity.info.setMaxAspectRatio(maxAspect);
|
||||
}
|
||||
if (screenOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
|
||||
activity.info.screenOrientation = screenOrientation;
|
||||
|
||||
@@ -136,7 +136,10 @@ class TestDisplayContent extends DisplayContent {
|
||||
final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
|
||||
mInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
|
||||
final TestDisplayContent newDisplay = createInternal(display);
|
||||
|
||||
// Ensure letterbox aspect ratio is not overridden on any device target.
|
||||
// {@link com.android.internal.R.dimen.config_taskLetterboxAspectRatio}, provided by
|
||||
// the below method, is set on some device form factors.
|
||||
mService.mWindowManager.setFixedOrientationLetterboxAspectRatio(0);
|
||||
// disable the normal system decorations
|
||||
final DisplayPolicy displayPolicy = newDisplay.getDisplayPolicy();
|
||||
spyOn(displayPolicy);
|
||||
|
||||
@@ -714,6 +714,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
private int mLaunchMode;
|
||||
private int mResizeMode = RESIZE_MODE_RESIZEABLE;
|
||||
private float mMaxAspectRatio;
|
||||
private float mMinAspectRatio;
|
||||
private boolean mSupportsSizeChanges;
|
||||
private int mScreenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
private boolean mLaunchTaskBehind = false;
|
||||
@@ -793,6 +794,11 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
ActivityBuilder setMinAspectRatio(float minAspectRatio) {
|
||||
mMinAspectRatio = minAspectRatio;
|
||||
return this;
|
||||
}
|
||||
|
||||
ActivityBuilder setSupportsSizeChanges(boolean supportsSizeChanges) {
|
||||
mSupportsSizeChanges = supportsSizeChanges;
|
||||
return this;
|
||||
@@ -884,7 +890,8 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
aInfo.flags |= mActivityFlags;
|
||||
aInfo.launchMode = mLaunchMode;
|
||||
aInfo.resizeMode = mResizeMode;
|
||||
aInfo.maxAspectRatio = mMaxAspectRatio;
|
||||
aInfo.setMaxAspectRatio(mMaxAspectRatio);
|
||||
aInfo.setMinAspectRatio(mMinAspectRatio);
|
||||
aInfo.supportsSizeChanges = mSupportsSizeChanges;
|
||||
aInfo.screenOrientation = mScreenOrientation;
|
||||
aInfo.configChanges |= mConfigChanges;
|
||||
|
||||
Reference in New Issue
Block a user