Loading services/core/java/com/android/server/wm/LetterboxConfiguration.java +36 −6 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ 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 android.annotation.DimenRes; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -266,10 +267,10 @@ final class LetterboxConfiguration { private boolean mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox; // Supplier for the value in pixel to consider when detecting vertical thin letterboxing private final IntSupplier mThinLetterboxWidthFn; private final DimenPxIntSupplier mThinLetterboxWidthPxSupplier; // Supplier for the value in pixel to consider when detecting horizontal thin letterboxing private final IntSupplier mThinLetterboxHeightFn; private final DimenPxIntSupplier mThinLetterboxHeightPxSupplier; // Allows to enable letterboxing strategy for translucent activities ignoring flags. private boolean mTranslucentLetterboxingOverrideEnabled; Loading Loading @@ -307,6 +308,34 @@ final class LetterboxConfiguration { // Flags dynamically updated with {@link android.provider.DeviceConfig}. @NonNull private final SynchedDeviceConfig mDeviceConfig; // Cached version of IntSupplier customised to evaluate new dimen in pixels // when density changes private static class DimenPxIntSupplier implements IntSupplier { @NonNull private final Context mContext; private final int mResourceId; private float mLastDensity = Float.MIN_VALUE; private int mValue = 0; private DimenPxIntSupplier(@NonNull Context context, @DimenRes int resourceId) { mContext = context; mResourceId = resourceId; } @Override public int getAsInt() { final float newDensity = mContext.getResources().getDisplayMetrics().density; if (newDensity != mLastDensity) { mLastDensity = newDensity; mValue = mContext.getResources().getDimensionPixelSize(mResourceId); } return mValue; } } LetterboxConfiguration(@NonNull final Context systemUiContext) { this(systemUiContext, new LetterboxConfigurationPersister( () -> readLetterboxHorizontalReachabilityPositionFromConfig( Loading Loading @@ -364,9 +393,10 @@ final class LetterboxConfiguration { R.bool.config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled); mIsPolicyForIgnoringRequestedOrientationEnabled = mContext.getResources().getBoolean( R.bool.config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled); mThinLetterboxWidthFn = () -> mContext.getResources().getDimensionPixelSize( mThinLetterboxWidthPxSupplier = new DimenPxIntSupplier(mContext, R.dimen.config_letterboxThinLetterboxWidthDp); mThinLetterboxHeightFn = () -> mContext.getResources().getDimensionPixelSize( mThinLetterboxHeightPxSupplier = new DimenPxIntSupplier(mContext, R.dimen.config_letterboxThinLetterboxHeightDp); mLetterboxConfigurationPersister = letterboxConfigurationPersister; Loading Loading @@ -1144,7 +1174,7 @@ final class LetterboxConfiguration { * is the maximum value for (W - w) / 2 to be considered for a thin letterboxed app. */ int getThinLetterboxWidthPx() { return mThinLetterboxWidthFn.getAsInt(); return mThinLetterboxWidthPxSupplier.getAsInt(); } /** Loading @@ -1153,7 +1183,7 @@ final class LetterboxConfiguration { * value for (H - h) / 2 to be considered for a thin letterboxed app. */ int getThinLetterboxHeightPx() { return mThinLetterboxHeightFn.getAsInt(); return mThinLetterboxHeightPxSupplier.getAsInt(); } /** Loading services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationTest.java +51 −3 Original line number Diff line number Diff line Loading @@ -18,15 +18,17 @@ package com.android.server.wm; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; 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; 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_TOP; import static com.android.server.wm.testing.Assert.assertThrows; import static junit.framework.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; Loading @@ -35,11 +37,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; import android.platform.test.annotations.Presubmit; import android.util.DisplayMetrics; import androidx.test.filters.SmallTest; import com.android.server.wm.testing.Assert; import com.android.internal.R; import org.junit.Before; import org.junit.Test; Loading Loading @@ -277,7 +281,7 @@ public class LetterboxConfigurationTest { } @Test public void test_lettterboxPositionWhenReachabilityEnabledIsSet() { public void test_letterboxPositionWhenReachabilityEnabledIsSet() { // Check that horizontal reachability is set with correct arguments mLetterboxConfiguration.setPersistentLetterboxPositionForHorizontalReachability( false /* forBookMode */, LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT); Loading Loading @@ -344,4 +348,48 @@ public class LetterboxConfigurationTest { mLetterboxConfiguration.setLetterboxTabletopModePositionMultiplier(0.5f); mLetterboxConfiguration.setLetterboxTabletopModePositionMultiplier(1); } @Test public void test_evaluateThinLetterboxWhenDensityChanges() { final Resources rs = mock(Resources.class); final DisplayMetrics dm = mock(DisplayMetrics.class); final LetterboxConfigurationPersister lp = mock(LetterboxConfigurationPersister.class); spyOn(mContext); when(rs.getDisplayMetrics()).thenReturn(dm); when(mContext.getResources()).thenReturn(rs); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxWidthDp)) .thenReturn(100); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxHeightDp)) .thenReturn(200); final LetterboxConfiguration configuration = new LetterboxConfiguration(mContext, lp); // Verify the values are the expected ones dm.density = 100; when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxWidthDp)) .thenReturn(100); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxHeightDp)) .thenReturn(200); final int thinWidthPx = configuration.getThinLetterboxWidthPx(); final int thinHeightPx = configuration.getThinLetterboxHeightPx(); assertEquals(100, thinWidthPx); assertEquals(200, thinHeightPx); // We change the values in the resources but not the update condition (density) and the // result should not change when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxWidthDp)) .thenReturn(300); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxHeightDp)) .thenReturn(400); final int thinWidthPx2 = configuration.getThinLetterboxWidthPx(); final int thinHeightPx2 = configuration.getThinLetterboxHeightPx(); assertEquals(100, thinWidthPx2); assertEquals(200, thinHeightPx2); // We update the condition (density) so the new resource values should be read dm.density = 150; final int thinWidthPx3 = configuration.getThinLetterboxWidthPx(); final int thinHeightPx3 = configuration.getThinLetterboxHeightPx(); assertEquals(300, thinWidthPx3); assertEquals(400, thinHeightPx3); } } Loading
services/core/java/com/android/server/wm/LetterboxConfiguration.java +36 −6 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ 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 android.annotation.DimenRes; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -266,10 +267,10 @@ final class LetterboxConfiguration { private boolean mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox; // Supplier for the value in pixel to consider when detecting vertical thin letterboxing private final IntSupplier mThinLetterboxWidthFn; private final DimenPxIntSupplier mThinLetterboxWidthPxSupplier; // Supplier for the value in pixel to consider when detecting horizontal thin letterboxing private final IntSupplier mThinLetterboxHeightFn; private final DimenPxIntSupplier mThinLetterboxHeightPxSupplier; // Allows to enable letterboxing strategy for translucent activities ignoring flags. private boolean mTranslucentLetterboxingOverrideEnabled; Loading Loading @@ -307,6 +308,34 @@ final class LetterboxConfiguration { // Flags dynamically updated with {@link android.provider.DeviceConfig}. @NonNull private final SynchedDeviceConfig mDeviceConfig; // Cached version of IntSupplier customised to evaluate new dimen in pixels // when density changes private static class DimenPxIntSupplier implements IntSupplier { @NonNull private final Context mContext; private final int mResourceId; private float mLastDensity = Float.MIN_VALUE; private int mValue = 0; private DimenPxIntSupplier(@NonNull Context context, @DimenRes int resourceId) { mContext = context; mResourceId = resourceId; } @Override public int getAsInt() { final float newDensity = mContext.getResources().getDisplayMetrics().density; if (newDensity != mLastDensity) { mLastDensity = newDensity; mValue = mContext.getResources().getDimensionPixelSize(mResourceId); } return mValue; } } LetterboxConfiguration(@NonNull final Context systemUiContext) { this(systemUiContext, new LetterboxConfigurationPersister( () -> readLetterboxHorizontalReachabilityPositionFromConfig( Loading Loading @@ -364,9 +393,10 @@ final class LetterboxConfiguration { R.bool.config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled); mIsPolicyForIgnoringRequestedOrientationEnabled = mContext.getResources().getBoolean( R.bool.config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled); mThinLetterboxWidthFn = () -> mContext.getResources().getDimensionPixelSize( mThinLetterboxWidthPxSupplier = new DimenPxIntSupplier(mContext, R.dimen.config_letterboxThinLetterboxWidthDp); mThinLetterboxHeightFn = () -> mContext.getResources().getDimensionPixelSize( mThinLetterboxHeightPxSupplier = new DimenPxIntSupplier(mContext, R.dimen.config_letterboxThinLetterboxHeightDp); mLetterboxConfigurationPersister = letterboxConfigurationPersister; Loading Loading @@ -1144,7 +1174,7 @@ final class LetterboxConfiguration { * is the maximum value for (W - w) / 2 to be considered for a thin letterboxed app. */ int getThinLetterboxWidthPx() { return mThinLetterboxWidthFn.getAsInt(); return mThinLetterboxWidthPxSupplier.getAsInt(); } /** Loading @@ -1153,7 +1183,7 @@ final class LetterboxConfiguration { * value for (H - h) / 2 to be considered for a thin letterboxed app. */ int getThinLetterboxHeightPx() { return mThinLetterboxHeightFn.getAsInt(); return mThinLetterboxHeightPxSupplier.getAsInt(); } /** Loading
services/tests/wmtests/src/com/android/server/wm/LetterboxConfigurationTest.java +51 −3 Original line number Diff line number Diff line Loading @@ -18,15 +18,17 @@ package com.android.server.wm; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; 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; 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_TOP; import static com.android.server.wm.testing.Assert.assertThrows; import static junit.framework.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; Loading @@ -35,11 +37,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; import android.platform.test.annotations.Presubmit; import android.util.DisplayMetrics; import androidx.test.filters.SmallTest; import com.android.server.wm.testing.Assert; import com.android.internal.R; import org.junit.Before; import org.junit.Test; Loading Loading @@ -277,7 +281,7 @@ public class LetterboxConfigurationTest { } @Test public void test_lettterboxPositionWhenReachabilityEnabledIsSet() { public void test_letterboxPositionWhenReachabilityEnabledIsSet() { // Check that horizontal reachability is set with correct arguments mLetterboxConfiguration.setPersistentLetterboxPositionForHorizontalReachability( false /* forBookMode */, LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT); Loading Loading @@ -344,4 +348,48 @@ public class LetterboxConfigurationTest { mLetterboxConfiguration.setLetterboxTabletopModePositionMultiplier(0.5f); mLetterboxConfiguration.setLetterboxTabletopModePositionMultiplier(1); } @Test public void test_evaluateThinLetterboxWhenDensityChanges() { final Resources rs = mock(Resources.class); final DisplayMetrics dm = mock(DisplayMetrics.class); final LetterboxConfigurationPersister lp = mock(LetterboxConfigurationPersister.class); spyOn(mContext); when(rs.getDisplayMetrics()).thenReturn(dm); when(mContext.getResources()).thenReturn(rs); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxWidthDp)) .thenReturn(100); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxHeightDp)) .thenReturn(200); final LetterboxConfiguration configuration = new LetterboxConfiguration(mContext, lp); // Verify the values are the expected ones dm.density = 100; when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxWidthDp)) .thenReturn(100); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxHeightDp)) .thenReturn(200); final int thinWidthPx = configuration.getThinLetterboxWidthPx(); final int thinHeightPx = configuration.getThinLetterboxHeightPx(); assertEquals(100, thinWidthPx); assertEquals(200, thinHeightPx); // We change the values in the resources but not the update condition (density) and the // result should not change when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxWidthDp)) .thenReturn(300); when(rs.getDimensionPixelSize(R.dimen.config_letterboxThinLetterboxHeightDp)) .thenReturn(400); final int thinWidthPx2 = configuration.getThinLetterboxWidthPx(); final int thinHeightPx2 = configuration.getThinLetterboxHeightPx(); assertEquals(100, thinWidthPx2); assertEquals(200, thinHeightPx2); // We update the condition (density) so the new resource values should be read dm.density = 150; final int thinWidthPx3 = configuration.getThinLetterboxWidthPx(); final int thinHeightPx3 = configuration.getThinLetterboxHeightPx(); assertEquals(300, thinWidthPx3); assertEquals(400, thinHeightPx3); } }