Make sure we hold WakeLock during mail sending (fixes #2180551)

* Don't runAsleep unless this is a Ping
* Relates to #2178288 in that it's possible that the system could
  sleep while we're trying to send (not sure if this is possible;
  will check), so we prevent it by holding a WakeLock in this case

Change-Id: Ib3f8786501b942e1cfcb7a0bbb07b8e3084e2a86
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index dc510de..a604669 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -408,6 +408,7 @@
     protected HttpResponse sendHttpClientPost(String cmd, HttpEntity entity, int timeout)
             throws IOException {
         HttpClient client = getHttpClient(timeout);
+        boolean sleepAllowed = cmd.equals(PING_COMMAND);
 
         // Split the mail sending commands
         String extra = null;
@@ -432,13 +433,17 @@
         method.setEntity(entity);
         synchronized(getSynchronizer()) {
             mPendingPost = method;
-            SyncManager.runAsleep(mMailboxId, timeout+(10*SECONDS));
+            if (sleepAllowed) {
+                SyncManager.runAsleep(mMailboxId, timeout+(10*SECONDS));
+            }
         }
         try {
             return client.execute(method);
         } finally {
             synchronized(getSynchronizer()) {
-                SyncManager.runAwake(mMailboxId);
+                if (sleepAllowed) {
+                    SyncManager.runAwake(mMailboxId);
+                }
                 mPendingPost = null;
             }
         }