Release held mailboxes after policy refresh

* When a sync fails due to a provisioning error (on initial sync
  or after policies are refreshed on the server), sync mailboxes go
  into a "hold" state until the security error is resolved.  Meanwhile,
  the account mailbox handles provisioning.  If this is NOT successful,
  we put a hold on the account and go through the UI steps of setting
  up security on the device.  When this is done, we release the hold on
  the account, which releases the hold on the mailboxes.
* If provisioning IS successful, however, a refresh of the existing
  settings would be an example, we do NOT release the adapters, and
  this is the bug we're seeing.
* This CL simply causes any held mailboxes in a successfully provisioned
  to be released from the hold

Bug: 2865623
Change-Id: I59e780e9bd4ea908182b786dfd0e5851f5bf5f3b
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index a1a76dc..1feaf01 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -1291,6 +1291,8 @@
                 if (policyKey != null) {
                     // Write the final policy key to the Account and say we've been successful
                     ps.writeAccount(mAccount, policyKey, true, mContext);
+                    // Release any mailboxes that might be in a security hold
+                    SyncManager.releaseSecurityHold(mAccount);
                     return true;
                 }
             } else {
diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java
index 7a56cbb..dcdf6db 100644
--- a/src/com/android/exchange/SyncManager.java
+++ b/src/com/android/exchange/SyncManager.java
@@ -896,6 +896,18 @@
     }
 
     /**
+     * Release security holds for the specified account
+     * @param account the account whose Mailboxes should be released from security hold
+     */
+    static public void releaseSecurityHold(Account account) {
+        SyncManager syncManager = INSTANCE;
+        if (syncManager != null) {
+            syncManager.releaseSyncHolds(INSTANCE, AbstractSyncService.EXIT_SECURITY_FAILURE,
+                    account);
+        }
+    }
+
+    /**
      * Release a specific type of hold (the reason) for the specified Account; if the account
      * is null, mailboxes from all accounts with the specified hold will be released
      * @param reason the reason for the SyncError (AbstractSyncService.EXIT_XXX)