From 74cc4db965deeb2e16a455deeec1b30669b709db Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Wed, 17 Nov 2021 17:11:49 +0800 Subject: Try to fix ActivityThreadTest failure on foldables The root cause of this failure is that we don't specify Configuration#orientation in test, so #handleActivityConfigurationChanged uses device orientation instead, which is landscape in the failure case. In this way, TestActivity receives 2 onConfigurationChanged callbacks, one is to make Activity portrait, the other is to make Activity landscape, which is from process configuration. This CL specifies orientation in each propagated Configuration to prevent orientation overridden by process Configuration. Bug: 204903019 Test: atest ActivityThreadTest Change-Id: I4d7720ef1128fc8612381b1a076b06beb765f1b6 --- .../coretests/src/android/app/activity/ActivityThreadTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/tests/coretests/src/android/app/activity/ActivityThreadTest.java b/core/tests/coretests/src/android/app/activity/ActivityThreadTest.java index 6f17ea994699..4a7c50d8b934 100644 --- a/core/tests/coretests/src/android/app/activity/ActivityThreadTest.java +++ b/core/tests/coretests/src/android/app/activity/ActivityThreadTest.java @@ -304,18 +304,22 @@ public class ActivityThreadTest { final int numOfConfig = activity.mNumOfConfigChanges; final Configuration processConfigLandscape = new Configuration(); + processConfigLandscape.orientation = ORIENTATION_LANDSCAPE; processConfigLandscape.windowConfiguration.setBounds(new Rect(0, 0, 100, 60)); processConfigLandscape.seq = BASE_SEQ + 1; final Configuration activityConfigLandscape = new Configuration(); + activityConfigLandscape.orientation = ORIENTATION_LANDSCAPE; activityConfigLandscape.windowConfiguration.setBounds(new Rect(0, 0, 100, 50)); activityConfigLandscape.seq = BASE_SEQ + 2; final Configuration processConfigPortrait = new Configuration(); + processConfigPortrait.orientation = ORIENTATION_PORTRAIT; processConfigPortrait.windowConfiguration.setBounds(new Rect(0, 0, 60, 100)); processConfigPortrait.seq = BASE_SEQ + 3; final Configuration activityConfigPortrait = new Configuration(); + activityConfigPortrait.orientation = ORIENTATION_PORTRAIT; activityConfigPortrait.windowConfiguration.setBounds(new Rect(0, 0, 50, 100)); activityConfigPortrait.seq = BASE_SEQ + 4; @@ -343,7 +347,8 @@ public class ActivityThreadTest { assertEquals(activityConfigPortrait.windowConfiguration.getBounds(), bounds); // Ensure that Activity#onConfigurationChanged() not be called because the changes in - // WindowConfiguration shouldn't be reported. + // WindowConfiguration shouldn't be reported, and we only apply the latest Configuration + // update in transaction. assertEquals(numOfConfig, activity.mNumOfConfigChanges); } -- cgit v1.2.3-59-g8ed1b