Merge "[3/n] Improve LetterboxConfiguration readability" into udc-qpr-dev

This commit is contained in:
Massimo Carli
2023-06-16 13:12:49 +00:00
committed by Android (Google) Code Review
8 changed files with 75 additions and 64 deletions

View File

@@ -1214,8 +1214,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mDisplayRotationCompatPolicy =
// Not checking DeviceConfig value here to allow enabling via DeviceConfig
// without the need to restart the device.
mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ false)
mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabledAtBuildTime()
? new DisplayRotationCompatPolicy(this) : null;
mRotationReversionController = new DisplayRotationReversionController(this);

View File

@@ -336,8 +336,7 @@ final class DisplayRotationCompatPolicy {
* </ul>
*/
private boolean isTreatmentEnabledForDisplay() {
return mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ true)
return mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled()
&& mDisplayContent.getIgnoreOrientationRequest()
// TODO(b/225928882): Support camera compat rotation for external displays
&& mDisplayContent.getDisplay().getType() == TYPE_INTERNAL;

View File

@@ -44,7 +44,7 @@ final class DisplayRotationImmersiveAppCompatPolicy {
@NonNull final DisplayRotation displayRotation,
@NonNull final DisplayContent displayContent) {
if (!letterboxConfiguration
.isDisplayRotationImmersiveAppCompatPolicyEnabled(/* checkDeviceConfig */ false)) {
.isDisplayRotationImmersiveAppCompatPolicyEnabledAtBuildTime()) {
return null;
}
@@ -87,8 +87,7 @@ final class DisplayRotationImmersiveAppCompatPolicy {
* @return {@code true}, if there is a need to lock screen rotation, {@code false} otherwise.
*/
boolean isRotationLockEnforced(@Surface.Rotation final int proposedRotation) {
if (!mLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled(
/* checkDeviceConfig */ true)) {
if (!mLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled()) {
return false;
}
synchronized (mDisplayContent.mWmService.mGlobalLock) {

View File

@@ -1125,15 +1125,19 @@ final class LetterboxConfiguration {
}
/**
* 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.
* @return Whether camera compatibility treatment is currently enabled.
*/
boolean isCameraCompatTreatmentEnabled(boolean checkDeviceConfig) {
return mDeviceConfig.isBuildTimeFlagEnabled(KEY_ENABLE_CAMERA_COMPAT_TREATMENT)
&& (!checkDeviceConfig
|| mDeviceConfig.getFlagValue(KEY_ENABLE_CAMERA_COMPAT_TREATMENT));
boolean isCameraCompatTreatmentEnabled() {
return mDeviceConfig.getFlagValue(KEY_ENABLE_CAMERA_COMPAT_TREATMENT);
}
/**
* @return Whether camera compatibility treatment is enabled at build time. This is used when
* we need to safely initialize a component before the {@link DeviceConfig} flag value is
* available.
*/
boolean isCameraCompatTreatmentEnabledAtBuildTime() {
return mDeviceConfig.isBuildTimeFlagEnabled(KEY_ENABLE_CAMERA_COMPAT_TREATMENT);
}
/** Whether camera compatibility refresh is enabled. */
@@ -1179,20 +1183,28 @@ final class LetterboxConfiguration {
/**
* Checks whether rotation compat policy for immersive apps that prevents auto rotation
* into non-optimal screen orientation while in fullscreen is enabled.
* into non-optimal screen orientation while in fullscreen is enabled at build time. This is
* used when we need to safely initialize a component before the {@link DeviceConfig} flag
* value is available.
*
* <p>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.
*
* @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) {
boolean isDisplayRotationImmersiveAppCompatPolicyEnabledAtBuildTime() {
return mDeviceConfig.isBuildTimeFlagEnabled(
KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY) && (!checkDeviceConfig
|| mDeviceConfig.getFlagValue(
KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY));
KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY);
}
/**
* Checks whether rotation compat policy for immersive apps that prevents auto rotation
* into non-optimal screen orientation while in fullscreen is currently enabled.
*
* <p>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.
*/
boolean isDisplayRotationImmersiveAppCompatPolicyEnabled() {
return mDeviceConfig.getFlagValue(KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY);
}
}

View File

@@ -294,18 +294,15 @@ final class LetterboxUiController {
PROPERTY_COMPAT_ENABLE_FAKE_FOCUS);
mBooleanPropertyCameraCompatAllowForceRotation =
readComponentProperty(packageManager, mActivityRecord.packageName,
() -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ true),
() -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(),
PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION);
mBooleanPropertyCameraCompatAllowRefresh =
readComponentProperty(packageManager, mActivityRecord.packageName,
() -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ true),
() -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(),
PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH);
mBooleanPropertyCameraCompatEnableRefreshViaPause =
readComponentProperty(packageManager, mActivityRecord.packageName,
() -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ true),
() -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(),
PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE);
mBooleanPropertyAllowOrientationOverride =
@@ -697,7 +694,7 @@ final class LetterboxUiController {
boolean shouldRefreshActivityForCameraCompat() {
return shouldEnableWithOptOutOverrideAndProperty(
/* gatingCondition */ () -> mLetterboxConfiguration
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true),
.isCameraCompatTreatmentEnabled(),
mIsOverrideCameraCompatDisableRefreshEnabled,
mBooleanPropertyCameraCompatAllowRefresh);
}
@@ -719,7 +716,7 @@ final class LetterboxUiController {
boolean shouldRefreshActivityViaPauseForCameraCompat() {
return shouldEnableWithOverrideAndProperty(
/* gatingCondition */ () -> mLetterboxConfiguration
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true),
.isCameraCompatTreatmentEnabled(),
mIsOverrideCameraCompatEnableRefreshViaPauseEnabled,
mBooleanPropertyCameraCompatEnableRefreshViaPause);
}
@@ -738,7 +735,7 @@ final class LetterboxUiController {
boolean shouldForceRotateForCameraCompat() {
return shouldEnableWithOptOutOverrideAndProperty(
/* gatingCondition */ () -> mLetterboxConfiguration
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true),
.isCameraCompatTreatmentEnabled(),
mIsOverrideCameraCompatDisableForceRotationEnabled,
mBooleanPropertyCameraCompatAllowForceRotation);
}

View File

@@ -103,8 +103,7 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
public void setUp() throws Exception {
mLetterboxConfiguration = mDisplayContent.mWmService.mLetterboxConfiguration;
spyOn(mLetterboxConfiguration);
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ anyBoolean()))
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled())
.thenReturn(true);
when(mLetterboxConfiguration.isCameraCompatRefreshEnabled())
.thenReturn(true);
@@ -177,8 +176,7 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
@Test
public void testOnScreenRotationAnimationFinished_treatmentNotEnabled_doNotShowToast() {
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ anyBoolean()))
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled())
.thenReturn(false);
spyOn(mDisplayRotationCompatPolicy);
@@ -238,8 +236,7 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
@Test
public void testTreatmentNotEnabled_noForceRotationOrRefresh() throws Exception {
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ anyBoolean()))
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled())
.thenReturn(false);
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
@@ -253,8 +250,7 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
@Test
public void testTreatmentDisabledViaDeviceConfig_noForceRotationOrRefresh() throws Exception {
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
/* checkDeviceConfig */ true))
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled())
.thenReturn(false);
configureActivity(SCREEN_ORIENTATION_PORTRAIT);

View File

@@ -31,7 +31,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import android.platform.test.annotations.Presubmit;
import android.view.Surface;
@@ -79,8 +78,11 @@ public class DisplayRotationImmersiveAppCompatPolicyTests extends WindowTestsBas
when(mDisplayContent.getIgnoreOrientationRequest()).thenReturn(true);
mMockLetterboxConfiguration = mock(LetterboxConfiguration.class);
when(mMockLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled(
/* checkDeviceConfig */ anyBoolean())).thenReturn(true);
when(mMockLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled())
.thenReturn(true);
when(mMockLetterboxConfiguration
.isDisplayRotationImmersiveAppCompatPolicyEnabledAtBuildTime())
.thenReturn(true);
mPolicy = DisplayRotationImmersiveAppCompatPolicy.createIfNeeded(
mMockLetterboxConfiguration, createDisplayRotationMock(),
@@ -204,8 +206,8 @@ public class DisplayRotationImmersiveAppCompatPolicyTests extends WindowTestsBas
@Test
public void testRotationChoiceEnforcedOnly_featureFlagDisabled_lockNotEnforced() {
when(mMockLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled(
/* checkDeviceConfig */ true)).thenReturn(false);
when(mMockLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled())
.thenReturn(false);
assertIsRotationLockEnforcedReturnsFalseForAllRotations();
}

View File

@@ -63,7 +63,6 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
@@ -147,7 +146,9 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@Test
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_REQUESTED_ORIENTATION})
public void testShouldIgnoreRequestedOrientation_cameraCompatTreatment_returnsTrue() {
doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(anyBoolean());
doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled();
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabledAtBuildTime();
// Recreate DisplayContent with DisplayRotationCompatPolicy
mActivity = setUpActivityWithComponent();
@@ -306,7 +307,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@Test
public void testShouldRefreshActivityForCameraCompat_flagIsDisabled_returnsFalse() {
doReturn(false).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
assertFalse(mController.shouldRefreshActivityForCameraCompat());
}
@@ -315,7 +316,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH})
public void testShouldRefreshActivityForCameraCompat_overrideEnabled_returnsFalse() {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
assertFalse(mController.shouldRefreshActivityForCameraCompat());
}
@@ -325,7 +326,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldRefreshActivityForCameraCompat_propertyIsTrueAndOverride_returnsFalse()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH, /* value */ true);
mController = new LetterboxUiController(mWm, mActivity);
@@ -337,7 +338,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldRefreshActivityForCameraCompat_propertyIsFalse_returnsFalse()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH, /* value */ false);
mController = new LetterboxUiController(mWm, mActivity);
@@ -349,7 +350,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldRefreshActivityForCameraCompat_propertyIsTrue_returnsTrue()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH, /* value */ true);
mController = new LetterboxUiController(mWm, mActivity);
@@ -363,7 +364,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE})
public void testShouldRefreshActivityViaPauseForCameraCompat_flagIsDisabled_returnsFalse() {
doReturn(false).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
assertFalse(mController.shouldRefreshActivityViaPauseForCameraCompat());
}
@@ -372,7 +373,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE})
public void testShouldRefreshActivityViaPauseForCameraCompat_overrideEnabled_returnsTrue() {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
assertTrue(mController.shouldRefreshActivityViaPauseForCameraCompat());
}
@@ -382,7 +383,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldRefreshActivityViaPauseForCameraCompat_propertyIsFalseAndOverride_returnFalse()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE, /* value */ false);
mController = new LetterboxUiController(mWm, mActivity);
@@ -394,7 +395,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldRefreshActivityViaPauseForCameraCompat_propertyIsTrue_returnsTrue()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE, /* value */ true);
mController = new LetterboxUiController(mWm, mActivity);
@@ -407,7 +408,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@Test
public void testShouldForceRotateForCameraCompat_flagIsDisabled_returnsFalse() {
doReturn(false).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
assertFalse(mController.shouldForceRotateForCameraCompat());
}
@@ -416,7 +417,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION})
public void testShouldForceRotateForCameraCompat_overrideEnabled_returnsFalse() {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
assertFalse(mController.shouldForceRotateForCameraCompat());
}
@@ -426,7 +427,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldForceRotateForCameraCompat_propertyIsTrueAndOverride_returnsFalse()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION, /* value */ true);
mController = new LetterboxUiController(mWm, mActivity);
@@ -438,7 +439,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldForceRotateForCameraCompat_propertyIsFalse_returnsFalse()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION, /* value */ false);
mController = new LetterboxUiController(mWm, mActivity);
@@ -450,7 +451,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
public void testShouldForceRotateForCameraCompat_propertyIsTrue_returnsTrue()
throws Exception {
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true);
.isCameraCompatTreatmentEnabled();
mockThatProperty(PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION, /* value */ true);
mController = new LetterboxUiController(mWm, mActivity);
@@ -741,7 +742,9 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT,
OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA})
public void testOverrideOrientationIfNeeded_whenCameraNotActive_returnsUnchanged() {
doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(anyBoolean());
doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled();
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabledAtBuildTime();
// Recreate DisplayContent with DisplayRotationCompatPolicy
mActivity = setUpActivityWithComponent();
@@ -759,7 +762,9 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT,
OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA})
public void testOverrideOrientationIfNeeded_whenCameraActive_returnsPortrait() {
doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(anyBoolean());
doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled();
doReturn(true).when(mLetterboxConfiguration)
.isCameraCompatTreatmentEnabledAtBuildTime();
// Recreate DisplayContent with DisplayRotationCompatPolicy
mActivity = setUpActivityWithComponent();
@@ -1060,7 +1065,9 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
@Test
public void testgetFixedOrientationLetterboxAspectRatio_splitScreenAspectEnabled() {
doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(anyBoolean());
.isCameraCompatTreatmentEnabled();
doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
.isCameraCompatTreatmentEnabledAtBuildTime();
doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
.isCameraCompatSplitScreenAspectRatioEnabled();
doReturn(false).when(mActivity.mWmService.mLetterboxConfiguration)