From d277280626df7d8f3d08556f60519bbebbf35dfb Mon Sep 17 00:00:00 2001 From: Vali Calinescu Date: Tue, 31 Jan 2023 17:04:48 +0000 Subject: [PATCH] Add listener for "enable_compat_fake_focus" Fix: 262866240 Test: atest WmTests:LetterboxUiControllerTest Change-Id: I168825a2961a06c9ac610c7e2cd526e5dbadb1ca --- .../server/wm/LetterboxConfiguration.java | 18 +++-------- .../LetterboxConfigurationDeviceConfig.java | 18 ++++++++++- .../server/wm/LetterboxConfigurationTest.java | 32 ------------------- 3 files changed, 22 insertions(+), 46 deletions(-) diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java index 7066a330cc1b0..513667024caa6 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java +++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java @@ -20,6 +20,7 @@ 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 android.annotation.IntDef; @@ -42,10 +43,6 @@ final class LetterboxConfiguration { private static final String TAG = TAG_WITH_CLASS_NAME ? "LetterboxConfiguration" : TAG_ATM; - @VisibleForTesting - static final String DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS = - "enable_compat_fake_focus"; - /** * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with * set-fixed-orientation-letterbox-aspect-ratio or via {@link @@ -115,12 +112,6 @@ final class LetterboxConfiguration { /** Letterboxed app window is aligned to the right side. */ static final int LETTERBOX_VERTICAL_REACHABILITY_POSITION_BOTTOM = 2; - @VisibleForTesting - static final String PROPERTY_COMPAT_FAKE_FOCUS_OPT_IN = "com.android.COMPAT_FAKE_FOCUS_OPT_IN"; - @VisibleForTesting - static final String PROPERTY_COMPAT_FAKE_FOCUS_OPT_OUT = - "com.android.COMPAT_FAKE_FOCUS_OPT_OUT"; - final Context mContext; // Responsible for the persistence of letterbox[Horizontal|Vertical]PositionMultiplier @@ -317,6 +308,9 @@ final class LetterboxConfiguration { mDeviceConfig.updateFlagActiveStatus( /* isActive */ true, /* key */ KEY_ALLOW_IGNORE_ORIENTATION_REQUEST); + mDeviceConfig.updateFlagActiveStatus( + /* isActive */ mIsCompatFakeFocusEnabled, + /* key */ KEY_ENABLE_COMPAT_FAKE_FOCUS); mLetterboxConfigurationPersister = letterboxConfigurationPersister; mLetterboxConfigurationPersister.start(); @@ -1066,9 +1060,7 @@ final class LetterboxConfiguration { /** Whether fake sending focus is enabled for unfocused apps in splitscreen */ boolean isCompatFakeFocusEnabled() { - return mIsCompatFakeFocusEnabled - && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS, true); + return mIsCompatFakeFocusEnabled && mDeviceConfig.getFlag(KEY_ENABLE_COMPAT_FAKE_FOCUS); } /** diff --git a/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java b/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java index d004fa6647753..b364872e56e7f 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java +++ b/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java @@ -45,6 +45,9 @@ final class LetterboxConfigurationDeviceConfig "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; + @VisibleForTesting static final Map sKeyToDefaultValueMap = Map.of( KEY_ENABLE_CAMERA_COMPAT_TREATMENT, @@ -52,7 +55,9 @@ final class LetterboxConfigurationDeviceConfig 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 + DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST, + KEY_ENABLE_COMPAT_FAKE_FOCUS, + DEFAULT_VALUE_ENABLE_COMPAT_FAKE_FOCUS ); // Whether camera compatibility treatment is enabled. @@ -72,6 +77,11 @@ final class LetterboxConfigurationDeviceConfig 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; + // Set of active device configs that need to be updated in // DeviceConfig.OnPropertiesChangedListener#onPropertiesChanged. private final ArraySet mActiveDeviceConfigsSet = new ArraySet<>(); @@ -117,6 +127,8 @@ final class LetterboxConfigurationDeviceConfig return mIsDisplayRotationImmersiveAppCompatPolicyEnabled; case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST: return mIsAllowIgnoreOrientationRequest; + case KEY_ENABLE_COMPAT_FAKE_FOCUS: + return mIsCompatFakeFocusAllowed; default: throw new AssertionError("Unexpected flag name: " + key); } @@ -140,6 +152,10 @@ final class LetterboxConfigurationDeviceConfig mIsAllowIgnoreOrientationRequest = getDeviceConfig(key, defaultValue); break; + case KEY_ENABLE_COMPAT_FAKE_FOCUS: + mIsCompatFakeFocusAllowed = + getDeviceConfig(key, defaultValue); + break; default: throw new AssertionError("Unexpected flag name: " + key); } diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationTest.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationTest.java index 12b7c9d5e5355..e1fc0cfdc317c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationTest.java @@ -18,7 +18,6 @@ package com.android.server.wm; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; -import static com.android.server.wm.LetterboxConfiguration.DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS; 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; @@ -26,8 +25,6 @@ import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_VERTICAL_RE 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 org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -37,7 +34,6 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.platform.test.annotations.Presubmit; -import android.provider.DeviceConfig; import androidx.test.filters.SmallTest; @@ -233,34 +229,6 @@ public class LetterboxConfigurationTest { LetterboxConfiguration::movePositionForVerticalReachabilityToNextBottomStop); } - @Test - public void testIsCompatFakeFocusEnabledOnDevice() { - boolean wasFakeFocusEnabled = DeviceConfig - .getBoolean(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS, false); - - // Set runtime flag to true and build time flag to false - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS, "true", false); - mLetterboxConfiguration.setIsCompatFakeFocusEnabled(false); - assertFalse(mLetterboxConfiguration.isCompatFakeFocusEnabled()); - - // Set runtime flag to false and build time flag to true - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS, "false", false); - mLetterboxConfiguration.setIsCompatFakeFocusEnabled(true); - assertFalse(mLetterboxConfiguration.isCompatFakeFocusEnabled()); - - // Set runtime flag to true so that both are enabled - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS, "true", false); - assertTrue(mLetterboxConfiguration.isCompatFakeFocusEnabled()); - - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER, - DEVICE_CONFIG_KEY_ENABLE_COMPAT_FAKE_FOCUS, Boolean.toString(wasFakeFocusEnabled), - false); - } - private void assertForHorizontalMove(int from, int expected, int expectedTime, boolean halfFoldPose, BiConsumer move) { // We are in the current position