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