Fix propagation of display overscan information.
Fix several problems in the way that the overscan was plumbed in
which could result in information not being delivered to applications.
There was also a violation of certain invariants regarding the
immutability of returned DisplayInfo objects.
Bug: 10213771
Change-Id: I21184a14305e44278b5e81353bf95d511e8517fb
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index f83b017..ae7120f 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -995,8 +995,10 @@
@Override
public void setInitialDisplaySize(Display display, int width, int height, int density) {
- if (display.getDisplayId() != Display.DEFAULT_DISPLAY) {
- throw new IllegalArgumentException("Can only set the default display");
+ // This method might be called before the policy has been fully initialized
+ // or for other displays we don't care about.
+ if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
+ return;
}
mDisplay = display;
diff --git a/services/java/com/android/server/display/DisplayManagerService.java b/services/java/com/android/server/display/DisplayManagerService.java
index 20db4cd..4b3463c 100644
--- a/services/java/com/android/server/display/DisplayManagerService.java
+++ b/services/java/com/android/server/display/DisplayManagerService.java
@@ -314,6 +314,9 @@
* to the display information synchronously so that applications will immediately
* observe the new state.
*
+ * NOTE: This method must be the only entry point by which the window manager
+ * influences the logical configuration of displays.
+ *
* @param displayId The logical display id.
* @param info The new data to be stored.
*/
@@ -322,9 +325,7 @@
synchronized (mSyncRoot) {
LogicalDisplay display = mLogicalDisplays.get(displayId);
if (display != null) {
- mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
- display.setDisplayInfoOverrideFromWindowManagerLocked(info);
- if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
+ if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
scheduleTraversalLocked(false);
}
@@ -333,18 +334,6 @@
}
/**
- * Sets the overscan insets for a particular display.
- */
- public void setOverscan(int displayId, int left, int top, int right, int bottom) {
- synchronized (mSyncRoot) {
- LogicalDisplay display = mLogicalDisplays.get(displayId);
- if (display != null) {
- display.setOverscan(left, top, right, bottom);
- }
- }
- }
-
- /**
* Called by the window manager to perform traversals while holding a
* surface flinger transaction.
*/
diff --git a/services/java/com/android/server/display/LogicalDisplay.java b/services/java/com/android/server/display/LogicalDisplay.java
index b9839c2..7e357c0 100644
--- a/services/java/com/android/server/display/LogicalDisplay.java
+++ b/services/java/com/android/server/display/LogicalDisplay.java
@@ -128,32 +128,24 @@
*
* @param info The logical display information, may be null.
*/
- public void setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo info) {
+ public boolean setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo info) {
if (info != null) {
if (mOverrideDisplayInfo == null) {
mOverrideDisplayInfo = new DisplayInfo(info);
mInfo = null;
- } else if (!mOverrideDisplayInfo.equals(info)) {
+ return true;
+ }
+ if (!mOverrideDisplayInfo.equals(info)) {
mOverrideDisplayInfo.copyFrom(info);
mInfo = null;
+ return true;
}
} else if (mOverrideDisplayInfo != null) {
mOverrideDisplayInfo = null;
mInfo = null;
+ return true;
}
- }
-
- public void setOverscan(int left, int top, int right, int bottom) {
- mInfo.overscanLeft = left;
- mInfo.overscanTop = top;
- mInfo.overscanRight = right;
- mInfo.overscanBottom = bottom;
- if (mOverrideDisplayInfo != null) {
- mOverrideDisplayInfo.overscanLeft = left;
- mOverrideDisplayInfo.overscanTop = top;
- mOverrideDisplayInfo.overscanRight = right;
- mOverrideDisplayInfo.overscanBottom = bottom;
- }
+ return false;
}
/**
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 27177f9..364b854 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -6961,12 +6961,7 @@
synchronized(mWindowMap) {
mIsTouchDevice = mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TOUCHSCREEN);
-
- final DisplayContent displayContent = getDefaultDisplayContentLocked();
- mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
- displayContent.mInitialDisplayWidth,
- displayContent.mInitialDisplayHeight,
- displayContent.mInitialDisplayDensity);
+ configureDisplayPolicyLocked(getDefaultDisplayContentLocked());
}
try {
@@ -7793,11 +7788,7 @@
// displayContent must not be null
private void reconfigureDisplayLocked(DisplayContent displayContent) {
// TODO: Multidisplay: for now only use with default display.
- mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
- displayContent.mBaseDisplayWidth,
- displayContent.mBaseDisplayHeight,
- displayContent.mBaseDisplayDensity);
-
+ configureDisplayPolicyLocked(displayContent);
displayContent.layoutNeeded = true;
boolean configChanged = updateOrientationFromAppTokensLocked(false);
@@ -7818,6 +7809,18 @@
performLayoutAndPlaceSurfacesLocked();
}
+ private void configureDisplayPolicyLocked(DisplayContent displayContent) {
+ mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
+ displayContent.mBaseDisplayWidth,
+ displayContent.mBaseDisplayHeight,
+ displayContent.mBaseDisplayDensity);
+
+ DisplayInfo displayInfo = displayContent.getDisplayInfo();
+ mPolicy.setDisplayOverscan(displayContent.getDisplay(),
+ displayInfo.overscanLeft, displayInfo.overscanTop,
+ displayInfo.overscanRight, displayInfo.overscanBottom);
+ }
+
@Override
public void setOverscan(int displayId, int left, int top, int right, int bottom) {
if (mContext.checkCallingOrSelfPermission(
@@ -7829,23 +7832,27 @@
synchronized(mWindowMap) {
DisplayContent displayContent = getDisplayContentLocked(displayId);
if (displayContent != null) {
- mDisplayManagerService.setOverscan(displayId, left, top, right, bottom);
- final DisplayInfo displayInfo = displayContent.getDisplayInfo();
- synchronized(displayContent.mDisplaySizeLock) {
- displayInfo.overscanLeft = left;
- displayInfo.overscanTop = top;
- displayInfo.overscanRight = right;
- displayInfo.overscanBottom = bottom;
- }
- mPolicy.setDisplayOverscan(displayContent.getDisplay(), left, top, right, bottom);
- displayContent.layoutNeeded = true;
- mDisplaySettings.setOverscanLocked(displayInfo.name, left, top, right, bottom);
- mDisplaySettings.writeSettingsLocked();
- performLayoutAndPlaceSurfacesLocked();
+ setOverscanLocked(displayContent, left, top, right, bottom);
}
}
}
+ private void setOverscanLocked(DisplayContent displayContent,
+ int left, int top, int right, int bottom) {
+ final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+ synchronized (displayContent.mDisplaySizeLock) {
+ displayInfo.overscanLeft = left;
+ displayInfo.overscanTop = top;
+ displayInfo.overscanRight = right;
+ displayInfo.overscanBottom = bottom;
+ }
+
+ mDisplaySettings.setOverscanLocked(displayInfo.name, left, top, right, bottom);
+ mDisplaySettings.writeSettingsLocked();
+
+ reconfigureDisplayLocked(displayContent);
+ }
+
// -------------------------------------------------------------
// Internals
// -------------------------------------------------------------
@@ -10719,17 +10726,19 @@
DisplayContent displayContent = new DisplayContent(display, this);
final int displayId = display.getDisplayId();
mDisplayContents.put(displayId, displayContent);
+
+ DisplayInfo displayInfo = displayContent.getDisplayInfo();
final Rect rect = new Rect();
- DisplayInfo info = displayContent.getDisplayInfo();
- mDisplaySettings.getOverscanLocked(info.name, rect);
- info.overscanLeft = rect.left;
- info.overscanTop = rect.top;
- info.overscanRight = rect.right;
- info.overscanBottom = rect.bottom;
- mDisplayManagerService.setOverscan(display.getDisplayId(), rect.left, rect.top,
- rect.right, rect.bottom);
- mPolicy.setDisplayOverscan(displayContent.getDisplay(), rect.left, rect.top,
- rect.right, rect.bottom);
+ mDisplaySettings.getOverscanLocked(displayInfo.name, rect);
+ synchronized (displayContent.mDisplaySizeLock) {
+ displayInfo.overscanLeft = rect.left;
+ displayInfo.overscanTop = rect.top;
+ displayInfo.overscanRight = rect.right;
+ displayInfo.overscanBottom = rect.bottom;
+ mDisplayManagerService.setDisplayInfoOverrideFromWindowManager(
+ displayId, displayInfo);
+ }
+ configureDisplayPolicyLocked(displayContent);
// TODO: Create an input channel for each display with touch capability.
if (displayId == Display.DEFAULT_DISPLAY) {