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

Commit f07f50aa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix screen size with compatibility override scale" into sc-dev am: 40ad7812

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13544385

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I7bf0d4eb554a9d40c2415c17adb112b05abec349
parents a157ee98 40ad7812
Loading
Loading
Loading
Loading
+2 −5
Original line number Original line Diff line number Diff line
@@ -252,9 +252,10 @@ public class CompatibilityInfo implements Parcelable {
            }
            }


            if (overrideScale != 1.0f) {
            if (overrideScale != 1.0f) {
                applicationDensity = DisplayMetrics.DENSITY_DEFAULT;
                applicationScale = overrideScale;
                applicationScale = overrideScale;
                applicationInvertedScale = 1.0f / overrideScale;
                applicationInvertedScale = 1.0f / overrideScale;
                applicationDensity = (int) ((DisplayMetrics.DENSITY_DEVICE_STABLE
                        * applicationInvertedScale) + .5f);
                compatFlags |= HAS_OVERRIDE_SCALING;
                compatFlags |= HAS_OVERRIDE_SCALING;
            } else if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
            } else if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
                applicationDensity = DisplayMetrics.DENSITY_DEVICE;
                applicationDensity = DisplayMetrics.DENSITY_DEVICE;
@@ -519,10 +520,6 @@ public class CompatibilityInfo implements Parcelable {
        if (isScalingRequired()) {
        if (isScalingRequired()) {
            float invertedRatio = applicationInvertedScale;
            float invertedRatio = applicationInvertedScale;
            inoutConfig.densityDpi = (int)((inoutConfig.densityDpi * invertedRatio) + .5f);
            inoutConfig.densityDpi = (int)((inoutConfig.densityDpi * invertedRatio) + .5f);
            inoutConfig.screenWidthDp = (int) ((inoutConfig.screenWidthDp * invertedRatio) + .5f);
            inoutConfig.screenHeightDp = (int) ((inoutConfig.screenHeightDp * invertedRatio) + .5f);
            inoutConfig.smallestScreenWidthDp =
                    (int) ((inoutConfig.smallestScreenWidthDp * invertedRatio) + .5f);
            inoutConfig.windowConfiguration.getMaxBounds().scale(invertedRatio);
            inoutConfig.windowConfiguration.getMaxBounds().scale(invertedRatio);
            inoutConfig.windowConfiguration.getBounds().scale(invertedRatio);
            inoutConfig.windowConfiguration.getBounds().scale(invertedRatio);
            final Rect appBounds = inoutConfig.windowConfiguration.getAppBounds();
            final Rect appBounds = inoutConfig.windowConfiguration.getAppBounds();
+1 −1
Original line number Original line Diff line number Diff line
@@ -1834,7 +1834,7 @@ public class DisplayContentTests extends WindowTestsBase {
        mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateInputWindows */);
        mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateInputWindows */);
    }
    }


    private void performLayout(DisplayContent dc) {
    static void performLayout(DisplayContent dc) {
        dc.setLayoutNeeded();
        dc.setLayoutNeeded();
        dc.performLayout(true /* initial */, false /* updateImeWindows */);
        dc.performLayout(true /* initial */, false /* updateImeWindows */);
    }
    }
+43 −0
Original line number Original line Diff line number Diff line
@@ -67,11 +67,14 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.graphics.Matrix;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.view.Gravity;
import android.view.InputWindowHandle;
import android.view.InputWindowHandle;
import android.view.InsetsState;
import android.view.InsetsState;
import android.view.SurfaceControl;
import android.view.SurfaceControl;
@@ -559,6 +562,46 @@ public class WindowStateTests extends WindowTestsBase {
        assertTrue(window.isVisibleByPolicy());
        assertTrue(window.isVisibleByPolicy());
    }
    }


    @Test
    public void testCompatOverrideScale() {
        final float overrideScale = 2; // 0.5x on client side.
        final CompatModePackages cmp = mWm.mAtmService.mCompatModePackages;
        spyOn(cmp);
        doReturn(overrideScale).when(cmp).getCompatScale(anyString(), anyInt());
        final WindowState w = createWindow(null, TYPE_APPLICATION_OVERLAY, "win");
        makeWindowVisible(w);
        w.setRequestedSize(100, 200);
        w.mAttrs.width = w.mAttrs.height = WindowManager.LayoutParams.WRAP_CONTENT;
        w.mAttrs.gravity = Gravity.TOP | Gravity.LEFT;
        DisplayContentTests.performLayout(mDisplayContent);

        // Frame on screen = 100x200. Compat frame on client = 50x100.
        final Rect unscaledCompatFrame = new Rect(w.getWindowFrames().mCompatFrame);
        unscaledCompatFrame.scale(overrideScale);
        assertEquals(w.getWindowFrames().mFrame, unscaledCompatFrame);

        // Surface should apply the scale.
        w.prepareSurfaces();
        verify(w.getPendingTransaction()).setMatrix(w.getSurfaceControl(),
                overrideScale, 0, 0, overrideScale);

        // According to "dp * density / 160 = px", density is scaled and the size in dp is the same.
        final CompatibilityInfo compatInfo = cmp.compatibilityInfoForPackageLocked(
                mContext.getApplicationInfo());
        final Configuration winConfig = w.getConfiguration();
        final Configuration clientConfig = new Configuration(w.getConfiguration());
        compatInfo.applyToConfiguration(clientConfig.densityDpi, clientConfig);

        assertEquals(winConfig.screenWidthDp, clientConfig.screenWidthDp);
        assertEquals(winConfig.screenHeightDp, clientConfig.screenHeightDp);
        assertEquals(winConfig.smallestScreenWidthDp, clientConfig.smallestScreenWidthDp);
        assertEquals(winConfig.densityDpi, (int) (clientConfig.densityDpi * overrideScale));

        final Rect unscaledClientBounds = new Rect(clientConfig.windowConfiguration.getBounds());
        unscaledClientBounds.scale(overrideScale);
        assertEquals(w.getWindowConfiguration().getBounds(), unscaledClientBounds);
    }

    @UseTestDisplay(addWindows = { W_ABOVE_ACTIVITY, W_NOTIFICATION_SHADE })
    @UseTestDisplay(addWindows = { W_ABOVE_ACTIVITY, W_NOTIFICATION_SHADE })
    @Test
    @Test
    public void testRequestDrawIfNeeded() {
    public void testRequestDrawIfNeeded() {
+1 −0
Original line number Original line Diff line number Diff line
@@ -337,6 +337,7 @@ class WindowTestsBase extends SystemServiceTestsBase {


        final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
        final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
        attrs.setTitle(name);
        attrs.setTitle(name);
        attrs.packageName = "test";


        final WindowState w = new WindowState(service, session, iWindow, token, parent,
        final WindowState w = new WindowState(service, session, iWindow, token, parent,
                OP_NONE, attrs, VISIBLE, ownerId, userId,
                OP_NONE, attrs, VISIBLE, ownerId, userId,