b/15746597. Adjust workflow when there are no results for a GAL search.

The actual crash is a wtf but the problem is we are not properly handling
empty results from Exchange. Now we are.  The wtf logging should remain
but the code around it needed changing.

Change-Id: I06c214cc79cf5690ec1685655e4adba817df9295
(cherry picked from commit 2db0b68170b046b41c0319768d7018d093e536a4)
diff --git a/src/com/android/exchange/adapter/GalParser.java b/src/com/android/exchange/adapter/GalParser.java
index f58f1a1..1a051e7 100644
--- a/src/com/android/exchange/adapter/GalParser.java
+++ b/src/com/android/exchange/adapter/GalParser.java
@@ -51,7 +51,10 @@
                 skipTag();
             }
          }
-         return mGalResult.total > 0;
+        // TODO: IO Exception if we can't get the result to parse and a false should be returned
+        // here if we can't parse the input stream in the case where the schema may have changed.
+        // To implement this, we'll have to dig a bit deeper into the parsing code.
+        return true;
      }
 
     private void parseProperties(final GalResult galResult) throws IOException {
diff --git a/src/com/android/exchange/eas/EasSearchGal.java b/src/com/android/exchange/eas/EasSearchGal.java
index 1edb5ee..0dbadd2 100644
--- a/src/com/android/exchange/eas/EasSearchGal.java
+++ b/src/com/android/exchange/eas/EasSearchGal.java
@@ -70,7 +70,7 @@
                 if (gp.parse()) {
                     mResult = gp.getGalResult();
                 } else {
-                    LogUtils.wtf(LogUtils.TAG, "failure to parse GalResult");
+                    LogUtils.wtf(LogUtils.TAG, "Failure to parse GalResult");
                 }
             } finally {
                 is.close();
diff --git a/src/com/android/exchange/provider/ExchangeDirectoryProvider.java b/src/com/android/exchange/provider/ExchangeDirectoryProvider.java
index b46b52c..6d9ea6e 100644
--- a/src/com/android/exchange/provider/ExchangeDirectoryProvider.java
+++ b/src/com/android/exchange/provider/ExchangeDirectoryProvider.java
@@ -328,7 +328,7 @@
                     // Get results from the Exchange account
                     final GalResult galResult = EasService.searchGal(getContext(), accountId,
                             filter, queryLimit);
-                    if (galResult != null) {
+                    if (galResult != null && (galResult.getNumEntries() > 0)) {
                          return buildGalResultCursor(
                                  projection, galResult, sortOrder, limit, isEmail, isPhone);
                     }
diff --git a/src/com/android/exchange/provider/GalResult.java b/src/com/android/exchange/provider/GalResult.java
index 4d0d908..a431237 100644
--- a/src/com/android/exchange/provider/GalResult.java
+++ b/src/com/android/exchange/provider/GalResult.java
@@ -42,6 +42,8 @@
         galData.add(data);
     }
 
+    public int getNumEntries() { return galData.size(); }
+
     public static class GalData {
         // PackedString constants for GalData
         public static final String ID = "_id";