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