Fix upsync of DAILY rrule with UNTIL

* Make sure we send UNTIL with FREQ=DAILY as appropriate
* Also to help debug this in the future...
    Add logging capability to utilities via SyncManager
    Add public log methods so that CalendarUtilities can log properly
    Change Log.d's to SyncManager.log in CalendarUtilities

Bug: 2623787
Change-Id: I3d651f00a3f7522e25c8d6e389469770c733953f
diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java
index 4ee48c6..0e17d08 100644
--- a/src/com/android/exchange/SyncManager.java
+++ b/src/com/android/exchange/SyncManager.java
@@ -953,16 +953,20 @@
         }.start();
     }
 
-    protected static void log(String str) {
+    public static void log(String str) {
+        log(TAG, str);
+    }
+
+    public static void log(String tag, String str) {
         if (Eas.USER_LOG) {
-            Log.d(TAG, str);
+            Log.d(tag, str);
             if (Eas.FILE_LOG) {
-                FileLogger.log(TAG, str);
+                FileLogger.log(tag, str);
             }
         }
     }
 
-    protected static void alwaysLog(String str) {
+    public static void alwaysLog(String str) {
         if (!Eas.USER_LOG) {
             Log.d(TAG, str);
         } else {
diff --git a/src/com/android/exchange/utility/CalendarUtilities.java b/src/com/android/exchange/utility/CalendarUtilities.java
index 78c719f..4051f1a 100644
--- a/src/com/android/exchange/utility/CalendarUtilities.java
+++ b/src/com/android/exchange/utility/CalendarUtilities.java
@@ -27,6 +27,7 @@
 import com.android.email.provider.EmailContent.Message;
 import com.android.exchange.Eas;
 import com.android.exchange.EasSyncService;
+import com.android.exchange.SyncManager;
 import com.android.exchange.adapter.Serializer;
 import com.android.exchange.adapter.Tags;
 
@@ -322,7 +323,7 @@
         String tziString = sTziStringCache.get(tz);
         if (tziString != null) {
             if (Eas.USER_LOG) {
-                Log.d(TAG, "TZI string for " + tz.getDisplayName() + " found in cache.");
+                SyncManager.log(TAG, "TZI string for " + tz.getDisplayName() + " found in cache.");
             }
             return tziString;
         }
@@ -695,14 +696,14 @@
         TimeZone timeZone = sTimeZoneCache.get(timeZoneString);
         if (timeZone != null) {
             if (Eas.USER_LOG) {
-                Log.d(TAG, " Using cached TimeZone " + timeZone.getDisplayName());
+                SyncManager.log(TAG, " Using cached TimeZone " + timeZone.getDisplayName());
             }
         } else {
             timeZone = tziStringToTimeZoneImpl(timeZoneString);
             if (timeZone == null) {
                 // If we don't find a match, we just return the current TimeZone.  In theory, this
                 // shouldn't be happening...
-                Log.w(TAG, "TimeZone not found using default: " + timeZoneString);
+                SyncManager.alwaysLog("TimeZone not found using default: " + timeZoneString);
                 timeZone = TimeZone.getDefault();
             }
             sTimeZoneCache.put(timeZoneString, timeZone);
@@ -742,7 +743,7 @@
                 String dn = timeZone.getDisplayName();
                 sTimeZoneCache.put(timeZoneString, timeZone);
                 if (Eas.USER_LOG) {
-                    Log.d(TAG, "TimeZone without DST found by offset: " + dn);
+                    SyncManager.log(TAG, "TimeZone without DST found by offset: " + dn);
                 }
                 return timeZone;
             } else {
@@ -1014,7 +1015,9 @@
     // This code must be updated when the Calendar adds new functionality
     static public void recurrenceFromRrule(String rrule, long startTime, Serializer s)
             throws IOException {
-        Log.d("RRULE", "rule: " + rrule);
+        if (Eas.USER_LOG) {
+            SyncManager.log(TAG, "RRULE: " + rrule);
+        }
         String freq = tokenFromRrule(rrule, "FREQ=");
         // If there's no FREQ=X, then we don't write a recurrence
         // Note that we duplicate s.start(Tags.CALENDAR_RECURRENCE); s.end(); to prevent the
@@ -1024,6 +1027,7 @@
                 s.start(Tags.CALENDAR_RECURRENCE);
                 s.data(Tags.CALENDAR_RECURRENCE_TYPE, "0");
                 s.data(Tags.CALENDAR_RECURRENCE_INTERVAL, "1");
+                addUntil(rrule, s);
                 s.end();
             } else if (freq.equals("WEEKLY")) {
                 s.start(Tags.CALENDAR_RECURRENCE);