CalendarContract.java revision fced9521be9abfeb59f0edbbc98922f85264e7bd
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.provider;
18
19
20import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
22import android.app.AlarmManager;
23import android.app.PendingIntent;
24import android.content.ContentProviderClient;
25import android.content.ContentResolver;
26import android.content.ContentUris;
27import android.content.ContentValues;
28import android.content.Context;
29import android.content.CursorEntityIterator;
30import android.content.Entity;
31import android.content.EntityIterator;
32import android.content.Intent;
33import android.database.Cursor;
34import android.database.DatabaseUtils;
35import android.net.Uri;
36import android.os.RemoteException;
37import android.text.format.DateUtils;
38import android.text.format.Time;
39import android.util.Log;
40
41/**
42 * <p>
43 * The contract between the calendar provider and applications. Contains
44 * definitions for the supported URIs and data columns.
45 * </p>
46 * <h3>Overview</h3>
47 * <p>
48 * CalendarContract defines the data model of calendar and event related
49 * information. This data is stored in a number of tables:
50 * </p>
51 * <ul>
52 * <li>The {@link Calendars} table holds the calendar specific information. Each
53 * row in this table contains the details for a single calendar, such as the
54 * name, color, sync info, etc.</li>
55 * <li>The {@link Events} table holds the event specific information. Each row
56 * in this table has the info for a single event. It contains information such
57 * as event title, location, start time, end time, etc. The event can occur
58 * one-time or can recur multiple times. Attendees, reminders, and extended
59 * properties are stored on separate tables and reference the {@link Events#_ID}
60 * to link them with the event.</li>
61 * <li>The {@link Instances} table holds the start and end time for occurrences
62 * of an event. Each row in this table represents a single occurrence. For
63 * one-time events there will be a 1:1 mapping of instances to events. For
64 * recurring events, multiple rows will automatically be generated which
65 * correspond to multiple occurrences of that event.</li>
66 * <li>The {@link Attendees} table holds the event attendee or guest
67 * information. Each row represents a single guest of an event. It specifies the
68 * type of guest they are and their attendance response for the event.</li>
69 * <li>The {@link Reminders} table holds the alert/notification data. Each row
70 * represents a single alert for an event. An event can have multiple reminders.
71 * The number of reminders per event is specified in
72 * {@link Calendars#MAX_REMINDERS} which is set by the Sync Adapter that owns
73 * the given calendar. Reminders are specified in minutes before the event and
74 * have a type.</li>
75 * <li>The {@link ExtendedProperties} table hold opaque data fields used by the
76 * sync adapter. The provider takes no action with items in this table except to
77 * delete them when their related events are deleted.</li>
78 * </ul>
79 * <p>
80 * Other tables include:
81 * </p>
82 * <ul>
83 * <li>
84 * {@link SyncState}, which contains free-form data maintained by the sync
85 * adapters</li>
86 * </ul>
87 *
88 */
89public final class CalendarContract {
90    private static final String TAG = "Calendar";
91
92    /**
93     * Broadcast Action: This is the intent that gets fired when an alarm
94     * notification needs to be posted for a reminder.
95     *
96     */
97    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
98    public static final String ACTION_EVENT_REMINDER = "android.intent.action.EVENT_REMINDER";
99
100    /**
101     * Intent Extras key: The start time of an event or an instance of a
102     * recurring event. (milliseconds since epoch)
103     */
104    public static final String EXTRA_EVENT_BEGIN_TIME = "beginTime";
105
106    /**
107     * Intent Extras key: The end time of an event or an instance of a recurring
108     * event. (milliseconds since epoch)
109     */
110    public static final String EXTRA_EVENT_END_TIME = "endTime";
111
112    /**
113     * Intent Extras key: When creating an event, set this to true to create an
114     * all-day event by default
115     */
116    public static final String EXTRA_EVENT_ALL_DAY = "allDay";
117
118    /**
119     * This authority is used for writing to or querying from the calendar
120     * provider. Note: This is set at first run and cannot be changed without
121     * breaking apps that access the provider.
122     */
123    public static final String AUTHORITY = "com.android.calendar";
124
125    /**
126     * The content:// style URL for the top-level calendar authority
127     */
128    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
129
130    /**
131     * An optional insert, update or delete URI parameter that allows the caller
132     * to specify that it is a sync adapter. The default value is false. If set
133     * to true, the modified row is not marked as "dirty" (needs to be synced)
134     * and when the provider calls
135     * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}
136     * , the third parameter "syncToNetwork" is set to false. Furthermore, if
137     * set to true, the caller must also include
138     * {@link Calendars#ACCOUNT_NAME} and {@link Calendars#ACCOUNT_TYPE} as
139     * query parameters.
140     *
141     * @see Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)
142     */
143    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
144
145    /**
146     * A special account type for calendars not associated with any account.
147     * Normally calendars that do not match an account on the device will be
148     * removed. Setting the account_type on a calendar to this will prevent it
149     * from being wiped if it does not match an existing account.
150     *
151     * @see SyncColumns#ACCOUNT_TYPE
152     */
153    public static final String ACCOUNT_TYPE_LOCAL = "LOCAL";
154
155    /**
156     * This utility class cannot be instantiated
157     */
158    private CalendarContract() {}
159
160    /**
161     * Generic columns for use by sync adapters. The specific functions of these
162     * columns are private to the sync adapter. Other clients of the API should
163     * not attempt to either read or write this column. These columns are
164     * editable as part of the Calendars Uri, but can only be read if accessed
165     * through any other Uri.
166     */
167    protected interface CalendarSyncColumns {
168
169
170        /**
171         * Generic column for use by sync adapters. Column name.
172         * <P>Type: TEXT</P>
173         */
174        public static final String CAL_SYNC1 = "cal_sync1";
175
176        /**
177         * Generic column for use by sync adapters. Column name.
178         * <P>Type: TEXT</P>
179         */
180        public static final String CAL_SYNC2 = "cal_sync2";
181
182        /**
183         * Generic column for use by sync adapters. Column name.
184         * <P>Type: TEXT</P>
185         */
186        public static final String CAL_SYNC3 = "cal_sync3";
187
188        /**
189         * Generic column for use by sync adapters. Column name.
190         * <P>Type: TEXT</P>
191         */
192        public static final String CAL_SYNC4 = "cal_sync4";
193
194        /**
195         * Generic column for use by sync adapters. Column name.
196         * <P>Type: TEXT</P>
197         */
198        public static final String CAL_SYNC5 = "cal_sync5";
199
200        /**
201         * Generic column for use by sync adapters. Column name.
202         * <P>Type: TEXT</P>
203         */
204        public static final String CAL_SYNC6 = "cal_sync6";
205
206        /**
207         * Generic column for use by sync adapters. Column name.
208         * <P>Type: TEXT</P>
209         */
210        public static final String CAL_SYNC7 = "cal_sync7";
211
212        /**
213         * Generic column for use by sync adapters. Column name.
214         * <P>Type: TEXT</P>
215         */
216        public static final String CAL_SYNC8 = "cal_sync8";
217
218        /**
219         * Generic column for use by sync adapters. Column name.
220         * <P>Type: TEXT</P>
221         */
222        public static final String CAL_SYNC9 = "cal_sync9";
223
224        /**
225         * Generic column for use by sync adapters. Column name.
226         * <P>Type: TEXT</P>
227         */
228        public static final String CAL_SYNC10 = "cal_sync10";
229    }
230
231    /**
232     * Columns for Sync information used by Calendars and Events tables. These
233     * have specific uses which are expected to be consistent by the app and
234     * sync adapter.
235     *
236     */
237    protected interface SyncColumns extends CalendarSyncColumns {
238        /**
239         * The account that was used to sync the entry to the device. If the
240         * account_type is not {@link #ACCOUNT_TYPE_LOCAL} then the name and
241         * type must match an account on the device or the calendar will be
242         * deleted.
243         * <P>Type: TEXT</P>
244         */
245        public static final String ACCOUNT_NAME = "account_name";
246
247        /**
248         * The type of the account that was used to sync the entry to the
249         * device. A type of {@link #ACCOUNT_TYPE_LOCAL} will keep this event
250         * form being deleted if there are no matching accounts on the device.
251         * <P>Type: TEXT</P>
252         */
253        public static final String ACCOUNT_TYPE = "account_type";
254
255        /**
256         * The unique ID for a row assigned by the sync source. NULL if the row
257         * has never been synced. This is used as a reference id for exceptions
258         * along with {@link BaseColumns#_ID}.
259         * <P>Type: TEXT</P>
260         */
261        public static final String _SYNC_ID = "_sync_id";
262
263        /**
264         * Used to indicate that local, unsynced, changes are present.
265         * <P>Type: INTEGER (long)</P>
266         */
267        public static final String DIRTY = "dirty";
268
269        /**
270         * Whether the row has been deleted but not synced to the server. A
271         * deleted row should be ignored.
272         * <P>
273         * Type: INTEGER (boolean)
274         * </P>
275         */
276        public static final String DELETED = "deleted";
277
278        /**
279         * If set to 1 this causes events on this calendar to be duplicated with
280         * {@link Events#LAST_SYNCED} set to 1 whenever the event
281         * transitions from non-dirty to dirty. The duplicated event will not be
282         * expanded in the instances table and will only show up in sync adapter
283         * queries of the events table. It will also be deleted when the
284         * originating event has its dirty flag cleared by the sync adapter.
285         * <P>Type: INTEGER (boolean)</P>
286         */
287        public static final String CAN_PARTIALLY_UPDATE = "canPartiallyUpdate";
288    }
289
290    /**
291     * Columns specific to the Calendars Uri that other Uris can query.
292     */
293    protected interface CalendarColumns {
294        /**
295         * The color of the calendar. This should only be updated by the sync
296         * adapter, not other apps, as changing a calendar's color can adversely
297         * affect its display.
298         * <P>Type: INTEGER (color value)</P>
299         */
300        public static final String CALENDAR_COLOR = "calendar_color";
301
302        /**
303         * An index for looking up a color from the {@link Colors} table. NULL
304         * or an empty string are reserved for indicating that the calendar does
305         * not use an index for looking up the color. The provider will update
306         * {@link #CALENDAR_COLOR} automatically when a valid index is written
307         * to this column. @see Colors
308         * <P>
309         * Type: TEXT
310         * </P>
311         * TODO UNHIDE
312         *
313         * @hide
314         */
315        public static final String CALENDAR_COLOR_INDEX = "calendar_color_index";
316
317        /**
318         * The display name of the calendar. Column name.
319         * <P>
320         * Type: TEXT
321         * </P>
322         */
323        public static final String CALENDAR_DISPLAY_NAME = "calendar_displayName";
324
325        /**
326         * The level of access that the user has for the calendar
327         * <P>Type: INTEGER (one of the values below)</P>
328         */
329        public static final String CALENDAR_ACCESS_LEVEL = "calendar_access_level";
330
331        /** Cannot access the calendar */
332        public static final int CAL_ACCESS_NONE = 0;
333        /** Can only see free/busy information about the calendar */
334        public static final int CAL_ACCESS_FREEBUSY = 100;
335        /** Can read all event details */
336        public static final int CAL_ACCESS_READ = 200;
337        /** Can reply yes/no/maybe to an event */
338        public static final int CAL_ACCESS_RESPOND = 300;
339        /** not used */
340        public static final int CAL_ACCESS_OVERRIDE = 400;
341        /** Full access to modify the calendar, but not the access control
342         * settings
343         */
344        public static final int CAL_ACCESS_CONTRIBUTOR = 500;
345        /** Full access to modify the calendar, but not the access control
346         * settings
347         */
348        public static final int CAL_ACCESS_EDITOR = 600;
349        /** Full access to the calendar */
350        public static final int CAL_ACCESS_OWNER = 700;
351        /** Domain admin */
352        public static final int CAL_ACCESS_ROOT = 800;
353
354        /**
355         * Is the calendar selected to be displayed?
356         * 0 - do not show events associated with this calendar.
357         * 1 - show events associated with this calendar
358         * <P>Type: INTEGER (boolean)</P>
359         */
360        public static final String VISIBLE = "visible";
361
362        /**
363         * The time zone the calendar is associated with.
364         * <P>Type: TEXT</P>
365         */
366        public static final String CALENDAR_TIME_ZONE = "calendar_timezone";
367
368        /**
369         * Is this calendar synced and are its events stored on the device?
370         * 0 - Do not sync this calendar or store events for this calendar.
371         * 1 - Sync down events for this calendar.
372         * <p>Type: INTEGER (boolean)</p>
373         */
374        public static final String SYNC_EVENTS = "sync_events";
375
376        /**
377         * The owner account for this calendar, based on the calendar feed.
378         * This will be different from the _SYNC_ACCOUNT for delegated calendars.
379         * Column name.
380         * <P>Type: String</P>
381         */
382        public static final String OWNER_ACCOUNT = "ownerAccount";
383
384        /**
385         * Can the organizer respond to the event?  If no, the status of the
386         * organizer should not be shown by the UI.  Defaults to 1. Column name.
387         * <P>Type: INTEGER (boolean)</P>
388         */
389        public static final String CAN_ORGANIZER_RESPOND = "canOrganizerRespond";
390
391        /**
392         * Can the organizer modify the time zone of the event? Column name.
393         * <P>Type: INTEGER (boolean)</P>
394        */
395        public static final String CAN_MODIFY_TIME_ZONE = "canModifyTimeZone";
396
397        /**
398         * The maximum number of reminders allowed for an event. Column name.
399         * <P>Type: INTEGER</P>
400         */
401        public static final String MAX_REMINDERS = "maxReminders";
402
403        /**
404         * A comma separated list of reminder methods supported for this
405         * calendar in the format "#,#,#". Valid types are
406         * {@link Reminders#METHOD_DEFAULT}, {@link Reminders#METHOD_ALERT},
407         * {@link Reminders#METHOD_EMAIL}, {@link Reminders#METHOD_SMS}. Column
408         * name.
409         * <P>Type: TEXT</P>
410         */
411        public static final String ALLOWED_REMINDERS = "allowedReminders";
412
413        /**
414         * A comma separated list of availability types supported for this
415         * calendar in the format "#,#,#". Valid types are
416         * {@link Events#AVAILABILITY_BUSY}, {@link Events#AVAILABILITY_FREE},
417         * {@link Events#AVAILABILITY_TENTATIVE}. Setting this field to only
418         * {@link Events#AVAILABILITY_BUSY} should be used to indicate that
419         * changing the availability is not supported.
420         *
421         * TODO UNHIDE, Update Calendars doc
422         *
423         * @hide
424         */
425        public static final String ALLOWED_AVAILABILITY = "allowedAvailability";
426
427        /**
428         * A comma separated list of attendee types supported for this calendar
429         * in the format "#,#,#". Valid types are {@link Attendees#TYPE_NONE},
430         * {@link Attendees#TYPE_OPTIONAL}, {@link Attendees#TYPE_REQUIRED},
431         * {@link Attendees#TYPE_RESOURCE}. Setting this field to only
432         * {@link Attendees#TYPE_NONE} should be used to indicate that changing
433         * the attendee type is not supported.
434         *
435         * TODO UNHIDE, Update Calendars doc
436         *
437         * @hide
438         */
439        public static final String ALLOWED_ATTENDEE_TYPES = "allowedAttendeeTypes";
440    }
441
442    /**
443     * Class that represents a Calendar Entity. There is one entry per calendar.
444     * This is a helper class to make batch operations easier.
445     */
446    public static final class CalendarEntity implements BaseColumns, SyncColumns, CalendarColumns {
447
448        /**
449         * The default Uri used when creating a new calendar EntityIterator.
450         */
451        @SuppressWarnings("hiding")
452        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
453                "/calendar_entities");
454
455        /**
456         * This utility class cannot be instantiated
457         */
458        private CalendarEntity() {}
459
460        /**
461         * Creates an entity iterator for the given cursor. It assumes the
462         * cursor contains a calendars query.
463         *
464         * @param cursor query on {@link #CONTENT_URI}
465         * @return an EntityIterator of calendars
466         */
467        public static EntityIterator newEntityIterator(Cursor cursor) {
468            return new EntityIteratorImpl(cursor);
469        }
470
471        private static class EntityIteratorImpl extends CursorEntityIterator {
472
473            public EntityIteratorImpl(Cursor cursor) {
474                super(cursor);
475            }
476
477            @Override
478            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
479                // we expect the cursor is already at the row we need to read from
480                final long calendarId = cursor.getLong(cursor.getColumnIndexOrThrow(_ID));
481
482                // Create the content value
483                ContentValues cv = new ContentValues();
484                cv.put(_ID, calendarId);
485
486                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
487                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
488
489                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID);
490                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
491
492                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC1);
493                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC2);
494                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC3);
495                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC4);
496                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC5);
497                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC6);
498                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC7);
499                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC8);
500                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC9);
501                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC10);
502
503                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.NAME);
504                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
505                        Calendars.CALENDAR_DISPLAY_NAME);
506                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
507                        Calendars.CALENDAR_COLOR);
508                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ACCESS_LEVEL);
509                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, VISIBLE);
510                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SYNC_EVENTS);
511                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
512                        Calendars.CALENDAR_LOCATION);
513                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CALENDAR_TIME_ZONE);
514                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
515                        Calendars.OWNER_ACCOUNT);
516                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
517                        Calendars.CAN_ORGANIZER_RESPOND);
518                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
519                        Calendars.CAN_MODIFY_TIME_ZONE);
520                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
521                        Calendars.MAX_REMINDERS);
522                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
523                        Calendars.CAN_PARTIALLY_UPDATE);
524                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
525                        Calendars.ALLOWED_REMINDERS);
526
527                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED);
528
529                // Create the Entity from the ContentValue
530                Entity entity = new Entity(cv);
531
532                // Set cursor to next row
533                cursor.moveToNext();
534
535                // Return the created Entity
536                return entity;
537            }
538        }
539     }
540
541    /**
542     * Constants and helpers for the Calendars table, which contains details for
543     * individual calendars. <h3>Operations</h3> All operations can be done
544     * either as an app or as a sync adapter. To perform an operation as a sync
545     * adapter {@link #CALLER_IS_SYNCADAPTER} should be set to true and
546     * {@link #ACCOUNT_NAME} and {@link #ACCOUNT_TYPE} must be set in the Uri
547     * parameters. See
548     * {@link Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)}
549     * for details on adding parameters. Sync adapters have write access to more
550     * columns but are restricted to a single account at a time. Calendars are
551     * designed to be primarily managed by a sync adapter and inserting new
552     * calendars should be done as a sync adapter. For the most part, apps
553     * should only update calendars (such as changing the color or display
554     * name). If a local calendar is required an app can do so by inserting as a
555     * sync adapter and using an {@link #ACCOUNT_TYPE} of
556     * {@link #ACCOUNT_TYPE_LOCAL} .
557     * <dl>
558     * <dt><b>Insert</b></dt>
559     * <dd>When inserting a new calendar the following fields must be included:
560     * <ul>
561     * <li>{@link #ACCOUNT_NAME}</li>
562     * <li>{@link #ACCOUNT_TYPE}</li>
563     * <li>{@link #NAME}</li>
564     * <li>{@link #CALENDAR_DISPLAY_NAME}</li>
565     * <li>{@link #CALENDAR_COLOR}</li>
566     * <li>{@link #CALENDAR_ACCESS_LEVEL}</li>
567     * <li>{@link #OWNER_ACCOUNT}</li>
568     * </ul>
569     * The following fields are not required when inserting a Calendar but are
570     * generally a good idea to include:
571     * <ul>
572     * <li>{@link #SYNC_EVENTS} set to 1</li>
573     * <li>{@link #CALENDAR_TIME_ZONE}</li>
574     * <li>{@link #ALLOWED_REMINDERS}</li>
575     * </ul>
576     * <dt><b>Update</b></dt>
577     * <dd>To perform an update on a calendar the {@link #_ID} of the calendar
578     * should be provided either as an appended id to the Uri (
579     * {@link ContentUris#withAppendedId}) or as the first selection item--the
580     * selection should start with "_id=?" and the first selectionArg should be
581     * the _id of the calendar. Calendars may also be updated using a selection
582     * without the id. In general, the {@link #ACCOUNT_NAME} and
583     * {@link #ACCOUNT_TYPE} should not be changed after a calendar is created
584     * as this can cause issues for sync adapters.
585     * <dt><b>Delete</b></dt>
586     * <dd>Calendars can be deleted either by the {@link #_ID} as an appended id
587     * on the Uri or using any standard selection. Deleting a calendar should
588     * generally be handled by a sync adapter as it will remove the calendar
589     * from the database and all associated data (aka events).</dd>
590     * <dt><b>Query</b></dt>
591     * <dd>Querying the Calendars table will get you all information about a set
592     * of calendars. There will be one row returned for each calendar that
593     * matches the query selection, or at most a single row if the {@link #_ID}
594     * is appended to the Uri.</dd>
595     * </dl>
596     * <h3>Calendar Columns</h3> The following Calendar columns are writable by
597     * both an app and a sync adapter.
598     * <ul>
599     * <li>{@link #NAME}</li>
600     * <li>{@link #CALENDAR_DISPLAY_NAME}</li>
601     * <li>{@link #VISIBLE}</li>
602     * <li>{@link #SYNC_EVENTS}</li>
603     * </ul>
604     * The following Calendars columns are writable only by a sync adapter
605     * <ul>
606     * <li>{@link #ACCOUNT_NAME}</li>
607     * <li>{@link #ACCOUNT_TYPE}</li>
608     * <li>{@link #CALENDAR_COLOR}</li>
609     * <li>{@link #_SYNC_ID}</li>
610     * <li>{@link #DIRTY}</li>
611     * <li>{@link #OWNER_ACCOUNT}</li>
612     * <li>{@link #MAX_REMINDERS}</li>
613     * <li>{@link #ALLOWED_REMINDERS}</li>
614     * <li>{@link #CAN_MODIFY_TIME_ZONE}</li>
615     * <li>{@link #CAN_ORGANIZER_RESPOND}</li>
616     * <li>{@link #CAN_PARTIALLY_UPDATE}</li>
617     * <li>{@link #CALENDAR_LOCATION}</li>
618     * <li>{@link #CALENDAR_TIME_ZONE}</li>
619     * <li>{@link #CALENDAR_ACCESS_LEVEL}</li>
620     * <li>{@link #DELETED}</li>
621     * <li>{@link #CAL_SYNC1}</li>
622     * <li>{@link #CAL_SYNC2}</li>
623     * <li>{@link #CAL_SYNC3}</li>
624     * <li>{@link #CAL_SYNC4}</li>
625     * <li>{@link #CAL_SYNC5}</li>
626     * <li>{@link #CAL_SYNC6}</li>
627     * <li>{@link #CAL_SYNC7}</li>
628     * <li>{@link #CAL_SYNC8}</li>
629     * <li>{@link #CAL_SYNC9}</li>
630     * <li>{@link #CAL_SYNC10}</li>
631     * </ul>
632     */
633    public static final class Calendars implements BaseColumns, SyncColumns, CalendarColumns {
634
635        /**
636         * This utility class cannot be instantiated
637         */
638        private Calendars() {}
639
640        /**
641         * The content:// style URL for accessing Calendars
642         */
643        @SuppressWarnings("hiding")
644        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/calendars");
645
646        /**
647         * The default sort order for this table
648         */
649        public static final String DEFAULT_SORT_ORDER = CALENDAR_DISPLAY_NAME;
650
651        /**
652         * The name of the calendar. Column name.
653         * <P>Type: TEXT</P>
654         */
655        public static final String NAME = "name";
656
657        /**
658         * The default location for the calendar. Column name.
659         * <P>Type: TEXT</P>
660         */
661        public static final String CALENDAR_LOCATION = "calendar_location";
662
663        /**
664         * These fields are only writable by a sync adapter. To modify them the
665         * caller must include {@link #CALLER_IS_SYNCADAPTER},
666         * {@link #ACCOUNT_NAME}, and {@link #ACCOUNT_TYPE} in the Uri's query
667         * parameters. TODO move to provider
668         *
669         * @hide
670         */
671        public static final String[] SYNC_WRITABLE_COLUMNS = new String[] {
672            ACCOUNT_NAME,
673            ACCOUNT_TYPE,
674            _SYNC_ID,
675            DIRTY,
676            OWNER_ACCOUNT,
677            MAX_REMINDERS,
678            ALLOWED_REMINDERS,
679            CAN_MODIFY_TIME_ZONE,
680            CAN_ORGANIZER_RESPOND,
681            CAN_PARTIALLY_UPDATE,
682            CALENDAR_LOCATION,
683            CALENDAR_TIME_ZONE,
684            CALENDAR_ACCESS_LEVEL,
685            DELETED,
686            CAL_SYNC1,
687            CAL_SYNC2,
688            CAL_SYNC3,
689            CAL_SYNC4,
690            CAL_SYNC5,
691            CAL_SYNC6,
692            CAL_SYNC7,
693            CAL_SYNC8,
694            CAL_SYNC9,
695            CAL_SYNC10,
696        };
697    }
698
699    /**
700     * Columns from the Attendees table that other tables join into themselves.
701     */
702    protected interface AttendeesColumns {
703
704        /**
705         * The id of the event. Column name.
706         * <P>Type: INTEGER</P>
707         */
708        public static final String EVENT_ID = "event_id";
709
710        /**
711         * The name of the attendee. Column name.
712         * <P>Type: STRING</P>
713         */
714        public static final String ATTENDEE_NAME = "attendeeName";
715
716        /**
717         * The email address of the attendee. Column name.
718         * <P>Type: STRING</P>
719         */
720        public static final String ATTENDEE_EMAIL = "attendeeEmail";
721
722        /**
723         * The relationship of the attendee to the user. Column name.
724         * <P>Type: INTEGER (one of {@link #RELATIONSHIP_ATTENDEE}, ...}.</P>
725         */
726        public static final String ATTENDEE_RELATIONSHIP = "attendeeRelationship";
727
728        public static final int RELATIONSHIP_NONE = 0;
729        public static final int RELATIONSHIP_ATTENDEE = 1;
730        public static final int RELATIONSHIP_ORGANIZER = 2;
731        public static final int RELATIONSHIP_PERFORMER = 3;
732        public static final int RELATIONSHIP_SPEAKER = 4;
733
734        /**
735         * The type of attendee. Column name.
736         * <P>
737         * Type: Integer (one of {@link #TYPE_REQUIRED}, {@link #TYPE_OPTIONAL}
738         * </P>
739         */
740        public static final String ATTENDEE_TYPE = "attendeeType";
741
742        public static final int TYPE_NONE = 0;
743        public static final int TYPE_REQUIRED = 1;
744        public static final int TYPE_OPTIONAL = 2;
745        /**
746         * This specifies that an attendee is a resource, such as a room, and
747         * not an actual person. TODO UNHIDE and add to ATTENDEE_TYPE comment
748         *
749         * @hide
750         */
751        public static final int TYPE_RESOURCE = 3;
752
753        /**
754         * The attendance status of the attendee. Column name.
755         * <P>Type: Integer (one of {@link #ATTENDEE_STATUS_ACCEPTED}, ...).</P>
756         */
757        public static final String ATTENDEE_STATUS = "attendeeStatus";
758
759        public static final int ATTENDEE_STATUS_NONE = 0;
760        public static final int ATTENDEE_STATUS_ACCEPTED = 1;
761        public static final int ATTENDEE_STATUS_DECLINED = 2;
762        public static final int ATTENDEE_STATUS_INVITED = 3;
763        public static final int ATTENDEE_STATUS_TENTATIVE = 4;
764    }
765
766    /**
767     * Fields and helpers for interacting with Attendees. Each row of this table
768     * represents a single attendee or guest of an event. Calling
769     * {@link #query(ContentResolver, long, String[])} will return a list of attendees for
770     * the event with the given eventId. Both apps and sync adapters may write
771     * to this table. There are six writable fields and all of them except
772     * {@link #ATTENDEE_NAME} must be included when inserting a new attendee.
773     * They are:
774     * <ul>
775     * <li>{@link #EVENT_ID}</li>
776     * <li>{@link #ATTENDEE_NAME}</li>
777     * <li>{@link #ATTENDEE_EMAIL}</li>
778     * <li>{@link #ATTENDEE_RELATIONSHIP}</li>
779     * <li>{@link #ATTENDEE_TYPE}</li>
780     * <li>{@link #ATTENDEE_STATUS}</li>
781     * </ul>
782     */
783    public static final class Attendees implements BaseColumns, AttendeesColumns, EventsColumns {
784
785        /**
786         * The content:// style URL for accessing Attendees data
787         */
788        @SuppressWarnings("hiding")
789        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/attendees");
790        private static final String ATTENDEES_WHERE = Attendees.EVENT_ID + "=?";
791
792        /**
793         * This utility class cannot be instantiated
794         */
795        private Attendees() {}
796
797        /**
798         * Queries all attendees associated with the given event. This is a
799         * blocking call and should not be done on the UI thread.
800         *
801         * @param cr The content resolver to use for the query
802         * @param eventId The id of the event to retrieve attendees for
803         * @param projection the columns to return in the cursor
804         * @return A Cursor containing all attendees for the event
805         */
806        public static final Cursor query(ContentResolver cr, long eventId, String[] projection) {
807            String[] attArgs = {Long.toString(eventId)};
808            return cr.query(CONTENT_URI, projection, ATTENDEES_WHERE, attArgs /* selection args */,
809                    null /* sort order */);
810        }
811    }
812
813    /**
814     * Columns from the Events table that other tables join into themselves.
815     */
816    protected interface EventsColumns {
817
818        /**
819         * The {@link Calendars#_ID} of the calendar the event belongs to.
820         * Column name.
821         * <P>Type: INTEGER</P>
822         */
823        public static final String CALENDAR_ID = "calendar_id";
824
825        /**
826         * The title of the event. Column name.
827         * <P>Type: TEXT</P>
828         */
829        public static final String TITLE = "title";
830
831        /**
832         * The description of the event. Column name.
833         * <P>Type: TEXT</P>
834         */
835        public static final String DESCRIPTION = "description";
836
837        /**
838         * Where the event takes place. Column name.
839         * <P>Type: TEXT</P>
840         */
841        public static final String EVENT_LOCATION = "eventLocation";
842
843        /**
844         * A secondary color for the individual event. This should only be
845         * updated by the sync adapter for a given account.
846         * <P>Type: INTEGER</P>
847         */
848        public static final String EVENT_COLOR = "eventColor";
849
850        /**
851         * A secondary color index for the individual event. NULL or an empty
852         * string are reserved for indicating that the event does not use an
853         * index for looking up the color. The provider will update
854         * {@link #EVENT_COLOR} automatically when a valid index is written to
855         * this column. @see Colors
856         * <P>Type: TEXT</P>
857         * TODO UNHIDE
858         *
859         * @hide
860         */
861        public static final String EVENT_COLOR_INDEX = "eventColor_index";
862
863        /**
864         * The event status. Column name.
865         * <P>Type: INTEGER (one of {@link #STATUS_TENTATIVE}...)</P>
866         */
867        public static final String STATUS = "eventStatus";
868
869        public static final int STATUS_TENTATIVE = 0;
870        public static final int STATUS_CONFIRMED = 1;
871        public static final int STATUS_CANCELED = 2;
872
873        /**
874         * This is a copy of the attendee status for the owner of this event.
875         * This field is copied here so that we can efficiently filter out
876         * events that are declined without having to look in the Attendees
877         * table. Column name.
878         *
879         * <P>Type: INTEGER (int)</P>
880         */
881        public static final String SELF_ATTENDEE_STATUS = "selfAttendeeStatus";
882
883        /**
884         * This column is available for use by sync adapters. Column name.
885         * <P>Type: TEXT</P>
886         */
887        public static final String SYNC_DATA1 = "sync_data1";
888
889        /**
890         * This column is available for use by sync adapters. Column name.
891         * <P>Type: TEXT</P>
892         */
893        public static final String SYNC_DATA2 = "sync_data2";
894
895        /**
896         * This column is available for use by sync adapters. Column name.
897         * <P>Type: TEXT</P>
898         */
899        public static final String SYNC_DATA3 = "sync_data3";
900
901        /**
902         * This column is available for use by sync adapters. Column name.
903         * <P>Type: TEXT</P>
904         */
905        public static final String SYNC_DATA4 = "sync_data4";
906
907        /**
908         * This column is available for use by sync adapters. Column name.
909         * <P>Type: TEXT</P>
910         */
911        public static final String SYNC_DATA5 = "sync_data5";
912
913        /**
914         * This column is available for use by sync adapters. Column name.
915         * <P>Type: TEXT</P>
916         */
917        public static final String SYNC_DATA6 = "sync_data6";
918
919        /**
920         * This column is available for use by sync adapters. Column name.
921         * <P>Type: TEXT</P>
922         */
923        public static final String SYNC_DATA7 = "sync_data7";
924
925        /**
926         * This column is available for use by sync adapters. Column name.
927         * <P>Type: TEXT</P>
928         */
929        public static final String SYNC_DATA8 = "sync_data8";
930
931        /**
932         * This column is available for use by sync adapters. Column name.
933         * <P>Type: TEXT</P>
934         */
935        public static final String SYNC_DATA9 = "sync_data9";
936
937        /**
938         * This column is available for use by sync adapters. Column name.
939         * <P>Type: TEXT</P>
940         */
941        public static final String SYNC_DATA10 = "sync_data10";
942
943        /**
944         * Used to indicate that a row is not a real event but an original copy of a locally
945         * modified event. A copy is made when an event changes from non-dirty to dirty and the
946         * event is on a calendar with {@link Calendars#CAN_PARTIALLY_UPDATE} set to 1. This copy
947         * does not get expanded in the instances table and is only visible in queries made by a
948         * sync adapter. The copy gets removed when the event is changed back to non-dirty by a
949         * sync adapter.
950         * <P>Type: INTEGER (boolean)</P>
951         */
952        public static final String LAST_SYNCED = "lastSynced";
953
954        /**
955         * The time the event starts in UTC millis since epoch. Column name.
956         * <P>Type: INTEGER (long; millis since epoch)</P>
957         */
958        public static final String DTSTART = "dtstart";
959
960        /**
961         * The time the event ends in UTC millis since epoch. Column name.
962         * <P>Type: INTEGER (long; millis since epoch)</P>
963         */
964        public static final String DTEND = "dtend";
965
966        /**
967         * The duration of the event in RFC2445 format. Column name.
968         * <P>Type: TEXT (duration in RFC2445 format)</P>
969         */
970        public static final String DURATION = "duration";
971
972        /**
973         * The timezone for the event. Column name.
974         * <P>Type: TEXT</P>
975         */
976        public static final String EVENT_TIMEZONE = "eventTimezone";
977
978        /**
979         * The timezone for the end time of the event. Column name.
980         * <P>Type: TEXT</P>
981         */
982        public static final String EVENT_END_TIMEZONE = "eventEndTimezone";
983
984        /**
985         * Is the event all day (time zone independent). Column name.
986         * <P>Type: INTEGER (boolean)</P>
987         */
988        public static final String ALL_DAY = "allDay";
989
990        /**
991         * Defines how the event shows up for others when the calendar is
992         * shared. Column name.
993         * <P>Type: INTEGER (One of {@link #ACCESS_DEFAULT}, ...)</P>
994         */
995        public static final String ACCESS_LEVEL = "accessLevel";
996
997        /**
998         * Default access is controlled by the server and will be treated as
999         * public on the device.
1000         */
1001        public static final int ACCESS_DEFAULT = 0;
1002        /**
1003         * Confidential is not used by the app.
1004         */
1005        public static final int ACCESS_CONFIDENTIAL = 1;
1006        /**
1007         * Private shares the event as a free/busy slot with no details.
1008         */
1009        public static final int ACCESS_PRIVATE = 2;
1010        /**
1011         * Public makes the contents visible to anyone with access to the
1012         * calendar.
1013         */
1014        public static final int ACCESS_PUBLIC = 3;
1015
1016        /**
1017         * If this event counts as busy time or is still free time that can be
1018         * scheduled over. Column name.
1019         * <P>Type: INTEGER (One of {@link #AVAILABILITY_BUSY},
1020         * {@link #AVAILABILITY_FREE})</P>
1021         */
1022        public static final String AVAILABILITY = "availability";
1023
1024        /**
1025         * Indicates that this event takes up time and will conflict with other
1026         * events.
1027         */
1028        public static final int AVAILABILITY_BUSY = 0;
1029        /**
1030         * Indicates that this event is free time and will not conflict with
1031         * other events.
1032         */
1033        public static final int AVAILABILITY_FREE = 1;
1034        /**
1035         * Indicates that the owner's availability may change, but should be
1036         * considered busy time that will conflict.
1037         *
1038         * TODO UNHIDE
1039         *
1040         * @hide
1041         */
1042        public static final int AVAILABILITY_TENTATIVE = 2;
1043
1044        /**
1045         * Whether the event has an alarm or not. Column name.
1046         * <P>Type: INTEGER (boolean)</P>
1047         */
1048        public static final String HAS_ALARM = "hasAlarm";
1049
1050        /**
1051         * Whether the event has extended properties or not. Column name.
1052         * <P>Type: INTEGER (boolean)</P>
1053         */
1054        public static final String HAS_EXTENDED_PROPERTIES = "hasExtendedProperties";
1055
1056        /**
1057         * The recurrence rule for the event. Column name.
1058         * <P>Type: TEXT</P>
1059         */
1060        public static final String RRULE = "rrule";
1061
1062        /**
1063         * The recurrence dates for the event. Column name.
1064         * <P>Type: TEXT</P>
1065         */
1066        public static final String RDATE = "rdate";
1067
1068        /**
1069         * The recurrence exception rule for the event. Column name.
1070         * <P>Type: TEXT</P>
1071         */
1072        public static final String EXRULE = "exrule";
1073
1074        /**
1075         * The recurrence exception dates for the event. Column name.
1076         * <P>Type: TEXT</P>
1077         */
1078        public static final String EXDATE = "exdate";
1079
1080        /**
1081         * The {@link Events#_ID} of the original recurring event for which this
1082         * event is an exception. Column name.
1083         * <P>Type: TEXT</P>
1084         */
1085        public static final String ORIGINAL_ID = "original_id";
1086
1087        /**
1088         * The _sync_id of the original recurring event for which this event is
1089         * an exception. The provider should keep the original_id in sync when
1090         * this is updated. Column name.
1091         * <P>Type: TEXT</P>
1092         */
1093        public static final String ORIGINAL_SYNC_ID = "original_sync_id";
1094
1095        /**
1096         * The original instance time of the recurring event for which this
1097         * event is an exception. Column name.
1098         * <P>Type: INTEGER (long; millis since epoch)</P>
1099         */
1100        public static final String ORIGINAL_INSTANCE_TIME = "originalInstanceTime";
1101
1102        /**
1103         * The allDay status (true or false) of the original recurring event
1104         * for which this event is an exception. Column name.
1105         * <P>Type: INTEGER (boolean)</P>
1106         */
1107        public static final String ORIGINAL_ALL_DAY = "originalAllDay";
1108
1109        /**
1110         * The last date this event repeats on, or NULL if it never ends. Column
1111         * name.
1112         * <P>Type: INTEGER (long; millis since epoch)</P>
1113         */
1114        public static final String LAST_DATE = "lastDate";
1115
1116        /**
1117         * Whether the event has attendee information.  True if the event
1118         * has full attendee data, false if the event has information about
1119         * self only. Column name.
1120         * <P>Type: INTEGER (boolean)</P>
1121         */
1122        public static final String HAS_ATTENDEE_DATA = "hasAttendeeData";
1123
1124        /**
1125         * Whether guests can modify the event. Column name.
1126         * <P>Type: INTEGER (boolean)</P>
1127         */
1128        public static final String GUESTS_CAN_MODIFY = "guestsCanModify";
1129
1130        /**
1131         * Whether guests can invite other guests. Column name.
1132         * <P>Type: INTEGER (boolean)</P>
1133         */
1134        public static final String GUESTS_CAN_INVITE_OTHERS = "guestsCanInviteOthers";
1135
1136        /**
1137         * Whether guests can see the list of attendees. Column name.
1138         * <P>Type: INTEGER (boolean)</P>
1139         */
1140        public static final String GUESTS_CAN_SEE_GUESTS = "guestsCanSeeGuests";
1141
1142        /**
1143         * Email of the organizer (owner) of the event. Column name.
1144         * <P>Type: STRING</P>
1145         */
1146        public static final String ORGANIZER = "organizer";
1147
1148        /**
1149         * Whether the user can invite others to the event. The
1150         * GUESTS_CAN_INVITE_OTHERS is a setting that applies to an arbitrary
1151         * guest, while CAN_INVITE_OTHERS indicates if the user can invite
1152         * others (either through GUESTS_CAN_INVITE_OTHERS or because the user
1153         * has modify access to the event). Column name.
1154         * <P>Type: INTEGER (boolean, readonly)</P>
1155         */
1156        public static final String CAN_INVITE_OTHERS = "canInviteOthers";
1157    }
1158
1159    /**
1160     * Class that represents an Event Entity. There is one entry per event.
1161     * Recurring events show up as a single entry. This is a helper class to
1162     * make batch operations easier. A {@link ContentResolver} or
1163     * {@link ContentProviderClient} is required as the helper does additional
1164     * queries to add reminders and attendees to each entry.
1165     */
1166    public static final class EventsEntity implements BaseColumns, SyncColumns, EventsColumns {
1167        /**
1168         * The content:// style URL for this table
1169         */
1170        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
1171                "/event_entities");
1172
1173        /**
1174         * This utility class cannot be instantiated
1175         */
1176        private EventsEntity() {}
1177
1178        /**
1179         * Creates a new iterator for events
1180         *
1181         * @param cursor An event query
1182         * @param resolver For performing additional queries
1183         * @return an EntityIterator containing one entity per event in the
1184         *         cursor
1185         */
1186        public static EntityIterator newEntityIterator(Cursor cursor, ContentResolver resolver) {
1187            return new EntityIteratorImpl(cursor, resolver);
1188        }
1189
1190        /**
1191         * Creates a new iterator for events
1192         *
1193         * @param cursor An event query
1194         * @param provider For performing additional queries
1195         * @return an EntityIterator containing one entity per event in the
1196         *         cursor
1197         */
1198        public static EntityIterator newEntityIterator(Cursor cursor,
1199                ContentProviderClient provider) {
1200            return new EntityIteratorImpl(cursor, provider);
1201        }
1202
1203        private static class EntityIteratorImpl extends CursorEntityIterator {
1204            private final ContentResolver mResolver;
1205            private final ContentProviderClient mProvider;
1206
1207            private static final String[] REMINDERS_PROJECTION = new String[] {
1208                    Reminders.MINUTES,
1209                    Reminders.METHOD,
1210            };
1211            private static final int COLUMN_MINUTES = 0;
1212            private static final int COLUMN_METHOD = 1;
1213
1214            private static final String[] ATTENDEES_PROJECTION = new String[] {
1215                    Attendees.ATTENDEE_NAME,
1216                    Attendees.ATTENDEE_EMAIL,
1217                    Attendees.ATTENDEE_RELATIONSHIP,
1218                    Attendees.ATTENDEE_TYPE,
1219                    Attendees.ATTENDEE_STATUS,
1220            };
1221            private static final int COLUMN_ATTENDEE_NAME = 0;
1222            private static final int COLUMN_ATTENDEE_EMAIL = 1;
1223            private static final int COLUMN_ATTENDEE_RELATIONSHIP = 2;
1224            private static final int COLUMN_ATTENDEE_TYPE = 3;
1225            private static final int COLUMN_ATTENDEE_STATUS = 4;
1226            private static final String[] EXTENDED_PROJECTION = new String[] {
1227                    ExtendedProperties._ID,
1228                    ExtendedProperties.NAME,
1229                    ExtendedProperties.VALUE
1230            };
1231            private static final int COLUMN_ID = 0;
1232            private static final int COLUMN_NAME = 1;
1233            private static final int COLUMN_VALUE = 2;
1234
1235            private static final String WHERE_EVENT_ID = "event_id=?";
1236
1237            public EntityIteratorImpl(Cursor cursor, ContentResolver resolver) {
1238                super(cursor);
1239                mResolver = resolver;
1240                mProvider = null;
1241            }
1242
1243            public EntityIteratorImpl(Cursor cursor, ContentProviderClient provider) {
1244                super(cursor);
1245                mResolver = null;
1246                mProvider = provider;
1247            }
1248
1249            @Override
1250            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
1251                // we expect the cursor is already at the row we need to read from
1252                final long eventId = cursor.getLong(cursor.getColumnIndexOrThrow(Events._ID));
1253                ContentValues cv = new ContentValues();
1254                cv.put(Events._ID, eventId);
1255                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ID);
1256                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, TITLE);
1257                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DESCRIPTION);
1258                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_LOCATION);
1259                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, STATUS);
1260                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SELF_ATTENDEE_STATUS);
1261                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTSTART);
1262                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTEND);
1263                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DURATION);
1264                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_TIMEZONE);
1265                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_END_TIMEZONE);
1266                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ALL_DAY);
1267                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ACCESS_LEVEL);
1268                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, AVAILABILITY);
1269                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, HAS_ALARM);
1270                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1271                        HAS_EXTENDED_PROPERTIES);
1272                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RRULE);
1273                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RDATE);
1274                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXRULE);
1275                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXDATE);
1276                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_SYNC_ID);
1277                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_ID);
1278                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
1279                        ORIGINAL_INSTANCE_TIME);
1280                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ORIGINAL_ALL_DAY);
1281                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_DATE);
1282                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, HAS_ATTENDEE_DATA);
1283                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
1284                        GUESTS_CAN_INVITE_OTHERS);
1285                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_MODIFY);
1286                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_SEE_GUESTS);
1287                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORGANIZER);
1288                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID);
1289                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
1290                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_SYNCED);
1291                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED);
1292                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA1);
1293                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA2);
1294                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA3);
1295                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA4);
1296                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA5);
1297                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA6);
1298                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA7);
1299                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA8);
1300                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA9);
1301                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA10);
1302                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC1);
1303                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC2);
1304                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC3);
1305                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC4);
1306                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC5);
1307                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC6);
1308                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC7);
1309                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC8);
1310                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC9);
1311                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC10);
1312
1313                Entity entity = new Entity(cv);
1314                Cursor subCursor;
1315                if (mResolver != null) {
1316                    subCursor = mResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
1317                            WHERE_EVENT_ID,
1318                            new String[] { Long.toString(eventId) }  /* selectionArgs */,
1319                            null /* sortOrder */);
1320                } else {
1321                    subCursor = mProvider.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
1322                            WHERE_EVENT_ID,
1323                            new String[] { Long.toString(eventId) }  /* selectionArgs */,
1324                            null /* sortOrder */);
1325                }
1326                try {
1327                    while (subCursor.moveToNext()) {
1328                        ContentValues reminderValues = new ContentValues();
1329                        reminderValues.put(Reminders.MINUTES, subCursor.getInt(COLUMN_MINUTES));
1330                        reminderValues.put(Reminders.METHOD, subCursor.getInt(COLUMN_METHOD));
1331                        entity.addSubValue(Reminders.CONTENT_URI, reminderValues);
1332                    }
1333                } finally {
1334                    subCursor.close();
1335                }
1336
1337                if (mResolver != null) {
1338                    subCursor = mResolver.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION,
1339                            WHERE_EVENT_ID,
1340                            new String[] { Long.toString(eventId) } /* selectionArgs */,
1341                            null /* sortOrder */);
1342                } else {
1343                    subCursor = mProvider.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION,
1344                            WHERE_EVENT_ID,
1345                            new String[] { Long.toString(eventId) } /* selectionArgs */,
1346                            null /* sortOrder */);
1347                }
1348                try {
1349                    while (subCursor.moveToNext()) {
1350                        ContentValues attendeeValues = new ContentValues();
1351                        attendeeValues.put(Attendees.ATTENDEE_NAME,
1352                                subCursor.getString(COLUMN_ATTENDEE_NAME));
1353                        attendeeValues.put(Attendees.ATTENDEE_EMAIL,
1354                                subCursor.getString(COLUMN_ATTENDEE_EMAIL));
1355                        attendeeValues.put(Attendees.ATTENDEE_RELATIONSHIP,
1356                                subCursor.getInt(COLUMN_ATTENDEE_RELATIONSHIP));
1357                        attendeeValues.put(Attendees.ATTENDEE_TYPE,
1358                                subCursor.getInt(COLUMN_ATTENDEE_TYPE));
1359                        attendeeValues.put(Attendees.ATTENDEE_STATUS,
1360                                subCursor.getInt(COLUMN_ATTENDEE_STATUS));
1361                        entity.addSubValue(Attendees.CONTENT_URI, attendeeValues);
1362                    }
1363                } finally {
1364                    subCursor.close();
1365                }
1366
1367                if (mResolver != null) {
1368                    subCursor = mResolver.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION,
1369                            WHERE_EVENT_ID,
1370                            new String[] { Long.toString(eventId) } /* selectionArgs */,
1371                            null /* sortOrder */);
1372                } else {
1373                    subCursor = mProvider.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION,
1374                            WHERE_EVENT_ID,
1375                            new String[] { Long.toString(eventId) } /* selectionArgs */,
1376                            null /* sortOrder */);
1377                }
1378                try {
1379                    while (subCursor.moveToNext()) {
1380                        ContentValues extendedValues = new ContentValues();
1381                        extendedValues.put(ExtendedProperties._ID,
1382                                subCursor.getString(COLUMN_ID));
1383                        extendedValues.put(ExtendedProperties.NAME,
1384                                subCursor.getString(COLUMN_NAME));
1385                        extendedValues.put(ExtendedProperties.VALUE,
1386                                subCursor.getString(COLUMN_VALUE));
1387                        entity.addSubValue(ExtendedProperties.CONTENT_URI, extendedValues);
1388                    }
1389                } finally {
1390                    subCursor.close();
1391                }
1392
1393                cursor.moveToNext();
1394                return entity;
1395            }
1396        }
1397    }
1398
1399    /**
1400     * Constants and helpers for the Events table, which contains details for
1401     * individual events. <h3>Operations</h3> All operations can be done either
1402     * as an app or as a sync adapter. To perform an operation as a sync adapter
1403     * {@link #CALLER_IS_SYNCADAPTER} should be set to true and
1404     * {@link #ACCOUNT_NAME} and {@link #ACCOUNT_TYPE} must be set in the Uri
1405     * parameters. See
1406     * {@link Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)}
1407     * for details on adding parameters. Sync adapters have write access to more
1408     * columns but are restricted to a single account at a time.
1409     * <dl>
1410     * <dt><b>Insert</b></dt>
1411     * <dd>When inserting a new event the following fields must be included:
1412     * <ul>
1413     * <li>dtstart</li>
1414     * <li>dtend -or- a (rrule or rdate) and a duration</li>
1415     * <li>a calendar_id</li>
1416     * </ul>
1417     * There are also further requirements when inserting or updating an event.
1418     * See the section on Writing to Events.</dd>
1419     * <dt><b>Update</b></dt>
1420     * <dd>To perform an update of an Event the {@link Events#_ID} of the event
1421     * should be provided either as an appended id to the Uri (
1422     * {@link ContentUris#withAppendedId}) or as the first selection item--the
1423     * selection should start with "_id=?" and the first selectionArg should be
1424     * the _id of the event. Updates may also be done using a selection and no
1425     * id. Updating an event must respect the same rules as inserting and is
1426     * further restricted in the fields that can be written. See the section on
1427     * Writing to Events.</dd>
1428     * <dt><b>Delete</b></dt>
1429     * <dd>Events can be deleted either by the {@link Events#_ID} as an appended
1430     * id on the Uri or using any standard selection. If an appended id is used
1431     * a selection is not allowed. There are two versions of delete: as an app
1432     * and as a sync adapter. An app delete will set the deleted column on an
1433     * event and remove all instances of that event. A sync adapter delete will
1434     * remove the event from the database and all associated data.</dd>
1435     * <dt><b>Query</b></dt>
1436     * <dd>Querying the Events table will get you all information about a set of
1437     * events except their reminders, attendees, and extended properties. There
1438     * will be one row returned for each event that matches the query selection,
1439     * or at most a single row if the {@link Events#_ID} is appended to the Uri.
1440     * Recurring events will only return a single row regardless of the number
1441     * of times that event repeats.</dd>
1442     * </dl>
1443     * <h3>Writing to Events</h3> There are further restrictions on all Updates
1444     * and Inserts in the Events table:
1445     * <ul>
1446     * <li>If allDay is set to 1 eventTimezone must be {@link Time#TIMEZONE_UTC}
1447     * and the time must correspond to a midnight boundary.</li>
1448     * <li>Exceptions are not allowed to recur. If rrule or rdate is not empty,
1449     * original_id and original_sync_id must be empty.</li>
1450     * <li>In general a calendar_id should not be modified after insertion. This
1451     * is not explicitly forbidden but many sync adapters will not behave in an
1452     * expected way if the calendar_id is modified.</li>
1453     * </ul>
1454     * The following Events columns are writable by both an app and a sync
1455     * adapter.
1456     * <ul>
1457     * <li>{@link #CALENDAR_ID}</li>
1458     * <li>{@link #ORGANIZER}</li>
1459     * <li>{@link #TITLE}</li>
1460     * <li>{@link #EVENT_LOCATION}</li>
1461     * <li>{@link #DESCRIPTION}</li>
1462     * <li>{@link #EVENT_COLOR}</li>
1463     * <li>{@link #DTSTART}</li>
1464     * <li>{@link #DTEND}</li>
1465     * <li>{@link #EVENT_TIMEZONE}</li>
1466     * <li>{@link #EVENT_END_TIMEZONE}</li>
1467     * <li>{@link #DURATION}</li>
1468     * <li>{@link #ALL_DAY}</li>
1469     * <li>{@link #RRULE}</li>
1470     * <li>{@link #RDATE}</li>
1471     * <li>{@link #EXRULE}</li>
1472     * <li>{@link #EXDATE}</li>
1473     * <li>{@link #ORIGINAL_ID}</li>
1474     * <li>{@link #ORIGINAL_SYNC_ID}</li>
1475     * <li>{@link #ORIGINAL_INSTANCE_TIME}</li>
1476     * <li>{@link #ORIGINAL_ALL_DAY}</li>
1477     * <li>{@link #ACCESS_LEVEL}</li>
1478     * <li>{@link #AVAILABILITY}</li>
1479     * <li>{@link #GUESTS_CAN_MODIFY}</li>
1480     * <li>{@link #GUESTS_CAN_INVITE_OTHERS}</li>
1481     * <li>{@link #GUESTS_CAN_SEE_GUESTS}</li>
1482     * </ul>
1483     * The following Events columns are writable only by a sync adapter
1484     * <ul>
1485     * <li>{@link #DIRTY}</li>
1486     * <li>{@link #_SYNC_ID}</li>
1487     * <li>{@link #SYNC_DATA1}</li>
1488     * <li>{@link #SYNC_DATA2}</li>
1489     * <li>{@link #SYNC_DATA3}</li>
1490     * <li>{@link #SYNC_DATA4}</li>
1491     * <li>{@link #SYNC_DATA5}</li>
1492     * <li>{@link #SYNC_DATA6}</li>
1493     * <li>{@link #SYNC_DATA7}</li>
1494     * <li>{@link #SYNC_DATA8}</li>
1495     * <li>{@link #SYNC_DATA9}</li>
1496     * <li>{@link #SYNC_DATA10}</li>
1497     * </ul>
1498     * The remaining columns are either updated by the provider only or are
1499     * views into other tables and cannot be changed through the Events table.
1500     */
1501    public static final class Events implements BaseColumns, SyncColumns, EventsColumns,
1502            CalendarColumns {
1503
1504        /**
1505         * The content:// style URL for interacting with events. Appending an
1506         * event id using {@link ContentUris#withAppendedId(Uri, long)} will
1507         * specify a single event.
1508         */
1509        @SuppressWarnings("hiding")
1510        public static final Uri CONTENT_URI =
1511                Uri.parse("content://" + AUTHORITY + "/events");
1512
1513        /**
1514         * The content:// style URI for recurring event exceptions.  Insertions require an
1515         * appended event ID.  Deletion of exceptions requires both the original event ID and
1516         * the exception event ID (see {@link Uri.Builder#appendPath}).
1517         */
1518        public static final Uri CONTENT_EXCEPTION_URI =
1519                Uri.parse("content://" + AUTHORITY + "/exception");
1520
1521        /**
1522         * This utility class cannot be instantiated
1523         */
1524        private Events() {}
1525
1526        /**
1527         * The default sort order for this table
1528         */
1529        private static final String DEFAULT_SORT_ORDER = "";
1530
1531        /**
1532         * These are columns that should only ever be updated by the provider,
1533         * either because they are views mapped to another table or because they
1534         * are used for provider only functionality. TODO move to provider
1535         *
1536         * @hide
1537         */
1538        public static String[] PROVIDER_WRITABLE_COLUMNS = new String[] {
1539                ACCOUNT_NAME,
1540                ACCOUNT_TYPE,
1541                CAL_SYNC1,
1542                CAL_SYNC2,
1543                CAL_SYNC3,
1544                CAL_SYNC4,
1545                CAL_SYNC5,
1546                CAL_SYNC6,
1547                CAL_SYNC7,
1548                CAL_SYNC8,
1549                CAL_SYNC9,
1550                CAL_SYNC10,
1551                ALLOWED_REMINDERS,
1552                CALENDAR_ACCESS_LEVEL,
1553                CALENDAR_COLOR,
1554                CALENDAR_TIME_ZONE,
1555                CAN_MODIFY_TIME_ZONE,
1556                CAN_ORGANIZER_RESPOND,
1557                CALENDAR_DISPLAY_NAME,
1558                CAN_PARTIALLY_UPDATE,
1559                SYNC_EVENTS,
1560                VISIBLE,
1561        };
1562
1563        /**
1564         * These fields are only writable by a sync adapter. To modify them the
1565         * caller must include CALLER_IS_SYNCADAPTER, _SYNC_ACCOUNT, and
1566         * _SYNC_ACCOUNT_TYPE in the query parameters. TODO move to provider.
1567         *
1568         * @hide
1569         */
1570        public static final String[] SYNC_WRITABLE_COLUMNS = new String[] {
1571            _SYNC_ID,
1572            DIRTY,
1573            SYNC_DATA1,
1574            SYNC_DATA2,
1575            SYNC_DATA3,
1576            SYNC_DATA4,
1577            SYNC_DATA5,
1578            SYNC_DATA6,
1579            SYNC_DATA7,
1580            SYNC_DATA8,
1581            SYNC_DATA9,
1582            SYNC_DATA10,
1583        };
1584    }
1585
1586    /**
1587     * Fields and helpers for interacting with Instances. An instance is a
1588     * single occurrence of an event including time zone specific start and end
1589     * days and minutes. The instances table is not writable and only provides a
1590     * way to query event occurrences.
1591     */
1592    public static final class Instances implements BaseColumns, EventsColumns, CalendarColumns {
1593
1594        private static final String WHERE_CALENDARS_SELECTED = Calendars.VISIBLE + "=?";
1595        private static final String[] WHERE_CALENDARS_ARGS = {
1596            "1"
1597        };
1598
1599        /**
1600         * This utility class cannot be instantiated
1601         */
1602        private Instances() {}
1603
1604        /**
1605         * Performs a query to return all visible instances in the given range.
1606         * This is a blocking function and should not be done on the UI thread.
1607         * This will cause an expansion of recurring events to fill this time
1608         * range if they are not already expanded and will slow down for larger
1609         * time ranges with many recurring events.
1610         *
1611         * @param cr The ContentResolver to use for the query
1612         * @param projection The columns to return
1613         * @param begin The start of the time range to query in UTC millis since
1614         *            epoch
1615         * @param end The end of the time range to query in UTC millis since
1616         *            epoch
1617         * @return A Cursor containing all instances in the given range
1618         */
1619        public static final Cursor query(ContentResolver cr, String[] projection,
1620                                         long begin, long end) {
1621            Uri.Builder builder = CONTENT_URI.buildUpon();
1622            ContentUris.appendId(builder, begin);
1623            ContentUris.appendId(builder, end);
1624            return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
1625                    WHERE_CALENDARS_ARGS, DEFAULT_SORT_ORDER);
1626        }
1627
1628        /**
1629         * Performs a query to return all visible instances in the given range
1630         * that match the given query. This is a blocking function and should
1631         * not be done on the UI thread. This will cause an expansion of
1632         * recurring events to fill this time range if they are not already
1633         * expanded and will slow down for larger time ranges with many
1634         * recurring events.
1635         *
1636         * @param cr The ContentResolver to use for the query
1637         * @param projection The columns to return
1638         * @param begin The start of the time range to query in UTC millis since
1639         *            epoch
1640         * @param end The end of the time range to query in UTC millis since
1641         *            epoch
1642         * @param searchQuery A string of space separated search terms. Segments
1643         *            enclosed by double quotes will be treated as a single
1644         *            term.
1645         * @return A Cursor of instances matching the search terms in the given
1646         *         time range
1647         */
1648        public static final Cursor query(ContentResolver cr, String[] projection,
1649                                         long begin, long end, String searchQuery) {
1650            Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon();
1651            ContentUris.appendId(builder, begin);
1652            ContentUris.appendId(builder, end);
1653            builder = builder.appendPath(searchQuery);
1654            return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
1655                    WHERE_CALENDARS_ARGS, DEFAULT_SORT_ORDER);
1656        }
1657
1658        /**
1659         * The content:// style URL for querying an instance range. The begin
1660         * and end of the range to query should be added as path segments if
1661         * this is used directly.
1662         */
1663        @SuppressWarnings("hiding")
1664        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
1665                "/instances/when");
1666        /**
1667         * The content:// style URL for querying an instance range by Julian
1668         * Day. The start and end day should be added as path segments if this
1669         * is used directly.
1670         */
1671        public static final Uri CONTENT_BY_DAY_URI =
1672            Uri.parse("content://" + AUTHORITY + "/instances/whenbyday");
1673        /**
1674         * The content:// style URL for querying an instance range with a search
1675         * term. The begin, end, and search string should be appended as path
1676         * segments if this is used directly.
1677         */
1678        public static final Uri CONTENT_SEARCH_URI = Uri.parse("content://" + AUTHORITY +
1679                "/instances/search");
1680        /**
1681         * The content:// style URL for querying an instance range with a search
1682         * term. The start day, end day, and search string should be appended as
1683         * path segments if this is used directly.
1684         */
1685        public static final Uri CONTENT_SEARCH_BY_DAY_URI =
1686            Uri.parse("content://" + AUTHORITY + "/instances/searchbyday");
1687
1688        /**
1689         * The default sort order for this table.
1690         */
1691        private static final String DEFAULT_SORT_ORDER = "begin ASC";
1692
1693        /**
1694         * The beginning time of the instance, in UTC milliseconds. Column name.
1695         * <P>Type: INTEGER (long; millis since epoch)</P>
1696         */
1697        public static final String BEGIN = "begin";
1698
1699        /**
1700         * The ending time of the instance, in UTC milliseconds. Column name.
1701         * <P>Type: INTEGER (long; millis since epoch)</P>
1702         */
1703        public static final String END = "end";
1704
1705        /**
1706         * The _id of the event for this instance. Column name.
1707         * <P>Type: INTEGER (long, foreign key to the Events table)</P>
1708         */
1709        public static final String EVENT_ID = "event_id";
1710
1711        /**
1712         * The Julian start day of the instance, relative to the local time
1713         * zone. Column name.
1714         * <P>Type: INTEGER (int)</P>
1715         */
1716        public static final String START_DAY = "startDay";
1717
1718        /**
1719         * The Julian end day of the instance, relative to the local time
1720         * zone. Column name.
1721         * <P>Type: INTEGER (int)</P>
1722         */
1723        public static final String END_DAY = "endDay";
1724
1725        /**
1726         * The start minute of the instance measured from midnight in the
1727         * local time zone. Column name.
1728         * <P>Type: INTEGER (int)</P>
1729         */
1730        public static final String START_MINUTE = "startMinute";
1731
1732        /**
1733         * The end minute of the instance measured from midnight in the
1734         * local time zone. Column name.
1735         * <P>Type: INTEGER (int)</P>
1736         */
1737        public static final String END_MINUTE = "endMinute";
1738    }
1739
1740    protected interface CalendarCacheColumns {
1741        /**
1742         * The key for the setting. Keys are defined in {@link CalendarCache}.
1743         */
1744        public static final String KEY = "key";
1745
1746        /**
1747         * The value of the given setting.
1748         */
1749        public static final String VALUE = "value";
1750    }
1751
1752    /**
1753     * CalendarCache stores some settings for calendar including the current
1754     * time zone for the instances. These settings are stored using a key/value
1755     * scheme. A {@link #KEY} must be specified when updating these values.
1756     */
1757    public static final class CalendarCache implements CalendarCacheColumns {
1758        /**
1759         * The URI to use for retrieving the properties from the Calendar db.
1760         */
1761        public static final Uri URI =
1762                Uri.parse("content://" + AUTHORITY + "/properties");
1763
1764        /**
1765         * This utility class cannot be instantiated
1766         */
1767        private CalendarCache() {}
1768
1769        /**
1770         * They key for updating the use of auto/home time zones in Calendar.
1771         * Valid values are {@link #TIMEZONE_TYPE_AUTO} or
1772         * {@link #TIMEZONE_TYPE_HOME}.
1773         */
1774        public static final String KEY_TIMEZONE_TYPE = "timezoneType";
1775
1776        /**
1777         * The key for updating the time zone used by the provider when it
1778         * generates the instances table. This should only be written if the
1779         * type is set to {@link #TIMEZONE_TYPE_HOME}. A valid time zone id
1780         * should be written to this field.
1781         */
1782        public static final String KEY_TIMEZONE_INSTANCES = "timezoneInstances";
1783
1784        /**
1785         * The key for reading the last time zone set by the user. This should
1786         * only be read by apps and it will be automatically updated whenever
1787         * {@link #KEY_TIMEZONE_INSTANCES} is updated with
1788         * {@link #TIMEZONE_TYPE_HOME} set.
1789         */
1790        public static final String KEY_TIMEZONE_INSTANCES_PREVIOUS = "timezoneInstancesPrevious";
1791
1792        /**
1793         * The value to write to {@link #KEY_TIMEZONE_TYPE} if the provider
1794         * should stay in sync with the device's time zone.
1795         */
1796        public static final String TIMEZONE_TYPE_AUTO = "auto";
1797
1798        /**
1799         * The value to write to {@link #KEY_TIMEZONE_TYPE} if the provider
1800         * should use a fixed time zone set by the user.
1801         */
1802        public static final String TIMEZONE_TYPE_HOME = "home";
1803    }
1804
1805    /**
1806     * A few Calendar globals are needed in the CalendarProvider for expanding
1807     * the Instances table and these are all stored in the first (and only) row
1808     * of the CalendarMetaData table.
1809     *
1810     * @hide
1811     */
1812    protected interface CalendarMetaDataColumns {
1813        /**
1814         * The local timezone that was used for precomputing the fields
1815         * in the Instances table.
1816         */
1817        public static final String LOCAL_TIMEZONE = "localTimezone";
1818
1819        /**
1820         * The minimum time used in expanding the Instances table,
1821         * in UTC milliseconds.
1822         * <P>Type: INTEGER</P>
1823         */
1824        public static final String MIN_INSTANCE = "minInstance";
1825
1826        /**
1827         * The maximum time used in expanding the Instances table,
1828         * in UTC milliseconds.
1829         * <P>Type: INTEGER</P>
1830         */
1831        public static final String MAX_INSTANCE = "maxInstance";
1832
1833        /**
1834         * The minimum Julian day in the EventDays table.
1835         * <P>Type: INTEGER</P>
1836         */
1837        public static final String MIN_EVENTDAYS = "minEventDays";
1838
1839        /**
1840         * The maximum Julian day in the EventDays table.
1841         * <P>Type: INTEGER</P>
1842         */
1843        public static final String MAX_EVENTDAYS = "maxEventDays";
1844    }
1845
1846    /**
1847     * @hide
1848     */
1849    public static final class CalendarMetaData implements CalendarMetaDataColumns, BaseColumns {
1850
1851        /**
1852         * This utility class cannot be instantiated
1853         */
1854        private CalendarMetaData() {}
1855    }
1856
1857    protected interface EventDaysColumns {
1858        /**
1859         * The Julian starting day number. Column name.
1860         * <P>Type: INTEGER (int)</P>
1861         */
1862        public static final String STARTDAY = "startDay";
1863        /**
1864         * The Julian ending day number. Column name.
1865         * <P>Type: INTEGER (int)</P>
1866         */
1867        public static final String ENDDAY = "endDay";
1868
1869    }
1870
1871    /**
1872     * Fields and helpers for querying for a list of days that contain events.
1873     */
1874    public static final class EventDays implements EventDaysColumns {
1875        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
1876                + "/instances/groupbyday");
1877        private static final String SELECTION = "selected=1";
1878
1879        /**
1880         * This utility class cannot be instantiated
1881         */
1882        private EventDays() {}
1883
1884        /**
1885         * Retrieves the days with events for the Julian days starting at
1886         * "startDay" for "numDays". It returns a cursor containing startday and
1887         * endday representing the max range of days for all events beginning on
1888         * each startday.This is a blocking function and should not be done on
1889         * the UI thread.
1890         *
1891         * @param cr the ContentResolver
1892         * @param startDay the first Julian day in the range
1893         * @param numDays the number of days to load (must be at least 1)
1894         * @param projection the columns to return in the cursor
1895         * @return a database cursor containing a list of start and end days for
1896         *         events
1897         */
1898        public static final Cursor query(ContentResolver cr, int startDay, int numDays,
1899                String[] projection) {
1900            if (numDays < 1) {
1901                return null;
1902            }
1903            int endDay = startDay + numDays - 1;
1904            Uri.Builder builder = CONTENT_URI.buildUpon();
1905            ContentUris.appendId(builder, startDay);
1906            ContentUris.appendId(builder, endDay);
1907            return cr.query(builder.build(), projection, SELECTION,
1908                    null /* selection args */, STARTDAY);
1909        }
1910    }
1911
1912    protected interface RemindersColumns {
1913        /**
1914         * The event the reminder belongs to. Column name.
1915         * <P>Type: INTEGER (foreign key to the Events table)</P>
1916         */
1917        public static final String EVENT_ID = "event_id";
1918
1919        /**
1920         * The minutes prior to the event that the alarm should ring.  -1
1921         * specifies that we should use the default value for the system.
1922         * Column name.
1923         * <P>Type: INTEGER</P>
1924         */
1925        public static final String MINUTES = "minutes";
1926
1927        /**
1928         * Passing this as a minutes value will use the default reminder
1929         * minutes.
1930         */
1931        public static final int MINUTES_DEFAULT = -1;
1932
1933        /**
1934         * The alarm method, as set on the server. {@link #METHOD_DEFAULT},
1935         * {@link #METHOD_ALERT}, {@link #METHOD_EMAIL}, and {@link #METHOD_SMS}
1936         * are possible values; the device will only process
1937         * {@link #METHOD_DEFAULT} and {@link #METHOD_ALERT} reminders (the
1938         * other types are simply stored so we can send the same reminder info
1939         * back to the server when we make changes).
1940         */
1941        public static final String METHOD = "method";
1942
1943        public static final int METHOD_DEFAULT = 0;
1944        public static final int METHOD_ALERT = 1;
1945        public static final int METHOD_EMAIL = 2;
1946        public static final int METHOD_SMS = 3;
1947    }
1948
1949    /**
1950     * Fields and helpers for accessing reminders for an event. Each row of this
1951     * table represents a single reminder for an event. Calling
1952     * {@link #query(ContentResolver, long, String[])} will return a list of reminders for
1953     * the event with the given eventId. Both apps and sync adapters may write
1954     * to this table. There are three writable fields and all of them must be
1955     * included when inserting a new reminder. They are:
1956     * <ul>
1957     * <li>{@link #EVENT_ID}</li>
1958     * <li>{@link #MINUTES}</li>
1959     * <li>{@link #METHOD}</li>
1960     * </ul>
1961     */
1962    public static final class Reminders implements BaseColumns, RemindersColumns, EventsColumns {
1963        private static final String REMINDERS_WHERE = CalendarContract.Reminders.EVENT_ID + "=?";
1964        @SuppressWarnings("hiding")
1965        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/reminders");
1966
1967        /**
1968         * This utility class cannot be instantiated
1969         */
1970        private Reminders() {}
1971
1972        /**
1973         * Queries all reminders associated with the given event. This is a
1974         * blocking call and should not be done on the UI thread.
1975         *
1976         * @param cr The content resolver to use for the query
1977         * @param eventId The id of the event to retrieve reminders for
1978         * @param projection the columns to return in the cursor
1979         * @return A Cursor containing all reminders for the event
1980         */
1981        public static final Cursor query(ContentResolver cr, long eventId, String[] projection) {
1982            String[] remArgs = {Long.toString(eventId)};
1983            return cr.query(CONTENT_URI, projection, REMINDERS_WHERE, remArgs /*selection args*/,
1984                    null /* sort order */);
1985        }
1986    }
1987
1988    protected interface CalendarAlertsColumns {
1989        /**
1990         * The event that the alert belongs to. Column name.
1991         * <P>Type: INTEGER (foreign key to the Events table)</P>
1992         */
1993        public static final String EVENT_ID = "event_id";
1994
1995        /**
1996         * The start time of the event, in UTC. Column name.
1997         * <P>Type: INTEGER (long; millis since epoch)</P>
1998         */
1999        public static final String BEGIN = "begin";
2000
2001        /**
2002         * The end time of the event, in UTC. Column name.
2003         * <P>Type: INTEGER (long; millis since epoch)</P>
2004         */
2005        public static final String END = "end";
2006
2007        /**
2008         * The alarm time of the event, in UTC. Column name.
2009         * <P>Type: INTEGER (long; millis since epoch)</P>
2010         */
2011        public static final String ALARM_TIME = "alarmTime";
2012
2013        /**
2014         * The creation time of this database entry, in UTC.
2015         * Useful for debugging missed reminders. Column name.
2016         * <P>Type: INTEGER (long; millis since epoch)</P>
2017         */
2018        public static final String CREATION_TIME = "creationTime";
2019
2020        /**
2021         * The time that the alarm broadcast was received by the Calendar app,
2022         * in UTC. Useful for debugging missed reminders. Column name.
2023         * <P>Type: INTEGER (long; millis since epoch)</P>
2024         */
2025        public static final String RECEIVED_TIME = "receivedTime";
2026
2027        /**
2028         * The time that the notification was created by the Calendar app,
2029         * in UTC. Useful for debugging missed reminders. Column name.
2030         * <P>Type: INTEGER (long; millis since epoch)</P>
2031         */
2032        public static final String NOTIFY_TIME = "notifyTime";
2033
2034        /**
2035         * The state of this alert. It starts out as {@link #STATE_SCHEDULED}, then
2036         * when the alarm goes off, it changes to {@link #STATE_FIRED}, and then when
2037         * the user dismisses the alarm it changes to {@link #STATE_DISMISSED}. Column
2038         * name.
2039         * <P>Type: INTEGER</P>
2040         */
2041        public static final String STATE = "state";
2042
2043        /**
2044         * An alert begins in this state when it is first created.
2045         */
2046        public static final int STATE_SCHEDULED = 0;
2047        /**
2048         * After a notification for an alert has been created it should be
2049         * updated to fired.
2050         */
2051        public static final int STATE_FIRED = 1;
2052        /**
2053         * Once the user has dismissed the notification the alert's state should
2054         * be set to dismissed so it is not fired again.
2055         */
2056        public static final int STATE_DISMISSED = 2;
2057
2058        /**
2059         * The number of minutes that this alarm precedes the start time. Column
2060         * name.
2061         * <P>Type: INTEGER</P>
2062         */
2063        public static final String MINUTES = "minutes";
2064
2065        /**
2066         * The default sort order for this alerts queries
2067         */
2068        public static final String DEFAULT_SORT_ORDER = "begin ASC,title ASC";
2069    }
2070
2071    /**
2072     * Fields and helpers for accessing calendar alerts information. These
2073     * fields are for tracking which alerts have been fired. Scheduled alarms
2074     * will generate an intent using {@link #ACTION_EVENT_REMINDER}. Apps that
2075     * receive this action may update the {@link #STATE} for the reminder when
2076     * they have finished handling it. Apps that have their notifications
2077     * disabled should not modify the table to ensure that they do not conflict
2078     * with another app that is generating a notification. In general, apps
2079     * should not need to write to this table directly except to update the
2080     * state of a reminder.
2081     */
2082    public static final class CalendarAlerts implements BaseColumns,
2083            CalendarAlertsColumns, EventsColumns, CalendarColumns {
2084
2085        /**
2086         * @hide
2087         */
2088        public static final String TABLE_NAME = "CalendarAlerts";
2089        /**
2090         * The Uri for querying calendar alert information
2091         */
2092        @SuppressWarnings("hiding")
2093        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
2094                "/calendar_alerts");
2095
2096        /**
2097         * This utility class cannot be instantiated
2098         */
2099        private CalendarAlerts() {}
2100
2101        private static final String WHERE_ALARM_EXISTS = EVENT_ID + "=?"
2102                + " AND " + BEGIN + "=?"
2103                + " AND " + ALARM_TIME + "=?";
2104
2105        private static final String WHERE_FINDNEXTALARMTIME = ALARM_TIME + ">=?";
2106        private static final String SORT_ORDER_ALARMTIME_ASC = ALARM_TIME + " ASC";
2107
2108        private static final String WHERE_RESCHEDULE_MISSED_ALARMS = STATE + "=" + STATE_SCHEDULED
2109                + " AND " + ALARM_TIME + "<?"
2110                + " AND " + ALARM_TIME + ">?"
2111                + " AND " + END + ">=?";
2112
2113        /**
2114         * This URI is for grouping the query results by event_id and begin
2115         * time.  This will return one result per instance of an event.  So
2116         * events with multiple alarms will appear just once, but multiple
2117         * instances of a repeating event will show up multiple times.
2118         */
2119        public static final Uri CONTENT_URI_BY_INSTANCE =
2120            Uri.parse("content://" + AUTHORITY + "/calendar_alerts/by_instance");
2121
2122        private static final boolean DEBUG = false;
2123
2124        /**
2125         * Helper for inserting an alarm time associated with an event TODO move
2126         * to Provider
2127         *
2128         * @hide
2129         */
2130        public static final Uri insert(ContentResolver cr, long eventId,
2131                long begin, long end, long alarmTime, int minutes) {
2132            ContentValues values = new ContentValues();
2133            values.put(CalendarAlerts.EVENT_ID, eventId);
2134            values.put(CalendarAlerts.BEGIN, begin);
2135            values.put(CalendarAlerts.END, end);
2136            values.put(CalendarAlerts.ALARM_TIME, alarmTime);
2137            long currentTime = System.currentTimeMillis();
2138            values.put(CalendarAlerts.CREATION_TIME, currentTime);
2139            values.put(CalendarAlerts.RECEIVED_TIME, 0);
2140            values.put(CalendarAlerts.NOTIFY_TIME, 0);
2141            values.put(CalendarAlerts.STATE, STATE_SCHEDULED);
2142            values.put(CalendarAlerts.MINUTES, minutes);
2143            return cr.insert(CONTENT_URI, values);
2144        }
2145
2146        /**
2147         * Finds the next alarm after (or equal to) the given time and returns
2148         * the time of that alarm or -1 if no such alarm exists. This is a
2149         * blocking call and should not be done on the UI thread. TODO move to
2150         * provider
2151         *
2152         * @param cr the ContentResolver
2153         * @param millis the time in UTC milliseconds
2154         * @return the next alarm time greater than or equal to "millis", or -1
2155         *         if no such alarm exists.
2156         * @hide
2157         */
2158        public static final long findNextAlarmTime(ContentResolver cr, long millis) {
2159            String selection = ALARM_TIME + ">=" + millis;
2160            // TODO: construct an explicit SQL query so that we can add
2161            // "LIMIT 1" to the end and get just one result.
2162            String[] projection = new String[] { ALARM_TIME };
2163            Cursor cursor = cr.query(CONTENT_URI, projection, WHERE_FINDNEXTALARMTIME,
2164                    (new String[] {
2165                        Long.toString(millis)
2166                    }), SORT_ORDER_ALARMTIME_ASC);
2167            long alarmTime = -1;
2168            try {
2169                if (cursor != null && cursor.moveToFirst()) {
2170                    alarmTime = cursor.getLong(0);
2171                }
2172            } finally {
2173                if (cursor != null) {
2174                    cursor.close();
2175                }
2176            }
2177            return alarmTime;
2178        }
2179
2180        /**
2181         * Searches the CalendarAlerts table for alarms that should have fired
2182         * but have not and then reschedules them. This method can be called at
2183         * boot time to restore alarms that may have been lost due to a phone
2184         * reboot. TODO move to provider
2185         *
2186         * @param cr the ContentResolver
2187         * @param context the Context
2188         * @param manager the AlarmManager
2189         * @hide
2190         */
2191        public static final void rescheduleMissedAlarms(ContentResolver cr,
2192                Context context, AlarmManager manager) {
2193            // Get all the alerts that have been scheduled but have not fired
2194            // and should have fired by now and are not too old.
2195            long now = System.currentTimeMillis();
2196            long ancient = now - DateUtils.DAY_IN_MILLIS;
2197            String[] projection = new String[] {
2198                    ALARM_TIME,
2199            };
2200
2201            // TODO: construct an explicit SQL query so that we can add
2202            // "GROUPBY" instead of doing a sort and de-dup
2203            Cursor cursor = cr.query(CalendarAlerts.CONTENT_URI, projection,
2204                    WHERE_RESCHEDULE_MISSED_ALARMS, (new String[] {
2205                            Long.toString(now), Long.toString(ancient), Long.toString(now)
2206                    }), SORT_ORDER_ALARMTIME_ASC);
2207            if (cursor == null) {
2208                return;
2209            }
2210
2211            if (DEBUG) {
2212                Log.d(TAG, "missed alarms found: " + cursor.getCount());
2213            }
2214
2215            try {
2216                long alarmTime = -1;
2217
2218                while (cursor.moveToNext()) {
2219                    long newAlarmTime = cursor.getLong(0);
2220                    if (alarmTime != newAlarmTime) {
2221                        if (DEBUG) {
2222                            Log.w(TAG, "rescheduling missed alarm. alarmTime: " + newAlarmTime);
2223                        }
2224                        scheduleAlarm(context, manager, newAlarmTime);
2225                        alarmTime = newAlarmTime;
2226                    }
2227                }
2228            } finally {
2229                cursor.close();
2230            }
2231        }
2232
2233        /**
2234         * Schedules an alarm intent with the system AlarmManager that will
2235         * notify listeners when a reminder should be fired. The provider will
2236         * keep scheduled reminders up to date but apps may use this to
2237         * implement snooze functionality without modifying the reminders table.
2238         * Scheduled alarms will generate an intent using
2239         * {@link #ACTION_EVENT_REMINDER}. TODO Move to provider
2240         *
2241         * @param context A context for referencing system resources
2242         * @param manager The AlarmManager to use or null
2243         * @param alarmTime The time to fire the intent in UTC millis since
2244         *            epoch
2245         * @hide
2246         */
2247        public static void scheduleAlarm(Context context, AlarmManager manager, long alarmTime) {
2248            if (DEBUG) {
2249                Time time = new Time();
2250                time.set(alarmTime);
2251                String schedTime = time.format(" %a, %b %d, %Y %I:%M%P");
2252                Log.d(TAG, "Schedule alarm at " + alarmTime + " " + schedTime);
2253            }
2254
2255            if (manager == null) {
2256                manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
2257            }
2258
2259            Intent intent = new Intent(ACTION_EVENT_REMINDER);
2260            intent.setData(ContentUris.withAppendedId(CalendarContract.CONTENT_URI, alarmTime));
2261            intent.putExtra(ALARM_TIME, alarmTime);
2262            PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
2263            manager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
2264        }
2265
2266        /**
2267         * Searches for an entry in the CalendarAlerts table that matches the
2268         * given event id, begin time and alarm time. If one is found then this
2269         * alarm already exists and this method returns true. TODO Move to
2270         * provider
2271         *
2272         * @param cr the ContentResolver
2273         * @param eventId the event id to match
2274         * @param begin the start time of the event in UTC millis
2275         * @param alarmTime the alarm time of the event in UTC millis
2276         * @return true if there is already an alarm for the given event with
2277         *         the same start time and alarm time.
2278         * @hide
2279         */
2280        public static final boolean alarmExists(ContentResolver cr, long eventId,
2281                long begin, long alarmTime) {
2282            // TODO: construct an explicit SQL query so that we can add
2283            // "LIMIT 1" to the end and get just one result.
2284            String[] projection = new String[] { ALARM_TIME };
2285            Cursor cursor = cr.query(CONTENT_URI, projection, WHERE_ALARM_EXISTS,
2286                    (new String[] {
2287                            Long.toString(eventId), Long.toString(begin), Long.toString(alarmTime)
2288                    }), null);
2289            boolean found = false;
2290            try {
2291                if (cursor != null && cursor.getCount() > 0) {
2292                    found = true;
2293                }
2294            } finally {
2295                if (cursor != null) {
2296                    cursor.close();
2297                }
2298            }
2299            return found;
2300        }
2301    }
2302
2303    /**
2304     * @hide
2305     * TODO UNHIDE
2306     */
2307    protected interface ColorsColumns extends SyncStateContract.Columns {
2308
2309        /**
2310         * The type of color, which describes how it should be used. Valid types
2311         * are {@link #TYPE_CALENDAR} and {@link #TYPE_EVENT}. Column name.
2312         * <P>
2313         * Type: INTEGER (NOT NULL)
2314         * </P>
2315         */
2316        public static final String COLOR_TYPE = "color_type";
2317
2318        /**
2319         * This indicateds a color that can be used for calendars.
2320         */
2321        public static final int TYPE_CALENDAR = 0;
2322        /**
2323         * This indicates a color that can be used for events.
2324         */
2325        public static final int TYPE_EVENT = 1;
2326
2327        /**
2328         * The index used to reference this color. This can be any non-empty
2329         * string, but must be unique for a given {@link #ACCOUNT_TYPE} and
2330         * {@link #ACCOUNT_NAME} . Column name.
2331         * <P>
2332         * Type: TEXT
2333         * </P>
2334         */
2335        public static final String COLOR_INDEX = "color_index";
2336
2337        /**
2338         * The version of this color that will work with dark text as an 8-bit
2339         * ARGB integer value. Colors should specify alpha as fully opaque (eg
2340         * 0xFF993322) as the alpha may be ignored or modified for display.
2341         * Column name.
2342         * <P>
2343         * Type: INTEGER (NOT NULL)
2344         * </P>
2345         */
2346        public static final String COLOR_LIGHT = "color_light";
2347
2348        /**
2349         * The version of this color that will work with light text as an 8-bit
2350         * ARGB integer value. Colors should specify alpha as fully opaque (eg
2351         * 0xFF993322) as the alpha may be ignored or modified for display.
2352         * Column name.
2353         * <P>
2354         * Type: INTEGER (NOT NULL)
2355         * </P>
2356         */
2357        public static final String COLOR_DARK = "color_dark";
2358
2359    }
2360
2361    /**
2362     * Fields for accessing colors available for a given account. Colors are
2363     * referenced by {@link #COLOR_INDEX} which must be unique for a given
2364     * account name/type. These values should only be updated by the sync
2365     * adapter.
2366     * TODO UNHIDE
2367     *
2368     * @hide
2369     */
2370    public static final class Colors implements ColorsColumns {
2371        /**
2372         * @hide
2373         */
2374        public static final String TABLE_NAME = "Colors";
2375        /**
2376         * The Uri for querying color information
2377         */
2378        @SuppressWarnings("hiding")
2379        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/colors");
2380
2381        /**
2382         * This utility class cannot be instantiated
2383         */
2384        private Colors() {
2385        }
2386    }
2387
2388    protected interface ExtendedPropertiesColumns {
2389        /**
2390         * The event the extended property belongs to. Column name.
2391         * <P>Type: INTEGER (foreign key to the Events table)</P>
2392         */
2393        public static final String EVENT_ID = "event_id";
2394
2395        /**
2396         * The name of the extended property.  This is a uri of the form
2397         * {scheme}#{local-name} convention. Column name.
2398         * <P>Type: TEXT</P>
2399         */
2400        public static final String NAME = "name";
2401
2402        /**
2403         * The value of the extended property. Column name.
2404         * <P>Type: TEXT</P>
2405         */
2406        public static final String VALUE = "value";
2407    }
2408
2409    /**
2410     * Fields for accessing the Extended Properties. This is a generic set of
2411     * name/value pairs for use by sync adapters or apps to add extra
2412     * information to events. There are three writable columns and all three
2413     * must be present when inserting a new value. They are:
2414     * <ul>
2415     * <li>{@link #EVENT_ID}</li>
2416     * <li>{@link #NAME}</li>
2417     * <li>{@link #VALUE}</li>
2418     * </ul>
2419     */
2420   public static final class ExtendedProperties implements BaseColumns,
2421            ExtendedPropertiesColumns, EventsColumns {
2422        public static final Uri CONTENT_URI =
2423                Uri.parse("content://" + AUTHORITY + "/extendedproperties");
2424
2425        /**
2426         * This utility class cannot be instantiated
2427         */
2428        private ExtendedProperties() {}
2429
2430        // TODO: fill out this class when we actually start utilizing extendedproperties
2431        // in the calendar application.
2432   }
2433
2434    /**
2435     * A table provided for sync adapters to use for storing private sync state data.
2436     *
2437     * @see SyncStateContract
2438     */
2439    public static final class SyncState implements SyncStateContract.Columns {
2440        /**
2441         * This utility class cannot be instantiated
2442         */
2443        private SyncState() {}
2444
2445        private static final String CONTENT_DIRECTORY =
2446                SyncStateContract.Constants.CONTENT_DIRECTORY;
2447
2448        /**
2449         * The content:// style URI for this table
2450         */
2451        public static final Uri CONTENT_URI =
2452                Uri.withAppendedPath(CalendarContract.CONTENT_URI, CONTENT_DIRECTORY);
2453    }
2454
2455    /**
2456     * Columns from the EventsRawTimes table
2457     *
2458     * @hide
2459     */
2460    protected interface EventsRawTimesColumns {
2461        /**
2462         * The corresponding event id. Column name.
2463         * <P>Type: INTEGER (long)</P>
2464         */
2465        public static final String EVENT_ID = "event_id";
2466
2467        /**
2468         * The RFC2445 compliant time the event starts. Column name.
2469         * <P>Type: TEXT</P>
2470         */
2471        public static final String DTSTART_2445 = "dtstart2445";
2472
2473        /**
2474         * The RFC2445 compliant time the event ends. Column name.
2475         * <P>Type: TEXT</P>
2476         */
2477        public static final String DTEND_2445 = "dtend2445";
2478
2479        /**
2480         * The RFC2445 compliant original instance time of the recurring event
2481         * for which this event is an exception. Column name.
2482         * <P>Type: TEXT</P>
2483         */
2484        public static final String ORIGINAL_INSTANCE_TIME_2445 = "originalInstanceTime2445";
2485
2486        /**
2487         * The RFC2445 compliant last date this event repeats on, or NULL if it
2488         * never ends. Column name.
2489         * <P>Type: TEXT</P>
2490         */
2491        public static final String LAST_DATE_2445 = "lastDate2445";
2492    }
2493
2494    /**
2495     * @hide
2496     */
2497    public static final class EventsRawTimes implements BaseColumns, EventsRawTimesColumns {
2498
2499        /**
2500         * This utility class cannot be instantiated
2501         */
2502        private EventsRawTimes() {}
2503    }
2504}
2505