Merge "Fix screen size with compatibility override scale" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
40ad781251
@@ -252,9 +252,10 @@ public class CompatibilityInfo implements Parcelable {
|
||||
}
|
||||
|
||||
if (overrideScale != 1.0f) {
|
||||
applicationDensity = DisplayMetrics.DENSITY_DEFAULT;
|
||||
applicationScale = overrideScale;
|
||||
applicationInvertedScale = 1.0f / overrideScale;
|
||||
applicationDensity = (int) ((DisplayMetrics.DENSITY_DEVICE_STABLE
|
||||
* applicationInvertedScale) + .5f);
|
||||
compatFlags |= HAS_OVERRIDE_SCALING;
|
||||
} else if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
|
||||
applicationDensity = DisplayMetrics.DENSITY_DEVICE;
|
||||
@@ -519,10 +520,6 @@ public class CompatibilityInfo implements Parcelable {
|
||||
if (isScalingRequired()) {
|
||||
float invertedRatio = applicationInvertedScale;
|
||||
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.getBounds().scale(invertedRatio);
|
||||
final Rect appBounds = inoutConfig.windowConfiguration.getAppBounds();
|
||||
|
||||
@@ -1834,7 +1834,7 @@ public class DisplayContentTests extends WindowTestsBase {
|
||||
mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateInputWindows */);
|
||||
}
|
||||
|
||||
private void performLayout(DisplayContent dc) {
|
||||
static void performLayout(DisplayContent dc) {
|
||||
dc.setLayoutNeeded();
|
||||
dc.performLayout(true /* initial */, false /* updateImeWindows */);
|
||||
}
|
||||
|
||||
@@ -67,11 +67,14 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.res.CompatibilityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Rect;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.view.Gravity;
|
||||
import android.view.InputWindowHandle;
|
||||
import android.view.InsetsState;
|
||||
import android.view.SurfaceControl;
|
||||
@@ -559,6 +562,46 @@ public class WindowStateTests extends WindowTestsBase {
|
||||
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 })
|
||||
@Test
|
||||
public void testRequestDrawIfNeeded() {
|
||||
|
||||
@@ -337,6 +337,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
|
||||
final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
|
||||
attrs.setTitle(name);
|
||||
attrs.packageName = "test";
|
||||
|
||||
final WindowState w = new WindowState(service, session, iWindow, token, parent,
|
||||
OP_NONE, attrs, VISIBLE, ownerId, userId,
|
||||
|
||||
Reference in New Issue
Block a user