OSDN Git Service

b/2358627 and b/2293263 Fixed multi-day events and oob crash.
authorErik <roboerik@android.com>
Thu, 7 Jan 2010 18:36:43 +0000 (10:36 -0800)
committerErik <roboerik@android.com>
Thu, 7 Jan 2010 22:02:57 +0000 (14:02 -0800)
Added better query processing to handle multi-day events and prevent index
out of bounds crashes.

src/com/android/calendar/EventLoader.java

index 6014f64..57201f2 100644 (file)
@@ -85,12 +85,19 @@ public class EventLoader {
             Cursor cursor = EventDays.query(cr, startDay, numDays);
             try {
                 int startDayColumnIndex = cursor.getColumnIndexOrThrow(EventDays.STARTDAY);
+                int endDayColumnIndex = cursor.getColumnIndexOrThrow(EventDays.ENDDAY);
 
                 //Set all the days with events to true
                 while (cursor.moveToNext()) {
-                    int day = cursor.getInt(startDayColumnIndex);
-                    int dayIndex = day - startDay;
-                    eventDays[dayIndex] = true;
+                    int firstDay = cursor.getInt(startDayColumnIndex);
+                    int lastDay = cursor.getInt(endDayColumnIndex);
+                    //we want the entire range the event occurs, but only within the month
+                    int firstIndex = Math.max(firstDay - startDay, 0);
+                    int lastIndex = Math.min(lastDay - startDay, 30);
+
+                    for(int i = firstIndex; i <= lastIndex; i++) {
+                        eventDays[i] = true;
+                    }
                 }
             } finally {
                 if (cursor != null) {