am af0995c2: am 47e18a70: am 27a7abda: am a8a1d1ad: am 303a529e: Set the sync_state after search finishes

* commit 'af0995c25374da2467a13a5755b856d801c97031':
  Set the sync_state after search finishes
diff --git a/src/com/android/exchange/eas/EasOperation.java b/src/com/android/exchange/eas/EasOperation.java
index ef7d2a8..b032bb7 100644
--- a/src/com/android/exchange/eas/EasOperation.java
+++ b/src/com/android/exchange/eas/EasOperation.java
@@ -314,6 +314,14 @@
             return RESULT_INITIALIZATION_FAILURE;
         }
 
+        try {
+            return performOperationInternal();
+        } finally {
+            onRequestComplete();
+        }
+    }
+
+    private int performOperationInternal() {
         // We handle server redirects by looping, but we need to protect against too much looping.
         int redirectCount = 0;
 
@@ -454,6 +462,13 @@
         // been sent. It will always be called, regardless of the status of the request.
     }
 
+    protected void onRequestComplete() {
+        // This can be overridden to do any cleanup that must happen after the request has
+        // finished. (i.e. either the response has come back and been processed, or some error
+        // has occurred and we have given up.
+        // It will always be called, regardless of the status of the response.
+    }
+
     protected int handleHttpError(final int httpStatus) {
         // This function can be overriden if the child class needs to change the result code
         // based on the http response status.
diff --git a/src/com/android/exchange/eas/EasSearch.java b/src/com/android/exchange/eas/EasSearch.java
index 34869bb..8020ee6 100644
--- a/src/com/android/exchange/eas/EasSearch.java
+++ b/src/com/android/exchange/eas/EasSearch.java
@@ -39,6 +39,7 @@
     final SearchParams mSearchParams;
     final long mDestMailboxId;
     int mTotalResults;
+    Mailbox mSearchMailbox;
 
     public EasSearch(final Context context, final long accountId, final SearchParams searchParams,
         final long destMailboxId) {
@@ -72,17 +73,17 @@
         }
 
         int res = 0;
-        final Mailbox searchMailbox = Mailbox.restoreMailboxWithId(mContext, mDestMailboxId);
+        mSearchMailbox = Mailbox.restoreMailboxWithId(mContext, mDestMailboxId);
         // Sanity check; account might have been deleted?
-        if (searchMailbox == null) {
+        if (mSearchMailbox == null) {
             LogUtils.i(LOG_TAG, "search mailbox ceased to exist");
             return null;
         }
-        final ContentValues statusValues = new ContentValues(2);
         try {
             // Set the status of this mailbox to indicate query
+            final ContentValues statusValues = new ContentValues(1);
             statusValues.put(Mailbox.UI_SYNC_STATUS, UIProvider.SyncStatus.LIVE_QUERY);
-            searchMailbox.update(mContext, statusValues);
+            mSearchMailbox.update(mContext, statusValues);
 
             final Serializer s = new Serializer();
             s.start(Tags.SEARCH_SEARCH).start(Tags.SEARCH_STORE);
@@ -133,12 +134,6 @@
             return makeEntity(s);
         } catch (IOException e) {
             LogUtils.d(LOG_TAG, e, "Search exception");
-        } finally {
-            // TODO: Handle error states
-            // Set the status of this mailbox to indicate query over
-            statusValues.put(Mailbox.SYNC_TIME, System.currentTimeMillis());
-            statusValues.put(Mailbox.UI_SYNC_STATUS, UIProvider.SyncStatus.NO_SYNC);
-            searchMailbox.update(mContext, statusValues);
         }
         LogUtils.i(LOG_TAG, "end returning null");
         return null;
@@ -162,4 +157,14 @@
         }
         return RESULT_OK;
     }
+
+    protected void onRequestComplete() {
+        if (mSearchMailbox != null) {
+            // TODO: Handle error states
+            final ContentValues statusValues = new ContentValues(2);
+            statusValues.put(Mailbox.UI_SYNC_STATUS, UIProvider.SyncStatus.NO_SYNC);
+            statusValues.put(Mailbox.SYNC_TIME, System.currentTimeMillis());
+            mSearchMailbox.update(mContext, statusValues);
+        }
+    }
 }