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

Commit 51a5a076 authored by Massimo Carli's avatar Massimo Carli
Browse files

Creates Flags for Letterbox blurred wallpaper background

Creates Feature Flag for the blue background feature in
the window_manager namespace.

Adds flags dependency in source code and tests.

Fix: 296582201
Bug: 297195682
Test: atest WmTests:LetterboxConfigurationTest

Change-Id: I3cc70d3334ad96db81f12be10390b854a3fab659
parent de446e71
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
package: "com.android.window.flags"

flag {
  name: "letterbox_background_wallpaper_flag"
  namespace: "large_screen_experiences_app_compat"
  description: "Whether the letterbox wallpaper style is enabled by default"
  bug: "297195682"
}
+15 −19
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.Slog;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.FeatureFlags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -90,13 +91,6 @@ final class LetterboxConfiguration {
            "enable_app_compat_user_aspect_ratio_fullscreen";
    private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN = true;

    // Whether the letterbox wallpaper style is enabled by default
    private static final String KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER =
            "enable_letterbox_background_wallpaper";

    // TODO(b/290048978): Enable wallpaper as default letterbox background.
    private static final boolean DEFAULT_VALUE_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER = false;

    /**
     * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with
     * set-fixed-orientation-letterbox-aspect-ratio or via {@link
@@ -185,6 +179,9 @@ final class LetterboxConfiguration {
    @NonNull
    private final LetterboxConfigurationPersister mLetterboxConfigurationPersister;

    @NonNull
    private final FeatureFlags mFeatureFlags;

    // Aspect ratio of letterbox for fixed orientation, values <=
    // MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO will be ignored.
    private float mFixedOrientationLetterboxAspectRatio;
@@ -301,7 +298,8 @@ final class LetterboxConfiguration {
    // Flags dynamically updated with {@link android.provider.DeviceConfig}.
    @NonNull private final SynchedDeviceConfig mDeviceConfig;

    LetterboxConfiguration(@NonNull final Context systemUiContext) {
    LetterboxConfiguration(@NonNull final Context systemUiContext,
                           @NonNull FeatureFlags featureFags) {
        this(systemUiContext, new LetterboxConfigurationPersister(
                () -> readLetterboxHorizontalReachabilityPositionFromConfig(
                        systemUiContext, /* forBookMode */ false),
@@ -310,14 +308,16 @@ final class LetterboxConfiguration {
                () -> readLetterboxHorizontalReachabilityPositionFromConfig(
                        systemUiContext, /* forBookMode */ true),
                () -> readLetterboxVerticalReachabilityPositionFromConfig(
                        systemUiContext, /* forTabletopMode */ true)));
                        systemUiContext, /* forTabletopMode */ true)),
                featureFags);
    }

    @VisibleForTesting
    LetterboxConfiguration(@NonNull final Context systemUiContext,
            @NonNull final LetterboxConfigurationPersister letterboxConfigurationPersister) {
            @NonNull final LetterboxConfigurationPersister letterboxConfigurationPersister,
            @NonNull FeatureFlags featureFags) {
        mContext = systemUiContext;

        mFeatureFlags = featureFags;
        mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
                R.dimen.config_fixedOrientationLetterboxAspectRatio);
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
@@ -385,8 +385,6 @@ final class LetterboxConfiguration {
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS,
                        mContext.getResources().getBoolean(
                                R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled))
                .addDeviceConfigEntry(KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER,
                        DEFAULT_VALUE_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER, /* enabled */ true)
                .addDeviceConfigEntry(KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
                        mContext.getResources().getBoolean(
@@ -544,8 +542,7 @@ final class LetterboxConfiguration {
    }

    /**
     * Resets letterbox background type value depending on the
     * {@link #KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER} built time and runtime flags.
     * Resets letterbox background type value depending on the built time and runtime flags.
     *
     * <p>If enabled, the letterbox background type value is set toZ
     * {@link #LETTERBOX_BACKGROUND_WALLPAPER}. When disabled the letterbox background type value
@@ -555,12 +552,11 @@ final class LetterboxConfiguration {
        mLetterboxBackgroundTypeOverride = LETTERBOX_BACKGROUND_OVERRIDE_UNSET;
    }

    // Returns KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER if the DeviceConfig flag is enabled
    // or the value in com.android.internal.R.integer.config_letterboxBackgroundType if the flag
    // is disabled.
    // Returns LETTERBOX_BACKGROUND_WALLPAPER if the flag is enabled or the value in
    // com.android.internal.R.integer.config_letterboxBackgroundType if the flag is disabled.
    @LetterboxBackgroundType
    private int getDefaultLetterboxBackgroundType() {
        return mDeviceConfig.getFlagValue(KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER)
        return mFeatureFlags.letterboxBackgroundWallpaperFlag()
                ? LETTERBOX_BACKGROUND_WALLPAPER : mLetterboxBackgroundType;
    }

+3 −2
Original line number Diff line number Diff line
@@ -97,7 +97,6 @@ import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_MULTIPLIER;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_MISSING_WINDOW;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_NOT_VISIBLE_ON_SCREEN;
import static android.window.WindowProviderService.isWindowProviderService;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ANIM;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_BOOT;
@@ -334,6 +333,7 @@ import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowManagerPolicy.ScreenOffListener;
import com.android.server.power.ShutdownThread;
import com.android.server.utils.PriorityDump;
import com.android.window.flags.FeatureFlagsImpl;

import dalvik.annotation.optimization.NeverCompile;

@@ -1175,7 +1175,8 @@ public class WindowManagerService extends IWindowManager.Stub

        mLetterboxConfiguration = new LetterboxConfiguration(
                // Using SysUI context to have access to Material colors extracted from Wallpaper.
                ActivityThread.currentActivityThread().getSystemUiContext());
                ActivityThread.currentActivityThread().getSystemUiContext(),
                new FeatureFlagsImpl());

        mInputManager = inputManager; // Must be before createDisplayContentLocked.
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
+45 −3
Original line number Diff line number Diff line
@@ -17,14 +17,15 @@
package com.android.server.wm;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_SOLID_COLOR;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_WALLPAPER;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_CENTER;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_RIGHT;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_VERTICAL_REACHABILITY_POSITION_BOTTOM;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_VERTICAL_REACHABILITY_POSITION_CENTER;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP;

import static junit.framework.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -37,6 +38,8 @@ import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;

import com.android.window.flags.FakeFeatureFlagsImpl;

import org.junit.Before;
import org.junit.Test;

@@ -57,12 +60,16 @@ public class LetterboxConfigurationTest {
    private LetterboxConfiguration mLetterboxConfiguration;
    private LetterboxConfigurationPersister mLetterboxConfigurationPersister;

    private MutableFakeFeatureFlagsImpl mMutableFakeFeatureFlags;


    @Before
    public void setUp() throws Exception {
        mContext = getInstrumentation().getTargetContext();
        mMutableFakeFeatureFlags = new MutableFakeFeatureFlagsImpl();
        mLetterboxConfigurationPersister = mock(LetterboxConfigurationPersister.class);
        mLetterboxConfiguration = new LetterboxConfiguration(mContext,
                mLetterboxConfigurationPersister);
                mLetterboxConfigurationPersister, mMutableFakeFeatureFlags);
    }

    @Test
@@ -91,6 +98,22 @@ public class LetterboxConfigurationTest {
        }
    }

    @Test
    public void test_whenFlagEnabled_wallpaperIsDefaultBackground() {
        mMutableFakeFeatureFlags.setLetterboxBackgroundWallpaperFlag(true);
        assertEquals(LETTERBOX_BACKGROUND_WALLPAPER,
                mLetterboxConfiguration.getLetterboxBackgroundType());
        assertEquals(1, mMutableFakeFeatureFlags.getInvocationCount());
    }

    @Test
    public void test_whenFlagDisabled_solidColorIsDefaultBackground() {
        mMutableFakeFeatureFlags.setLetterboxBackgroundWallpaperFlag(false);
        assertEquals(LETTERBOX_BACKGROUND_SOLID_COLOR,
                mLetterboxConfiguration.getLetterboxBackgroundType());
        assertEquals(1, mMutableFakeFeatureFlags.getInvocationCount());
    }

    @Test
    public void test_whenMovedHorizontally_updatePositionAccordingly() {
        // Starting from center
@@ -288,4 +311,23 @@ public class LetterboxConfigurationTest {
                false /* forTabletopMode */,
                LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP);
    }

    private static class MutableFakeFeatureFlagsImpl extends FakeFeatureFlagsImpl {
        private boolean mLetterboxBackgroundWallpaperFlag;
        private int mInvocationCount;

        public void setLetterboxBackgroundWallpaperFlag(boolean letterboxBackgroundWallpaperFlag) {
            mLetterboxBackgroundWallpaperFlag = letterboxBackgroundWallpaperFlag;
        }

        @Override
        public boolean letterboxBackgroundWallpaperFlag() {
            mInvocationCount++;
            return mLetterboxBackgroundWallpaperFlag;
        }

        int getInvocationCount() {
            return mInvocationCount;
        }
    }
}