Implement issue #1780928: Need support hiding nav keys.

This implements support for devices whose hardware can hide
their navigation keys.  It works much like the existing keyboardHidden
configuration, and for compatibility uses the same configuration
change bit.

Also add FLAG_TURN_ON_SCREEN for windows, which has the system
cause the screen to be turned on when the window is displayed.
Great fun when used with FLAG_SHOW_WHEN_LOCKED!

Change-Id: I0b867f19af85cfd8786a14cea194b34f7bdd9b7a
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 27783ef..1ad13c5 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -217,7 +217,9 @@
     public static final int CONFIG_KEYBOARD = 0x0010;
     /**
      * Bit in {@link #configChanges} that indicates that the activity
-     * can itself handle changes to the keyboard being hidden/exposed. 
+     * can itself handle changes to the keyboard or navigation being hidden/exposed.
+     * Note that inspite of the name, this applies to the changes to any
+     * hidden states: keyboard or navigation.
      * Set from the {@link android.R.attr#configChanges} attribute.
      */
     public static final int CONFIG_KEYBOARD_HIDDEN = 0x0020;
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index cbf8410..1fe34b5 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -138,6 +138,18 @@
      */
     public int navigation;
     
+    public static final int NAVIGATIONHIDDEN_UNDEFINED = 0;
+    public static final int NAVIGATIONHIDDEN_NO = 1;
+    public static final int NAVIGATIONHIDDEN_YES = 2;
+    
+    /**
+     * A flag indicating whether any 5-way or DPAD navigation available.
+     * This will be set on a device with a mechanism to hide the navigation
+     * controls from the user, when that mechanism is closed.  One of:
+     * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}.
+     */
+    public int navigationHidden;
+    
     public static final int ORIENTATION_UNDEFINED = 0;
     public static final int ORIENTATION_PORTRAIT = 1;
     public static final int ORIENTATION_LANDSCAPE = 2;
@@ -174,6 +186,7 @@
         keyboardHidden = o.keyboardHidden;
         hardKeyboardHidden = o.hardKeyboardHidden;
         navigation = o.navigation;
+        navigationHidden = o.navigationHidden;
         orientation = o.orientation;
         screenLayout = o.screenLayout;
     }
@@ -198,6 +211,8 @@
         sb.append(hardKeyboardHidden);
         sb.append(" nav=");
         sb.append(navigation);
+        sb.append("/");
+        sb.append(navigationHidden);
         sb.append(" orien=");
         sb.append(orientation);
         sb.append(" layout=");
@@ -219,6 +234,7 @@
         keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
         hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
         navigation = NAVIGATION_UNDEFINED;
+        navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
         orientation = ORIENTATION_UNDEFINED;
         screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
     }
@@ -286,6 +302,11 @@
             changed |= ActivityInfo.CONFIG_NAVIGATION;
             navigation = delta.navigation;
         }
+        if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
+                && navigationHidden != delta.navigationHidden) {
+            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
+            navigationHidden = delta.navigationHidden;
+        }
         if (delta.orientation != ORIENTATION_UNDEFINED
                 && orientation != delta.orientation) {
             changed |= ActivityInfo.CONFIG_ORIENTATION;
@@ -360,6 +381,10 @@
                 && navigation != delta.navigation) {
             changed |= ActivityInfo.CONFIG_NAVIGATION;
         }
+        if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
+                && navigationHidden != delta.navigationHidden) {
+            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
+        }
         if (delta.orientation != ORIENTATION_UNDEFINED
                 && orientation != delta.orientation) {
             changed |= ActivityInfo.CONFIG_ORIENTATION;
@@ -416,6 +441,7 @@
         dest.writeInt(keyboardHidden);
         dest.writeInt(hardKeyboardHidden);
         dest.writeInt(navigation);
+        dest.writeInt(navigationHidden);
         dest.writeInt(orientation);
         dest.writeInt(screenLayout);
     }
@@ -448,6 +474,7 @@
         keyboardHidden = source.readInt();
         hardKeyboardHidden = source.readInt();
         navigation = source.readInt();
+        navigationHidden = source.readInt();
         orientation = source.readInt();
         screenLayout = source.readInt();
     }
@@ -478,6 +505,8 @@
         if (n != 0) return n;
         n = this.navigation - that.navigation;
         if (n != 0) return n;
+        n = this.navigationHidden - that.navigationHidden;
+        if (n != 0) return n;
         n = this.orientation - that.orientation;
         if (n != 0) return n;
         n = this.screenLayout - that.screenLayout;
@@ -503,6 +532,7 @@
         return ((int)this.fontScale) + this.mcc + this.mnc
                 + this.locale.hashCode() + this.touchscreen
                 + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
-                + this.navigation + this.orientation + this.screenLayout;
+                + this.navigation + this.navigationHidden
+                + this.orientation + this.screenLayout;
     }
 }
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 8c12656..f67c4aa 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -500,6 +500,12 @@
          */
         public static final int FLAG_SHOW_WALLPAPER = 0x00100000;
         
+        /** Window flag: when set as a window is being added or made
+         * visible, once the window has been shown then the system will
+         * poke the power manager's user activity (as if the user had woken
+         * up the device) to turn the screen on. */
+        public static final int FLAG_TURN_SCREEN_ON = 0x00200000;
+        
         /** Window flag: special flag to limit the size of the window to be
          * original size ([320x480] x density). Used to create window for applications
          * running under compatibility mode.
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 7aaf218..365363a 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -504,8 +504,10 @@
         <!-- The keyboard type has changed, for example the user has plugged
              in an external keyboard. -->
         <flag name="keyboard" value="0x0010" />
-        <!-- The keyboard accessibility has changed, for example the user has
-             slid the keyboard out to expose it. -->
+        <!-- The keyboard or navigation accessibility has changed, for example
+             the user has slid the keyboard out to expose it.  Note that
+             inspite of its name, this applied to any accessibility: keyboard
+             or navigation. -->
         <flag name="keyboardHidden" value="0x0020" />
         <!-- The navigation type has changed.  Should never normally happen. -->
         <flag name="navigation" value="0x0040" />
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 117e139..b84a0d9 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -35,6 +35,9 @@
     <!-- The duration (in milliseconds) of a long animation. -->
     <integer name="config_longAnimTime">300</integer>
 
+    <!-- XXXXX NOTE THE FOLLOWING RESOURCES USE THE WRONG NAMING CONVENTION.
+         Please don't copy them, copy anything else. -->
+         
     <!-- This string array should be overridden by the device to present a list of network attributes.  This is used by the connectivity manager to decide which networks can coexist based on the hardward -->
     <!-- An Array of "[type-name],[associated radio-name],[priority]  -->
     <string-array translatable="false" name="networkAttributes">
@@ -53,6 +56,16 @@
         <item>"wifi,1,1"</item>
         <item>"mobile,0,1"</item>
     </string-array>
+    
+    <!-- Flag indicating whether the keyguard should be bypassed when
+         the slider is open.  This can be set or unset depending how easily
+         the slider can be opened (for example, in a pocket or purse). -->
+    <bool name="config_bypass_keyguard_if_slider_open">true</bool>
+    
+    <!-- Flag indicating whether the device supports automatic brightness mode. -->
+    <bool name="config_automatic_brightness_available">false</bool>
+    
+    <!-- XXXXXX END OF RESOURCES USING WRONG NAMING CONVENTION -->
 
     <!-- The number of degrees to rotate the display when the keyboard is open. -->
     <integer name="config_lidOpenRotation">90</integer>
@@ -60,11 +73,18 @@
     <!-- The number of degrees to rotate the display when the device is in a dock. -->
     <integer name="config_dockedRotation">90</integer>
 
-    <!-- Flag indicating whether the keyguard should be bypassed when
-         the slider is open.  This can be set or unset depending how easily
-         the slider can be opened (for example, in a pocket or purse). -->
-    <bool name="config_bypass_keyguard_if_slider_open">true</bool>
-    
+    <!-- Indicate whether the lid state impacts the accessibility of
+         the physical keyboard.  0 means it doesn't, 1 means it is accessible
+         when the lid is open, 2 means it is accessible when the lid is
+         closed.  The default is 1. -->
+    <integer name="config_lidKeyboardAccessibility">1</integer>
+
+    <!-- Indicate whether the lid state impacts the accessibility of
+         the physical keyboard.  0 means it doesn't, 1 means it is accessible
+         when the lid is open, 2 means it is accessible when the lid is
+         closed.  The default is 0. -->
+    <integer name="config_lidNavigationAccessibility">0</integer>
+
     <!-- Vibrator pattern for feedback about a long screen/key press -->
     <integer-array name="config_longPressVibePattern">
         <item>0</item>
@@ -81,6 +101,4 @@
         <item>30</item>
     </integer-array>
     
-    <!-- Flag indicating whether the device supports automatic brightness mode. -->
-    <bool name="config_automatic_brightness_available">false</bool>
 </resources>