From 2833289b21a6347565f27b49d62ef466e26a6a49 Mon Sep 17 00:00:00 2001 From: Vali Calinescu Date: Wed, 10 May 2023 15:10:55 +0000 Subject: [PATCH] Refresh activity after stronger letterboxing for camera compat We used to refresh the activity only if the display rotation configuration was changing and the treatment was allowed. Now we are also refreshing the activity after stronger letterboxing (split screen aspect ratio is used for the camera activity). This is needed because we want to keep applying the camera compat treatment when the activity is resumed. Fix: 277818827 Test: atest WmTests:DisplayRotationCompatPolicyTests#testOnActivityConfigurationChanging_splitScreenAspectRatioAllowed_refresh Change-Id: I61b807f18dc89582c9e1634cd533b1fa9e364d32 --- data/etc/services.core.protolog.json | 12 ++++++------ .../server/wm/DisplayRotationCompatPolicy.java | 11 +++++++---- .../android/server/wm/LetterboxConfiguration.java | 4 ++-- .../android/server/wm/LetterboxUiController.java | 2 +- .../wm/DisplayRotationCompatPolicyTests.java | 15 +++++++++++++++ 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json index 7c2759af156fa..92c0dabfd13e7 100644 --- a/data/etc/services.core.protolog.json +++ b/data/etc/services.core.protolog.json @@ -3865,6 +3865,12 @@ "group": "WM_DEBUG_ADD_REMOVE", "at": "com\/android\/server\/wm\/WindowState.java" }, + "1511273241": { + "message": "Refreshing activity for camera compatibility treatment, activityRecord=%s", + "level": "VERBOSE", + "group": "WM_DEBUG_STATES", + "at": "com\/android\/server\/wm\/DisplayRotationCompatPolicy.java" + }, "1518495446": { "message": "removeWindowToken: Attempted to remove non-existing token: %s", "level": "WARN", @@ -4297,12 +4303,6 @@ "group": "WM_DEBUG_REMOTE_ANIMATIONS", "at": "com\/android\/server\/wm\/RemoteAnimationController.java" }, - "1967643923": { - "message": "Refershing activity for camera compatibility treatment, activityRecord=%s", - "level": "VERBOSE", - "group": "WM_DEBUG_STATES", - "at": "com\/android\/server\/wm\/DisplayRotationCompatPolicy.java" - }, "1967975839": { "message": "Changing app %s visible=%b performLayout=%b", "level": "VERBOSE", diff --git a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java index ae93a9496f7c1..2b72215f1b729 100644 --- a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java @@ -223,7 +223,7 @@ final class DisplayRotationCompatPolicy { try { activity.mLetterboxUiController.setIsRefreshAfterRotationRequested(true); ProtoLog.v(WM_DEBUG_STATES, - "Refershing activity for camera compatibility treatment, " + "Refreshing activity for camera compatibility treatment, " + "activityRecord=%s", activity); final ClientTransaction transaction = ClientTransaction.obtain( activity.app.getThread(), activity.token); @@ -311,11 +311,14 @@ final class DisplayRotationCompatPolicy { } } - // Refreshing only when configuration changes after rotation. + // Refreshing only when configuration changes after rotation or camera split screen aspect ratio + // treatment is enabled private boolean shouldRefreshActivity(ActivityRecord activity, Configuration newConfig, Configuration lastReportedConfig) { - return newConfig.windowConfiguration.getDisplayRotation() - != lastReportedConfig.windowConfiguration.getDisplayRotation() + final boolean displayRotationChanged = (newConfig.windowConfiguration.getDisplayRotation() + != lastReportedConfig.windowConfiguration.getDisplayRotation()); + return (displayRotationChanged + || activity.mLetterboxUiController.isCameraCompatSplitScreenAspectRatioAllowed()) && isTreatmentEnabledForActivity(activity) && activity.mLetterboxUiController.shouldRefreshActivityForCameraCompat(); } diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java index f492bab0728f9..a93cb8ad2d974 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java +++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java @@ -214,7 +214,7 @@ final class LetterboxConfiguration { // otherwise the apps get blacked out when they are resumed and do not have focus yet. private boolean mIsCompatFakeFocusEnabled; - // Whether should use split screen aspect ratio for the activity when camera compat treatment + // Whether we should use split screen aspect ratio for the activity when camera compat treatment // is enabled and activity is connected to the camera in fullscreen. private final boolean mIsCameraCompatSplitScreenAspectRatioEnabled; @@ -1118,7 +1118,7 @@ final class LetterboxConfiguration { } /** - * Whether should use split screen aspect ratio for the activity when camera compat treatment + * Whether we should use split screen aspect ratio for the activity when camera compat treatment * is enabled and activity is connected to the camera in fullscreen. */ boolean isCameraCompatSplitScreenAspectRatioEnabled() { diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 0288e4bbb26ec..5b39790d5fdad 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -958,7 +958,7 @@ final class LetterboxUiController { * Whether we use split screen aspect ratio for the activity when camera compat treatment * is active because the corresponding config is enabled and activity supports resizing. */ - private boolean isCameraCompatSplitScreenAspectRatioAllowed() { + boolean isCameraCompatSplitScreenAspectRatioAllowed() { return mLetterboxConfiguration.isCameraCompatSplitScreenAspectRatioEnabled() && !mActivityRecord.shouldCreateCompatDisplayInsets(); } 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 a3117269eb01a..3ca35ef7cc26f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java @@ -479,6 +479,8 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase { public void testOnActivityConfigurationChanging_displayRotationNotChanging_noRefresh() throws Exception { configureActivity(SCREEN_ORIENTATION_PORTRAIT); + doReturn(false).when(mActivity.mLetterboxUiController) + .isCameraCompatSplitScreenAspectRatioAllowed(); mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); callOnActivityConfigurationChanging(mActivity, /* isDisplayRotationChanging */ false); @@ -486,6 +488,19 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase { assertActivityRefreshRequested(/* refreshRequested */ false); } + @Test + public void testOnActivityConfigurationChanging_splitScreenAspectRatioAllowed_refresh() + throws Exception { + configureActivity(SCREEN_ORIENTATION_PORTRAIT); + doReturn(true).when(mActivity.mLetterboxUiController) + .isCameraCompatSplitScreenAspectRatioAllowed(); + + mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); + callOnActivityConfigurationChanging(mActivity, /* isDisplayRotationChanging */ false); + + assertActivityRefreshRequested(/* refreshRequested */ true); + } + @Test public void testOnActivityConfigurationChanging_cycleThroughStopDisabled() throws Exception { when(mLetterboxConfiguration.isCameraCompatRefreshCycleThroughStopEnabled())