// AND any starting window associated with it, AND below the
// maximum layer the policy allows for wallpapers.
while (wallpaperTargetIndex > 0) {
- WindowState wb = windows.get(wallpaperTargetIndex - 1);
- if (wb.mBaseLayer < maxLayer &&
- wb.mParentWindow != wallpaperTarget &&
- (wallpaperTarget.mParentWindow == null ||
- wb.mParentWindow != wallpaperTarget.mParentWindow) &&
- (wb.mAttrs.type != TYPE_APPLICATION_STARTING
+ final WindowState wb = windows.get(wallpaperTargetIndex - 1);
+ final WindowState wbParentWindow = wb.getParentWindow();
+ final WindowState wallpaperParentWindow = wallpaperTarget.getParentWindow();
+ if (wb.mBaseLayer < maxLayer
+ && wbParentWindow != wallpaperTarget
+ && (wallpaperParentWindow == null || wbParentWindow != wallpaperParentWindow)
+ && (wb.mAttrs.type != TYPE_APPLICATION_STARTING
|| wallpaperTarget.mToken == null
|| wb.mToken != wallpaperTarget.mToken)) {
// This window is not related to the previous one in any
mWindowsChanged = true;
}
- private void addAttachedWindowToListLocked(final WindowState win, boolean addToToken) {
+ private void addChildWindowToListLocked(final WindowState win, boolean addToToken) {
final WindowToken token = win.mToken;
final DisplayContent displayContent = win.getDisplayContent();
if (displayContent == null) {
return;
}
- final WindowState attached = win.mParentWindow;
+ final WindowState parentWindow = win.getParentWindow();
WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent);
- // Figure out this window's ordering relative to the window
- // it is attached to.
+ // Figure out this window's ordering relative to the parent window.
final int NA = tokenWindowList.size();
final int sublayer = win.mSubLayer;
int largestSublayer = Integer.MIN_VALUE;
windowWithLargestSublayer = w;
}
if (sublayer < 0) {
- // For negative sublayers, we go below all windows
- // in the same sublayer.
+ // For negative sublayers, we go below all windows in the same sublayer.
if (wSublayer >= sublayer) {
if (addToToken) {
if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "Adding " + win + " to " + token);
token.windows.add(i, win);
}
- placeWindowBefore(wSublayer >= 0 ? attached : w, win);
+ placeWindowBefore(wSublayer >= 0 ? parentWindow : w, win);
break;
}
} else {
- // For positive sublayers, we go above all windows
- // in the same sublayer.
+ // For positive sublayers, we go above all windows in the same sublayer.
if (wSublayer > sublayer) {
if (addToToken) {
if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "Adding " + win + " to " + token);
token.windows.add(win);
}
if (sublayer < 0) {
- placeWindowBefore(attached, win);
+ placeWindowBefore(parentWindow, win);
} else {
- placeWindowAfter(largestSublayer >= 0
- ? windowWithLargestSublayer
- : attached,
- win);
+ placeWindowAfter(
+ largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow, win);
}
}
}
token.windows.add(tokenWindowsPos, win);
}
} else {
- addAttachedWindowToListLocked(win, addToToken);
+ addChildWindowToListLocked(win, addToToken);
}
final AppWindowToken appToken = win.mAppToken;
if (mInputMethodWindow != null) {
while (pos < windows.size()) {
WindowState wp = windows.get(pos);
- if (wp == mInputMethodWindow || wp.mParentWindow == mInputMethodWindow) {
+ if (wp == mInputMethodWindow || wp.getParentWindow() == mInputMethodWindow) {
pos++;
continue;
}
// modified they will need to be locked.
final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
final DeathRecipient mDeathRecipient;
- final WindowState mParentWindow;
+ private final WindowState mParentWindow;
private final WindowList mChildWindows = new WindowList();
final int mBaseLayer;
final int mSubLayer;
*/
final Rect mInsetFrame = new Rect();
- private static final Rect sTmpRect = new Rect();
-
boolean mContentChanged;
// If a window showing a wallpaper: the requested offset for the
mIsFloatingLayer = mIsImWindow || mIsWallpaper;
}
- WindowState appWin = this;
- while (appWin.isChildWindow()) {
- appWin = appWin.mParentWindow;
- }
+ final WindowState appWin = getTopParentWindow();
WindowToken appToken = appWin.mToken;
while (appToken.appWindowToken == null) {
WindowToken parent = mService.mTokenMap.get(appToken.token);
@Override
public int getBaseType() {
- WindowState win = this;
- while (win.isChildWindow()) {
- win = win.mParentWindow;
- }
- return win.mAttrs.type;
+ return getTopParentWindow().mAttrs.type;
}
@Override
}
boolean isHiddenFromUserLocked() {
- // Attached windows are evaluated based on the window that they are attached to.
- WindowState win = this;
- while (win.isChildWindow()) {
- win = win.mParentWindow;
- }
+ // Child windows are evaluated based on their parent window.
+ final WindowState win = getTopParentWindow();
if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
&& win.mAppToken != null && win.mAppToken.showForAllUsers) {
return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
}
+ /** Returns the parent window if this is a child of another window, else null. */
+ WindowState getParentWindow() {
+ return mParentWindow;
+ }
+
+ /** Returns the topmost parent window if this is a child of another window, else this. */
+ WindowState getTopParentWindow() {
+ WindowState w = this;
+ while (w.isChildWindow()) {
+ w = w.getParentWindow();
+ }
+ return w;
+ }
+
boolean isParentWindowHidden() {
return (mParentWindow != null) ? mParentWindow.mHidden : false;
}
}
mWin = win;
- mParentWinAnimator = !win.isChildWindow() ? null : win.mParentWindow.mWinAnimator;
+ mParentWinAnimator = !win.isChildWindow() ? null : win.getParentWindow().mWinAnimator;
mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
mSession = win.mSession;
mAttrType = win.mAttrs.type;
// Initialize the decor rect to the entire frame.
if (w.isDockedResizing() ||
- (w.isChildWindow() && w.mParentWindow.isDockedResizing())) {
+ (w.isChildWindow() && w.getParentWindow().isDockedResizing())) {
// If we are resizing with the divider, the task bounds might be smaller than the
// stack bounds. The system decor is used to clip to the task bounds, which we don't
mDeferTransactionUntilFrame = frameNumber;
mDeferTransactionTime = System.currentTimeMillis();
mSurfaceController.deferTransactionUntil(
- mWin.mParentWindow.mWinAnimator.mSurfaceController.getHandle(),
- frameNumber);
+ mWin.getParentWindow().mWinAnimator.mSurfaceController.getHandle(), frameNumber);
}
// Defer the current transaction to the frame number of the last saved transaction.
mDeferTransactionUntilFrame = -1;
} else {
mSurfaceController.deferTransactionUntil(
- mWin.mParentWindow.mWinAnimator.mSurfaceController.getHandle(),
+ mWin.getParentWindow().mWinAnimator.mSurfaceController.getHandle(),
mDeferTransactionUntilFrame);
}
}
// (in the new coordinate space). We then freeze layer updates until the resize
// occurs, at which point we undo, them.
if (w.isChildWindow() && mSurfaceController.getTransformToDisplayInverse()) {
- frameRect.set(x, y, x+width, y+height);
+ frameRect.set(x, y, x + width, y + height);
transform.mapRect(frameRect);
- w.mAttrs.x = (int) frameRect.left - w.mParentWindow.mFrame.left;
- w.mAttrs.y = (int) frameRect.top - w.mParentWindow.mFrame.top;
+ final Rect parentWindowFrame = w.getParentWindow().mFrame;
+ w.mAttrs.x = (int) frameRect.left - parentWindowFrame.left;
+ w.mAttrs.y = (int) frameRect.top - parentWindowFrame.top;
w.mAttrs.width = (int) Math.ceil(frameRect.width());
w.mAttrs.height = (int) Math.ceil(frameRect.height());
for (int i = windows.size() - 1; i >= 0; i--) {
WindowState w = windows.get(i);
if (w.mHasSurface) {
- mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs,
- w.mParentWindow);
+ mService.mPolicy.applyPostLayoutPolicyLw(
+ w, w.mAttrs, w.getParentWindow());
}
}
displayContent.pendingLayoutChanges |=
}
win.mLayoutNeeded = false;
win.prelayout();
- mService.mPolicy.layoutWindowLw(win, win.mParentWindow);
+ mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
win.mLayoutSeq = seq;
if (DEBUG_LAYOUT) Slog.v(TAG,
" LAYOUT: mFrame=" + win.mFrame + " mContainingFrame="
package com.android.server.wm;
-import com.android.server.LocalServices;
-
import android.content.Context;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
-import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
assertEquals(child4, parentWindow.getBottomChild());
}
+ public void testGetParentWindow() throws Exception {
+ final WindowState parentWindow = createWindow(null, TYPE_APPLICATION);
+ final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW);
+ final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW);
+
+ assertNull(parentWindow.getParentWindow());
+ assertEquals(parentWindow, child1.getParentWindow());
+ assertEquals(parentWindow, child2.getParentWindow());
+ }
+
+ public void testGetTopParentWindow() throws Exception {
+ final WindowState root = createWindow(null, TYPE_APPLICATION);
+ final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW);
+ final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW);
+
+ assertEquals(root, root.getTopParentWindow());
+ assertEquals(root, child1.getTopParentWindow());
+ assertEquals(child1, child2.getParentWindow());
+ assertEquals(root, child2.getTopParentWindow());
+ }
+
private WindowState createWindow(WindowState parent, int type) {
final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);