diff options
author | Varun Shah <varunshah@google.com> | 2020-10-27 18:32:06 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-10-27 18:32:06 +0000 |
commit | 45662404725d9b721376848edb31801d73f62ae2 (patch) | |
tree | 605665fd4ffef5d892dd6c4bac5ecca1c32f2405 | |
parent | 26a609b74633c3ff44e572e87ae345affb4bb9ae (diff) | |
parent | a4898f721aa89aae45f67586679ca7b5890e76c9 (diff) | |
download | CalendarProvider-45662404725d9b721376848edb31801d73f62ae2.tar.gz |
Merge "Update Time API usage."
6 files changed, 95 insertions, 94 deletions
diff --git a/src/com/android/providers/calendar/CalendarAlarmManager.java b/src/com/android/providers/calendar/CalendarAlarmManager.java index 9d5a816..c8daec2 100644 --- a/src/com/android/providers/calendar/CalendarAlarmManager.java +++ b/src/com/android/providers/calendar/CalendarAlarmManager.java @@ -261,7 +261,7 @@ public class CalendarAlarmManager { if (Log.isLoggable(CalendarProvider2.TAG, Log.DEBUG)) { time.set(start); - String startTimeStr = time.format(" %a, %b %d, %Y %I:%M%P"); + String startTimeStr = time.format(); Log.d(CalendarProvider2.TAG, "runScheduleNextAlarm() start search: " + startTimeStr); } @@ -306,9 +306,9 @@ public class CalendarAlarmManager { // string query parameter to an int in myAlarmtime>=?, so the comparison // will fail. This could be simplified if bug 2464440 is resolved. - time.setToNow(); - time.normalize(false); - long localOffset = time.gmtoff * 1000; + time.set(System.currentTimeMillis()); + time.normalize(); + long localOffset = time.getGmtOffset() * 1000; String allDayOffset = " -(" + localOffset + ") "; String subQueryPrefix = "SELECT " + Instances.BEGIN; @@ -373,7 +373,7 @@ public class CalendarAlarmManager { if (Log.isLoggable(CalendarProvider2.TAG, Log.DEBUG)) { time.set(nextAlarmTime); - String alarmTimeStr = time.format(" %a, %b %d, %Y %I:%M%P"); + String alarmTimeStr = time.format(); Log.d(CalendarProvider2.TAG, "cursor results: " + cursor.getCount() + " nextAlarmTime: " + alarmTimeStr); } @@ -394,9 +394,9 @@ public class CalendarAlarmManager { if (Log.isLoggable(CalendarProvider2.TAG, Log.DEBUG)) { time.set(alarmTime); - String schedTime = time.format(" %a, %b %d, %Y %I:%M%P"); + String schedTime = time.format(); time.set(startTime); - String startTimeStr = time.format(" %a, %b %d, %Y %I:%M%P"); + String startTimeStr = time.format(); Log.d(CalendarProvider2.TAG, " looking at id: " + eventId + " " + startTime + startTimeStr diff --git a/src/com/android/providers/calendar/CalendarDatabaseHelper.java b/src/com/android/providers/calendar/CalendarDatabaseHelper.java index 7008837..b96dada 100644 --- a/src/com/android/providers/calendar/CalendarDatabaseHelper.java +++ b/src/com/android/providers/calendar/CalendarDatabaseHelper.java @@ -1476,10 +1476,10 @@ import java.util.TimeZone; private static boolean fixAllDayTime(Time time, String timezone, Long timeInMillis) { time.set(timeInMillis); - if(time.hour != 0 || time.minute != 0 || time.second != 0) { - time.hour = 0; - time.minute = 0; - time.second = 0; + if(time.getHour() != 0 || time.getMinute() != 0 || time.getSecond() != 0) { + time.setHour(0); + time.setMinute(0); + time.setSecond(0); return true; } return false; @@ -2576,22 +2576,22 @@ import java.util.TimeZone; time.clear(timezone); update |= fixAllDayTime(time, timezone, dtstart); - dtstart = time.normalize(false); + dtstart = time.normalize(); time.clear(timezone); update |= fixAllDayTime(time, timezone, dtend); - dtend = time.normalize(false); + dtend = time.normalize(); if (dtstart2 != null) { time.clear(timezone2); update |= fixAllDayTime(time, timezone2, dtstart2); - dtstart2 = time.normalize(false); + dtstart2 = time.normalize(); } if (dtend2 != null) { time.clear(timezone2); update |= fixAllDayTime(time, timezone2, dtend2); - dtend2 = time.normalize(false); + dtend2 = time.normalize(); } if (!TextUtils.isEmpty(duration)) { @@ -2637,12 +2637,12 @@ import java.util.TimeZone; time.clear(timezone); update |= fixAllDayTime(time, timezone, dtstart); - dtstart = time.normalize(false); + dtstart = time.normalize(); if (dtstart2 != null) { time.clear(timezone2); update |= fixAllDayTime(time, timezone2, dtstart2); - dtstart2 = time.normalize(false); + dtstart2 = time.normalize(); } if (TextUtils.isEmpty(duration)) { @@ -2756,17 +2756,17 @@ import java.util.TimeZone; oldTime.clear(eTz); oldTime.set(dtstart); newTime.clear(tz); - newTime.set(oldTime.monthDay, oldTime.month, oldTime.year); - newTime.normalize(false); - dtstart = newTime.toMillis(false /*ignoreDst*/); + newTime.set(oldTime.getDay(), oldTime.getMonth(), oldTime.getYear()); + newTime.normalize(); + dtstart = newTime.toMillis(); // Convert end time for all day events into the timezone of their calendar oldTime.clear(eTz); oldTime.set(dtend); newTime.clear(tz); - newTime.set(oldTime.monthDay, oldTime.month, oldTime.year); - newTime.normalize(false); - dtend = newTime.toMillis(false /*ignoreDst*/); + newTime.set(oldTime.getDay(), oldTime.getMonth(), oldTime.getYear()); + newTime.normalize(); + dtend = newTime.toMillis(); newData[0] = String.valueOf(dtstart); newData[1] = String.valueOf(dtend); diff --git a/src/com/android/providers/calendar/CalendarInstancesHelper.java b/src/com/android/providers/calendar/CalendarInstancesHelper.java index 1fd6921..8e2fdc7 100644 --- a/src/com/android/providers/calendar/CalendarInstancesHelper.java +++ b/src/com/android/providers/calendar/CalendarInstancesHelper.java @@ -288,9 +288,9 @@ public class CalendarInstancesHelper { } // need to parse the event into a local calendar. - eventTime.timezone = eventTimezone; + eventTime.setTimezone(eventTimezone); eventTime.set(dtstartMillis); - eventTime.allDay = allDay; + eventTime.setAllDay(allDay); if (durationStr == null) { // should not happen. @@ -332,9 +332,9 @@ public class CalendarInstancesHelper { // Initialize the "eventTime" timezone outside the loop. // This is used in computeTimezoneDependentFields(). if (allDay) { - eventTime.timezone = Time.TIMEZONE_UTC; + eventTime.setTimezone(Time.TIMEZONE_UTC); } else { - eventTime.timezone = localTimezone; + eventTime.setTimezone(localTimezone); } long durationMillis = duration.getMillis(); @@ -404,9 +404,9 @@ public class CalendarInstancesHelper { initialValues.put(Events.DELETED, deleted); if (allDay) { - eventTime.timezone = Time.TIMEZONE_UTC; + eventTime.setTimezone(Time.TIMEZONE_UTC); } else { - eventTime.timezone = localTimezone; + eventTime.setTimezone(localTimezone); } CalendarInstancesHelper.computeTimezoneDependentFields(dtstartMillis, dtendMillis, eventTime, initialValues); @@ -703,9 +703,9 @@ public class CalendarInstancesHelper { // Update the timezone-dependent fields. Time local = new Time(); if (allDay) { - local.timezone = Time.TIMEZONE_UTC; + local.setTimezone(Time.TIMEZONE_UTC); } else { - local.timezone = fields.timezone; + local.setTimezone(fields.timezone); } CalendarInstancesHelper.computeTimezoneDependentFields(dtstartMillis, dtendMillis, @@ -889,12 +889,12 @@ public class CalendarInstancesHelper { static void computeTimezoneDependentFields(long begin, long end, Time local, ContentValues values) { local.set(begin); - int startDay = Time.getJulianDay(begin, local.gmtoff); - int startMinute = local.hour * 60 + local.minute; + int startDay = Time.getJulianDay(begin, local.getGmtOffset()); + int startMinute = local.getHour() * 60 + local.getMinute(); local.set(end); - int endDay = Time.getJulianDay(end, local.gmtoff); - int endMinute = local.hour * 60 + local.minute; + int endDay = Time.getJulianDay(end, local.getGmtOffset()); + int endMinute = local.getHour() * 60 + local.getMinute(); // Special case for midnight, which has endMinute == 0. Change // that to +24 hours on the previous day to make everything simpler. diff --git a/src/com/android/providers/calendar/CalendarProvider2.java b/src/com/android/providers/calendar/CalendarProvider2.java index 7e5b017..57f60d9 100644 --- a/src/com/android/providers/calendar/CalendarProvider2.java +++ b/src/com/android/providers/calendar/CalendarProvider2.java @@ -65,7 +65,6 @@ import android.provider.CalendarContract.SyncState; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; -import android.util.TimeFormatException; import android.util.TimeUtils; import com.android.calendarcommon2.DateException; @@ -732,13 +731,13 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun Time time = (timezone != null) ? new Time(timezone) : new Time(); try { time.parse(dt2445); - } catch (TimeFormatException e) { + } catch (IllegalArgumentException e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Cannot parse RFC2445 date " + dt2445); } return 0; } - return time.toMillis(true /* ignore DST */); + return time.toMillis(); } private void updateEventsStartEndLocked(long eventId, @@ -803,12 +802,12 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun String instancesTimezone = mCalendarCache.readTimezoneInstances(); Time time = new Time(instancesTimezone); time.set(now); - time.monthDay = 1; - time.hour = 0; - time.minute = 0; - time.second = 0; + time.setDay(1); + time.setHour(0); + time.setMinute(0); + time.setSecond(0); - long begin = time.normalize(true); + long begin = time.normalize(); long end = begin + MINIMUM_EXPANSION_SPAN; Cursor cursor = null; @@ -1725,11 +1724,11 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun // Change dtstart so h,m,s are 0 if necessary. time.clear(Time.TIMEZONE_UTC); time.set(dtstart.longValue()); - if (time.hour != 0 || time.minute != 0 || time.second != 0) { - time.hour = 0; - time.minute = 0; - time.second = 0; - modValues.put(Events.DTSTART, time.toMillis(true)); + if (time.getHour() != 0 || time.getMinute() != 0 || time.getSecond() != 0) { + time.setHour(0); + time.setMinute(0); + time.setSecond(0); + modValues.put(Events.DTSTART, time.toMillis()); neededCorrection = true; } @@ -1737,11 +1736,11 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun if (dtend != null) { time.clear(Time.TIMEZONE_UTC); time.set(dtend.longValue()); - if (time.hour != 0 || time.minute != 0 || time.second != 0) { - time.hour = 0; - time.minute = 0; - time.second = 0; - dtend = time.toMillis(true); + if (time.getHour() != 0 || time.getMinute() != 0 || time.getSecond() != 0) { + time.setHour(0); + time.setMinute(0); + time.setSecond(0); + dtend = time.toMillis(); modValues.put(Events.DTEND, dtend); neededCorrection = true; } @@ -1814,7 +1813,7 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun // Get the start time of the first instance in the original recurrence. long startTimeMillis = values.getAsLong(Events.DTSTART); Time dtstart = new Time(); - dtstart.timezone = values.getAsString(Events.EVENT_TIMEZONE); + dtstart.setTimezone(values.getAsString(Events.EVENT_TIMEZONE)); dtstart.set(startTimeMillis); ContentValues updateValues = new ContentValues(); @@ -1853,26 +1852,30 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun // to display it properly. For all-day events, the "until" time string // must include just the date field, and not the time field. The // repeating events repeat up to and including the "until" time. - untilTime.timezone = Time.TIMEZONE_UTC; + untilTime.setTimezone(Time.TIMEZONE_UTC); // Subtract one second from the exception begin time to get the "until" time. untilTime.set(endTimeMillis - 1000); // subtract one second (1000 millis) if (origAllDay) { - untilTime.hour = untilTime.minute = untilTime.second = 0; - untilTime.allDay = true; - untilTime.normalize(false); + untilTime.setHour(0); + untilTime.setMinute(0); + untilTime.setSecond(0); + untilTime.setAllDay(true); + untilTime.normalize(); // This should no longer be necessary -- DTSTART should already be in the correct // format for an all-day event. - dtstart.hour = dtstart.minute = dtstart.second = 0; - dtstart.allDay = true; - dtstart.timezone = Time.TIMEZONE_UTC; + dtstart.setHour(0); + dtstart.setMinute(0); + dtstart.setSecond(0); + dtstart.setAllDay(true); + dtstart.setTimezone(Time.TIMEZONE_UTC); } origRecurrence.until = untilTime.format2445(); } updateValues.put(Events.RRULE, origRecurrence.toString()); - updateValues.put(Events.DTSTART, dtstart.normalize(true)); + updateValues.put(Events.DTSTART, dtstart.normalize()); return updateValues; } @@ -3282,7 +3285,7 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun } Time time = new Time(timezone); - time.allDay = allDay; + time.setAllDay(allDay); Long dtstartMillis = values.getAsLong(Events.DTSTART); if (dtstartMillis != null) { time.set(dtstartMillis); @@ -3302,7 +3305,7 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun // date correctly. allDayInteger = values.getAsInteger(Events.ORIGINAL_ALL_DAY); if (allDayInteger != null) { - time.allDay = allDayInteger != 0; + time.setAllDay(allDayInteger != 0); } time.set(originalInstanceMillis); rawValues.put(CalendarContract.EventsRawTimes.ORIGINAL_INSTANCE_TIME_2445, @@ -3311,7 +3314,7 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun Long lastDateMillis = values.getAsLong(Events.LAST_DATE); if (lastDateMillis != null) { - time.allDay = allDay; + time.setAllDay(allDay); time.set(lastDateMillis); rawValues.put(CalendarContract.EventsRawTimes.LAST_DATE_2445, time.format2445()); } diff --git a/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java b/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java index a2925d4..873ec63 100644 --- a/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java +++ b/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java @@ -427,7 +427,6 @@ public class CalendarDatabaseHelperTest { } @Test - @Ignore("b/140236227") public void testUpgradeToCurrentVersion() { // Create event tables bootstrapDbVersion50(mBadDb); @@ -464,7 +463,6 @@ public class CalendarDatabaseHelperTest { private static final String[] PROJECTION = {"tbl_name", "sql"}; @Test - @Ignore("b/140236227") public void testSchemasEqualForAllTables() { CalendarDatabaseHelper cDbHelper = new CalendarDatabaseHelper(new MockContext()); diff --git a/tests/src/com/android/providers/calendar/CalendarProvider2Test.java b/tests/src/com/android/providers/calendar/CalendarProvider2Test.java index 532a840..11bccd4 100644 --- a/tests/src/com/android/providers/calendar/CalendarProvider2Test.java +++ b/tests/src/com/android/providers/calendar/CalendarProvider2Test.java @@ -132,7 +132,7 @@ public class CalendarProvider2Test extends AndroidTestCase { private static long parseTimeStringToMillis(String timeStr, String timeZone) { Time time = new Time(timeZone); time.parse3339(timeStr); - return time.toMillis(false /* use isDst */); + return time.toMillis(); } private static String WORK_DEFAULT_TIMEZONE = TIME_ZONE_AMERICA_LOS_ANGELES; @@ -343,9 +343,9 @@ public class CalendarProvider2Test extends AndroidTestCase { public DumpInstances(String startDate, String endDate) { Time time = new Time(DEFAULT_TIMEZONE); time.parse3339(startDate); - begin = time.toMillis(false /* use isDst */); + begin = time.toMillis(); time.parse3339(endDate); - end = time.toMillis(false /* use isDst */); + end = time.toMillis(); } public void execute() { @@ -367,9 +367,9 @@ public class CalendarProvider2Test extends AndroidTestCase { public QueryNumInstances(String startDate, String endDate, int expected) { Time time = new Time(DEFAULT_TIMEZONE); time.parse3339(startDate); - begin = time.toMillis(false /* use isDst */); + begin = time.toMillis(); time.parse3339(endDate); - end = time.toMillis(false /* use isDst */); + end = time.toMillis(); this.expected = expected; } @@ -395,9 +395,9 @@ public class CalendarProvider2Test extends AndroidTestCase { public VerifyAllInstances(String startDate, String endDate, String[] dates) { Time time = new Time(DEFAULT_TIMEZONE); time.parse3339(startDate); - begin = time.toMillis(false /* use isDst */); + begin = time.toMillis(); time.parse3339(endDate); - end = time.toMillis(false /* use isDst */); + end = time.toMillis(); if (dates == null) { return; @@ -409,7 +409,7 @@ public class CalendarProvider2Test extends AndroidTestCase { int index = 0; for (String instance : dates) { time.parse3339(instance); - this.instances[index++] = time.toMillis(false /* use isDst */); + this.instances[index++] = time.toMillis(); } } @@ -490,14 +490,14 @@ public class CalendarProvider2Test extends AndroidTestCase { public VerifyInstance(String startDate, String endDate, String date) { Time time = new Time(DEFAULT_TIMEZONE); time.parse3339(startDate); - begin = time.toMillis(false /* use isDst */); + begin = time.toMillis(); time.parse3339(endDate); - end = time.toMillis(false /* use isDst */); + end = time.toMillis(); // Convert the instance date string to UTC milliseconds time.parse3339(date); - allDay = time.allDay; - instance = time.toMillis(false /* use isDst */); + allDay = time.isAllDay(); + instance = time.toMillis(); } public void execute() { @@ -566,15 +566,15 @@ public class CalendarProvider2Test extends AndroidTestCase { mTitle = title; Time time = new Time(); if (allDay) { - time.timezone = Time.TIMEZONE_UTC; + time.setTimezone(Time.TIMEZONE_UTC); } else if (timezone != null) { - time.timezone = timezone; + time.setTimezone(timezone); } - mTimezone = time.timezone; + mTimezone = time.getTimezone(); time.parse3339(startDate); - mDtstart = time.toMillis(false /* use isDst */); + mDtstart = time.toMillis(); time.parse3339(endDate); - mDtend = time.toMillis(false /* use isDst */); + mDtend = time.toMillis(); mDuration = null; mRrule = null; mAllDay = allDay; @@ -601,16 +601,16 @@ public class CalendarProvider2Test extends AndroidTestCase { mDescription = description; Time time = new Time(); if (allDay) { - time.timezone = Time.TIMEZONE_UTC; + time.setTimezone(Time.TIMEZONE_UTC); } else if (timezone != null) { - time.timezone = timezone; + time.setTimezone(timezone); } - mTimezone = time.timezone; + mTimezone = time.getTimezone(); time.parse3339(startDate); - mDtstart = time.toMillis(false /* use isDst */); + mDtstart = time.toMillis(); if (endDate != null) { time.parse3339(endDate); - mDtend = time.toMillis(false /* use isDst */); + mDtend = time.toMillis(); } if (allDay) { long days = 1; @@ -642,7 +642,7 @@ public class CalendarProvider2Test extends AndroidTestCase { mOriginalTitle = originalTitle; Time time = new Time(timezone); time.parse3339(originalInstance); - mOriginalInstance = time.toMillis(false /* use isDst */); + mOriginalInstance = time.toMillis(); mCustomAppPackage = customPackageName; mCustomAppUri = customPackageUri; mUid2445 = uid2445; @@ -661,9 +661,9 @@ public class CalendarProvider2Test extends AndroidTestCase { mEvent = findEvent(eventName); Time time = new Time(mEvent.mTimezone); time.parse3339(startDate); - mBegin = time.toMillis(false /* use isDst */); + mBegin = time.toMillis(); time.parse3339(endDate); - mEnd = time.toMillis(false /* use isDst */); + mEnd = time.toMillis(); mExpectedOccurrences = expected; } } @@ -1953,7 +1953,7 @@ public class CalendarProvider2Test extends AndroidTestCase { Time time = new Time(DEFAULT_TIMEZONE); time.parse3339(START); - long startMs = time.toMillis(true /* ignoreDst */); + long startMs = time.toMillis(); // Query starting from way in the past to one hour into the event. // Query is more than 2 months so the range won't get extended by the provider. Cursor cursor = null; @@ -2763,7 +2763,7 @@ public class CalendarProvider2Test extends AndroidTestCase { Time time = new Time(DEFAULT_TIMEZONE); time.parse3339(START); - long startMs = time.toMillis(true /* ignoreDst */); + long startMs = time.toMillis(); // Query starting from way in the past to one hour into the event. // Query is more than 2 months so the range won't get extended by the provider. Cursor cursor = queryInstances(mResolver, PROJECTION, |