Clean up use of DisplayContent from WindowState.
Follow up to ag/1483993 where WindowTokens can now only be on one display.
Clean-up some existing code that dealt with having WindowTokens on
multiple displays.
Test: Existing tests pass.
Change-Id: Ie908eda37bc44097dea773b0fc163d35cc9baf35
diff --git a/services/core/java/com/android/server/wm/AppWindowAnimator.java b/services/core/java/com/android/server/wm/AppWindowAnimator.java
index 305e47f..429cb2d 100644
--- a/services/core/java/com/android/server/wm/AppWindowAnimator.java
+++ b/services/core/java/com/android/server/wm/AppWindowAnimator.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
@@ -332,7 +333,7 @@
}
// This must be called while inside a transaction.
- boolean stepAnimationLocked(long currentTime, final int displayId) {
+ boolean stepAnimationLocked(long currentTime) {
if (mService.okToDisplay()) {
// We will run animations as long as the display isn't frozen.
@@ -383,8 +384,7 @@
return false;
}
- mAppToken.setAppLayoutChanges(
- WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM, "AppWindowToken", displayId);
+ mAppToken.setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "AppWindowToken");
clearAnimation();
animating = false;
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index f1df94f..ee7c6d2 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -270,7 +270,7 @@
final WindowState window = findMainWindow();
//TODO (multidisplay): Magnification is supported only for the default display.
if (window != null && accessibilityController != null
- && window.getDisplayId() == DEFAULT_DISPLAY) {
+ && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
accessibilityController.onAppWindowTransitionLocked(window, transit);
}
changed = true;
@@ -418,22 +418,15 @@
* surfaces that's eligible, if the app is already stopped.
*/
private void destroySurfaces(boolean cleanupOnResume) {
- final ArrayList<DisplayContent> displayList = new ArrayList();
+ boolean destroyedSomething = false;
for (int i = mChildren.size() - 1; i >= 0; i--) {
final WindowState win = mChildren.get(i);
- final boolean destroyed = win.destroySurface(cleanupOnResume, mAppStopped);
-
- if (destroyed) {
- final DisplayContent displayContent = win.getDisplayContent();
- if (displayContent != null && !displayList.contains(displayContent)) {
- displayList.add(displayContent);
- }
- }
+ destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
}
- for (int i = 0; i < displayList.size(); i++) {
- final DisplayContent displayContent = displayList.get(i);
- mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
- displayContent.setLayoutNeeded();
+ if (destroyedSomething) {
+ final DisplayContent dc = getDisplayContent();
+ mService.mLayersController.assignLayersLocked(dc.getWindowList());
+ dc.setLayoutNeeded();
}
}
@@ -700,7 +693,7 @@
}
}
- boolean waitingForReplacement() {
+ private boolean waitingForReplacement() {
for (int i = mChildren.size() - 1; i >= 0; i--) {
final WindowState candidate = mChildren.get(i);
if (candidate.waitingForReplacement()) {
@@ -816,17 +809,12 @@
}
}
- void setAppLayoutChanges(int changes, String reason, int displayId) {
- final WindowAnimator windowAnimator = mAppAnimator.mAnimator;
- for (int i = mChildren.size() - 1; i >= 0; i--) {
- // Child windows will be on the same display as their parents.
- if (displayId == (mChildren.get(i)).getDisplayId()) {
- windowAnimator.setPendingLayoutChanges(displayId, changes);
- if (DEBUG_LAYOUT_REPEATS) {
- mService.mWindowPlacerLocked.debugLayoutRepeats(
- reason, windowAnimator.getPendingLayoutChanges(displayId));
- }
- break;
+ void setAppLayoutChanges(int changes, String reason) {
+ if (!mChildren.isEmpty()) {
+ final DisplayContent dc = getDisplayContent();
+ dc.pendingLayoutChanges |= changes;
+ if (DEBUG_LAYOUT_REPEATS) {
+ mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
}
}
}
@@ -931,7 +919,7 @@
if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
"Removing starting window: " + tStartingWindow);
- tStartingWindow.getWindowList().remove(tStartingWindow);
+ getDisplayContent().getWindowList().remove(tStartingWindow);
mService.mWindowsChanged = true;
if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
"Removing starting " + tStartingWindow + " from " + fromToken);
@@ -1028,7 +1016,7 @@
}
@Override
- void checkAppWindowsReadyToShow(int displayId) {
+ void checkAppWindowsReadyToShow() {
if (allDrawn == mAppAnimator.allDrawn) {
return;
}
@@ -1047,9 +1035,9 @@
+ " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
// This will set mOrientationChangeComplete and cause a pass through layout.
setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
- "checkAppWindowsReadyToShow: freezingScreen", displayId);
+ "checkAppWindowsReadyToShow: freezingScreen");
} else {
- setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow", displayId);
+ setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
// We can now show all of the drawn windows!
if (!mService.mOpeningApps.contains(this)) {
@@ -1170,16 +1158,15 @@
}
@Override
- void stepAppWindowsAnimation(long currentTime, int displayId) {
+ void stepAppWindowsAnimation(long currentTime) {
mAppAnimator.wasAnimating = mAppAnimator.animating;
- if (mAppAnimator.stepAnimationLocked(currentTime, displayId)) {
+ if (mAppAnimator.stepAnimationLocked(currentTime)) {
mAppAnimator.animating = true;
mService.mAnimator.setAnimating(true);
mService.mAnimator.mAppWindowAnimating = true;
} else if (mAppAnimator.wasAnimating) {
// stopped animating, do one more pass through the layout
- setAppLayoutChanges(
- FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done", displayId);
+ setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
}
}
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index fa3112d..10f919c 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -49,6 +49,7 @@
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
+import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
import static com.android.server.wm.WindowManagerService.dipToPixel;
import static com.android.server.wm.WindowManagerService.localLOGV;
import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
@@ -63,6 +64,7 @@
import android.graphics.Region.Op;
import android.hardware.display.DisplayManagerInternal;
import android.os.Debug;
+import android.os.Handler;
import android.os.IBinder;
import android.util.DisplayMetrics;
import android.util.Slog;
@@ -301,14 +303,6 @@
}
}
- void checkAppWindowsReadyToShow() {
- super.checkAppWindowsReadyToShow(mDisplayId);
- }
-
- void stepAppWindowsAnimation(long currentTime) {
- super.stepAppWindowsAnimation(currentTime, mDisplayId);
- }
-
@Override
boolean fillsParent() {
return true;
@@ -870,15 +864,14 @@
return;
}
final int lostFocusUid = oldFocus.mOwnerUid;
- WindowList windows = getWindowList();
+ final WindowList windows = getWindowList();
final int windowCount = windows.size();
+ final Handler handler = mService.mH;
for (int i = 0; i < windowCount; i++) {
- WindowState window = windows.get(i);
+ final WindowState window = windows.get(i);
if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
- if (!mService.mH.hasMessages(WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window)) {
- mService.mH.sendMessageDelayed(
- mService.mH.obtainMessage(
- WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window),
+ if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, window)) {
+ handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, window),
window.mAttrs.hideTimeoutMilliseconds);
}
}
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 4622329..05ffe2d 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -54,6 +54,7 @@
import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
@@ -762,19 +763,16 @@
final boolean hasFocus = child == inputFocus;
final boolean isVisible = child.isVisibleLw();
- if ((privateFlags
- & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS)
- != 0) {
+ if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
disableWallpaperTouchEvents = true;
}
final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child)
- && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0
+ && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
&& !disableWallpaperTouchEvents;
- final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY);
// If there's a drag in progress and 'child' is a potential drop target,
// make sure it's been told about the drag
- if (inDrag && isVisible && onDefaultDisplay) {
+ if (inDrag && isVisible && dc.isDefaultDisplay) {
mService.mDragState.sendDragStartedIfNeededLw(child);
}
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index 56fdc33..7c39bd2 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -29,6 +29,7 @@
import static android.view.WindowManager.DOCKED_LEFT;
import static android.view.WindowManager.DOCKED_RIGHT;
import static android.view.WindowManager.DOCKED_TOP;
+import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT;
@@ -1429,8 +1430,8 @@
return super.checkCompleteDeferredRemoval();
}
- void stepAppWindowsAnimation(long currentTime, int displayId) {
- super.stepAppWindowsAnimation(currentTime, displayId);
+ void stepAppWindowsAnimation(long currentTime) {
+ super.stepAppWindowsAnimation(currentTime);
// TODO: Why aren't we just using the loop above for this? mAppAnimator.animating isn't set
// below but is set in the loop above. See if it really matters...
@@ -1438,14 +1439,13 @@
for (int i = 0; i < exitingCount; i++) {
final AppWindowAnimator appAnimator = mExitingAppTokens.get(i).mAppAnimator;
appAnimator.wasAnimating = appAnimator.animating;
- if (appAnimator.stepAnimationLocked(currentTime, displayId)) {
+ if (appAnimator.stepAnimationLocked(currentTime)) {
mService.mAnimator.setAnimating(true);
mService.mAnimator.mAppWindowAnimating = true;
} else if (appAnimator.wasAnimating) {
// stopped animating, do one more pass through the layout
- appAnimator.mAppToken.setAppLayoutChanges(
- WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
- "exiting appToken " + appAnimator.mAppToken + " done", displayId);
+ appAnimator.mAppToken.setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
+ "exiting appToken " + appAnimator.mAppToken + " done");
if (DEBUG_ANIM) Slog.v(TAG_WM,
"updateWindowsApps...: done animating exiting " + appAnimator.mAppToken);
}
diff --git a/services/core/java/com/android/server/wm/WallpaperController.java b/services/core/java/com/android/server/wm/WallpaperController.java
index 962325f..0841231 100644
--- a/services/core/java/com/android/server/wm/WallpaperController.java
+++ b/services/core/java/com/android/server/wm/WallpaperController.java
@@ -146,18 +146,11 @@
}
void updateWallpaperVisibility() {
- final DisplayContent displayContent = mWallpaperTarget.getDisplayContent();
- if (displayContent == null) {
- return;
- }
final boolean visible = isWallpaperVisible(mWallpaperTarget);
- final DisplayInfo displayInfo = displayContent.getDisplayInfo();
- final int dw = displayInfo.logicalWidth;
- final int dh = displayInfo.logicalHeight;
for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) {
final WindowToken token = mWallpaperTokens.get(curTokenNdx);
- token.updateWallpaperVisibility(dw, dh, visible, displayContent);
+ token.updateWallpaperVisibility(visible);
}
}
@@ -309,7 +302,7 @@
return null;
}
- void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
+ private void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
final DisplayContent displayContent = changingTarget.getDisplayContent();
if (displayContent == null) {
return;
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 981b813..285c40b 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -383,22 +383,18 @@
}
/** Checks if all windows in an app are all drawn and shows them if needed. */
- // TODO: The displayId shouldn't be needed as there shouldn't be a container on more than one
- // display. Remove once we migrate DisplayContent to use WindowContainer.
- void checkAppWindowsReadyToShow(int displayId) {
+ void checkAppWindowsReadyToShow() {
for (int i = mChildren.size() - 1; i >= 0; --i) {
final WindowContainer wc = mChildren.get(i);
- wc.checkAppWindowsReadyToShow(displayId);
+ wc.checkAppWindowsReadyToShow();
}
}
/** Step currently ongoing animation for App window containers. */
- // TODO: The displayId shouldn't be needed as there shouldn't be a container on more than one
- // display. Remove once we migrate DisplayContent to use WindowContainer.
- void stepAppWindowsAnimation(long currentTime, int displayId) {
+ void stepAppWindowsAnimation(long currentTime) {
for (int i = mChildren.size() - 1; i >= 0; --i) {
final WindowContainer wc = mChildren.get(i);
- wc.stepAppWindowsAnimation(currentTime, displayId);
+ wc.stepAppWindowsAnimation(currentTime);
}
}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 3ad43ce..02d04cc 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -1183,7 +1183,7 @@
WindowState highestTarget = null;
int highestPos = 0;
if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
- WindowList curWindows = curTarget.getWindowList();
+ WindowList curWindows = token.getDisplayContent().getWindowList();
int pos = curWindows.indexOf(curTarget);
while (pos >= 0) {
WindowState win = curWindows.get(pos);
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index a13c4d0..fa4dbc4 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -544,7 +544,7 @@
private static final Region sEmptyRegion = new Region();
/**
- * Compares to window sub-layers and returns -1 if the first is lesser than the second in terms
+ * Compares two window sub-layers and returns -1 if the first is lesser than the second in terms
* of z-order and 1 otherwise.
*/
private static final Comparator<WindowState> sWindowSubLayerComparator = (w1, w2) -> {
@@ -657,8 +657,7 @@
mYOffset = 0;
mLayer = 0;
mInputWindowHandle = new InputWindowHandle(
- mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
- getDisplayContent().getDisplayId());
+ mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, getDisplayId());
}
void attach() {
@@ -2984,7 +2983,7 @@
* Report a focus change. Must be called with no locks held, and consistently
* from the same serialized thread (such as dispatched from a handler).
*/
- public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
+ void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
try {
mClient.windowFocusChanged(focused, inTouchMode);
} catch (RemoteException e) {
@@ -3094,7 +3093,7 @@
if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
return frame;
}
- DisplayInfo displayInfo = getDisplayInfo();
+ final DisplayInfo displayInfo = getDisplayInfo();
mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
return mTmpRect;
}
diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
index 91eab14..218972a 100644
--- a/services/core/java/com/android/server/wm/WindowToken.java
+++ b/services/core/java/com/android/server/wm/WindowToken.java
@@ -21,6 +21,7 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;
+import android.view.DisplayInfo;
import java.io.PrintWriter;
@@ -109,15 +110,11 @@
final int count = mChildren.size();
boolean changed = false;
boolean delayed = false;
- DisplayContent displayContent = null;
for (int i = 0; i < count; i++) {
final WindowState win = mChildren.get(i);
if (win.mWinAnimator.isAnimationSet()) {
delayed = true;
- // TODO: This is technically wrong as a token can have windows on multi-displays
- // currently. That will change moving forward though.
- displayContent = win.getDisplayContent();
}
changed |= win.onSetAppExiting();
}
@@ -129,8 +126,8 @@
mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /*updateInputWindows*/);
}
- if (delayed && displayContent != null) {
- displayContent.mExitingTokens.add(this);
+ if (delayed) {
+ mDisplayContent.mExitingTokens.add(this);
}
}
@@ -174,22 +171,19 @@
void addWindow(final WindowState win) {
if (DEBUG_FOCUS) Slog.d(TAG_WM, "addWindow: win=" + win + " Callers=" + Debug.getCallers(5));
- final DisplayContent dc = win.getDisplayContent();
if (!win.isChildWindow()) {
int tokenWindowsPos = 0;
- if (dc != null) {
- if (asAppWindowToken() != null) {
- tokenWindowsPos = dc.addAppWindowToWindowList(win);
- } else {
- dc.addNonAppWindowToWindowList(win);
- }
+ if (asAppWindowToken() != null) {
+ tokenWindowsPos = mDisplayContent.addAppWindowToWindowList(win);
+ } else {
+ mDisplayContent.addNonAppWindowToWindowList(win);
}
if (!mChildren.contains(win)) {
if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "Adding " + win + " to " + this);
addChild(win, tokenWindowsPos);
}
- } else if (dc != null) {
- dc.addChildWindowToWindowList(win);
+ } else {
+ mDisplayContent.addChildWindowToWindowList(win);
}
}
@@ -289,11 +283,15 @@
}
}
- void updateWallpaperVisibility(int dw, int dh, boolean visible, DisplayContent displayContent) {
+ void updateWallpaperVisibility(boolean visible) {
+ final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
+ final int dw = displayInfo.logicalWidth;
+ final int dh = displayInfo.logicalHeight;
+
if (hidden == visible) {
hidden = !visible;
// Need to do a layout to ensure the wallpaper now has the correct size.
- displayContent.setLayoutNeeded();
+ mDisplayContent.setLayoutNeeded();
}
final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
@@ -316,7 +314,7 @@
"Wallpaper token " + token + " hidden=" + !visible);
hidden = !visible;
// Need to do a layout to ensure the wallpaper now has the correct size.
- mService.getDefaultDisplayContentLocked().setLayoutNeeded();
+ mDisplayContent.setLayoutNeeded();
}
final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;