Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b46d3493 authored by Galia Peycheva's avatar Galia Peycheva
Browse files

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
parent d166b3b8
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -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 + "  ";
+14 −5
Original line number Diff line number Diff line
@@ -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;
        }
    }
}