Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c32253a authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Compute config based on original override for inherited letterbox

In shell transition, the relative display rotation between parent
will be used as the transform of surface (see WindowContainer
#updateSurfacePosition). Anyway, the original full config contains
too many unrelated non-undefined config fields, which may not be
needed to be the override.

By updating requested override configuration of transparent activity
directly, it won't mis-request unnecessary override fields. Such
as inconsistent max bounds can also be fixed by the way.

Fix: 276711259
Test: SizeCompatTests#testApplyStrategyToTranslucentActivities \
      RetainsWindowConfigurationProperties
Test: adb shell wm set-letterbox-style \
      --isTranslucentLetterboxingEnabled 1
      adb shell cmd window set-ignore-orientation-request 1
      Launch a fixed orientation opaque activity and then
      a translucent activity in the same task. Rotate display.
Change-Id: Iae4347036f98de345d7d8a367ceb5121974d39f7
parent ebba1751
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -1597,11 +1597,10 @@ final class LetterboxUiController {
        inheritConfiguration(firstOpaqueActivityBeneath);
        mLetterboxConfigListener = WindowContainer.overrideConfigurationPropagation(
                mActivityRecord, firstOpaqueActivityBeneath,
                (opaqueConfig, transparentConfig) -> {
                    final Configuration mutatedConfiguration =
                            fromOriginalTranslucentConfig(transparentConfig);
                (opaqueConfig, transparentOverrideConfig) -> {
                    resetTranslucentOverrideConfig(transparentOverrideConfig);
                    final Rect parentBounds = parent.getWindowConfiguration().getBounds();
                    final Rect bounds = mutatedConfiguration.windowConfiguration.getBounds();
                    final Rect bounds = transparentOverrideConfig.windowConfiguration.getBounds();
                    final Rect letterboxBounds = opaqueConfig.windowConfiguration.getBounds();
                    // We cannot use letterboxBounds directly here because the position relies on
                    // letterboxing. Using letterboxBounds directly, would produce a double offset.
@@ -1610,9 +1609,9 @@ final class LetterboxUiController {
                            parentBounds.top + letterboxBounds.height());
                    // We need to initialize appBounds to avoid NPE. The actual value will
                    // be set ahead when resolving the Configuration for the activity.
                    mutatedConfiguration.windowConfiguration.setAppBounds(new Rect());
                    transparentOverrideConfig.windowConfiguration.setAppBounds(new Rect());
                    inheritConfiguration(firstOpaqueActivityBeneath);
                    return mutatedConfiguration;
                    return transparentOverrideConfig;
                });
    }

@@ -1691,20 +1690,16 @@ final class LetterboxUiController {
                true /* traverseTopToBottom */));
    }

    // When overriding translucent activities configuration we need to keep some of the
    // original properties
    private Configuration fromOriginalTranslucentConfig(Configuration translucentConfig) {
        final Configuration configuration = new Configuration(translucentConfig);
    /** Resets the screen size related fields so they can be resolved by requested bounds later. */
    private static void resetTranslucentOverrideConfig(Configuration config) {
        // The values for the following properties will be defined during the configuration
        // resolution in {@link ActivityRecord#resolveOverrideConfiguration} using the
        // properties inherited from the first not finishing opaque activity beneath.
        configuration.orientation = ORIENTATION_UNDEFINED;
        configuration.screenWidthDp = configuration.compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
        configuration.screenHeightDp =
                configuration.compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
        configuration.smallestScreenWidthDp =
                configuration.compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
        return configuration;
        config.orientation = ORIENTATION_UNDEFINED;
        config.screenWidthDp = config.compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
        config.screenHeightDp = config.compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
        config.smallestScreenWidthDp = config.compatSmallestScreenWidthDp =
                SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
    }

    private void inheritConfiguration(ActivityRecord firstOpaque) {
+1 −1
Original line number Diff line number Diff line
@@ -4047,7 +4047,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                final Configuration mergedConfiguration =
                        configurationMerger != null
                                ? configurationMerger.merge(mergedOverrideConfig,
                                receiver.getConfiguration())
                                        receiver.getRequestedOverrideConfiguration())
                                : supplier.getConfiguration();
                receiver.onRequestedOverrideConfigurationChanged(mergedConfiguration);
            }
+12 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ROTATION_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
@@ -428,20 +429,24 @@ public class SizeCompatTests extends WindowTestsBase {
                .setLaunchedFromUid(mActivity.getUid())
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        WindowConfiguration translucentWinConf = translucentActivity.getWindowConfiguration();
        translucentActivity.setActivityType(ACTIVITY_TYPE_STANDARD);
        translucentActivity.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW);
        translucentActivity.setDisplayWindowingMode(WINDOWING_MODE_MULTI_WINDOW);
        translucentActivity.setAlwaysOnTop(true);
        final Configuration requestedConfig =
                translucentActivity.getRequestedOverrideConfiguration();
        final WindowConfiguration translucentWinConf = requestedConfig.windowConfiguration;
        translucentWinConf.setActivityType(ACTIVITY_TYPE_STANDARD);
        translucentWinConf.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW);
        translucentWinConf.setDisplayWindowingMode(WINDOWING_MODE_MULTI_WINDOW);
        translucentWinConf.setAlwaysOnTop(true);
        translucentActivity.onRequestedOverrideConfigurationChanged(requestedConfig);

        mTask.addChild(translucentActivity);

        // We check the WIndowConfiguration properties
        translucentWinConf = translucentActivity.getWindowConfiguration();
        // The original override of WindowConfiguration should keep.
        assertEquals(ACTIVITY_TYPE_STANDARD, translucentActivity.getActivityType());
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, translucentWinConf.getWindowingMode());
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, translucentWinConf.getDisplayWindowingMode());
        assertTrue(translucentWinConf.isAlwaysOnTop());
        // Unless display is going to be rotated, it should always inherit from parent.
        assertEquals(ROTATION_UNDEFINED, translucentWinConf.getDisplayRotation());
    }

    @Test