Handle "no password" policies properly

* If passwords are not enabled, make sure we ignore any
  subsequent settings that set password requirements

Bug: 5030487
Change-Id: I2bad2c856d3744168b5dda7aaebca1d96e5a8c26
diff --git a/src/com/android/exchange/adapter/ProvisionParser.java b/src/com/android/exchange/adapter/ProvisionParser.java
index 7fc031f..3f72bc2 100644
--- a/src/com/android/exchange/adapter/ProvisionParser.java
+++ b/src/com/android/exchange/adapter/ProvisionParser.java
@@ -87,6 +87,7 @@
     private void parseProvisionDocWbxml() throws IOException {
         Policy policy = new Policy();
         ArrayList<Integer> unsupportedList = new ArrayList<Integer>();
+        boolean passwordEnabled = false;
 
         while (nextTag(Tags.PROVISION_EAS_PROVISION_DOC) != END) {
             boolean tagIsSupported = true;
@@ -94,6 +95,7 @@
             switch (tag) {
                 case Tags.PROVISION_DEVICE_PASSWORD_ENABLED:
                     if (getValueInt() == 1) {
+                        passwordEnabled = true;
                         if (policy.mPasswordMode == Policy.PASSWORD_MODE_NONE) {
                             policy.mPasswordMode = Policy.PASSWORD_MODE_SIMPLE;
                         }
@@ -300,7 +302,10 @@
             }
         }
 
-        // Make sure policy settings are valid
+        // Make sure policy settings are valid; password not enabled trumps other password settings
+        if (!passwordEnabled) {
+            policy.mPasswordMode = Policy.PASSWORD_MODE_NONE;
+        }
         setPolicy(policy);
 
         // We can only determine whether encryption is supported on device by using isSupported here