Only acquire wakelock after ping if we had it to start.

Bug: 8640907

Change-Id: Ifff22f13a9e076a7718b8269371a2e976ee70593
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index 773b7de..d7cbb8c 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -1278,12 +1278,17 @@
      * @return the HttpResponse
      * @throws IOException
      */
-    protected EasResponse executePostWithTimeout(HttpClient client, HttpPost method, int timeout,
-            boolean isPingCommand) throws IOException {
+    protected EasResponse executePostWithTimeout(HttpClient client, HttpPost method,
+            final int timeout, final boolean isPingCommand) throws IOException {
+        final boolean hasWakeLock;
         synchronized(getSynchronizer()) {
+            hasWakeLock = ExchangeService.isHoldingWakeLock(mMailboxId);
+            if (isPingCommand && !hasWakeLock) {
+                Log.e(TAG, "executePostWithTimeout (ping) without holding wakelock");
+            }
             mPendingPost = method;
             long alarmTime = timeout + WATCHDOG_TIMEOUT_ALLOWANCE;
-            if (isPingCommand) {
+            if (isPingCommand && hasWakeLock) {
                 ExchangeService.runAsleep(mMailboxId, alarmTime);
             } else {
                 ExchangeService.setWatchdogAlarm(mMailboxId, alarmTime);
@@ -1293,7 +1298,7 @@
             return EasResponse.fromHttpRequest(getClientConnectionManager(), client, method);
         } finally {
             synchronized(getSynchronizer()) {
-                if (isPingCommand) {
+                if (isPingCommand && hasWakeLock) {
                     ExchangeService.runAwake(mMailboxId);
                 } else {
                     ExchangeService.clearWatchdogAlarm(mMailboxId);