ContactsContract.java revision 3c513ed95cee2e0bcd7208cb7e46307f09c907c9
1/*
2 * Copyright (C) 2009 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
19import android.accounts.Account;
20import android.content.ContentProviderClient;
21import android.content.ContentProviderOperation;
22import android.content.ContentResolver;
23import android.content.ContentUris;
24import android.content.Context;
25import android.content.Intent;
26import android.content.res.Resources;
27import android.database.Cursor;
28import android.graphics.BitmapFactory;
29import android.net.Uri;
30import android.os.RemoteException;
31import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
32import android.text.TextUtils;
33
34import java.io.ByteArrayInputStream;
35import java.io.InputStream;
36
37/**
38 * The contract between the contacts provider and applications. Contains definitions
39 * for the supported URIs and columns.
40 *
41 * @hide
42 */
43public final class ContactsContract {
44    /** The authority for the contacts provider */
45    public static final String AUTHORITY = "com.android.contacts";
46    /** A content:// style uri to the authority for the contacts provider */
47    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
48
49    public interface SyncStateColumns extends SyncStateContract.Columns {
50    }
51
52    public static final class SyncState {
53        /**
54         * This utility class cannot be instantiated
55         */
56        private SyncState() {}
57
58        public static final String CONTENT_DIRECTORY =
59                SyncStateContract.Constants.CONTENT_DIRECTORY;
60
61        /**
62         * The content:// style URI for this table
63         */
64        public static final Uri CONTENT_URI =
65                Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY);
66
67        /**
68         * @see android.provider.SyncStateContract.Helpers#get
69         */
70        public static byte[] get(ContentProviderClient provider, Account account)
71                throws RemoteException {
72            return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
73        }
74
75        /**
76         * @see android.provider.SyncStateContract.Helpers#set
77         */
78        public static void set(ContentProviderClient provider, Account account, byte[] data)
79                throws RemoteException {
80            SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
81        }
82
83        /**
84         * @see android.provider.SyncStateContract.Helpers#newSetOperation
85         */
86        public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
87            return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
88        }
89    }
90
91    /**
92     * Generic columns for use by sync adapters. The specific functions of
93     * these columns are private to the sync adapter. Other clients of the API
94     * should not attempt to either read or write this column.
95     */
96    private interface BaseSyncColumns {
97
98        /** Generic column for use by sync adapters. */
99        public static final String SYNC1 = "sync1";
100        /** Generic column for use by sync adapters. */
101        public static final String SYNC2 = "sync2";
102        /** Generic column for use by sync adapters. */
103        public static final String SYNC3 = "sync3";
104        /** Generic column for use by sync adapters. */
105        public static final String SYNC4 = "sync4";
106    }
107
108    /**
109     * Columns that appear when each row of a table belongs to a specific
110     * account, including sync information that an account may need.
111     */
112    private interface SyncColumns extends BaseSyncColumns {
113        /**
114         * The name of the account instance to which this row belongs.
115         * <P>Type: TEXT</P>
116         */
117        public static final String ACCOUNT_NAME = "account_name";
118
119        /**
120         * The type of account to which this row belongs, which when paired with
121         * {@link #ACCOUNT_NAME} identifies a specific account.
122         * <P>Type: TEXT</P>
123         */
124        public static final String ACCOUNT_TYPE = "account_type";
125
126        /**
127         * String that uniquely identifies this row to its source account.
128         * <P>Type: TEXT</P>
129         */
130        public static final String SOURCE_ID = "sourceid";
131
132        /**
133         * Version number that is updated whenever this row or its related data
134         * changes.
135         * <P>Type: INTEGER</P>
136         */
137        public static final String VERSION = "version";
138
139        /**
140         * Flag indicating that {@link #VERSION} has changed, and this row needs
141         * to be synchronized by its owning account.
142         * <P>Type: INTEGER (boolean)</P>
143         */
144        public static final String DIRTY = "dirty";
145    }
146
147    public interface ContactOptionsColumns {
148        /**
149         * The number of times a person has been contacted
150         * <P>Type: INTEGER</P>
151         */
152        public static final String TIMES_CONTACTED = "times_contacted";
153
154        /**
155         * The last time a person was contacted.
156         * <P>Type: INTEGER</P>
157         */
158        public static final String LAST_TIME_CONTACTED = "last_time_contacted";
159
160        /**
161         * Is the contact starred?
162         * <P>Type: INTEGER (boolean)</P>
163         */
164        public static final String STARRED = "starred";
165
166        /**
167         * A custom ringtone associated with a person. Not always present.
168         * <P>Type: TEXT (URI to the ringtone)</P>
169         */
170        public static final String CUSTOM_RINGTONE = "custom_ringtone";
171
172        /**
173         * Whether the person should always be sent to voicemail. Not always
174         * present.
175         * <P>Type: INTEGER (0 for false, 1 for true)</P>
176         */
177        public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
178    }
179
180    private interface ContactsColumns {
181        /**
182         * The display name for the contact.
183         * <P>Type: TEXT</P>
184         */
185        public static final String DISPLAY_NAME = "display_name";
186
187        /**
188         * Reference to the row in the data table holding the photo.
189         * <P>Type: INTEGER REFERENCES data(_id)</P>
190         */
191        public static final String PHOTO_ID = "photo_id";
192
193        /**
194         * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of
195         * any {@link GroupMembership} for this contact.
196         */
197        public static final String IN_VISIBLE_GROUP = "in_visible_group";
198
199        /**
200         * Contact presence status.  See {@link android.provider.Im.CommonPresenceColumns}
201         * for individual status definitions.
202         */
203        public static final String PRESENCE_STATUS = Presence.PRESENCE_STATUS;
204
205        /**
206         * An indicator of whether this contact has at least one phone number. "1" if there is
207         * at least one phone number, "0" otherwise.
208         * <P>Type: INTEGER</P>
209         */
210        public static final String HAS_PHONE_NUMBER = "has_phone_number";
211    }
212
213    /**
214     * Constants for the contacts table, which contains a record per group
215     * of raw contact representing the same person.
216     */
217    public static class Contacts implements BaseColumns, ContactsColumns,
218            ContactOptionsColumns {
219        /**
220         * This utility class cannot be instantiated
221         */
222        private Contacts()  {}
223
224        /**
225         * The content:// style URI for this table
226         */
227        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");
228
229        /**
230         * The content:// style URI for this table joined with useful data from
231         * {@link Data}.
232         */
233        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
234                "contacts_summary");
235
236        /**
237         * The content:// style URI used for "type-to-filter" functionality on the
238         * {@link #CONTENT_SUMMARY_URI} URI. The filter string will be used to match
239         * various parts of the contact name. The filter argument should be passed
240         * as an additional path segment after this URI.
241         */
242        public static final Uri CONTENT_SUMMARY_FILTER_URI = Uri.withAppendedPath(
243                CONTENT_SUMMARY_URI, "filter");
244
245        /**
246         * The content:// style URI for this table joined with useful data from
247         * {@link Data}, filtered to include only starred contacts
248         * and the most frequently contacted contacts.
249         */
250        public static final Uri CONTENT_SUMMARY_STREQUENT_URI = Uri.withAppendedPath(
251                CONTENT_SUMMARY_URI, "strequent");
252
253        /**
254         * The content:// style URI used for "type-to-filter" functionality on the
255         * {@link #CONTENT_SUMMARY_STREQUENT_URI} URI. The filter string will be used to match
256         * various parts of the contact name. The filter argument should be passed
257         * as an additional path segment after this URI.
258         */
259        public static final Uri CONTENT_SUMMARY_STREQUENT_FILTER_URI = Uri.withAppendedPath(
260                CONTENT_SUMMARY_STREQUENT_URI, "filter");
261
262        public static final Uri CONTENT_SUMMARY_GROUP_URI = Uri.withAppendedPath(
263                CONTENT_SUMMARY_URI, "group");
264        /**
265         * The MIME type of {@link #CONTENT_URI} providing a directory of
266         * people.
267         */
268        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact";
269
270        /**
271         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
272         * person.
273         */
274        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact";
275
276        /**
277         * A sub-directory of a single contact that contains all of the constituent raw contact
278         * {@link Data} rows.
279         */
280        public static final class Data implements BaseColumns, DataColumns {
281            /**
282             * no public constructor since this is a utility class
283             */
284            private Data() {}
285
286            /**
287             * The directory twig for this sub-table
288             */
289            public static final String CONTENT_DIRECTORY = "data";
290        }
291
292        /**
293         * A sub-directory of a single contact aggregate that contains all aggregation suggestions
294         * (other contacts).  The aggregation suggestions are computed based on approximate
295         * data matches with this contact.
296         */
297        public static final class AggregationSuggestions implements BaseColumns, ContactsColumns {
298            /**
299             * No public constructor since this is a utility class
300             */
301            private AggregationSuggestions() {}
302
303            /**
304             * The directory twig for this sub-table
305             */
306            public static final String CONTENT_DIRECTORY = "suggestions";
307        }
308
309        /**
310         * Returns a URI that can be used to retrieve the contact's default photo.
311         *
312         * @param contactUri the contact whose photo should be used
313         */
314        public static Uri getPhotoUri(ContentResolver cr, Uri contactUri) {
315            long photoId = -1;
316            Cursor cursor = cr.query(contactUri, new String[]{Contacts.PHOTO_ID}, null, null, null);
317            try {
318                if (!cursor.moveToNext()) {
319                    return null;
320                }
321
322                if (cursor.isNull(0)) {
323                    return null;
324                }
325
326                photoId = cursor.getLong(0);
327            } finally {
328                cursor.close();
329            }
330
331            return ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photoId);
332        }
333
334        /**
335         * Opens an InputStream for the person's default photo and returns the
336         * photo as a Bitmap stream.
337         *
338         * @param contactUri the contact whose photo should be used
339         */
340        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
341            Uri photoUri = getPhotoUri(cr, contactUri);
342            Cursor cursor = cr.query(photoUri,
343                    new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null);
344            try {
345                if (!cursor.moveToNext()) {
346                    return null;
347                }
348                byte[] data = cursor.getBlob(0);
349                if (data == null) {
350                    return null;
351                }
352                return new ByteArrayInputStream(data);
353            } finally {
354                cursor.close();
355            }
356        }
357    }
358
359    private interface RawContactsColumns {
360        /**
361         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} that this
362         * data belongs to.
363         * <P>Type: INTEGER</P>
364         */
365        public static final String CONTACT_ID = "contact_id";
366
367        /**
368         * Flag indicating that this {@link RawContacts} entry and its children has
369         * been restricted to specific platform apps.
370         * <P>Type: INTEGER (boolean)</P>
371         *
372         * @hide until finalized in future platform release
373         */
374        public static final String IS_RESTRICTED = "is_restricted";
375
376        /**
377         * The aggregation mode for this contact.
378         * <P>Type: INTEGER</P>
379         */
380        public static final String AGGREGATION_MODE = "aggregation_mode";
381
382        /**
383         * The "deleted" flag: "0" by default, "1" if the row has been marked
384         * for deletion. When {@link android.content.ContentResolver#delete} is
385         * called on a raw contact, it is marked for deletion and removed from its
386         * aggregate contact. The sync adaptor deletes the raw contact on the server and
387         * then calls ContactResolver.delete once more, this time passing the
388         * {@link RawContacts#DELETE_PERMANENTLY} query parameter to finalize the data removal.
389         * <P>Type: INTEGER</P>
390         */
391        public static final String DELETED = "deleted";
392    }
393
394    /**
395     * Constants for the raw_contacts table, which contains the base contact
396     * information per sync source. Sync adapters and contact management apps
397     * are the primary consumers of this API.
398     */
399    public static final class RawContacts implements BaseColumns, RawContactsColumns,
400            ContactOptionsColumns, SyncColumns  {
401        /**
402         * This utility class cannot be instantiated
403         */
404        private RawContacts() {
405        }
406
407        /**
408         * The content:// style URI for this table
409         */
410        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts");
411
412        /**
413         * The content:// style URL for filtering people by email address. The
414         * filter argument should be passed as an additional path segment after
415         * this URI.
416         *
417         * @hide
418         */
419        @Deprecated
420        public static final Uri CONTENT_FILTER_EMAIL_URI =
421                Uri.withAppendedPath(CONTENT_URI, "filter_email");
422
423        /**
424         * The MIME type of {@link #CONTENT_URI} providing a directory of
425         * people.
426         */
427        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact";
428
429        /**
430         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
431         * person.
432         */
433        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact";
434
435        /**
436         * Query parameter that can be passed with the {@link #CONTENT_URI} URI
437         * to the {@link android.content.ContentResolver#delete} method to
438         * indicate that the raw contact can be deleted physically, rather than
439         * merely marked as deleted.
440         */
441        public static final String DELETE_PERMANENTLY = "delete_permanently";
442
443        /**
444         * Aggregation mode: aggregate asynchronously.
445         */
446        public static final int AGGREGATION_MODE_DEFAULT = 0;
447
448        /**
449         * Aggregation mode: aggregate at the time the raw contact is inserted/updated.
450         */
451        public static final int AGGREGATION_MODE_IMMEDITATE = 1;
452
453        /**
454         * Aggregation mode: never aggregate this raw contact (note that the raw contact will not
455         * have a corresponding Aggregate and therefore will not be included in Aggregates
456         * query results.)
457         */
458        public static final int AGGREGATION_MODE_DISABLED = 2;
459
460        /**
461         * A sub-directory of a single raw contact that contains all of their {@link Data} rows.
462         * To access this directory append
463         */
464        public static final class Data implements BaseColumns, DataColumns {
465            /**
466             * no public constructor since this is a utility class
467             */
468            private Data() {
469            }
470
471            /**
472             * The directory twig for this sub-table
473             */
474            public static final String CONTENT_DIRECTORY = "data";
475        }
476    }
477
478    private interface DataColumns {
479        /**
480         * The package name to use when creating {@link Resources} objects for
481         * this data row. This value is only designed for use when building user
482         * interfaces, and should not be used to infer the owner.
483         */
484        public static final String RES_PACKAGE = "res_package";
485
486        /**
487         * The MIME type of the item represented by this row.
488         */
489        public static final String MIMETYPE = "mimetype";
490
491        /**
492         * A reference to the {@link RawContacts#_ID}
493         * that this data belongs to.
494         */
495        public static final String RAW_CONTACT_ID = "raw_contact_id";
496
497        /**
498         * Whether this is the primary entry of its kind for the raw contact it belongs to
499         * <P>Type: INTEGER (if set, non-0 means true)</P>
500         */
501        public static final String IS_PRIMARY = "is_primary";
502
503        /**
504         * Whether this is the primary entry of its kind for the aggregate
505         * contact it belongs to. Any data record that is "super primary" must
506         * also be "primary".
507         * <P>Type: INTEGER (if set, non-0 means true)</P>
508         */
509        public static final String IS_SUPER_PRIMARY = "is_super_primary";
510
511        /**
512         * The version of this data record. This is a read-only value. The data column is
513         * guaranteed to not change without the version going up. This value is monotonically
514         * increasing.
515         * <P>Type: INTEGER</P>
516         */
517        public static final String DATA_VERSION = "data_version";
518
519        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
520        public static final String DATA1 = "data1";
521        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
522        public static final String DATA2 = "data2";
523        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
524        public static final String DATA3 = "data3";
525        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
526        public static final String DATA4 = "data4";
527        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
528        public static final String DATA5 = "data5";
529        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
530        public static final String DATA6 = "data6";
531        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
532        public static final String DATA7 = "data7";
533        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
534        public static final String DATA8 = "data8";
535        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
536        public static final String DATA9 = "data9";
537        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
538        public static final String DATA10 = "data10";
539        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
540        public static final String DATA11 = "data11";
541        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
542        public static final String DATA12 = "data12";
543        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
544        public static final String DATA13 = "data13";
545        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
546        public static final String DATA14 = "data14";
547        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
548        public static final String DATA15 = "data15";
549
550        /** Generic column for use by sync adapters. */
551        public static final String SYNC1 = "data_sync1";
552        /** Generic column for use by sync adapters. */
553        public static final String SYNC2 = "data_sync2";
554        /** Generic column for use by sync adapters. */
555        public static final String SYNC3 = "data_sync3";
556        /** Generic column for use by sync adapters. */
557        public static final String SYNC4 = "data_sync4";
558
559        /**
560         * An optional insert, update or delete URI parameter that determines if
561         * the corresponding raw contact should be marked as dirty. The default
562         * value is true.
563         */
564        public static final String MARK_AS_DIRTY = "mark_as_dirty";
565    }
566
567    /**
568     * Constants for the data table, which contains data points tied to a raw contact.
569     * For example, a phone number or email address. Each row in this table contains a type
570     * definition and some generic columns. Each data type can define the meaning for each of
571     * the generic columns.
572     */
573    public static final class Data implements BaseColumns, DataColumns {
574        /**
575         * This utility class cannot be instantiated
576         */
577        private Data() {}
578
579        /**
580         * The content:// style URI for this table
581         */
582        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
583
584        /**
585         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
586         */
587        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
588    }
589
590    private interface PhoneLookupColumns {
591        /**
592         * The phone number as the user entered it.
593         * <P>Type: TEXT</P>
594         */
595        public static final String NUMBER = "number";
596
597        /**
598         * The type of phone number, for example Home or Work.
599         * <P>Type: INTEGER</P>
600         */
601        public static final String TYPE = "type";
602
603        /**
604         * The user defined label for the phone number.
605         * <P>Type: TEXT</P>
606         */
607        public static final String LABEL = "label";
608    }
609
610    /**
611     * A table that represents the result of looking up a phone number, for
612     * example for caller ID. To perform a lookup you must append the number you
613     * want to find to {@link #CONTENT_FILTER_URI}.
614     */
615    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
616            ContactsColumns, ContactOptionsColumns {
617        /**
618         * This utility class cannot be instantiated
619         */
620        private PhoneLookup() {}
621
622        /**
623         * The content:// style URI for this table. Append the phone number you want to lookup
624         * to this URI and query it to perform a lookup. For example:
625         *
626         * {@code
627         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, phoneNumber);
628         * }
629         */
630        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
631                "phone_lookup");
632    }
633
634    /**
635     * Additional data mixed in with {@link Im.CommonPresenceColumns} to link
636     * back to specific {@link ContactsContract.Contacts#_ID} entries.
637     */
638    private interface PresenceColumns {
639
640        /**
641         * The unique ID for a row.
642         * <P>Type: INTEGER (long)</P>
643         */
644        public static final String _ID = "presence_id";
645
646        /**
647         * Reference to the {@link RawContacts#_ID} this presence references.
648         * <P>Type: INTEGER</P>
649         */
650        public static final String RAW_CONTACT_ID = "presence_raw_contact_id";
651
652        /**
653         * Reference to the {@link Data#_ID} entry that owns this presence.
654         * <P>Type: INTEGER</P>
655         */
656        public static final String DATA_ID = "presence_data_id";
657
658        /**
659         * The IM service the presence is coming from. Formatted using either
660         * {@link CommonDataKinds.Im#encodePredefinedImProtocol(int)} or
661         * {@link CommonDataKinds.Im#encodeCustomImProtocol(String)}.
662         * <P>Type: TEXT</P>
663         */
664        public static final String IM_PROTOCOL = "im_protocol";
665
666        /**
667         * The IM handle the presence item is for. The handle is scoped to the
668         * {@link #IM_PROTOCOL}.
669         * <P>Type: TEXT</P>
670         */
671        public static final String IM_HANDLE = "im_handle";
672
673        /**
674         * The IM account for the local user that the presence data came from.
675         * <P>Type: TEXT</P>
676         */
677        public static final String IM_ACCOUNT = "im_account";
678    }
679
680    public static final class Presence implements PresenceColumns, Im.CommonPresenceColumns {
681        /**
682         * This utility class cannot be instantiated
683         */
684        private Presence() {
685        }
686
687        /**
688         * The content:// style URI for this table
689         */
690        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "presence");
691
692        /**
693         * Gets the resource ID for the proper presence icon.
694         *
695         * @param status the status to get the icon for
696         * @return the resource ID for the proper presence icon
697         */
698        public static final int getPresenceIconResourceId(int status) {
699            switch (status) {
700                case AVAILABLE:
701                    return android.R.drawable.presence_online;
702                case IDLE:
703                case AWAY:
704                    return android.R.drawable.presence_away;
705                case DO_NOT_DISTURB:
706                    return android.R.drawable.presence_busy;
707                case INVISIBLE:
708                    return android.R.drawable.presence_invisible;
709                case OFFLINE:
710                default:
711                    return android.R.drawable.presence_offline;
712            }
713        }
714
715        /**
716         * Returns the precedence of the status code the higher number being the higher precedence.
717         *
718         * @param status The status code.
719         * @return An integer representing the precedence, 0 being the lowest.
720         */
721        public static final int getPresencePrecedence(int status) {
722            // Keep this function here incase we want to enforce a different precedence than the
723            // natural order of the status constants.
724            return status;
725        }
726
727        /**
728         * The MIME type of {@link #CONTENT_URI} providing a directory of
729         * presence details.
730         */
731        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/im-presence";
732
733        /**
734         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
735         * presence detail.
736         */
737        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im-presence";
738    }
739
740    /**
741     * Container for definitions of common data types stored in the {@link Data} table.
742     */
743    public static final class CommonDataKinds {
744        /**
745         * The {@link Data#RES_PACKAGE} value for common data that should be
746         * shown using a default style.
747         */
748        public static final String PACKAGE_COMMON = "common";
749
750        /**
751         * Columns common across the specific types.
752         */
753        private interface BaseCommonColumns {
754            /**
755             * The package name to use when creating {@link Resources} objects for
756             * this data row. This value is only designed for use when building user
757             * interfaces, and should not be used to infer the owner.
758             */
759            public static final String RES_PACKAGE = "res_package";
760
761            /**
762             * The MIME type of the item represented by this row.
763             */
764            public static final String MIMETYPE = "mimetype";
765
766            /**
767             * The {@link RawContacts#_ID} that this data belongs to.
768             */
769            public static final String RAW_CONTACT_ID = "raw_contact_id";
770        }
771
772        /**
773         * The base types that all "Typed" data kinds support.
774         */
775        public interface BaseTypes {
776
777            /**
778             * A custom type. The custom label should be supplied by user.
779             */
780            public static int TYPE_CUSTOM = 0;
781        }
782
783        /**
784         * Columns common across the specific types.
785         */
786        private interface CommonColumns extends BaseTypes{
787            /**
788             * The type of data, for example Home or Work.
789             * <P>Type: INTEGER</P>
790             */
791            public static final String TYPE = "data1";
792
793            /**
794             * The data for the contact method.
795             * <P>Type: TEXT</P>
796             */
797            public static final String DATA = "data2";
798
799            /**
800             * The user defined label for the the contact method.
801             * <P>Type: TEXT</P>
802             */
803            public static final String LABEL = "data3";
804        }
805
806        /**
807         * Parts of the name.
808         */
809        public static final class StructuredName implements BaseCommonColumns {
810            private StructuredName() {}
811
812            /** MIME type used when storing this in data table. */
813            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
814
815            /**
816             * The given name for the contact.
817             * <P>Type: TEXT</P>
818             */
819            public static final String GIVEN_NAME = "data1";
820
821            /**
822             * The family name for the contact.
823             * <P>Type: TEXT</P>
824             */
825            public static final String FAMILY_NAME = "data2";
826
827            /**
828             * The contact's honorific prefix, e.g. "Sir"
829             * <P>Type: TEXT</P>
830             */
831            public static final String PREFIX = "data3";
832
833            /**
834             * The contact's middle name
835             * <P>Type: TEXT</P>
836             */
837            public static final String MIDDLE_NAME = "data4";
838
839            /**
840             * The contact's honorific suffix, e.g. "Jr"
841             */
842            public static final String SUFFIX = "data5";
843
844            /**
845             * The phonetic version of the given name for the contact.
846             * <P>Type: TEXT</P>
847             */
848            public static final String PHONETIC_GIVEN_NAME = "data6";
849
850            /**
851             * The phonetic version of the additional name for the contact.
852             * <P>Type: TEXT</P>
853             */
854            public static final String PHONETIC_MIDDLE_NAME = "data7";
855
856            /**
857             * The phonetic version of the family name for the contact.
858             * <P>Type: TEXT</P>
859             */
860            public static final String PHONETIC_FAMILY_NAME = "data8";
861
862            /**
863             * The name that should be used to display the contact.
864             * <i>Unstructured component of the name should be consistent with
865             * its structured representation.</i>
866             * <p>
867             * Type: TEXT
868             */
869            public static final String DISPLAY_NAME = "data9";
870        }
871
872        /**
873         * A nickname.
874         */
875        public static final class Nickname implements CommonColumns, BaseCommonColumns {
876            private Nickname() {}
877
878            /** MIME type used when storing this in data table. */
879            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
880
881            public static final int TYPE_DEFAULT = 1;
882            public static final int TYPE_OTHER_NAME = 2;
883            public static final int TYPE_MAINDEN_NAME = 3;
884            public static final int TYPE_SHORT_NAME = 4;
885            public static final int TYPE_INITIALS = 5;
886
887            /**
888             * The name itself
889             */
890            public static final String NAME = DATA;
891        }
892
893        /**
894         * Common data definition for telephone numbers.
895         */
896        public static final class Phone implements BaseCommonColumns, CommonColumns {
897            private Phone() {}
898
899            /** MIME type used when storing this in data table. */
900            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone";
901
902            /**
903             * The MIME type of {@link #CONTENT_URI} providing a directory of
904             * phones.
905             */
906            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone";
907
908            /**
909             * The content:// style URI for all data records of the
910             * {@link Phone#CONTENT_ITEM_TYPE} MIME type, combined with the
911             * associated raw contact and aggregate contact data.
912             */
913            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
914                    "phones");
915
916            /**
917             * The content:// style URI for filtering data records of the
918             * {@link Phone#CONTENT_ITEM_TYPE} MIME type, combined with the
919             * associated raw contact and aggregate contact data. The filter argument should
920             * be passed as an additional path segment after this URI.
921             */
922            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
923                    "filter");
924
925            public static final int TYPE_HOME = 1;
926            public static final int TYPE_MOBILE = 2;
927            public static final int TYPE_WORK = 3;
928            public static final int TYPE_FAX_WORK = 4;
929            public static final int TYPE_FAX_HOME = 5;
930            public static final int TYPE_PAGER = 6;
931            public static final int TYPE_OTHER = 7;
932            public static final int TYPE_CALLBACK = 8;
933            public static final int TYPE_CAR = 9;
934            public static final int TYPE_COMPANY_MAIN = 10;
935            public static final int TYPE_ISDN = 11;
936            public static final int TYPE_MAIN = 12;
937            public static final int TYPE_OTHER_FAX = 13;
938            public static final int TYPE_RADIO = 14;
939            public static final int TYPE_TELEX = 15;
940            public static final int TYPE_TTY_TDD = 16;
941            public static final int TYPE_WORK_MOBILE = 17;
942            public static final int TYPE_WORK_PAGER = 18;
943            public static final int TYPE_ASSISTANT = 19;
944
945            /**
946             * The phone number as the user entered it.
947             * <P>Type: TEXT</P>
948             */
949            public static final String NUMBER = DATA;
950
951            public static final CharSequence getDisplayLabel(Context context, int type,
952                    CharSequence label, CharSequence[] labelArray) {
953                CharSequence display = "";
954
955                if (type != Phone.TYPE_CUSTOM) {
956                    CharSequence[] labels = labelArray != null? labelArray
957                            : context.getResources().getTextArray(
958                                    com.android.internal.R.array.phoneTypes);
959                    try {
960                        display = labels[type - 1];
961                    } catch (ArrayIndexOutOfBoundsException e) {
962                        display = labels[Phone.TYPE_CUSTOM];
963                    }
964                } else {
965                    if (!TextUtils.isEmpty(label)) {
966                        display = label;
967                    }
968                }
969                return display;
970            }
971
972            public static final CharSequence getDisplayLabel(Context context, int type,
973                    CharSequence label) {
974                return getDisplayLabel(context, type, label, null);
975            }
976        }
977
978        /**
979         * Common data definition for email addresses.
980         */
981        public static final class Email implements BaseCommonColumns, CommonColumns {
982            private Email() {}
983
984            /** MIME type used when storing this in data table. */
985            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email";
986
987            /**
988             * The content:// style URI for all data records of the
989             * {@link Email#CONTENT_ITEM_TYPE} MIME type, combined with the
990             * associated raw contact and aggregate contact data.
991             */
992            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
993                    "emails");
994
995            /**
996             * The content:// style URL for filtering data rows by email address. The
997             * filter argument should be passed as an additional path segment after
998             * this URI.
999             */
1000            public static final Uri CONTENT_FILTER_EMAIL_URI = Uri.withAppendedPath(CONTENT_URI,
1001                    "filter");
1002
1003            public static final int TYPE_HOME = 1;
1004            public static final int TYPE_WORK = 2;
1005            public static final int TYPE_OTHER = 3;
1006
1007            /**
1008             * The display name for the email address
1009             * <P>Type: TEXT</P>
1010             */
1011            public static final String DISPLAY_NAME = "data4";
1012        }
1013
1014        /**
1015         * Common data definition for postal addresses.
1016         */
1017        public static final class StructuredPostal implements BaseCommonColumns, CommonColumns {
1018            private StructuredPostal() {
1019            }
1020
1021            /** MIME type used when storing this in data table. */
1022            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/postal-address";
1023
1024            /**
1025             * The MIME type of {@link #CONTENT_URI} providing a directory of
1026             * postal addresses.
1027             */
1028            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address";
1029
1030            /**
1031             * The content:// style URI for all data records of the
1032             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
1033             */
1034            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
1035                    "postals");
1036
1037            public static final int TYPE_HOME = 1;
1038            public static final int TYPE_WORK = 2;
1039            public static final int TYPE_OTHER = 3;
1040
1041            /**
1042             * The full, unstructured postal address. <i>This field must be
1043             * consistent with any structured data.</i>
1044             * <p>
1045             * Type: TEXT
1046             */
1047            public static final String FORMATTED_ADDRESS = DATA;
1048
1049            /**
1050             * The agent who actually receives the mail. Used in work addresses.
1051             * Also for 'in care of' or 'c/o'.
1052             * <p>
1053             * Type: TEXT
1054             * @deprecated since this isn't supported by gd:structuredPostalAddress
1055             */
1056            @Deprecated
1057            public static final String AGENT = "data4";
1058
1059            /**
1060             * Used in places where houses or buildings have names (and not
1061             * necessarily numbers), eg. "The Pillars".
1062             * <p>
1063             * Type: TEXT
1064             * @deprecated since this isn't supported by gd:structuredPostalAddress
1065             */
1066            @Deprecated
1067            public static final String HOUSENAME = "data5";
1068
1069            /**
1070             * Can be street, avenue, road, etc. This element also includes the
1071             * house number and room/apartment/flat/floor number.
1072             * <p>
1073             * Type: TEXT
1074             */
1075            public static final String STREET = "data6";
1076
1077            /**
1078             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
1079             * usually but not always mutually exclusive with street.
1080             * <p>
1081             * Type: TEXT
1082             */
1083            public static final String POBOX = "data7";
1084
1085            /**
1086             * This is used to disambiguate a street address when a city
1087             * contains more than one street with the same name, or to specify a
1088             * small place whose mail is routed through a larger postal town. In
1089             * China it could be a county or a minor city.
1090             * <p>
1091             * Type: TEXT
1092             */
1093            public static final String NEIGHBORHOOD = "data8";
1094
1095            /**
1096             * Can be city, village, town, borough, etc. This is the postal town
1097             * and not necessarily the place of residence or place of business.
1098             * <p>
1099             * Type: TEXT
1100             */
1101            public static final String CITY = "data9";
1102
1103            /**
1104             * Handles administrative districts such as U.S. or U.K. counties
1105             * that are not used for mail addressing purposes. Subregion is not
1106             * intended for delivery addresses.
1107             * <p>
1108             * Type: TEXT
1109             * @deprecated since this isn't supported by gd:structuredPostalAddress
1110             */
1111            @Deprecated
1112            public static final String SUBREGION = "data10";
1113
1114            /**
1115             * A state, province, county (in Ireland), Land (in Germany),
1116             * departement (in France), etc.
1117             * <p>
1118             * Type: TEXT
1119             */
1120            public static final String REGION = "data11";
1121
1122            /**
1123             * Postal code. Usually country-wide, but sometimes specific to the
1124             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
1125             * <p>
1126             * Type: TEXT
1127             */
1128            public static final String POSTCODE = "data12";
1129
1130            /**
1131             * The name or code of the country.
1132             * <p>
1133             * Type: TEXT
1134             */
1135            public static final String COUNTRY = "data13";
1136        }
1137
1138        /**
1139         * Common data definition for IM addresses.
1140         */
1141        public static final class Im implements BaseCommonColumns, CommonColumns {
1142            private Im() {}
1143
1144            /** MIME type used when storing this in data table. */
1145            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
1146
1147            public static final int TYPE_HOME = 1;
1148            public static final int TYPE_WORK = 2;
1149            public static final int TYPE_OTHER = 3;
1150
1151            public static final String PROTOCOL = "data5";
1152
1153            public static final String CUSTOM_PROTOCOL = "data6";
1154
1155            /**
1156             * The predefined IM protocol types. The protocol can either be non-present, one
1157             * of these types, or a free-form string. These cases are encoded in the PROTOCOL
1158             * column as:
1159             * <ul>
1160             * <li>null</li>
1161             * <li>pre:&lt;an integer, one of the protocols below&gt;</li>
1162             * <li>custom:&lt;a string&gt;</li>
1163             * </ul>
1164             */
1165            public static final int PROTOCOL_CUSTOM = -1;
1166            public static final int PROTOCOL_AIM = 0;
1167            public static final int PROTOCOL_MSN = 1;
1168            public static final int PROTOCOL_YAHOO = 2;
1169            public static final int PROTOCOL_SKYPE = 3;
1170            public static final int PROTOCOL_QQ = 4;
1171            public static final int PROTOCOL_GOOGLE_TALK = 5;
1172            public static final int PROTOCOL_ICQ = 6;
1173            public static final int PROTOCOL_JABBER = 7;
1174            public static final int PROTOCOL_NETMEETING = 8;
1175        }
1176
1177        /**
1178         * Common data definition for organizations.
1179         */
1180        public static final class Organization implements BaseCommonColumns, CommonColumns {
1181            private Organization() {}
1182
1183            /** MIME type used when storing this in data table. */
1184            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
1185
1186            public static final int TYPE_WORK = 1;
1187            public static final int TYPE_OTHER = 2;
1188
1189            /**
1190             * The company as the user entered it.
1191             * <P>Type: TEXT</P>
1192             */
1193            public static final String COMPANY = DATA;
1194
1195            /**
1196             * The position title at this company as the user entered it.
1197             * <P>Type: TEXT</P>
1198             */
1199            public static final String TITLE = "data4";
1200
1201            /**
1202             * The department at this company as the user entered it.
1203             * <P>Type: TEXT</P>
1204             */
1205            public static final String DEPARTMENT = "data5";
1206
1207            /**
1208             * The job description at this company as the user entered it.
1209             * <P>Type: TEXT</P>
1210             */
1211            public static final String JOB_DESCRIPTION = "data6";
1212
1213            /**
1214             * The symbol of this company as the user entered it.
1215             * <P>Type: TEXT</P>
1216             */
1217            public static final String SYMBOL = "data7";
1218
1219            /**
1220             * The phonetic name of this company as the user entered it.
1221             * <P>Type: TEXT</P>
1222             */
1223            public static final String PHONETIC_NAME = "data8";
1224        }
1225
1226        /**
1227         * Common data definition for miscellaneous information.
1228         */
1229        public static final class Miscellaneous implements BaseCommonColumns {
1230            private Miscellaneous() {}
1231
1232            /** MIME type used when storing this in data table. */
1233            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/misc";
1234
1235            /**
1236             * The birthday as the user entered it.
1237             * <P>Type: TEXT</P>
1238             */
1239            public static final String BIRTHDAY = "data1";
1240
1241            /**
1242             * The nickname as the user entered it.
1243             * <P>Type: TEXT</P>
1244             */
1245            public static final String NICKNAME = "data2";
1246        }
1247
1248        /**
1249         * Common data definition for relations.
1250         */
1251        public static final class Relation implements BaseCommonColumns, CommonColumns {
1252            private Relation() {}
1253
1254            /** MIME type used when storing this in data table. */
1255            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
1256
1257            public static final int TYPE_ASSISTANT = 1;
1258            public static final int TYPE_BROTHER = 2;
1259            public static final int TYPE_CHILD = 3;
1260            public static final int TYPE_DOMESTIC_PARTNER = 4;
1261            public static final int TYPE_FATHER = 5;
1262            public static final int TYPE_FRIEND = 6;
1263            public static final int TYPE_MANAGER = 7;
1264            public static final int TYPE_MOTHER = 8;
1265            public static final int TYPE_PARENT = 9;
1266            public static final int TYPE_PARTNER = 10;
1267            public static final int TYPE_REFERRED_BY = 11;
1268            public static final int TYPE_RELATIVE = 12;
1269            public static final int TYPE_SISTER = 13;
1270            public static final int TYPE_SPOUSE = 14;
1271
1272            /**
1273             * The name of the relative as the user entered it.
1274             * <P>Type: TEXT</P>
1275             */
1276            public static final String NAME = DATA;
1277        }
1278
1279        /**
1280         * Common data definition for events.
1281         */
1282        public static final class Event implements BaseCommonColumns, CommonColumns {
1283            private Event() {}
1284
1285            /** MIME type used when storing this in data table. */
1286            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/event";
1287
1288            public static final int TYPE_ANNIVERSARY = 1;
1289            public static final int TYPE_OTHER = 2;
1290
1291            /**
1292             * The event start date as the user entered it.
1293             * <P>Type: TEXT</P>
1294             */
1295            public static final String START_DATE = DATA;
1296        }
1297
1298        /**
1299         * Photo of the contact.
1300         */
1301        public static final class Photo implements BaseCommonColumns {
1302            private Photo() {}
1303
1304            /** MIME type used when storing this in data table. */
1305            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
1306
1307            /**
1308             * Thumbnail photo of the raw contact. This is the raw bytes of an image
1309             * that could be inflated using {@link BitmapFactory}.
1310             * <p>
1311             * Type: BLOB
1312             */
1313            public static final String PHOTO = "data1";
1314        }
1315
1316        /**
1317         * Notes about the contact.
1318         */
1319        public static final class Note implements BaseCommonColumns {
1320            private Note() {}
1321
1322            /** MIME type used when storing this in data table. */
1323            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
1324
1325            /**
1326             * The note text.
1327             * <P>Type: TEXT</P>
1328             */
1329            public static final String NOTE = "data1";
1330        }
1331
1332        /**
1333         * Group Membership.
1334         */
1335        public static final class GroupMembership implements BaseCommonColumns {
1336            private GroupMembership() {}
1337
1338            /** MIME type used when storing this in data table. */
1339            public static final String CONTENT_ITEM_TYPE =
1340                    "vnd.android.cursor.item/group_membership";
1341
1342            /**
1343             * The row id of the group that this group membership refers to. Exactly one of
1344             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
1345             * <P>Type: INTEGER</P>
1346             */
1347            public static final String GROUP_ROW_ID = "data1";
1348
1349            /**
1350             * The sourceid of the group that this group membership refers to.  Exactly one of
1351             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
1352             * <P>Type: TEXT</P>
1353             */
1354            public static final String GROUP_SOURCE_ID = "group_sourceid";
1355        }
1356
1357        /**
1358         * Website related to the contact.
1359         */
1360        public static final class Website implements BaseCommonColumns, CommonColumns {
1361            private Website() {}
1362
1363            /** MIME type used when storing this in data table. */
1364            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
1365
1366            public static final int TYPE_HOMEPAGE = 1;
1367            public static final int TYPE_BLOG = 2;
1368            public static final int TYPE_PROFILE = 3;
1369            public static final int TYPE_HOME = 4;
1370            public static final int TYPE_WORK = 5;
1371            public static final int TYPE_FTP = 6;
1372            public static final int TYPE_OTHER = 7;
1373
1374            /**
1375             * The website URL string.
1376             * <P>Type: TEXT</P>
1377             */
1378            public static final String URL = "data1";
1379        }
1380    }
1381
1382    // TODO: make this private before unhiding
1383    public interface GroupsColumns {
1384        /**
1385         * The display title of this group.
1386         * <p>
1387         * Type: TEXT
1388         */
1389        public static final String TITLE = "title";
1390
1391        /**
1392         * The package name to use when creating {@link Resources} objects for
1393         * this group. This value is only designed for use when building user
1394         * interfaces, and should not be used to infer the owner.
1395         */
1396        public static final String RES_PACKAGE = "res_package";
1397
1398        /**
1399         * The display title of this group to load as a resource from
1400         * {@link #RES_PACKAGE}, which may be localized.
1401         * <P>Type: TEXT</P>
1402         */
1403        public static final String TITLE_RES = "title_res";
1404
1405        /**
1406         * Notes about the group.
1407         * <p>
1408         * Type: TEXT
1409         */
1410        public static final String NOTES = "notes";
1411
1412        /**
1413         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
1414         * to the sync adapter, null otherwise.
1415         * <P>Type: TEXT</P>
1416         */
1417        public static final String SYSTEM_ID = "system_id";
1418
1419        /**
1420         * The total number of {@link Contacts} that have
1421         * {@link GroupMembership} in this group. Read-only value that is only
1422         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
1423         * <p>
1424         * Type: INTEGER
1425         */
1426        public static final String SUMMARY_COUNT = "summ_count";
1427
1428        /**
1429         * The total number of {@link Contacts} that have both
1430         * {@link GroupMembership} in this group, and also have phone numbers.
1431         * Read-only value that is only present when querying
1432         * {@link Groups#CONTENT_SUMMARY_URI}.
1433         * <p>
1434         * Type: INTEGER
1435         */
1436        public static final String SUMMARY_WITH_PHONES = "summ_phones";
1437
1438        /**
1439         * Flag indicating if the contacts belonging to this group should be
1440         * visible in any user interface.
1441         * <p>
1442         * Type: INTEGER (boolean)
1443         */
1444        public static final String GROUP_VISIBLE = "group_visible";
1445
1446        /**
1447         * The "deleted" flag: "0" by default, "1" if the row has been marked
1448         * for deletion. When {@link android.content.ContentResolver#delete} is
1449         * called on a raw contact, it is marked for deletion and removed from its
1450         * aggregate contact. The sync adaptor deletes the raw contact on the server and
1451         * then calls ContactResolver.delete once more, this time passing the
1452         * {@link RawContacts#DELETE_PERMANENTLY} query parameter to finalize the data removal.
1453         * <P>Type: INTEGER</P>
1454         */
1455        public static final String DELETED = "deleted";
1456
1457        /**
1458         * Whether this group should be synced if the SYNC_EVERYTHING settings
1459         * is false for this group's account.
1460         * <p>
1461         * Type: INTEGER (boolean)
1462         */
1463        public static final String SHOULD_SYNC = "should_sync";
1464    }
1465
1466    /**
1467     * Constants for the groups table.
1468     */
1469    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
1470        /**
1471         * This utility class cannot be instantiated
1472         */
1473        private Groups() {
1474        }
1475
1476        /**
1477         * The content:// style URI for this table
1478         */
1479        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
1480
1481        /**
1482         * The content:// style URI for this table joined with details data from
1483         * {@link Data}.
1484         */
1485        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
1486                "groups_summary");
1487
1488        /**
1489         * The MIME type of a directory of groups.
1490         */
1491        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
1492
1493        /**
1494         * The MIME type of a single group.
1495         */
1496        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
1497
1498        /**
1499         * Query parameter that can be passed with the {@link #CONTENT_URI} URI
1500         * to the {@link android.content.ContentResolver#delete} method to
1501         * indicate that the raw contact can be deleted physically, rather than
1502         * merely marked as deleted.
1503         */
1504        public static final String DELETE_PERMANENTLY = "delete_permanently";
1505
1506        /**
1507         * An optional update or insert URI parameter that determines if the
1508         * group should be marked as dirty. The default value is true.
1509         */
1510        public static final String MARK_AS_DIRTY = "mark_as_dirty";
1511    }
1512
1513    /**
1514     * Constants for the contact aggregation exceptions table, which contains
1515     * aggregation rules overriding those used by automatic aggregation.  This type only
1516     * supports query and update. Neither insert nor delete are supported.
1517     */
1518    public static final class AggregationExceptions implements BaseColumns {
1519        /**
1520         * This utility class cannot be instantiated
1521         */
1522        private AggregationExceptions() {}
1523
1524        /**
1525         * The content:// style URI for this table
1526         */
1527        public static final Uri CONTENT_URI =
1528                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
1529
1530        /**
1531         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
1532         */
1533        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
1534
1535        /**
1536         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
1537         */
1538        public static final String CONTENT_ITEM_TYPE =
1539                "vnd.android.cursor.item/aggregation_exception";
1540
1541        /**
1542         * The type of exception: {@link #TYPE_KEEP_IN}, {@link #TYPE_KEEP_OUT} or
1543         * {@link #TYPE_AUTOMATIC}.
1544         *
1545         * <P>Type: INTEGER</P>
1546         */
1547        public static final String TYPE = "type";
1548
1549        /**
1550         * Allows the provider to automatically decide whether the aggregate
1551         * contact should include a particular raw contact or not.
1552         */
1553        public static final int TYPE_AUTOMATIC = 0;
1554
1555        /**
1556         * Makes sure that the specified raw contact is included in the
1557         * specified aggregate contact.
1558         */
1559        public static final int TYPE_KEEP_IN = 1;
1560
1561        /**
1562         * Makes sure that the specified raw contact is NOT included in the
1563         * specified aggregate contact.
1564         */
1565        public static final int TYPE_KEEP_OUT = 2;
1566
1567        /**
1568         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} of the
1569         * aggregate contact that the rule applies to.
1570         */
1571        public static final String CONTACT_ID = "contact_id";
1572
1573        /**
1574         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
1575         */
1576        public static final String RAW_CONTACT_ID = "raw_contact_id";
1577    }
1578
1579    private interface SettingsColumns {
1580        /**
1581         * The name of the account instance to which this row belongs.
1582         * <P>Type: TEXT</P>
1583         */
1584        public static final String ACCOUNT_NAME = "account_name";
1585
1586        /**
1587         * The type of account to which this row belongs, which when paired with
1588         * {@link #ACCOUNT_NAME} identifies a specific account.
1589         * <P>Type: TEXT</P>
1590         */
1591        public static final String ACCOUNT_TYPE = "account_type";
1592
1593        /**
1594         * Setting to indicate how this source handles {@link #SHOULD_SYNC} and
1595         * {@link Groups#SHOULD_SYNC} flags. This mode should be one of
1596         * {@link Settings#SYNC_MODE_EVERYTHING},
1597         * {@link Settings#SYNC_MODE_UNGROUPED}, or
1598         * {@link Settings#SYNC_MODE_UNSUPPORTED}.
1599         * <p>
1600         * Type: INTEGER
1601         */
1602        public static final String SHOULD_SYNC_MODE = "should_sync_mode";
1603
1604        /**
1605         * When modes is {@link Settings#SYNC_MODE_EVERYTHING}, this flag
1606         * overrides any children {@link Groups#SHOULD_SYNC} when set. When mode
1607         * is {@link Settings#SYNC_MODE_UNGROUPED}, this flag indicates the
1608         * syncing behavior for contacts not belonging to any group.
1609         * <p>
1610         * Type: INTEGER (boolean)
1611         */
1612        public static final String SHOULD_SYNC = "should_sync";
1613
1614        /**
1615         * Flag indicating if contacts without any {@link GroupMembership}
1616         * entries should be visible in any user interface.
1617         * <p>
1618         * Type: INTEGER (boolean)
1619         */
1620        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
1621    }
1622
1623    /**
1624     * Contacts-specific settings for various {@link Account}.
1625     */
1626    public static final class Settings implements BaseColumns, SettingsColumns {
1627        /**
1628         * This utility class cannot be instantiated
1629         */
1630        private Settings() {
1631        }
1632
1633        /**
1634         * The content:// style URI for this table
1635         */
1636        public static final Uri CONTENT_URI =
1637                Uri.withAppendedPath(AUTHORITY_URI, "settings");
1638
1639        /**
1640         * The MIME-type of {@link #CONTENT_URI} providing a directory of
1641         * settings.
1642         */
1643        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
1644
1645        /**
1646         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
1647         */
1648        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
1649
1650        /**
1651         * Mode for {@link #SHOULD_SYNC_MODE} that indicates this data source
1652         * doesn't support per-group {@link Groups#SHOULD_SYNC} flags.
1653         */
1654        public static final int SYNC_MODE_UNSUPPORTED = 0;
1655
1656        /**
1657         * Mode for {@link #SHOULD_SYNC_MODE} that indicates this data source
1658         * fully supports per-group {@link Groups#SHOULD_SYNC} flags and assumes
1659         * that {@link #SHOULD_SYNC} refers to contacts without any
1660         * {@link GroupMembership}.
1661         */
1662        public static final int SYNC_MODE_UNGROUPED = 1;
1663
1664        /**
1665         * Mode for {@link #SHOULD_SYNC_MODE} that indicates this data source
1666         * fully supports per-group {@link Groups#SHOULD_SYNC} flags but assumes
1667         * that {@link #SHOULD_SYNC} overrides per-group flags when set.
1668         */
1669        public static final int SYNC_MODE_EVERYTHING = 2;
1670    }
1671
1672    /**
1673     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
1674     * that involve contacts.
1675     */
1676    public static final class Intents {
1677        /**
1678         * This is the intent that is fired when a search suggestion is clicked on.
1679         */
1680        public static final String SEARCH_SUGGESTION_CLICKED =
1681                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
1682
1683        /**
1684         * This is the intent that is fired when a search suggestion for dialing a number
1685         * is clicked on.
1686         */
1687        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
1688                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
1689
1690        /**
1691         * This is the intent that is fired when a search suggestion for creating a contact
1692         * is clicked on.
1693         */
1694        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
1695                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
1696
1697        /**
1698         * Starts an Activity that lets the user pick a contact to attach an image to.
1699         * After picking the contact it launches the image cropper in face detection mode.
1700         */
1701        public static final String ATTACH_IMAGE =
1702                "com.android.contacts.action.ATTACH_IMAGE";
1703
1704        /**
1705         * Takes as input a data URI with a mailto: or tel: scheme. If a single
1706         * contact exists with the given data it will be shown. If no contact
1707         * exists, a dialog will ask the user if they want to create a new
1708         * contact with the provided details filled in. If multiple contacts
1709         * share the data the user will be prompted to pick which contact they
1710         * want to view.
1711         * <p>
1712         * For <code>mailto:</code> URIs, the scheme specific portion must be a
1713         * raw email address, such as one built using
1714         * {@link Uri#fromParts(String, String, String)}.
1715         * <p>
1716         * For <code>tel:</code> URIs, the scheme specific portion is compared
1717         * to existing numbers using the standard caller ID lookup algorithm.
1718         * The number must be properly encoded, for example using
1719         * {@link Uri#fromParts(String, String, String)}.
1720         * <p>
1721         * Any extras from the {@link Insert} class will be passed along to the
1722         * create activity if there are no contacts to show.
1723         * <p>
1724         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
1725         * prompting the user when the contact doesn't exist.
1726         */
1727        public static final String SHOW_OR_CREATE_CONTACT =
1728                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
1729
1730        /**
1731         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
1732         * contact if no matching contact found. Otherwise, default behavior is
1733         * to prompt user with dialog before creating.
1734         * <p>
1735         * Type: BOOLEAN
1736         */
1737        public static final String EXTRA_FORCE_CREATE =
1738                "com.android.contacts.action.FORCE_CREATE";
1739
1740        /**
1741         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
1742         * description to be shown when prompting user about creating a new
1743         * contact.
1744         * <p>
1745         * Type: STRING
1746         */
1747        public static final String EXTRA_CREATE_DESCRIPTION =
1748            "com.android.contacts.action.CREATE_DESCRIPTION";
1749
1750        /**
1751         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
1752         * dialog location using screen coordinates. When not specified, the
1753         * dialog will be centered.
1754         */
1755        public static final String EXTRA_TARGET_RECT = "target_rect";
1756
1757        /**
1758         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
1759         * desired dialog style, usually a variation on size. One of
1760         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
1761         */
1762        public static final String EXTRA_MODE = "mode";
1763
1764        /**
1765         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
1766         */
1767        public static final int MODE_SMALL = 1;
1768
1769        /**
1770         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
1771         */
1772        public static final int MODE_MEDIUM = 2;
1773
1774        /**
1775         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
1776         */
1777        public static final int MODE_LARGE = 3;
1778
1779        /**
1780         * Intents related to the Contacts app UI.
1781         */
1782        public static final class UI {
1783            /**
1784             * The action for the default contacts list tab.
1785             */
1786            public static final String LIST_DEFAULT =
1787                    "com.android.contacts.action.LIST_DEFAULT";
1788
1789            /**
1790             * The action for the contacts list tab.
1791             */
1792            public static final String LIST_GROUP_ACTION =
1793                    "com.android.contacts.action.LIST_GROUP";
1794
1795            /**
1796             * When in LIST_GROUP_ACTION mode, this is the group to display.
1797             */
1798            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
1799
1800            /**
1801             * The action for the all contacts list tab.
1802             */
1803            public static final String LIST_ALL_CONTACTS_ACTION =
1804                    "com.android.contacts.action.LIST_ALL_CONTACTS";
1805
1806            /**
1807             * The action for the contacts with phone numbers list tab.
1808             */
1809            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
1810                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
1811
1812            /**
1813             * The action for the starred contacts list tab.
1814             */
1815            public static final String LIST_STARRED_ACTION =
1816                    "com.android.contacts.action.LIST_STARRED";
1817
1818            /**
1819             * The action for the frequent contacts list tab.
1820             */
1821            public static final String LIST_FREQUENT_ACTION =
1822                    "com.android.contacts.action.LIST_FREQUENT";
1823
1824            /**
1825             * The action for the "strequent" contacts list tab. It first lists the starred
1826             * contacts in alphabetical order and then the frequent contacts in descending
1827             * order of the number of times they have been contacted.
1828             */
1829            public static final String LIST_STREQUENT_ACTION =
1830                    "com.android.contacts.action.LIST_STREQUENT";
1831
1832            /**
1833             * A key for to be used as an intent extra to set the activity
1834             * title to a custom String value.
1835             */
1836            public static final String TITLE_EXTRA_KEY =
1837                "com.android.contacts.extra.TITLE_EXTRA";
1838
1839            /**
1840             * Activity Action: Display a filtered list of contacts
1841             * <p>
1842             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
1843             * filtering
1844             * <p>
1845             * Output: Nothing.
1846             */
1847            public static final String FILTER_CONTACTS_ACTION =
1848                "com.android.contacts.action.FILTER_CONTACTS";
1849
1850            /**
1851             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
1852             * intents to supply the text on which to filter.
1853             */
1854            public static final String FILTER_TEXT_EXTRA_KEY =
1855                "com.android.contacts.extra.FILTER_TEXT";
1856        }
1857
1858        /**
1859         * Convenience class that contains string constants used
1860         * to create contact {@link android.content.Intent Intents}.
1861         */
1862        public static final class Insert {
1863            /** The action code to use when adding a contact */
1864            public static final String ACTION = Intent.ACTION_INSERT;
1865
1866            /**
1867             * If present, forces a bypass of quick insert mode.
1868             */
1869            public static final String FULL_MODE = "full_mode";
1870
1871            /**
1872             * The extra field for the contact name.
1873             * <P>Type: String</P>
1874             */
1875            public static final String NAME = "name";
1876
1877            // TODO add structured name values here.
1878
1879            /**
1880             * The extra field for the contact phonetic name.
1881             * <P>Type: String</P>
1882             */
1883            public static final String PHONETIC_NAME = "phonetic_name";
1884
1885            /**
1886             * The extra field for the contact company.
1887             * <P>Type: String</P>
1888             */
1889            public static final String COMPANY = "company";
1890
1891            /**
1892             * The extra field for the contact job title.
1893             * <P>Type: String</P>
1894             */
1895            public static final String JOB_TITLE = "job_title";
1896
1897            /**
1898             * The extra field for the contact notes.
1899             * <P>Type: String</P>
1900             */
1901            public static final String NOTES = "notes";
1902
1903            /**
1904             * The extra field for the contact phone number.
1905             * <P>Type: String</P>
1906             */
1907            public static final String PHONE = "phone";
1908
1909            /**
1910             * The extra field for the contact phone number type.
1911             * <P>Type: Either an integer value from
1912             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1913             *  or a string specifying a custom label.</P>
1914             */
1915            public static final String PHONE_TYPE = "phone_type";
1916
1917            /**
1918             * The extra field for the phone isprimary flag.
1919             * <P>Type: boolean</P>
1920             */
1921            public static final String PHONE_ISPRIMARY = "phone_isprimary";
1922
1923            /**
1924             * The extra field for an optional second contact phone number.
1925             * <P>Type: String</P>
1926             */
1927            public static final String SECONDARY_PHONE = "secondary_phone";
1928
1929            /**
1930             * The extra field for an optional second contact phone number type.
1931             * <P>Type: Either an integer value from
1932             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1933             *  or a string specifying a custom label.</P>
1934             */
1935            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
1936
1937            /**
1938             * The extra field for an optional third contact phone number.
1939             * <P>Type: String</P>
1940             */
1941            public static final String TERTIARY_PHONE = "tertiary_phone";
1942
1943            /**
1944             * The extra field for an optional third contact phone number type.
1945             * <P>Type: Either an integer value from
1946             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1947             *  or a string specifying a custom label.</P>
1948             */
1949            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
1950
1951            /**
1952             * The extra field for the contact email address.
1953             * <P>Type: String</P>
1954             */
1955            public static final String EMAIL = "email";
1956
1957            /**
1958             * The extra field for the contact email type.
1959             * <P>Type: Either an integer value from
1960             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1961             *  or a string specifying a custom label.</P>
1962             */
1963            public static final String EMAIL_TYPE = "email_type";
1964
1965            /**
1966             * The extra field for the email isprimary flag.
1967             * <P>Type: boolean</P>
1968             */
1969            public static final String EMAIL_ISPRIMARY = "email_isprimary";
1970
1971            /**
1972             * The extra field for an optional second contact email address.
1973             * <P>Type: String</P>
1974             */
1975            public static final String SECONDARY_EMAIL = "secondary_email";
1976
1977            /**
1978             * The extra field for an optional second contact email type.
1979             * <P>Type: Either an integer value from
1980             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1981             *  or a string specifying a custom label.</P>
1982             */
1983            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
1984
1985            /**
1986             * The extra field for an optional third contact email address.
1987             * <P>Type: String</P>
1988             */
1989            public static final String TERTIARY_EMAIL = "tertiary_email";
1990
1991            /**
1992             * The extra field for an optional third contact email type.
1993             * <P>Type: Either an integer value from
1994             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1995             *  or a string specifying a custom label.</P>
1996             */
1997            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
1998
1999            /**
2000             * The extra field for the contact postal address.
2001             * <P>Type: String</P>
2002             */
2003            public static final String POSTAL = "postal";
2004
2005            /**
2006             * The extra field for the contact postal address type.
2007             * <P>Type: Either an integer value from
2008             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2009             *  or a string specifying a custom label.</P>
2010             */
2011            public static final String POSTAL_TYPE = "postal_type";
2012
2013            /**
2014             * The extra field for the postal isprimary flag.
2015             * <P>Type: boolean</P>
2016             */
2017            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
2018
2019            /**
2020             * The extra field for an IM handle.
2021             * <P>Type: String</P>
2022             */
2023            public static final String IM_HANDLE = "im_handle";
2024
2025            /**
2026             * The extra field for the IM protocol
2027             * <P>Type: the result of {@link CommonDataKinds.Im#encodePredefinedImProtocol(int)}
2028             * or {@link CommonDataKinds.Im#encodeCustomImProtocol(String)}.</P>
2029             */
2030            public static final String IM_PROTOCOL = "im_protocol";
2031
2032            /**
2033             * The extra field for the IM isprimary flag.
2034             * <P>Type: boolean</P>
2035             */
2036            public static final String IM_ISPRIMARY = "im_isprimary";
2037        }
2038    }
2039
2040}
2041