Fix keyboard hidden flag.

Configuration.hardKeyboardHidden should be set to
HARDKEYBOARDHIDDEN_YES when no keyboard is present or when it is
disabled.  The code in PhoneWindowManager.adjustConfigurationLw
does the right thing.  It also takes care of setting keyboardHidden
correctly when only a soft keyboard is available.

So it turns out that all we need to do to disable the hard keyboard
is to set Configuration.keyboard to KEYBOARD_NOKEYS *before* asking
the policy to adjust the configuration.

Bug: 3406101
Change-Id: I3519d02af30d8068198cb3d6b8fdde601c2fe8b4
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 7c79b8a..7a3ef14 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -5787,11 +5787,7 @@
         }
         config.screenLayout = mScreenLayout;
 
-        config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
-        config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
-        mPolicy.adjustConfigurationLw(config);
-
-        // Adjust the hard keyboard configuration based on whether the hard keyboard is enabled.
+        // Determine whether a hard keyboard is available and enabled.
         boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
         if (hardKeyboardAvailable != mHardKeyboardAvailable) {
             mHardKeyboardAvailable = hardKeyboardAvailable;
@@ -5802,8 +5798,15 @@
         }
         if (!mHardKeyboardEnabled) {
             config.keyboard = Configuration.KEYBOARD_NOKEYS;
-            config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
         }
+
+        // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
+        // based on whether a hard or soft keyboard is present, whether navigation keys
+        // are present and the lid switch state.
+        config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
+        config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
+        config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
+        mPolicy.adjustConfigurationLw(config);
         return true;
     }