OSDN Git Service

Made WindowState.mParentWindow private scoped.
authorWale Ogunwale <ogunwale@google.com>
Sun, 17 Jul 2016 21:50:26 +0000 (14:50 -0700)
committerWale Ogunwale <ogunwale@google.com>
Wed, 20 Jul 2016 03:18:11 +0000 (20:18 -0700)
Bug: 30060889
Change-Id: Ic1d702cb6329fb2f03d006939f5610681d1d07bd

services/core/java/com/android/server/wm/WallpaperController.java
services/core/java/com/android/server/wm/WindowManagerService.java
services/core/java/com/android/server/wm/WindowState.java
services/core/java/com/android/server/wm/WindowStateAnimator.java
services/core/java/com/android/server/wm/WindowSurfacePlacer.java
services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java

index 749ea12..edb01f8 100644 (file)
@@ -659,12 +659,13 @@ class WallpaperController {
             // 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
index 76189be..6a9fb58 100644 (file)
@@ -1354,18 +1354,17 @@ public class WindowManagerService extends IWindowManager.Stub
         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;
@@ -1379,19 +1378,17 @@ public class WindowManagerService extends IWindowManager.Stub
                 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);
@@ -1408,12 +1405,10 @@ public class WindowManagerService extends IWindowManager.Stub
                 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);
             }
         }
     }
@@ -1434,7 +1429,7 @@ public class WindowManagerService extends IWindowManager.Stub
                 token.windows.add(tokenWindowsPos, win);
             }
         } else {
-            addAttachedWindowToListLocked(win, addToToken);
+            addChildWindowToListLocked(win, addToToken);
         }
 
         final AppWindowToken appToken = win.mAppToken;
@@ -1685,7 +1680,7 @@ public class WindowManagerService extends IWindowManager.Stub
             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;
                     }
index 4dbac7e..f756ae9 100644 (file)
@@ -160,7 +160,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
     // 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;
@@ -341,8 +341,6 @@ final class WindowState implements WindowManagerPolicy.WindowState {
      */
     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
@@ -619,10 +617,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
             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);
@@ -1048,11 +1043,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
 
     @Override
     public int getBaseType() {
-        WindowState win = this;
-        while (win.isChildWindow()) {
-            win = win.mParentWindow;
-        }
-        return win.mAttrs.type;
+        return getTopParentWindow().mAttrs.type;
     }
 
     @Override
@@ -2187,11 +2178,8 @@ final class WindowState implements WindowManagerPolicy.WindowState {
     }
 
     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) {
 
@@ -2883,6 +2871,20 @@ final class WindowState implements WindowManagerPolicy.WindowState {
         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;
     }
index 673d28c..34e5260 100644 (file)
@@ -258,7 +258,7 @@ class WindowStateAnimator {
         }
 
         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;
@@ -1080,7 +1080,7 @@ class WindowStateAnimator {
 
         // 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
@@ -1883,8 +1883,7 @@ class WindowStateAnimator {
         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.
@@ -1903,7 +1902,7 @@ class WindowStateAnimator {
             mDeferTransactionUntilFrame = -1;
         } else {
             mSurfaceController.deferTransactionUntil(
-                    mWin.mParentWindow.mWinAnimator.mSurfaceController.getHandle(),
+                    mWin.getParentWindow().mWinAnimator.mSurfaceController.getHandle(),
                     mDeferTransactionUntilFrame);
         }
     }
@@ -1986,11 +1985,12 @@ class WindowStateAnimator {
         //     (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());
 
index 1b9eeb0..4a2325c 100644 (file)
@@ -663,8 +663,8 @@ class WindowSurfacePlacer {
                     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 |=
@@ -1040,7 +1040,7 @@ class WindowSurfacePlacer {
                     }
                     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="
index 68c64f7..64de15d 100644 (file)
@@ -16,8 +16,6 @@
 
 package com.android.server.wm;
 
-import com.android.server.LocalServices;
-
 import android.content.Context;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
@@ -27,7 +25,6 @@ import android.view.WindowManagerPolicy;
 
 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;
 
@@ -129,6 +126,27 @@ public class WindowStateTests extends AndroidTestCase {
         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);