Merge "Add system insets to windows." into jb-dev
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
index 6917fb2..9d36677 100644
--- a/core/java/android/service/wallpaper/WallpaperService.java
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -154,6 +154,7 @@
         int mCurWindowPrivateFlags = mWindowPrivateFlags;
         final Rect mVisibleInsets = new Rect();
         final Rect mWinFrame = new Rect();
+        final Rect mSystemInsets = new Rect();
         final Rect mContentInsets = new Rect();
         final Configuration mConfiguration = new Configuration();
         
@@ -253,7 +254,7 @@
 
         final BaseIWindow mWindow = new BaseIWindow() {
             @Override
-            public void resized(int w, int h, Rect coveredInsets,
+            public void resized(int w, int h, Rect systemInsets, Rect contentInsets,
                     Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
                 Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED,
                         reportDraw ? 1 : 0);
@@ -620,7 +621,7 @@
 
                     final int relayoutResult = mSession.relayout(
                         mWindow, mWindow.mSeq, mLayout, mWidth, mHeight,
-                            View.VISIBLE, 0, mWinFrame, mContentInsets,
+                            View.VISIBLE, 0, mWinFrame, mSystemInsets, mContentInsets,
                             mVisibleInsets, mConfiguration, mSurfaceHolder.mSurface);
 
                     if (DEBUG) Log.v(TAG, "New surface: " + mSurfaceHolder.mSurface
diff --git a/core/java/android/view/IWindow.aidl b/core/java/android/view/IWindow.aidl
index d73723a..555f306 100644
--- a/core/java/android/view/IWindow.aidl
+++ b/core/java/android/view/IWindow.aidl
@@ -45,8 +45,8 @@
      */
     void executeCommand(String command, String parameters, in ParcelFileDescriptor descriptor);
 
-    void resized(int w, int h, in Rect coveredInsets, in Rect visibleInsets,
-            boolean reportDraw, in Configuration newConfig);
+    void resized(int w, int h, in Rect systemInsets, in Rect contentInsets,
+            in Rect visibleInsets, boolean reportDraw, in Configuration newConfig);
     void dispatchAppVisibility(boolean visible);
     void dispatchGetNewSurface();
     void dispatchScreenState(boolean on);
diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl
index 53d6e1f..f26d5e1 100644
--- a/core/java/android/view/IWindowSession.aidl
+++ b/core/java/android/view/IWindowSession.aidl
@@ -58,6 +58,10 @@
      * {@link WindowManagerImpl#RELAYOUT_DEFER_SURFACE_DESTROY}.
      * @param outFrame Rect in which is placed the new position/size on
      * screen.
+     * @param outSystemInsets Rect in which is placed the offsets from
+     * <var>outFrame</var> over which any core system UI elements are
+     * currently covering the window.  This is not generally used for
+     * layout, but just to know where the window is obscured.
      * @param outContentInsets Rect in which is placed the offsets from
      * <var>outFrame</var> in which the content of the window should be
      * placed.  This can be used to modify the window layout to ensure its
@@ -79,9 +83,9 @@
      */
     int relayout(IWindow window, int seq, in WindowManager.LayoutParams attrs,
             int requestedWidth, int requestedHeight, int viewVisibility,
-            int flags, out Rect outFrame, out Rect outContentInsets,
-            out Rect outVisibleInsets, out Configuration outConfig,
-            out Surface outSurface);
+            int flags, out Rect outFrame, out Rect outSystemInsets,
+            out Rect outContentInsets, out Rect outVisibleInsets,
+            out Configuration outConfig, out Surface outSurface);
 
     /**
      * If a call to relayout() asked to have the surface destroy deferred,
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index c658a80..ee322f8 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -98,6 +98,7 @@
     MyWindow mWindow;
     final Rect mVisibleInsets = new Rect();
     final Rect mWinFrame = new Rect();
+    final Rect mSystemInsets = new Rect();
     final Rect mContentInsets = new Rect();
     final Configuration mConfiguration = new Configuration();
     
@@ -471,7 +472,7 @@
                         mWindow, mWindow.mSeq, mLayout, mWidth, mHeight,
                             visible ? VISIBLE : GONE,
                             WindowManagerImpl.RELAYOUT_DEFER_SURFACE_DESTROY,
-                            mWinFrame, mContentInsets,
+                            mWinFrame, mSystemInsets, mContentInsets,
                             mVisibleInsets, mConfiguration, mNewSurface);
                     if ((relayoutResult&WindowManagerImpl.RELAYOUT_RES_FIRST_TIME) != 0) {
                         mReportDrawNeeded = true;
@@ -605,7 +606,7 @@
             mSurfaceView = new WeakReference<SurfaceView>(surfaceView);
         }
 
-        public void resized(int w, int h, Rect coveredInsets,
+        public void resized(int w, int h, Rect systemInsets, Rect contentInsets,
                 Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
             SurfaceView surfaceView = mSurfaceView.get();
             if (surfaceView != null) {
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 21e57db..9565547 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -261,6 +261,7 @@
 
     final Rect mPendingVisibleInsets = new Rect();
     final Rect mPendingContentInsets = new Rect();
+    final Rect mPendingSystemInsets = new Rect();
     final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets
             = new ViewTreeObserver.InternalInsetsInfo();
 
@@ -3846,7 +3847,7 @@
                 (int) (mView.getMeasuredWidth() * appScale + 0.5f),
                 (int) (mView.getMeasuredHeight() * appScale + 0.5f),
                 viewVisibility, insetsPending ? WindowManagerImpl.RELAYOUT_INSETS_PENDING : 0,
-                mWinFrame, mPendingContentInsets, mPendingVisibleInsets,
+                mWinFrame, mPendingSystemInsets, mPendingContentInsets, mPendingVisibleInsets,
                 mPendingConfiguration, mSurface);
         //Log.d(TAG, "<<<<<< BACK FROM relayout");
         if (restore) {
@@ -4689,11 +4690,11 @@
             mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor);
         }
 
-        public void resized(int w, int h, Rect coveredInsets, Rect visibleInsets,
-                boolean reportDraw, Configuration newConfig) {
+        public void resized(int w, int h, Rect systemInsets, Rect contentInsets,
+                Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
             final ViewRootImpl viewAncestor = mViewAncestor.get();
             if (viewAncestor != null) {
-                viewAncestor.dispatchResized(w, h, coveredInsets, visibleInsets, reportDraw,
+                viewAncestor.dispatchResized(w, h, contentInsets, visibleInsets, reportDraw,
                         newConfig);
             }
         }
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index 27baaea..94762b9 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -140,6 +140,10 @@
          * @param displayFrame The frame of the overall display in which this
          * window can appear, used for constraining the overall dimensions
          * of the window.
+         * @param systemFrame The frame within the display that any system
+         * elements are currently covering.  These indicate which parts of
+         * the window should be considered completely obscured by the screen
+         * decorations.
          * @param contentFrame The frame within the display in which we would
          * like active content to appear.  This will cause windows behind to
          * be resized to match the given content frame.
@@ -151,7 +155,7 @@
          * are visible.
          */
         public void computeFrameLw(Rect parentFrame, Rect displayFrame,
-                Rect contentFrame, Rect visibleFrame);
+                Rect systemFrame, Rect contentFrame, Rect visibleFrame);
 
         /**
          * Retrieve the current frame of the window that has been assigned by
@@ -173,12 +177,20 @@
          * Retrieve the frame of the display that this window was last
          * laid out in.  Must be called with the
          * window manager lock held.
-         * 
+         *
          * @return Rect The rectangle holding the display frame.
          */
         public Rect getDisplayFrameLw();
 
         /**
+         * Retrieve the frame of the system elements that last covered the window.
+         * Must be called with the window manager lock held.
+         *
+         * @return Rect The rectangle holding the system frame.
+         */
+        public Rect getSystemFrameLw();
+
+        /**
          * Retrieve the frame of the content area that this window was last
          * laid out in.  This is the area in which the content of the window
          * should be placed.  It will be smaller than the display frame to
@@ -298,6 +310,12 @@
         boolean isDisplayedLw();
 
         /**
+         * Return true if this window (or a window it is attached to, but not
+         * considering its app token) is currently animating.
+         */
+        public boolean isAnimatingLw();
+
+        /**
          * Is this window considered to be gone for purposes of layout?
          */
         boolean isGoneForLayoutLw();
@@ -305,8 +323,6 @@
         /**
          * Returns true if this window has been shown on screen at some time in 
          * the past.  Must be called with the window manager lock held.
-         * 
-         * @return boolean
          */
         public boolean hasDrawnLw();
 
diff --git a/core/java/com/android/internal/view/BaseIWindow.java b/core/java/com/android/internal/view/BaseIWindow.java
index a649ee1..fbed4859 100644
--- a/core/java/com/android/internal/view/BaseIWindow.java
+++ b/core/java/com/android/internal/view/BaseIWindow.java
@@ -33,7 +33,7 @@
         mSession = session;
     }
     
-    public void resized(int w, int h, Rect coveredInsets,
+    public void resized(int w, int h, Rect systemInsets, Rect contentInsets,
             Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
         if (reportDraw) {
             try {
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index d2053ff..319eb36 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -407,6 +407,9 @@
     // that area of the display from all other windows.
     int mRestrictedScreenLeft, mRestrictedScreenTop;
     int mRestrictedScreenWidth, mRestrictedScreenHeight;
+    // During layout, the current screen borders accounting for any currently
+    // visible system UI elements.
+    int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
     // For applications requesting stable content insets, these are them.
     int mStableLeft, mStableTop, mStableRight, mStableBottom;
     // During layout, the current screen borders with all outer decoration
@@ -423,6 +426,8 @@
     int mDockLeft, mDockTop, mDockRight, mDockBottom;
     // During layout, the layer at which the doc window is placed.
     int mDockLayer;
+    // During layout, this is the layer of the status bar.
+    int mStatusBarLayer;
     int mLastSystemUiFlags;
     // Bits that we are in the process of clearing, so we want to prevent
     // them from being set by applications until everything has been updated
@@ -438,6 +443,7 @@
 
     static final Rect mTmpParentFrame = new Rect();
     static final Rect mTmpDisplayFrame = new Rect();
+    static final Rect mTmpSystemFrame = new Rect();
     static final Rect mTmpContentFrame = new Rect();
     static final Rect mTmpVisibleFrame = new Rect();
     static final Rect mTmpNavigationFrame = new Rect();
@@ -2168,11 +2174,12 @@
         mRestrictedScreenLeft = mRestrictedScreenTop = 0;
         mRestrictedScreenWidth = displayWidth;
         mRestrictedScreenHeight = displayHeight;
-        mDockLeft = mContentLeft = mStableLeft = mCurLeft = 0;
-        mDockTop = mContentTop = mStableTop = mCurTop = 0;
-        mDockRight = mContentRight = mStableRight = mCurRight = displayWidth;
-        mDockBottom = mContentBottom = mStableBottom = mCurBottom = displayHeight;
+        mDockLeft = mContentLeft = mStableLeft = mSystemLeft = mCurLeft = 0;
+        mDockTop = mContentTop = mStableTop = mSystemTop = mCurTop = 0;
+        mDockRight = mContentRight = mStableRight = mSystemRight = mCurRight = displayWidth;
+        mDockBottom = mContentBottom = mStableBottom = mSystemBottom = mCurBottom = displayHeight;
         mDockLayer = 0x10000000;
+        mStatusBarLayer = -1;
 
         // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
         final Rect pf = mTmpParentFrame;
@@ -2232,6 +2239,12 @@
                     // We currently want to hide the navigation UI.
                     mNavigationBar.hideLw(true);
                 }
+                if (navVisible && !mNavigationBar.isAnimatingLw()) {
+                    // If the nav bar is currently requested to be visible,
+                    // and not in the process of animating on or off, then
+                    // we can tell the app that it is covered by it.
+                    mSystemBottom = mTmpNavigationFrame.top;
+                }
             } else {
                 // Landscape screen; nav bar goes to the right.
                 int left = displayWidth - mNavigationBarWidthForRotation[displayRotation];
@@ -2250,6 +2263,12 @@
                     // We currently want to hide the navigation UI.
                     mNavigationBar.hideLw(true);
                 }
+                if (navVisible && !mNavigationBar.isAnimatingLw()) {
+                    // If the nav bar is currently requested to be visible,
+                    // and not in the process of animating on or off, then
+                    // we can tell the app that it is covered by it.
+                    mSystemRight = mTmpNavigationFrame.left;
+                }
             }
             // Make sure the content and current rectangles are updated to
             // account for the restrictions from the navigation bar.
@@ -2257,9 +2276,10 @@
             mContentBottom = mCurBottom = mDockBottom;
             mContentLeft = mCurLeft = mDockLeft;
             mContentRight = mCurRight = mDockRight;
+            mStatusBarLayer = mNavigationBar.getSurfaceLayer();
             // And compute the final frame.
             mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
-                    mTmpNavigationFrame, mTmpNavigationFrame);
+                    mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
             if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
         }
         if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
@@ -2277,8 +2297,10 @@
             vf.right = mStableRight;
             vf.bottom = mStableBottom;
 
+            mStatusBarLayer = mStatusBar.getSurfaceLayer();
+
             // Let the status bar determine its size.
-            mStatusBar.computeFrameLw(pf, df, vf, vf);
+            mStatusBar.computeFrameLw(pf, df, df, vf, vf);
 
             // For layout, the status bar is always at the top with our fixed height.
             mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
@@ -2303,6 +2325,12 @@
                         mContentLeft, mContentTop, mContentRight, mContentBottom,
                         mCurLeft, mCurTop, mCurRight, mCurBottom));
             }
+            if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
+                // If the status bar is currently requested to be visible,
+                // and not in the process of animating on or off, then
+                // we can tell the app that it is covered by it.
+                mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
+            }
         }
     }
 
@@ -2368,6 +2396,7 @@
 
         final Rect pf = mTmpParentFrame;
         final Rect df = mTmpDisplayFrame;
+        final Rect sf = mTmpSystemFrame;
         final Rect cf = mTmpContentFrame;
         final Rect vf = mTmpVisibleFrame;
         
@@ -2611,6 +2640,20 @@
             df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
         }
 
+        // Compute the system frame.  This is easy: for things behind the
+        // status bar, it is any application windows; otherwise it is not set.
+        int parentType = attached != null ? attached.getAttrs().type : attrs.type;
+        if (win.getSurfaceLayer() < mStatusBarLayer
+                && parentType < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW) {
+            sf.left = mSystemLeft;
+            sf.top = mSystemTop;
+            sf.right = mSystemRight;
+            sf.bottom = mSystemBottom;
+        } else {
+            sf.left = sf.top = -10000;
+            sf.right = sf.bottom = 10000;
+        }
+
         if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
                 + ": sim=#" + Integer.toHexString(sim)
                 + " attach=" + attached + " type=" + attrs.type 
@@ -2618,7 +2661,7 @@
                 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
                 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
         
-        win.computeFrameLw(pf, df, cf, vf);
+        win.computeFrameLw(pf, df, sf, cf, vf);
         
         // Dock windows carve out the bottom of the screen, so normal windows
         // can't appear underneath them.
@@ -4193,6 +4236,10 @@
                 pw.print(","); pw.print(mStableTop);
                 pw.print(")-("); pw.print(mStableRight);
                 pw.print(","); pw.print(mStableBottom); pw.println(")");
+        pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
+                pw.print(","); pw.print(mSystemTop);
+                pw.print(")-("); pw.print(mSystemRight);
+                pw.print(","); pw.print(mSystemBottom); pw.println(")");
         pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
                 pw.print(","); pw.print(mCurTop);
                 pw.print(")-("); pw.print(mCurRight);
@@ -4205,7 +4252,8 @@
                 pw.print(","); pw.print(mDockTop);
                 pw.print(")-("); pw.print(mDockRight);
                 pw.print(","); pw.print(mDockBottom); pw.println(")");
-        pw.print(prefix); pw.print("mDockLayer="); pw.println(mDockLayer);
+        pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
+                pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
         pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
                 pw.println(mTopFullscreenOpaqueWindowState);
         pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
diff --git a/services/java/com/android/server/wm/Session.java b/services/java/com/android/server/wm/Session.java
index 77575f2..53c0e07 100644
--- a/services/java/com/android/server/wm/Session.java
+++ b/services/java/com/android/server/wm/Session.java
@@ -151,13 +151,14 @@
 
     public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
             int requestedWidth, int requestedHeight, int viewFlags,
-            int flags, Rect outFrame, Rect outContentInsets,
+            int flags, Rect outFrame, Rect outSystemInsets, Rect outContentInsets,
             Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
         if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED relayout from "
                 + Binder.getCallingPid());
         int res = mService.relayoutWindow(this, window, seq, attrs,
                 requestedWidth, requestedHeight, viewFlags, flags,
-                outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
+                outFrame, outSystemInsets, outContentInsets, outVisibleInsets,
+                outConfig, outSurface);
         if (false) Slog.d(WindowManagerService.TAG, "<<<<<< EXITING relayout to "
                 + Binder.getCallingPid());
         return res;
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 1dce5dd..16aeb35 100755
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -2647,8 +2647,8 @@
     public int relayoutWindow(Session session, IWindow client, int seq,
             WindowManager.LayoutParams attrs, int requestedWidth,
             int requestedHeight, int viewVisibility, int flags,
-            Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
-            Configuration outConfig, Surface outSurface) {
+            Rect outFrame, Rect outSystemInsets, Rect outContentInsets,
+            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
         boolean displayed = false;
         boolean inTouchMode;
         boolean configChanged;
@@ -2939,6 +2939,7 @@
                 win.mAppToken.updateReportedVisibilityLocked();
             }
             outFrame.set(win.mCompatFrame);
+            outSystemInsets.set(win.mSystemInsets);
             outContentInsets.set(win.mContentInsets);
             outVisibleInsets.set(win.mVisibleInsets);
             if (localLOGV) Slog.v(
@@ -8092,10 +8093,12 @@
     private void updateResizingWindows(final WindowState w) {
         final WindowStateAnimator winAnimator = w.mWinAnimator;
         if (w.mHasSurface && !w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
+            w.mSystemInsetsChanged |=
+                    !w.mLastSystemInsets.equals(w.mSystemInsets);
             w.mContentInsetsChanged |=
-                !w.mLastContentInsets.equals(w.mContentInsets);
+                    !w.mLastContentInsets.equals(w.mContentInsets);
             w.mVisibleInsetsChanged |=
-                !w.mLastVisibleInsets.equals(w.mVisibleInsets);
+                    !w.mLastVisibleInsets.equals(w.mVisibleInsets);
             boolean configChanged =
                 w.mConfiguration != mCurConfiguration
                 && (w.mConfiguration == null
@@ -8108,7 +8111,8 @@
                     + ": configChanged=" + configChanged
                     + " last=" + w.mLastFrame + " frame=" + w.mFrame);
             w.mLastFrame.set(w.mFrame);
-            if (w.mContentInsetsChanged
+            if (w.mSystemInsetsChanged
+                    || w.mContentInsetsChanged
                     || w.mVisibleInsetsChanged
                     || winAnimator.mSurfaceResized
                     || configChanged) {
@@ -8120,6 +8124,7 @@
                             + " configChanged=" + configChanged);
                 }
 
+                w.mLastSystemInsets.set(w.mSystemInsets);
                 w.mLastContentInsets.set(w.mContentInsets);
                 w.mLastVisibleInsets.set(w.mVisibleInsets);
                 makeWindowFreezingScreenIfNeededLocked(w);
@@ -8505,10 +8510,11 @@
                             winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) Slog.i(
                             TAG, "Resizing " + win + " WITH DRAW PENDING");
                     win.mClient.resized((int)winAnimator.mSurfaceW,
-                            (int)winAnimator.mSurfaceH,
+                            (int)winAnimator.mSurfaceH, win.mLastSystemInsets,
                             win.mLastContentInsets, win.mLastVisibleInsets,
                             winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING,
                             configChanged ? win.mConfiguration : null);
+                    win.mSystemInsetsChanged = false;
                     win.mContentInsetsChanged = false;
                     win.mVisibleInsetsChanged = false;
                     winAnimator.mSurfaceResized = false;
diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java
index 4de6425..05e7d3a 100644
--- a/services/java/com/android/server/wm/WindowState.java
+++ b/services/java/com/android/server/wm/WindowState.java
@@ -124,7 +124,8 @@
     boolean mVisibleInsetsChanged;
 
     /**
-     * Insets that are covered by system windows.  These are in the application's
+     * Insets that are covered by system windows (such as the status bar) and
+     * transient docking windows (such as the IME).  These are in the application's
      * coordinate space (without compatibility scale applied).
      */
     final Rect mContentInsets = new Rect();
@@ -132,6 +133,14 @@
     boolean mContentInsetsChanged;
 
     /**
+     * Insets that are covered by system windows such as the status bar.  These
+     * are in the application's coordinate space (without compatibility scale applied).
+     */
+    final Rect mSystemInsets = new Rect();
+    final Rect mLastSystemInsets = new Rect();
+    boolean mSystemInsetsChanged;
+
+    /**
      * Set to true if we are waiting for this window to receive its
      * given internal insets before laying out other windows based on it.
      */
@@ -178,6 +187,7 @@
 
     final Rect mContainingFrame = new Rect();
     final Rect mDisplayFrame = new Rect();
+    final Rect mSystemFrame = new Rect();
     final Rect mContentFrame = new Rect();
     final Rect mParentFrame = new Rect();
     final Rect mVisibleFrame = new Rect();
@@ -346,7 +356,7 @@
     }
 
     @Override
-    public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
+    public void computeFrameLw(Rect pf, Rect df, Rect sf, Rect cf, Rect vf) {
         mHaveFrame = true;
 
         final Rect container = mContainingFrame;
@@ -403,6 +413,9 @@
             mContentChanged = true;
         }
 
+        final Rect system = mSystemFrame;
+        system.set(sf);
+
         final Rect content = mContentFrame;
         content.set(cf);
 
@@ -434,8 +447,12 @@
         // Now make sure the window fits in the overall display.
         Gravity.applyDisplay(mAttrs.gravity, df, frame);
 
-        // Make sure the content and visible frames are inside of the
+        // Make sure the system, content and visible frames are inside of the
         // final window frame.
+        if (system.left < frame.left) system.left = frame.left;
+        if (system.top < frame.top) system.top = frame.top;
+        if (system.right > frame.right) system.right = frame.right;
+        if (system.bottom > frame.bottom) system.bottom = frame.bottom;
         if (content.left < frame.left) content.left = frame.left;
         if (content.top < frame.top) content.top = frame.top;
         if (content.right > frame.right) content.right = frame.right;
@@ -445,6 +462,12 @@
         if (visible.right > frame.right) visible.right = frame.right;
         if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
 
+        final Rect systemInsets = mSystemInsets;
+        systemInsets.left = system.left-frame.left;
+        systemInsets.top = system.top-frame.top;
+        systemInsets.right = frame.right-system.right;
+        systemInsets.bottom = frame.bottom-system.bottom;
+
         final Rect contentInsets = mContentInsets;
         contentInsets.left = content.left-frame.left;
         contentInsets.top = content.top-frame.top;
@@ -462,6 +485,7 @@
             // If there is a size compatibility scale being applied to the
             // window, we need to apply this to its insets so that they are
             // reported to the app in its coordinate space.
+            systemInsets.scale(mInvGlobalScale);
             contentInsets.scale(mInvGlobalScale);
             visibleInsets.scale(mInvGlobalScale);
 
@@ -482,6 +506,7 @@
                         + mRequestedWidth + ", mRequestedheight="
                         + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
                         + "): frame=" + mFrame.toShortString()
+                        + " si=" + systemInsets.toShortString()
                         + " ci=" + contentInsets.toShortString()
                         + " vi=" + visibleInsets.toShortString());
             //}
@@ -504,6 +529,11 @@
     }
 
     @Override
+    public Rect getSystemFrameLw() {
+        return mSystemFrame;
+    }
+
+    @Override
     public Rect getContentFrameLw() {
         return mContentFrame;
     }
@@ -723,6 +753,14 @@
                     || mWinAnimator.mAnimating);
     }
 
+    /**
+     * Return true if this window (or a window it is attached to, but not
+     * considering its app token) is currently animating.
+     */
+    public boolean isAnimatingLw() {
+        return mWinAnimator.mAnimation != null;
+    }
+
     public boolean isGoneForLayoutLw() {
         final AppWindowToken atoken = mAppToken;
         return mViewVisibility == View.GONE
@@ -1035,20 +1073,22 @@
                     pw.println();
         }
         if (dumpAll) {
-            pw.print(prefix); pw.print("mContainingFrame=");
+            pw.print(prefix); pw.print("Frames: containing=");
                     mContainingFrame.printShortString(pw);
-                    pw.print(" mParentFrame=");
-                    mParentFrame.printShortString(pw);
-                    pw.print(" mDisplayFrame=");
-                    mDisplayFrame.printShortString(pw);
+                    pw.print(" parent="); mParentFrame.printShortString(pw);
+                    pw.print(" display="); mDisplayFrame.printShortString(pw);
                     pw.println();
-            pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
-                    pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
+            pw.print(prefix); pw.print("    system="); mSystemFrame.printShortString(pw);
+                    pw.print(" content="); mContentFrame.printShortString(pw);
+                    pw.print(" visible="); mVisibleFrame.printShortString(pw);
                     pw.println();
-            pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
-                    pw.print(" last="); mLastContentInsets.printShortString(pw);
-                    pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
-                    pw.print(" last="); mLastVisibleInsets.printShortString(pw);
+            pw.print(prefix); pw.print("Cur insets: system="); mSystemInsets.printShortString(pw);
+                    pw.print(" content="); mContentInsets.printShortString(pw);;
+                    pw.print(" visible="); mVisibleInsets.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("Lst insets: system="); mLastSystemInsets.printShortString(pw);
+                    pw.print(" content="); mLastContentInsets.printShortString(pw);;
+                    pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
                     pw.println();
         }
         mWinAnimator.dump(pw, prefix, dumpAll);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java
index 434ae9d..c44ddc6 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java
@@ -47,8 +47,8 @@
     }
 
     @Override
-    public void resized(int arg0, int arg1, Rect arg2, Rect arg3, boolean arg4, Configuration arg5)
-            throws RemoteException {
+    public void resized(int arg0, int arg1, Rect argBlah, Rect arg2, Rect arg3,
+            boolean arg4, Configuration arg5) throws RemoteException {
         // pass for now.
     }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java
index d3721ed..3996d26 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java
@@ -69,8 +69,8 @@
     }
     @Override
     public int relayout(IWindow arg0, int seq, LayoutParams arg1, int arg2, int arg3, int arg4,
-            int arg4_5, Rect arg5, Rect arg6, Rect arg7, Configuration arg7b, Surface arg8)
-            throws RemoteException {
+            int arg4_5, Rect arg4_6, Rect arg5, Rect arg6, Rect arg7, Configuration arg7b,
+            Surface arg8) throws RemoteException {
         // pass for now.
         return 0;
     }