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

Commit 711ccaae authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "Creates Flags for Letterbox blurred wallpaper background" into main

parents 037dfad7 51a5a076
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line 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 Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.Slog;


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


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
@@ -90,13 +91,6 @@ final class LetterboxConfiguration {
            "enable_app_compat_user_aspect_ratio_fullscreen";
            "enable_app_compat_user_aspect_ratio_fullscreen";
    private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN = true;
    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
     * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with
     * set-fixed-orientation-letterbox-aspect-ratio or via {@link
     * set-fixed-orientation-letterbox-aspect-ratio or via {@link
@@ -185,6 +179,9 @@ final class LetterboxConfiguration {
    @NonNull
    @NonNull
    private final LetterboxConfigurationPersister mLetterboxConfigurationPersister;
    private final LetterboxConfigurationPersister mLetterboxConfigurationPersister;


    @NonNull
    private final FeatureFlags mFeatureFlags;

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


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


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

        mFeatureFlags = featureFags;
        mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
        mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
                R.dimen.config_fixedOrientationLetterboxAspectRatio);
                R.dimen.config_fixedOrientationLetterboxAspectRatio);
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
@@ -385,8 +385,6 @@ final class LetterboxConfiguration {
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS,
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS,
                        mContext.getResources().getBoolean(
                        mContext.getResources().getBoolean(
                                R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled))
                                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,
                .addDeviceConfigEntry(KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
                        mContext.getResources().getBoolean(
                        mContext.getResources().getBoolean(
@@ -544,8 +542,7 @@ final class LetterboxConfiguration {
    }
    }


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


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


+3 −2
Original line number Original line 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_MISSING_WINDOW;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_NOT_VISIBLE_ON_SCREEN;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_NOT_VISIBLE_ON_SCREEN;
import static android.window.WindowProviderService.isWindowProviderService;
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_ADD_REMOVE;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ANIM;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ANIM;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_BOOT;
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.policy.WindowManagerPolicy.ScreenOffListener;
import com.android.server.power.ShutdownThread;
import com.android.server.power.ShutdownThread;
import com.android.server.utils.PriorityDump;
import com.android.server.utils.PriorityDump;
import com.android.window.flags.FeatureFlagsImpl;


import dalvik.annotation.optimization.NeverCompile;
import dalvik.annotation.optimization.NeverCompile;


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


        mLetterboxConfiguration = new LetterboxConfiguration(
        mLetterboxConfiguration = new LetterboxConfiguration(
                // Using SysUI context to have access to Material colors extracted from Wallpaper.
                // 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.
        mInputManager = inputManager; // Must be before createDisplayContentLocked.
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
+45 −3
Original line number Original line Diff line number Diff line
@@ -17,14 +17,15 @@
package com.android.server.wm;
package com.android.server.wm;


import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
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_CENTER;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT;
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_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_BOTTOM;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_VERTICAL_REACHABILITY_POSITION_CENTER;
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 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.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
@@ -37,6 +38,8 @@ import android.platform.test.annotations.Presubmit;


import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.window.flags.FakeFeatureFlagsImpl;

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


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


    private MutableFakeFeatureFlagsImpl mMutableFakeFeatureFlags;


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


    @Test
    @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
    @Test
    public void test_whenMovedHorizontally_updatePositionAccordingly() {
    public void test_whenMovedHorizontally_updatePositionAccordingly() {
        // Starting from center
        // Starting from center
@@ -288,4 +311,23 @@ public class LetterboxConfigurationTest {
                false /* forTabletopMode */,
                false /* forTabletopMode */,
                LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP);
                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;
        }
    }
}
}