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