diff options
| author | 2023-03-30 21:05:08 +0000 | |
|---|---|---|
| committer | 2023-04-05 16:55:27 +0000 | |
| commit | b46d3493f085c947eedf061cec03864c70d82fc5 (patch) | |
| tree | eb81200c44dd9f83e5fcca55a8f5615aab32418e | |
| parent | d166b3b832d1c4aedb56c60e82df0b141a58b07e (diff) | |
Always use SizeSpecDefaultImpl on TV
The SizeSpecLargeScreenOptimizedImpl makes the PiP too big for TV. This
CL switches TVs to using the old SizeSpecDefaultImpl.
We use a runtime check rather than flipping the flag off to avoid wrong
set up in error states, when the default (true) value is returned from
the flag check.
Bug: 275555661
Test: m && flash && start Pip and see that it is normal-sized
Change-Id: If8761cb6261f6daf2a1289a8e79e1ccc0b03b8d1
2 files changed, 28 insertions, 9 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipSizeSpecHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipSizeSpecHandler.java index a7171fd5b220..82fe38ccc7b3 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipSizeSpecHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipSizeSpecHandler.java @@ -21,6 +21,7 @@ import static com.android.wm.shell.pip.PipUtils.dpToPx; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Point; import android.graphics.PointF; @@ -366,11 +367,8 @@ public class PipSizeSpecHandler { mContext = context; mPipDisplayLayoutState = pipDisplayLayoutState; - boolean enablePipSizeLargeScreen = SystemProperties - .getBoolean("persist.wm.debug.enable_pip_size_large_screen", true); - // choose between two implementations of size spec logic - if (enablePipSizeLargeScreen) { + if (supportsPipSizeLargeScreen()) { mSizeSpecSourceImpl = new SizeSpecLargeScreenOptimizedImpl(); } else { mSizeSpecSourceImpl = new SizeSpecDefaultImpl(); @@ -515,6 +513,18 @@ public class PipSizeSpecHandler { } } + @VisibleForTesting + boolean supportsPipSizeLargeScreen() { + // TODO(b/271468706): switch Tv to having a dedicated SizeSpecSource once the SizeSpecSource + // can be injected + return SystemProperties + .getBoolean("persist.wm.debug.enable_pip_size_large_screen", true) && !isTv(); + } + + private boolean isTv() { + return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); + } + /** Dumps internal state. */ public void dump(PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipSizeSpecHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipSizeSpecHandlerTest.java index 390c830069eb..425bbf056b85 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipSizeSpecHandlerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipSizeSpecHandlerTest.java @@ -18,7 +18,6 @@ package com.android.wm.shell.pip.phone; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession; -import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; @@ -76,7 +75,7 @@ public class PipSizeSpecHandlerTest extends ShellTestCase { @Mock private Resources mResources; private PipDisplayLayoutState mPipDisplayLayoutState; - private PipSizeSpecHandler mPipSizeSpecHandler; + private TestPipSizeSpecHandler mPipSizeSpecHandler; /** * Sets up static Mockito session for SystemProperties and mocks necessary static methods. @@ -84,8 +83,6 @@ public class PipSizeSpecHandlerTest extends ShellTestCase { private static void setUpStaticSystemPropertiesSession() { sStaticMockitoSession = mockitoSession() .mockStatic(SystemProperties.class).startMocking(); - // make sure the feature flag is on - when(SystemProperties.getBoolean(anyString(), anyBoolean())).thenReturn(true); when(SystemProperties.get(anyString(), anyString())).thenAnswer(invocation -> { String property = invocation.getArgument(0); if (property.equals("com.android.wm.shell.pip.phone.def_percentage")) { @@ -161,7 +158,7 @@ public class PipSizeSpecHandlerTest extends ShellTestCase { mPipDisplayLayoutState.setDisplayLayout(displayLayout); setUpStaticSystemPropertiesSession(); - mPipSizeSpecHandler = new PipSizeSpecHandler(mContext, mPipDisplayLayoutState); + mPipSizeSpecHandler = new TestPipSizeSpecHandler(mContext, mPipDisplayLayoutState); // no overridden min edge size by default mPipSizeSpecHandler.setOverrideMinSize(null); @@ -214,4 +211,16 @@ public class PipSizeSpecHandlerTest extends ShellTestCase { Assert.assertEquals(expectedSize, actualSize); } + + static class TestPipSizeSpecHandler extends PipSizeSpecHandler { + + TestPipSizeSpecHandler(Context context, PipDisplayLayoutState displayLayoutState) { + super(context, displayLayoutState); + } + + @Override + boolean supportsPipSizeLargeScreen() { + return true; + } + } } |