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