Expose the window flags for lights out mode.

I hadn't wanted to do this, but it makes porting the FLAG_FULLSCREEN
stuff over to this simpler because you don't have to go find a view
to proxy through.

This change also clears the flag everywhere when the window manager
notifies the views that the change has come back.

Change-Id: I48392c7550925bcca50c5bb9e1f263e99de6c7bc
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 449091a..f8971cc 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -10807,6 +10807,7 @@
     /**
      */
     public void dispatchSystemUiVisibilityChanged(int visibility) {
+        mSystemUiVisibility = visibility;
         if (mOnSystemUiVisibilityChangeListener != null) {
             mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange(visibility);
         }
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index b0553c6..042095a 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -903,8 +903,9 @@
             attachInfo.mSystemUiVisibility = 0;
             attachInfo.mHasSystemUiListeners = false;
             host.dispatchCollectViewAttributes(0);
-            if (attachInfo.mKeepScreenOn != oldScreenOn ||
-                    attachInfo.mSystemUiVisibility != oldVis) {
+            if (attachInfo.mKeepScreenOn != oldScreenOn
+                    || attachInfo.mSystemUiVisibility != oldVis
+                    || attachInfo.mHasSystemUiListeners) {
                 params = lp;
             }
         }
@@ -987,8 +988,10 @@
                     if (attachInfo.mKeepScreenOn) {
                         params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
                     }
-                    params.systemUiVisibility = attachInfo.mSystemUiVisibility;
-                    params.hasSystemUiListeners = attachInfo.mHasSystemUiListeners;
+                    params.subtreeSystemUiVisibility = attachInfo.mSystemUiVisibility;
+                    params.hasSystemUiListeners = attachInfo.mHasSystemUiListeners
+                            || params.subtreeSystemUiVisibility != 0
+                            || params.systemUiVisibility != 0;
                 }
                 if (DEBUG_LAYOUT) {
                     Log.i(TAG, "host=w:" + host.getMeasuredWidth() + ", h:" +
@@ -2854,6 +2857,9 @@
 
     public void handleDispatchSystemUiVisibilityChanged(int visibility) {
         if (mView == null) return;
+        if (mAttachInfo != null) {
+            mAttachInfo.mSystemUiVisibility = visibility;
+        }
         mView.dispatchSystemUiVisibilityChanged(visibility);
     }
 
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 491a79f..c26fa93 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -953,11 +953,20 @@
 
         /**
          * Control the visibility of the status bar.
-         * @hide
+         *
+         * @see View#STATUS_BAR_VISIBLE
+         * @see View#STATUS_BAR_HIDDEN
          */
         public int systemUiVisibility;
 
         /**
+         * @hide
+         * The ui visibility as requested by the views in this hierarchy.
+         * the combined value should be systemUiVisibility | subtreeSystemUiVisibility.
+         */
+        public int subtreeSystemUiVisibility;
+
+        /**
          * Get callbacks about the system ui visibility changing.
          * 
          * TODO: Maybe there should be a bitfield of optional callbacks that we need.
@@ -1046,6 +1055,7 @@
             TextUtils.writeToParcel(mTitle, out, parcelableFlags);
             out.writeInt(screenOrientation);
             out.writeInt(systemUiVisibility);
+            out.writeInt(subtreeSystemUiVisibility);
             out.writeInt(hasSystemUiListeners ? 1 : 0);
         }
         
@@ -1083,6 +1093,7 @@
             mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
             screenOrientation = in.readInt();
             systemUiVisibility = in.readInt();
+            subtreeSystemUiVisibility = in.readInt();
             hasSystemUiListeners = in.readInt() != 0;
         }
     
@@ -1212,8 +1223,10 @@
                 changes |= SCREEN_ORIENTATION_CHANGED;
             }
 
-            if (systemUiVisibility != o.systemUiVisibility) {
+            if (systemUiVisibility != o.systemUiVisibility
+                    || subtreeSystemUiVisibility != o.subtreeSystemUiVisibility) {
                 systemUiVisibility = o.systemUiVisibility;
+                subtreeSystemUiVisibility = o.subtreeSystemUiVisibility;
                 changes |= SYSTEM_UI_VISIBILITY_CHANGED;
             }
 
@@ -1298,6 +1311,10 @@
                 sb.append(" sysui=0x");
                 sb.append(Integer.toHexString(systemUiVisibility));
             }
+            if (subtreeSystemUiVisibility != 0) {
+                sb.append(" vsysui=0x");
+                sb.append(Integer.toHexString(subtreeSystemUiVisibility));
+            }
             if (hasSystemUiListeners) {
                 sb.append(" sysuil=");
                 sb.append(hasSystemUiListeners);