From 7c72668f19d404b01412abc67937b1b5c660df71 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Fri, 6 Feb 2015 17:34:28 -0800 Subject: Adjust activity display metrics based on stack configuration. Apps normally use context.getResources().getDisplayMetrics() or getWindowManager().getDefaultDisplay() to get information about the screen dimensions. Not all the screen space is available for apps in a multi-window environment, so we limit the dimensions of the display object exposed to the app to that of the containing stack. Bug: 19225079 Bug: 19354838 Change-Id: I8dc3a6c9b99ecedcca28fc4ddaba9f31feb4f871 --- core/java/android/view/Display.java | 2 +- core/java/android/view/DisplayAdjustments.java | 30 +++++++++++--------------- core/java/android/view/DisplayInfo.java | 28 +++++++++++++++--------- core/java/android/view/ViewRootImpl.java | 1 - 4 files changed, 32 insertions(+), 29 deletions(-) (limited to 'core/java/android/view') diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index cfb0297..71863b7 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -716,7 +716,7 @@ public final class Display { updateDisplayInfoLocked(); mDisplayInfo.getLogicalMetrics(outMetrics, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, - mDisplayAdjustments.getActivityToken()); + mDisplayAdjustments.getConfiguration()); } } diff --git a/core/java/android/view/DisplayAdjustments.java b/core/java/android/view/DisplayAdjustments.java index 35fb504..272740f 100644 --- a/core/java/android/view/DisplayAdjustments.java +++ b/core/java/android/view/DisplayAdjustments.java @@ -17,7 +17,7 @@ package android.view; import android.content.res.CompatibilityInfo; -import android.os.IBinder; +import android.content.res.Configuration; import java.util.Objects; @@ -28,22 +28,18 @@ public class DisplayAdjustments { public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments(); private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; - private volatile IBinder mActivityToken; + private Configuration mConfiguration = Configuration.EMPTY; public DisplayAdjustments() { } - public DisplayAdjustments(IBinder token) { - mActivityToken = token; + public DisplayAdjustments(Configuration configuration) { + mConfiguration = configuration; } public DisplayAdjustments(DisplayAdjustments daj) { - this (daj.getCompatibilityInfo(), daj.getActivityToken()); - } - - public DisplayAdjustments(CompatibilityInfo compatInfo, IBinder token) { - setCompatibilityInfo(compatInfo); - mActivityToken = token; + setCompatibilityInfo(daj.mCompatInfo); + mConfiguration = daj.mConfiguration; } public void setCompatibilityInfo(CompatibilityInfo compatInfo) { @@ -63,16 +59,16 @@ public class DisplayAdjustments { return mCompatInfo; } - public void setActivityToken(IBinder token) { + public void setConfiguration(Configuration configuration) { if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { throw new IllegalArgumentException( - "setActivityToken: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); + "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); } - mActivityToken = token; + mConfiguration = configuration; } - public IBinder getActivityToken() { - return mActivityToken; + public Configuration getConfiguration() { + return mConfiguration; } @Override @@ -80,7 +76,7 @@ public class DisplayAdjustments { int hash = 17; hash = hash * 31 + mCompatInfo.hashCode(); if (DEVELOPMENT_RESOURCES_DEPEND_ON_ACTIVITY_TOKEN) { - hash = hash * 31 + (mActivityToken == null ? 0 : mActivityToken.hashCode()); + hash = hash * 31 + (mConfiguration == null ? 0 : mConfiguration.hashCode()); } return hash; } @@ -92,6 +88,6 @@ public class DisplayAdjustments { } DisplayAdjustments daj = (DisplayAdjustments)o; return Objects.equals(daj.mCompatInfo, mCompatInfo) && - Objects.equals(daj.mActivityToken, mActivityToken); + Objects.equals(daj.mConfiguration, mConfiguration); } } diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java index 9feb681..ecf45b4 100644 --- a/core/java/android/view/DisplayInfo.java +++ b/core/java/android/view/DisplayInfo.java @@ -17,7 +17,7 @@ package android.view; import android.content.res.CompatibilityInfo; -import android.os.IBinder; +import android.content.res.Configuration; import android.os.Parcel; import android.os.Parcelable; import android.util.DisplayMetrics; @@ -401,16 +401,17 @@ public final class DisplayInfo implements Parcelable { public void getAppMetrics(DisplayMetrics outMetrics, DisplayAdjustments displayAdjustments) { getMetricsWithSize(outMetrics, displayAdjustments.getCompatibilityInfo(), - displayAdjustments.getActivityToken(), appWidth, appHeight); + displayAdjustments.getConfiguration(), appWidth, appHeight); } - public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfo ci, IBinder token) { - getMetricsWithSize(outMetrics, ci, token, appWidth, appHeight); + public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfo ci, + Configuration configuration) { + getMetricsWithSize(outMetrics, ci, configuration, appWidth, appHeight); } public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, - IBinder token) { - getMetricsWithSize(outMetrics, compatInfo, token, logicalWidth, logicalHeight); + Configuration configuration) { + getMetricsWithSize(outMetrics, compatInfo, configuration, logicalWidth, logicalHeight); } public int getNaturalWidth() { @@ -431,17 +432,24 @@ public final class DisplayInfo implements Parcelable { } private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, - IBinder token, int width, int height) { + Configuration configuration, int width, int height) { outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi; - outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width; - outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height; - outMetrics.density = outMetrics.noncompatDensity = logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density; outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi; outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi; + width = (configuration != null + && configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) + ? (int)((configuration.screenWidthDp * outMetrics.density) + 0.5f) : width; + height = (configuration != null + && configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) + ? (int)((configuration.screenHeightDp * outMetrics.density) + 0.5f) : height; + + outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width; + outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height; + if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { compatInfo.applyToDisplayMetrics(outMetrics); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index fb2a8d8..24fae8a 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -478,7 +478,6 @@ public final class ViewRootImpl implements ViewParent, CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); mTranslator = compatibilityInfo.getTranslator(); - mDisplayAdjustments.setActivityToken(attrs.token); // If the application owns the surface, don't enable hardware acceleration if (mSurfaceHolder == null) { -- cgit v1.1