Merge "[7/n] Camera Compat: Split screen aspect ratio for resizeable activities" into tm-qpr-dev

This commit is contained in:
Mariia Sandrikova
2023-03-24 12:29:22 +00:00
committed by Android (Google) Code Review
6 changed files with 87 additions and 20 deletions

View File

@@ -5422,6 +5422,10 @@
split screen. -->
<bool name="config_isWindowManagerCameraCompatTreatmentEnabled">false</bool>
<!-- Whether should use split screen aspect ratio for the activity when camera compat treatment
is enabled and activity is connected to the camera in fullscreen. -->
<bool name="config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled">false</bool>
<!-- Whether a camera compat controller is enabled to allow the user to apply or revert
treatment for stretched issues in camera viewfinder. -->
<bool name="config_isCameraCompatControlForStretchedIssuesEnabled">false</bool>

View File

@@ -4489,6 +4489,7 @@
<java-symbol type="bool" name="config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled" />
<java-symbol type="bool" name="config_isCompatFakeFocusEnabled" />
<java-symbol type="bool" name="config_isWindowManagerCameraCompatTreatmentEnabled" />
<java-symbol type="bool" name="config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled" />
<java-symbol type="bool" name="config_isCameraCompatControlForStretchedIssuesEnabled" />
<java-symbol type="bool" name="config_hideDisplayCutoutWithDisplayArea" />

View File

@@ -378,10 +378,7 @@ final class DisplayRotationCompatPolicy {
// Checking whether an activity in fullscreen rather than the task as this camera
// compat treatment doesn't cover activity embedding.
if (topActivity.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) {
if (topActivity.mLetterboxUiController
.isOverrideOrientationOnlyForCameraEnabled()) {
topActivity.recomputeConfiguration();
}
topActivity.mLetterboxUiController.recomputeConfigurationForCameraCompatIfNeeded();
mDisplayContent.updateOrientation();
return;
}
@@ -447,9 +444,7 @@ final class DisplayRotationCompatPolicy {
|| topActivity.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) {
return;
}
if (topActivity.mLetterboxUiController.isOverrideOrientationOnlyForCameraEnabled()) {
topActivity.recomputeConfiguration();
}
topActivity.mLetterboxUiController.recomputeConfigurationForCameraCompatIfNeeded();
mDisplayContent.updateOrientation();
}
}

View File

@@ -212,6 +212,10 @@ final class LetterboxConfiguration {
// otherwise the apps get blacked out when they are resumed and do not have focus yet.
private boolean mIsCompatFakeFocusEnabled;
// Whether 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;
@@ -300,6 +304,8 @@ final class LetterboxConfiguration {
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(
@@ -1122,6 +1128,14 @@ final class LetterboxConfiguration {
return mIsPolicyForIgnoringRequestedOrientationEnabled;
}
/**
* Whether should use split screen aspect ratio for the activity when camera compat treatment
* is enabled and activity is connected to the camera in fullscreen.
*/
boolean isCameraCompatSplitScreenAspectRatioEnabled() {
return mIsCameraCompatSplitScreenAspectRatioEnabled;
}
/** Whether camera compatibility treatment is enabled. */
boolean isCameraCompatTreatmentEnabled(boolean checkDeviceConfig) {
return mIsCameraCompatTreatmentEnabled && (!checkDeviceConfig

View File

@@ -398,13 +398,7 @@ final class LetterboxUiController {
+ mActivityRecord);
return true;
}
DisplayContent displayContent = mActivityRecord.mDisplayContent;
if (displayContent == null) {
return false;
}
if (displayContent.mDisplayRotationCompatPolicy != null
&& displayContent.mDisplayRotationCompatPolicy
.isTreatmentEnabledForActivity(mActivityRecord)) {
if (isCameraCompatTreatmentActive()) {
Slog.w(TAG, "Ignoring orientation update to "
+ screenOrientationToString(requestedOrientation)
+ " due to camera compat treatment for " + mActivityRecord);
@@ -642,6 +636,16 @@ final class LetterboxUiController {
mBooleanPropertyCameraCompatAllowForceRotation);
}
private boolean isCameraCompatTreatmentActive() {
DisplayContent displayContent = mActivityRecord.mDisplayContent;
if (displayContent == null) {
return false;
}
return displayContent.mDisplayRotationCompatPolicy != null
&& displayContent.mDisplayRotationCompatPolicy
.isTreatmentEnabledForActivity(mActivityRecord);
}
private boolean isCompatChangeEnabled(long overrideChangeId) {
return mActivityRecord.info.isChangeEnabled(overrideChangeId);
}
@@ -904,13 +908,35 @@ final class LetterboxUiController {
}
float getFixedOrientationLetterboxAspectRatio(@NonNull Configuration parentConfiguration) {
// Don't resize to split screen size when half folded if letterbox position is centered
return shouldUseSplitScreenAspectRatio(parentConfiguration)
? getSplitScreenAspectRatio()
: mActivityRecord.shouldCreateCompatDisplayInsets()
? getDefaultMinAspectRatioForUnresizableApps()
: getDefaultMinAspectRatio();
}
void recomputeConfigurationForCameraCompatIfNeeded() {
if (isOverrideOrientationOnlyForCameraEnabled()
|| isCameraCompatSplitScreenAspectRatioAllowed()) {
mActivityRecord.recomputeConfiguration();
}
}
/**
* Whether we use split screen aspect ratio for the activity when camera compat treatment
* is active because the corresponding config is enabled and activity supports resizing.
*/
private boolean isCameraCompatSplitScreenAspectRatioAllowed() {
return mLetterboxConfiguration.isCameraCompatSplitScreenAspectRatioEnabled()
&& !mActivityRecord.shouldCreateCompatDisplayInsets();
}
private boolean shouldUseSplitScreenAspectRatio(@NonNull Configuration parentConfiguration) {
return isDisplayFullScreenAndSeparatingHinge()
&& getHorizontalPositionMultiplier(parentConfiguration) != 0.5f
? getSplitScreenAspectRatio()
: mActivityRecord.shouldCreateCompatDisplayInsets()
? getDefaultMinAspectRatioForUnresizableApps()
: getDefaultMinAspectRatio();
// Don't resize to split screen size when half folded and centered
&& getHorizontalPositionMultiplier(parentConfiguration) != 0.5f
|| isCameraCompatSplitScreenAspectRatioAllowed()
&& isCameraCompatTreatmentActive();
}
private float getDefaultMinAspectRatioForUnresizableApps() {

View File

@@ -820,6 +820,33 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
assertTrue(mController.shouldSendFakeFocus());
}
@Test
public void testgetFixedOrientationLetterboxAspectRatio_splitScreenAspectEnabled() {
doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
.isCameraCompatTreatmentEnabled(anyBoolean());
doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
.isCameraCompatSplitScreenAspectRatioEnabled();
doReturn(false).when(mActivity.mWmService.mLetterboxConfiguration)
.getIsDisplayAspectRatioEnabledForFixedOrientationLetterbox();
doReturn(1.5f).when(mActivity.mWmService.mLetterboxConfiguration)
.getFixedOrientationLetterboxAspectRatio();
// Recreate DisplayContent with DisplayRotationCompatPolicy
mActivity = setUpActivityWithComponent();
mController = new LetterboxUiController(mWm, mActivity);
assertEquals(mController.getFixedOrientationLetterboxAspectRatio(
mActivity.getParent().getConfiguration()), 1.5f, /* delta */ 0.01);
spyOn(mDisplayContent.mDisplayRotationCompatPolicy);
doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy)
.isTreatmentEnabledForActivity(eq(mActivity));
assertEquals(mController.getFixedOrientationLetterboxAspectRatio(
mActivity.getParent().getConfiguration()), mController.getSplitScreenAspectRatio(),
/* delta */ 0.01);
}
private void mockThatProperty(String propertyName, boolean value) throws Exception {
Property property = new Property(propertyName, /* value */ value, /* packageName */ "",
/* className */ "");