Merge "Fix unit tests if universal_resizable_by_default is enabled" into main
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index c30b4bb..c3466b9 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -139,7 +139,6 @@
import android.os.Process;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
-import android.platform.test.annotations.RequiresFlagsEnabled;
import android.provider.DeviceConfig;
import android.util.MutableBoolean;
import android.view.DisplayInfo;
@@ -2662,8 +2661,11 @@
}
@Test
- @RequiresFlagsEnabled(Flags.FLAG_UNIVERSAL_RESIZABLE_BY_DEFAULT)
public void testSetOrientation_restrictedByTargetSdk() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_UNIVERSAL_RESIZABLE_BY_DEFAULT);
+ mDisplayContent.setIgnoreOrientationRequest(true);
+ makeDisplayLargeScreen(mDisplayContent);
+
assertSetOrientation(Build.VERSION_CODES.CUR_DEVELOPMENT, CATEGORY_SOCIAL, false);
assertSetOrientation(Build.VERSION_CODES.CUR_DEVELOPMENT, CATEGORY_GAME, true);
@@ -2673,12 +2675,13 @@
}
private void assertSetOrientation(int targetSdk, int category, boolean expectRotate) {
- final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();
- activity.mTargetSdk = targetSdk;
+ final String packageName = targetSdk <= Build.VERSION_CODES.VANILLA_ICE_CREAM
+ ? mContext.getPackageName() // WmTests uses legacy sdk.
+ : null; // Simulate CUR_DEVELOPMENT by invalid package (see PlatformCompat).
+ final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true)
+ .setComponent(getUniqueComponentName(packageName)).build();
activity.info.applicationInfo.category = category;
- activity.setVisible(true);
-
// Assert orientation is unspecified to start.
assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, activity.getOrientation());
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
index c8a3559..08963f1 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
@@ -307,6 +307,8 @@
void createNewTaskWithBaseActivity() {
final Task newTask = new WindowTestsBase.TaskBuilder(mSupervisor)
.setCreateActivity(true)
+ // Respect "@ChangeId" according to test package's target sdk.
+ .setPackage(mAtm.mContext.getPackageName())
.setDisplay(mDisplayContent).build();
mTaskStack.push(newTask);
pushActivity(newTask.getTopNonFinishingActivity());
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 5c0d424..2bebcc3 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -1081,7 +1081,8 @@
final DisplayRotation dr = dc.getDisplayRotation();
spyOn(dr);
doReturn(false).when(dr).useDefaultSettingsProvider();
- final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true).build();
+ final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true)
+ .setComponent(getUniqueComponentName(mContext.getPackageName())).build();
app.setOrientation(SCREEN_ORIENTATION_LANDSCAPE, app);
assertFalse(dc.getRotationReversionController().isAnyOverrideActive());
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java
index 35c9e3f..f4fa12e 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java
@@ -51,6 +51,7 @@
import android.app.servertransaction.RefreshCallbackItem;
import android.app.servertransaction.ResumeActivityItem;
import android.content.ComponentName;
+import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo.ScreenOrientation;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -592,6 +593,11 @@
.setTask(mTask)
.build();
+ spyOn(mActivity.info.applicationInfo);
+ // Disable for camera compat.
+ doReturn(false).when(mActivity.info.applicationInfo).isChangeEnabled(
+ ActivityInfo.UNIVERSAL_RESIZABLE_BY_DEFAULT);
+
spyOn(mActivity.mAtmService.getLifecycleManager());
spyOn(mActivity.mAppCompatController.getAppCompatCameraOverrides());
diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
index e956e22..e66dfeb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
@@ -4824,12 +4824,7 @@
assertFalse(mActivity.isUniversalResizeable());
mDisplayContent.setIgnoreOrientationRequest(true);
- final int swDp = mDisplayContent.getConfiguration().smallestScreenWidthDp;
- if (swDp < WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP) {
- final int height = 100 + (int) (mDisplayContent.getDisplayMetrics().density
- * WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP);
- resizeDisplay(mDisplayContent, 100 + height, height);
- }
+ makeDisplayLargeScreen(mDisplayContent);
assertTrue(mActivity.isUniversalResizeable());
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
index a215c0a..757c358 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
@@ -1123,6 +1123,15 @@
displayContent.onRequestedOverrideConfigurationChanged(c);
}
+ static void makeDisplayLargeScreen(DisplayContent displayContent) {
+ final int swDp = displayContent.getConfiguration().smallestScreenWidthDp;
+ if (swDp < WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP) {
+ final int height = 100 + (int) (displayContent.getDisplayMetrics().density
+ * WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP);
+ resizeDisplay(displayContent, 100 + height, height);
+ }
+ }
+
/** Used for the tests that assume the display is portrait by default. */
static void makeDisplayPortrait(DisplayContent displayContent) {
if (displayContent.mBaseDisplayHeight <= displayContent.mBaseDisplayWidth) {
@@ -1223,7 +1232,14 @@
}
static ComponentName getUniqueComponentName() {
- return ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
+ return getUniqueComponentName(DEFAULT_COMPONENT_PACKAGE_NAME);
+ }
+
+ static ComponentName getUniqueComponentName(String packageName) {
+ if (packageName == null) {
+ packageName = DEFAULT_COMPONENT_PACKAGE_NAME;
+ }
+ return ComponentName.createRelative(packageName,
DEFAULT_COMPONENT_CLASS_NAME + sCurrentActivityId++);
}
@@ -1298,8 +1314,7 @@
ActivityBuilder setActivityTheme(int theme) {
mActivityTheme = theme;
// Use the real package of test so it can get a valid context for theme.
- mComponent = ComponentName.createRelative(mService.mContext.getPackageName(),
- DEFAULT_COMPONENT_CLASS_NAME + sCurrentActivityId++);
+ mComponent = getUniqueComponentName(mService.mContext.getPackageName());
return this;
}
@@ -1743,7 +1758,7 @@
if (mIntent == null) {
mIntent = new Intent();
if (mComponent == null) {
- mComponent = getUniqueComponentName();
+ mComponent = getUniqueComponentName(mPackage);
}
mIntent.setComponent(mComponent);
mIntent.setFlags(mFlags);