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