Merge "Fix #2420732 (crash in Google Services Framework)"
diff --git a/EXCHANGE.readme b/EXCHANGE.readme
deleted file mode 100644
index d637372..0000000
--- a/EXCHANGE.readme
+++ /dev/null
@@ -1,11 +0,0 @@
-Exchange support in the Email application can be removed.  In order to do so,
-run the remove-exchange-support.sh script and rebuild the application.  In case
-the script doesn't work, here's how to do it manually.
-
-1. Remove everything under src/com/android/exchange/ and
-   tests/src/com/android/exchange/.
-2. Check all the *.xml and *.java files, and remove all the lines surrounded by
-   EXCHANGE-REMOVE-SECTION-START and EXCHANGE-REMOVE-SECTION-END.
-3. Check all the *.java files and remove all imports from com.android.exchange
-   and its subpackages.
-
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3a50a47..99d374c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -19,25 +19,7 @@
     <!-- Deprecated strings - Move the identifiers to this section, mark as DO NOT TRANSLATE,
          and remove the actual text.  These will be removed in a bulk operation. -->
     <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_name_inbox"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_display_name_inbox"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_display_name_outbox"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_display_name_drafts"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_display_name_trash"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_display_name_sent"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="special_mailbox_display_name_junk"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="account_setup_incoming_delete_policy_7days_label"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="account_setup_incoming_security_ssl_optional_label"></string>
-    <!-- Do Not Translate.  Unused string. -->
-    <string name="account_setup_incoming_security_tls_optional_label"></string>
+    <string name="account_setup_failed_security_policies_required"></string>
 
     <!-- Permissions label for reading attachments -->
     <string name="read_attachment_label">Read Email attachments</string>
@@ -505,8 +487,20 @@
     <string name="account_setup_failed_security">Unable to open connection to server due to security error.</string>
     <!-- Additional diagnostic text when server connection failed due to io error (connection) -->
     <string name="account_setup_failed_ioerror">Unable to open connection to server.</string>
-    <!-- Additional diagnostic text when validation failed due to required provisioning not being supported -->
-    <string name="account_setup_failed_security_policies_required">This Exchange ActiveSync server requires security features your phone does not support.</string>
+
+    <!-- Dialog title when validation requires security provisioning (e.g. support
+         for device lock PIN, or remote wipe.) and we ask the user permission before continuing -->
+    <string name="account_setup_security_required_title">Remote security administration</string>
+    <!-- Additional diagnostic text when validation requires security provisioning (e.g. support
+         for device lock PIN, or remote wipe.) and we ask the user permission before continuing. -->
+    <string name="account_setup_security_policies_required_fmt">
+         The server <xliff:g id="server">%s</xliff:g> requires that you allow it to remotely control
+         some security features of your phone.  Do you wish to finish setting up this account?
+         </string>
+    <!-- Additional diagnostic text when validation failed due to required provisioning not
+         being supported -->
+    <string name="account_setup_failed_security_policies_unsupported">
+         This server requires security features your phone does not support.</string>
 
     <!-- "Setup could not finish" dialog action button -->
     <string name="account_setup_failed_dlg_edit_details_action">Edit details</string>
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index 544a82f..b15dac7 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -234,7 +234,9 @@
             svc.mPassword = password;
             svc.mSsl = ssl;
             svc.mTrustSsl = trustCertificates;
-            svc.mDeviceId = SyncManager.getDeviceId();
+            // We mustn't use the "real" device id or we'll screw up current accounts
+            // Any string will do, but we'll go for "validate"
+            svc.mDeviceId = "validate";
             HttpResponse resp = svc.sendHttpClientOptions();
             int code = resp.getStatusLine().getStatusCode();
             userLog("Validation (OPTIONS) response: " + code);
@@ -255,8 +257,19 @@
                 resp = svc.sendHttpClientPost("FolderSync", s.toByteArray());
                 code = resp.getStatusLine().getStatusCode();
                 if (code == HttpStatus.SC_FORBIDDEN) {
-                    throw new MessagingException(MessagingException.SECURITY_POLICIES_REQUIRED);
+                    throw new MessagingException(MessagingException.SECURITY_POLICIES_UNSUPPORTED);
                 }
+                // PLACEHOLDER:  Replace the above simple check with a more sophisticated
+                // check of server-mandated security policy support.  There are three outcomes.
+                // 1.  As below, if no policies required, simply return here as-is.
+                // 2.  As above, if policies are required that we do not support, throw
+                //     MessagingException.SECURITY_POLICIES_UNSUPPORTED.  This is a validation
+                //     failure.
+                // 3.  New code:  If policies are required that we *do* support, throw
+                //     MessagingException.SECURITY_POLICIES_REQUIRED.  This is an advisory to the
+                //     UI that new policies will be required in order to use this account.
+                // See also:  isSupported(PolicySet policies)
+
                 userLog("Validation successful");
                 return;
             }
diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java
index 58f976d..2a1e10b 100644
--- a/src/com/android/exchange/SyncManager.java
+++ b/src/com/android/exchange/SyncManager.java
@@ -768,7 +768,7 @@
                 return id;
             } else if (f.createNewFile()) {
                 BufferedWriter w = new BufferedWriter(new FileWriter(f), 128);
-                id = "droid" + System.currentTimeMillis();
+                id = "android" + System.currentTimeMillis();
                 w.write(id);
                 w.close();
                 sDeviceId = id;