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
This commit is contained in:
Wale Ogunwale
2016-10-17 10:13:07 -07:00
parent e5bfd737ee
commit b0f3b836b9
10 changed files with 68 additions and 104 deletions

View File

@@ -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 @@ public class AppWindowAnimator {
}
// 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 @@ public class AppWindowAnimator {
return false;
}
mAppToken.setAppLayoutChanges(
WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM, "AppWindowToken", displayId);
mAppToken.setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "AppWindowToken");
clearAnimation();
animating = false;

View File

@@ -270,7 +270,7 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
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 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
* 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 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
}
}
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 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
}
}
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 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
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 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
}
@Override
void checkAppWindowsReadyToShow(int displayId) {
void checkAppWindowsReadyToShow() {
if (allDrawn == mAppAnimator.allDrawn) {
return;
}
@@ -1047,9 +1035,9 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
+ " 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 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
}
@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);
}
}

View File

@@ -49,6 +49,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEME
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;
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 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
}
}
void checkAppWindowsReadyToShow() {
super.checkAppWindowsReadyToShow(mDisplayId);
}
void stepAppWindowsAnimation(long currentTime) {
super.stepAppWindowsAnimation(currentTime, mDisplayId);
}
@Override
boolean fillsParent() {
return true;
@@ -870,15 +864,14 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
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);
}
}

View File

@@ -54,6 +54,7 @@ import static android.view.WindowManager.INPUT_CONSUMER_PIP;
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 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
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);
}

View File

@@ -29,6 +29,7 @@ import static android.view.WindowManager.DOCKED_INVALID;
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 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
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 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
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);
}

View File

@@ -146,18 +146,11 @@ class WallpaperController {
}
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 @@ class WallpaperController {
return null;
}
void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
private void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
final DisplayContent displayContent = changingTarget.getDisplayContent();
if (displayContent == null) {
return;

View File

@@ -383,22 +383,18 @@ class WindowContainer<E extends WindowContainer> implements Comparable<WindowCon
}
/** 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);
}
}

View File

@@ -1183,7 +1183,7 @@ public class WindowManagerService extends IWindowManager.Stub
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);

View File

@@ -544,7 +544,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
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 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
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 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
* 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 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
return frame;
}
DisplayInfo displayInfo = getDisplayInfo();
final DisplayInfo displayInfo = getDisplayInfo();
mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
return mTmpRect;
}

View File

@@ -21,6 +21,7 @@ import android.os.Debug;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;
import android.view.DisplayInfo;
import java.io.PrintWriter;
@@ -109,15 +110,11 @@ class WindowToken extends WindowContainer<WindowState> {
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 @@ class WindowToken extends WindowContainer<WindowState> {
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 @@ class WindowToken extends WindowContainer<WindowState> {
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 @@ class WindowToken extends WindowContainer<WindowState> {
}
}
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 @@ class WindowToken extends WindowContainer<WindowState> {
"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;