diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java index 067a18c88aaa6..cfb9534b558ea 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java +++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java @@ -18,11 +18,6 @@ package com.android.server.wm; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; -import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ALLOW_IGNORE_ORIENTATION_REQUEST; -import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ENABLE_CAMERA_COMPAT_TREATMENT; -import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ENABLE_COMPAT_FAKE_FOCUS; -import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY; -import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY; import android.annotation.IntDef; import android.annotation.NonNull; @@ -44,6 +39,45 @@ final class LetterboxConfiguration { private static final String TAG = TAG_WITH_CLASS_NAME ? "LetterboxConfiguration" : TAG_ATM; + // Whether camera compatibility treatment is enabled. + // See DisplayRotationCompatPolicy for context. + private static final String KEY_ENABLE_CAMERA_COMPAT_TREATMENT = + "enable_compat_camera_treatment"; + + private static final boolean DEFAULT_VALUE_ENABLE_CAMERA_COMPAT_TREATMENT = true; + + // Whether enabling rotation compat policy for immersive apps that prevents auto + // rotation into non-optimal screen orientation while in fullscreen. This is needed + // because immersive apps, such as games, are often not optimized for all + // orientations and can have a poor UX when rotated. Additionally, some games rely + // on sensors for the gameplay so users can trigger such rotations accidentally + // when auto rotation is on. + private static final String KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY = + "enable_display_rotation_immersive_app_compat_policy"; + + private static final boolean DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY = + true; + + // Whether ignore orientation request is allowed + private static final String KEY_ALLOW_IGNORE_ORIENTATION_REQUEST = + "allow_ignore_orientation_request"; + + private static final boolean DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST = true; + + // Whether sending compat fake focus is enabled for unfocused apps in splitscreen. + // Some game engines wait to get focus before drawing the content of the app so + // this needs to be used otherwise the apps get blacked out when they are resumed + // and do not have focus yet. + private static final String KEY_ENABLE_COMPAT_FAKE_FOCUS = "enable_compat_fake_focus"; + + private static final boolean DEFAULT_VALUE_ENABLE_COMPAT_FAKE_FOCUS = true; + + // Whether translucent activities policy is enabled + private static final String KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY = + "enable_letterbox_translucent_activity"; + + private static final boolean DEFAULT_VALUE_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY = true; + /** * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with * set-fixed-orientation-letterbox-aspect-ratio or via {@link @@ -205,26 +239,13 @@ final class LetterboxConfiguration { // unresizable apps private boolean mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox; - // Whether letterboxing strategy is enabled for translucent activities. If {@value false} - // all the feature is disabled - private boolean mTranslucentLetterboxingEnabled; - // Allows to enable letterboxing strategy for translucent activities ignoring flags. private boolean mTranslucentLetterboxingOverrideEnabled; - // Whether sending compat fake focus is enabled for unfocused apps in splitscreen. Some game - // engines wait to get focus before drawing the content of the app so this needs to be used - // otherwise the apps get blacked out when they are resumed and do not have focus yet. - private boolean mIsCompatFakeFocusEnabled; - // 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; - // Whether camera compatibility treatment is enabled. - // See DisplayRotationCompatPolicy for context. - private final boolean mIsCameraCompatTreatmentEnabled; - // Whether activity "refresh" in camera compatibility treatment is enabled. // See RefreshCallbackItem for context. private boolean mIsCameraCompatTreatmentRefreshEnabled = true; @@ -240,15 +261,8 @@ final class LetterboxConfiguration { // LetterboxUiController#shouldIgnoreRequestedOrientation for details. private final boolean mIsPolicyForIgnoringRequestedOrientationEnabled; - // Whether enabling rotation compat policy for immersive apps that prevents auto rotation - // into non-optimal screen orientation while in fullscreen. This is needed because immersive - // apps, such as games, are often not optimized for all orientations and can have a poor UX - // when rotated. Additionally, some games rely on sensors for the gameplay so users can trigger - // such rotations accidentally when auto rotation is on. - private final boolean mIsDisplayRotationImmersiveAppCompatPolicyEnabled; - // Flags dynamically updated with {@link android.provider.DeviceConfig}. - @NonNull private final LetterboxConfigurationDeviceConfig mDeviceConfig; + @NonNull private final SynchedDeviceConfig mDeviceConfig; LetterboxConfiguration(@NonNull final Context systemUiContext) { this(systemUiContext, @@ -267,7 +281,6 @@ final class LetterboxConfiguration { LetterboxConfiguration(@NonNull final Context systemUiContext, @NonNull final LetterboxConfigurationPersister letterboxConfigurationPersister) { mContext = systemUiContext; - mDeviceConfig = new LetterboxConfigurationDeviceConfig(systemUiContext.getMainExecutor()); mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat( R.dimen.config_fixedOrientationLetterboxAspectRatio); @@ -305,36 +318,34 @@ final class LetterboxConfiguration { mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox = mContext.getResources() .getBoolean(R.bool .config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled); - mTranslucentLetterboxingEnabled = mContext.getResources().getBoolean( - R.bool.config_letterboxIsEnabledForTranslucentActivities); - mIsCameraCompatTreatmentEnabled = mContext.getResources().getBoolean( - R.bool.config_isWindowManagerCameraCompatTreatmentEnabled); mIsCameraCompatSplitScreenAspectRatioEnabled = mContext.getResources().getBoolean( R.bool.config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled); - mIsCompatFakeFocusEnabled = mContext.getResources().getBoolean( - R.bool.config_isCompatFakeFocusEnabled); mIsPolicyForIgnoringRequestedOrientationEnabled = mContext.getResources().getBoolean( R.bool.config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled); - mIsDisplayRotationImmersiveAppCompatPolicyEnabled = mContext.getResources().getBoolean( - R.bool.config_letterboxIsDisplayRotationImmersiveAppCompatPolicyEnabled); - mDeviceConfig.updateFlagActiveStatus( - /* isActive */ mIsCameraCompatTreatmentEnabled, - /* key */ KEY_ENABLE_CAMERA_COMPAT_TREATMENT); - mDeviceConfig.updateFlagActiveStatus( - /* isActive */ mIsDisplayRotationImmersiveAppCompatPolicyEnabled, - /* key */ KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY); - mDeviceConfig.updateFlagActiveStatus( - /* isActive */ true, - /* key */ KEY_ALLOW_IGNORE_ORIENTATION_REQUEST); - mDeviceConfig.updateFlagActiveStatus( - /* isActive */ mIsCompatFakeFocusEnabled, - /* key */ KEY_ENABLE_COMPAT_FAKE_FOCUS); - mDeviceConfig.updateFlagActiveStatus( - /* isActive */ mTranslucentLetterboxingEnabled, - /* key */ KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY); mLetterboxConfigurationPersister = letterboxConfigurationPersister; mLetterboxConfigurationPersister.start(); + + mDeviceConfig = SynchedDeviceConfig.builder(DeviceConfig.NAMESPACE_WINDOW_MANAGER, + systemUiContext.getMainExecutor()) + .addDeviceConfigEntry(KEY_ENABLE_CAMERA_COMPAT_TREATMENT, + DEFAULT_VALUE_ENABLE_CAMERA_COMPAT_TREATMENT, + mContext.getResources().getBoolean( + R.bool.config_isWindowManagerCameraCompatTreatmentEnabled)) + .addDeviceConfigEntry(KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY, + DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY, + mContext.getResources().getBoolean(R.bool + .config_letterboxIsDisplayRotationImmersiveAppCompatPolicyEnabled)) + .addDeviceConfigEntry(KEY_ALLOW_IGNORE_ORIENTATION_REQUEST, + DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST, /* enabled */ true) + .addDeviceConfigEntry(KEY_ENABLE_COMPAT_FAKE_FOCUS, + DEFAULT_VALUE_ENABLE_COMPAT_FAKE_FOCUS, + mContext.getResources().getBoolean(R.bool.config_isCompatFakeFocusEnabled)) + .addDeviceConfigEntry(KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY, + DEFAULT_VALUE_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY, + mContext.getResources().getBoolean( + R.bool.config_letterboxIsEnabledForTranslucentActivities)) + .build(); } /** @@ -342,7 +353,7 @@ final class LetterboxConfiguration { * via {@link android.provider.DeviceConfig}. */ boolean isIgnoreOrientationRequestAllowed() { - return mDeviceConfig.getFlag(KEY_ALLOW_IGNORE_ORIENTATION_REQUEST); + return mDeviceConfig.getFlagValue(KEY_ALLOW_IGNORE_ORIENTATION_REQUEST); } /** @@ -1049,28 +1060,21 @@ final class LetterboxConfiguration { } boolean isTranslucentLetterboxingEnabled() { - return mTranslucentLetterboxingOverrideEnabled || (mTranslucentLetterboxingEnabled - && mDeviceConfig.getFlag(KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY)); - } - - void setTranslucentLetterboxingEnabled(boolean translucentLetterboxingEnabled) { - mTranslucentLetterboxingEnabled = translucentLetterboxingEnabled; + return mTranslucentLetterboxingOverrideEnabled + || mDeviceConfig.getFlagValue(KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY); } void setTranslucentLetterboxingOverrideEnabled( boolean translucentLetterboxingOverrideEnabled) { mTranslucentLetterboxingOverrideEnabled = translucentLetterboxingOverrideEnabled; - setTranslucentLetterboxingEnabled(translucentLetterboxingOverrideEnabled); } /** * Resets whether we use the constraints override strategy for letterboxing when dealing - * with translucent activities {@link R.bool.config_letterboxIsEnabledForTranslucentActivities}. + * with translucent activities + * {@link mDeviceConfig.getFlagValue(KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY)}. */ void resetTranslucentLetterboxingEnabled() { - final boolean newValue = mContext.getResources().getBoolean( - R.bool.config_letterboxIsEnabledForTranslucentActivities); - setTranslucentLetterboxingEnabled(newValue); setTranslucentLetterboxingOverrideEnabled(false); } @@ -1100,15 +1104,7 @@ final class LetterboxConfiguration { /** Whether fake sending focus is enabled for unfocused apps in splitscreen */ boolean isCompatFakeFocusEnabled() { - return mIsCompatFakeFocusEnabled && mDeviceConfig.getFlag(KEY_ENABLE_COMPAT_FAKE_FOCUS); - } - - /** - * Overrides whether fake sending focus is enabled for unfocused apps in splitscreen - */ - @VisibleForTesting - void setIsCompatFakeFocusEnabled(boolean enabled) { - mIsCompatFakeFocusEnabled = enabled; + return mDeviceConfig.getFlagValue(KEY_ENABLE_COMPAT_FAKE_FOCUS); } /** @@ -1128,10 +1124,16 @@ final class LetterboxConfiguration { return mIsCameraCompatSplitScreenAspectRatioEnabled; } - /** Whether camera compatibility treatment is enabled. */ + /** + * Whether camera compatibility treatment is enabled. + * + * @param checkDeviceConfig whether it should check both build time flag and a dynamic property + * from {@link DeviceConfig} or only build time flag value. + */ boolean isCameraCompatTreatmentEnabled(boolean checkDeviceConfig) { - return mIsCameraCompatTreatmentEnabled && (!checkDeviceConfig - || mDeviceConfig.getFlag(KEY_ENABLE_CAMERA_COMPAT_TREATMENT)); + return mDeviceConfig.isBuildTimeFlagEnabled(KEY_ENABLE_CAMERA_COMPAT_TREATMENT) + && (!checkDeviceConfig + || mDeviceConfig.getFlagValue(KEY_ENABLE_CAMERA_COMPAT_TREATMENT)); } /** Whether camera compatibility refresh is enabled. */ @@ -1183,12 +1185,14 @@ final class LetterboxConfiguration { * orientations and can have a poor UX when rotated. Additionally, some games rely on sensors * for the gameplay so users can trigger such rotations accidentally when auto rotation is on. * - * @param checkDeviceConfig whether should check both static config and a dynamic property - * from {@link DeviceConfig} or only static value. + * @param checkDeviceConfig whether it should check both build time flag and a dynamic property + * from {@link DeviceConfig} or only build time flag value. */ boolean isDisplayRotationImmersiveAppCompatPolicyEnabled(final boolean checkDeviceConfig) { - return mIsDisplayRotationImmersiveAppCompatPolicyEnabled && (!checkDeviceConfig - || mDeviceConfig.getFlag(KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY)); + return mDeviceConfig.isBuildTimeFlagEnabled( + KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY) && (!checkDeviceConfig + || mDeviceConfig.getFlagValue( + KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY)); } } diff --git a/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java b/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java deleted file mode 100644 index a739e42410a98..0000000000000 --- a/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wm; - -import android.annotation.NonNull; -import android.provider.DeviceConfig; -import android.util.ArraySet; - -import com.android.internal.annotations.VisibleForTesting; - -import java.util.Map; -import java.util.concurrent.Executor; - -/** - * Utility class that caches {@link DeviceConfig} flags for app compat features and listens - * to updates by implementing {@link DeviceConfig.OnPropertiesChangedListener}. - */ -final class LetterboxConfigurationDeviceConfig - implements DeviceConfig.OnPropertiesChangedListener { - - static final String KEY_ENABLE_CAMERA_COMPAT_TREATMENT = "enable_compat_camera_treatment"; - private static final boolean DEFAULT_VALUE_ENABLE_CAMERA_COMPAT_TREATMENT = true; - - static final String KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY = - "enable_display_rotation_immersive_app_compat_policy"; - private static final boolean DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY = - true; - - static final String KEY_ALLOW_IGNORE_ORIENTATION_REQUEST = - "allow_ignore_orientation_request"; - private static final boolean DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST = true; - - static final String KEY_ENABLE_COMPAT_FAKE_FOCUS = "enable_compat_fake_focus"; - private static final boolean DEFAULT_VALUE_ENABLE_COMPAT_FAKE_FOCUS = true; - - static final String KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY = - "enable_letterbox_translucent_activity"; - - private static final boolean DEFAULT_VALUE_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY = true; - - @VisibleForTesting - static final Map sKeyToDefaultValueMap = Map.of( - KEY_ENABLE_CAMERA_COMPAT_TREATMENT, - DEFAULT_VALUE_ENABLE_CAMERA_COMPAT_TREATMENT, - KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY, - DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY, - KEY_ALLOW_IGNORE_ORIENTATION_REQUEST, - DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST, - KEY_ENABLE_COMPAT_FAKE_FOCUS, - DEFAULT_VALUE_ENABLE_COMPAT_FAKE_FOCUS, - KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY, - DEFAULT_VALUE_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY - ); - - // Whether camera compatibility treatment is enabled. - // See DisplayRotationCompatPolicy for context. - private boolean mIsCameraCompatTreatmentEnabled = - DEFAULT_VALUE_ENABLE_CAMERA_COMPAT_TREATMENT; - - // Whether enabling rotation compat policy for immersive apps that prevents auto rotation - // into non-optimal screen orientation while in fullscreen. This is needed because immersive - // apps, such as games, are often not optimized for all orientations and can have a poor UX - // when rotated. Additionally, some games rely on sensors for the gameplay so users can trigger - // such rotations accidentally when auto rotation is on. - private boolean mIsDisplayRotationImmersiveAppCompatPolicyEnabled = - DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY; - - // Whether enabling ignoreOrientationRequest is allowed on the device. - private boolean mIsAllowIgnoreOrientationRequest = - DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST; - - // Whether sending compat fake focus for split screen resumed activities is enabled. This is - // needed because some game engines wait to get focus before drawing the content of the app - // which isn't guaranteed by default in multi-window modes. - private boolean mIsCompatFakeFocusAllowed = DEFAULT_VALUE_ENABLE_COMPAT_FAKE_FOCUS; - - // Whether the letterbox strategy for transparent activities is allowed - private boolean mIsTranslucentLetterboxingAllowed = - DEFAULT_VALUE_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY; - - // Set of active device configs that need to be updated in - // DeviceConfig.OnPropertiesChangedListener#onPropertiesChanged. - private final ArraySet mActiveDeviceConfigsSet = new ArraySet<>(); - - LetterboxConfigurationDeviceConfig(@NonNull final Executor executor) { - DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - executor, /* onPropertiesChangedListener */ this); - } - - @Override - public void onPropertiesChanged(@NonNull final DeviceConfig.Properties properties) { - for (int i = mActiveDeviceConfigsSet.size() - 1; i >= 0; i--) { - String key = mActiveDeviceConfigsSet.valueAt(i); - // Reads the new configuration, if the device config properties contain the key. - if (properties.getKeyset().contains(key)) { - readAndSaveValueFromDeviceConfig(key); - } - } - } - - /** - * Adds {@code key} to a set of flags that can be updated from the server if - * {@code isActive} is {@code true} and read it's current value from {@link DeviceConfig}. - */ - void updateFlagActiveStatus(boolean isActive, String key) { - if (!isActive) { - return; - } - mActiveDeviceConfigsSet.add(key); - readAndSaveValueFromDeviceConfig(key); - } - - /** - * Returns values of the {@code key} flag. - * - * @throws AssertionError {@code key} isn't recognised. - */ - boolean getFlag(String key) { - switch (key) { - case KEY_ENABLE_CAMERA_COMPAT_TREATMENT: - return mIsCameraCompatTreatmentEnabled; - case KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY: - return mIsDisplayRotationImmersiveAppCompatPolicyEnabled; - case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST: - return mIsAllowIgnoreOrientationRequest; - case KEY_ENABLE_COMPAT_FAKE_FOCUS: - return mIsCompatFakeFocusAllowed; - case KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY: - return mIsTranslucentLetterboxingAllowed; - default: - throw new AssertionError("Unexpected flag name: " + key); - } - } - - private void readAndSaveValueFromDeviceConfig(String key) { - Boolean defaultValue = sKeyToDefaultValueMap.get(key); - if (defaultValue == null) { - throw new AssertionError("Haven't found default value for flag: " + key); - } - switch (key) { - case KEY_ENABLE_CAMERA_COMPAT_TREATMENT: - mIsCameraCompatTreatmentEnabled = getDeviceConfig(key, defaultValue); - break; - case KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY: - mIsDisplayRotationImmersiveAppCompatPolicyEnabled = - getDeviceConfig(key, defaultValue); - break; - case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST: - mIsAllowIgnoreOrientationRequest = getDeviceConfig(key, defaultValue); - break; - case KEY_ENABLE_COMPAT_FAKE_FOCUS: - mIsCompatFakeFocusAllowed = getDeviceConfig(key, defaultValue); - break; - case KEY_ENABLE_LETTERBOX_TRANSLUCENT_ACTIVITY: - mIsTranslucentLetterboxingAllowed = getDeviceConfig(key, defaultValue); - break; - default: - throw new AssertionError("Unexpected flag name: " + key); - } - } - - private boolean getDeviceConfig(String key, boolean defaultValue) { - return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - key, defaultValue); - } -} diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationDeviceConfigTests.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationDeviceConfigTests.java deleted file mode 100644 index 2b7a06bd35f3f..0000000000000 --- a/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationDeviceConfigTests.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wm; - -import static com.android.server.wm.LetterboxConfigurationDeviceConfig.sKeyToDefaultValueMap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import android.platform.test.annotations.Presubmit; -import android.provider.DeviceConfig; - -import androidx.test.filters.SmallTest; - -import com.android.modules.utils.testing.TestableDeviceConfig; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import java.util.Map; - -/** - * Test class for {@link LetterboxConfigurationDeviceConfig}. - * - * atest WmTests:LetterboxConfigurationDeviceConfigTests - */ -@SmallTest -@Presubmit -public class LetterboxConfigurationDeviceConfigTests { - - private LetterboxConfigurationDeviceConfig mDeviceConfig; - - @Rule - public final TestableDeviceConfig.TestableDeviceConfigRule - mDeviceConfigRule = new TestableDeviceConfig.TestableDeviceConfigRule(); - - @Before - public void setUp() { - mDeviceConfig = new LetterboxConfigurationDeviceConfig(/* executor */ Runnable::run); - } - - @Test - public void testGetFlag_flagIsActive_flagChanges() throws Throwable { - for (Map.Entry entry : sKeyToDefaultValueMap.entrySet()) { - testGetFlagForKey_flagIsActive_flagChanges(entry.getKey(), entry.getValue()); - } - } - - private void testGetFlagForKey_flagIsActive_flagChanges(final String key, boolean defaultValue) - throws InterruptedException { - mDeviceConfig.updateFlagActiveStatus(/* isActive */ true, key); - - assertEquals("Unexpected default value for " + key, - mDeviceConfig.getFlag(key), defaultValue); - - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, key, - /* value */ Boolean.TRUE.toString(), /* makeDefault */ false); - - assertTrue("Flag " + key + "is not true after change", mDeviceConfig.getFlag(key)); - - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, key, - /* value */ Boolean.FALSE.toString(), /* makeDefault */ false); - - assertFalse("Flag " + key + "is not false after change", mDeviceConfig.getFlag(key)); - } - - @Test - public void testGetFlag_flagIsNotActive_alwaysReturnDefaultValue() throws Throwable { - for (Map.Entry entry : sKeyToDefaultValueMap.entrySet()) { - testGetFlagForKey_flagIsNotActive_alwaysReturnDefaultValue( - entry.getKey(), entry.getValue()); - } - } - - private void testGetFlagForKey_flagIsNotActive_alwaysReturnDefaultValue(final String key, - boolean defaultValue) throws InterruptedException { - assertEquals("Unexpected default value for " + key, - mDeviceConfig.getFlag(key), defaultValue); - - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, key, - /* value */ Boolean.TRUE.toString(), /* makeDefault */ false); - - assertEquals("Flag " + key + "is not set to default after change", - mDeviceConfig.getFlag(key), defaultValue); - - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, key, - /* value */ Boolean.FALSE.toString(), /* makeDefault */ false); - - assertEquals("Flag " + key + "is not set to default after change", - mDeviceConfig.getFlag(key), defaultValue); - } - -}