ContactsContract.java revision 97bda4c5ae3f77a1b450d4abc06f3cf378cc6c1d
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
1043            /**
1044             * The phone number as the user entered it.
1045             * <P>Type: TEXT</P>
1046             */
1047            public static final String NUMBER = DATA;
1048
1049            public static final CharSequence getDisplayLabel(Context context, int type,
1050                    CharSequence label, CharSequence[] labelArray) {
1051                CharSequence display = "";
1052
1053                if (type != Phone.TYPE_CUSTOM) {
1054                    CharSequence[] labels = labelArray != null? labelArray
1055                            : context.getResources().getTextArray(
1056                                    com.android.internal.R.array.phoneTypes);
1057                    try {
1058                        display = labels[type - 1];
1059                    } catch (ArrayIndexOutOfBoundsException e) {
1060                        display = labels[Phone.TYPE_CUSTOM];
1061                    }
1062                } else {
1063                    if (!TextUtils.isEmpty(label)) {
1064                        display = label;
1065                    }
1066                }
1067                return display;
1068            }
1069
1070            public static final CharSequence getDisplayLabel(Context context, int type,
1071                    CharSequence label) {
1072                return getDisplayLabel(context, type, label, null);
1073            }
1074        }
1075
1076        /**
1077         * Common data definition for email addresses.
1078         */
1079        public static final class Email implements BaseCommonColumns, CommonColumns {
1080            private Email() {}
1081
1082            /** MIME type used when storing this in data table. */
1083            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
1084
1085            /**
1086             * The content:// style URI for all data records of the
1087             * {@link Email#CONTENT_ITEM_TYPE} MIME type, combined with the
1088             * associated raw contact and aggregate contact data.
1089             */
1090            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
1091                    "emails");
1092
1093            /**
1094             * The content:// style URL for looking up data rows by email address. The
1095             * lookup argument, an email address, should be passed as an additional path segment
1096             * after this URI.
1097             */
1098            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
1099                    "lookup");
1100
1101            @Deprecated
1102            public static final Uri CONTENT_FILTER_EMAIL_URI = CONTENT_LOOKUP_URI;
1103
1104            /**
1105             * The content:// style URL for email lookup using a filter. The filter returns
1106             * records of MIME type {@link Email#CONTENT_ITEM_TYPE}. The filter is applied
1107             * to display names as well as email addresses. The filter argument should be passed
1108             * as an additional path segment after this URI.
1109             */
1110            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
1111                    "filter");
1112
1113            public static final int TYPE_HOME = 1;
1114            public static final int TYPE_WORK = 2;
1115            public static final int TYPE_OTHER = 3;
1116            public static final int TYPE_MOBILE = 4;
1117
1118            /**
1119             * The display name for the email address
1120             * <P>Type: TEXT</P>
1121             */
1122            public static final String DISPLAY_NAME = "data4";
1123        }
1124
1125        /**
1126         * Common data definition for postal addresses.
1127         */
1128        public static final class StructuredPostal implements BaseCommonColumns, CommonColumns {
1129            private StructuredPostal() {
1130            }
1131
1132            /** MIME type used when storing this in data table. */
1133            public static final String CONTENT_ITEM_TYPE =
1134                    "vnd.android.cursor.item/postal-address_v2";
1135
1136            /**
1137             * The MIME type of {@link #CONTENT_URI} providing a directory of
1138             * postal addresses.
1139             */
1140            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
1141
1142            /**
1143             * The content:// style URI for all data records of the
1144             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
1145             */
1146            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
1147                    "postals");
1148
1149            public static final int TYPE_HOME = 1;
1150            public static final int TYPE_WORK = 2;
1151            public static final int TYPE_OTHER = 3;
1152
1153            /**
1154             * The full, unstructured postal address. <i>This field must be
1155             * consistent with any structured data.</i>
1156             * <p>
1157             * Type: TEXT
1158             */
1159            public static final String FORMATTED_ADDRESS = DATA;
1160
1161            /**
1162             * Can be street, avenue, road, etc. This element also includes the
1163             * house number and room/apartment/flat/floor number.
1164             * <p>
1165             * Type: TEXT
1166             */
1167            public static final String STREET = "data6";
1168
1169            /**
1170             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
1171             * usually but not always mutually exclusive with street.
1172             * <p>
1173             * Type: TEXT
1174             */
1175            public static final String POBOX = "data7";
1176
1177            /**
1178             * This is used to disambiguate a street address when a city
1179             * contains more than one street with the same name, or to specify a
1180             * small place whose mail is routed through a larger postal town. In
1181             * China it could be a county or a minor city.
1182             * <p>
1183             * Type: TEXT
1184             */
1185            public static final String NEIGHBORHOOD = "data8";
1186
1187            /**
1188             * Can be city, village, town, borough, etc. This is the postal town
1189             * and not necessarily the place of residence or place of business.
1190             * <p>
1191             * Type: TEXT
1192             */
1193            public static final String CITY = "data9";
1194
1195            /**
1196             * A state, province, county (in Ireland), Land (in Germany),
1197             * departement (in France), etc.
1198             * <p>
1199             * Type: TEXT
1200             */
1201            public static final String REGION = "data11";
1202
1203            /**
1204             * Postal code. Usually country-wide, but sometimes specific to the
1205             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
1206             * <p>
1207             * Type: TEXT
1208             */
1209            public static final String POSTCODE = "data12";
1210
1211            /**
1212             * The name or code of the country.
1213             * <p>
1214             * Type: TEXT
1215             */
1216            public static final String COUNTRY = "data13";
1217        }
1218
1219        /**
1220         * Common data definition for IM addresses.
1221         */
1222        public static final class Im implements BaseCommonColumns, CommonColumns {
1223            private Im() {}
1224
1225            /** MIME type used when storing this in data table. */
1226            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
1227
1228            public static final int TYPE_HOME = 1;
1229            public static final int TYPE_WORK = 2;
1230            public static final int TYPE_OTHER = 3;
1231
1232            /**
1233             * This column should be populated with one of the defined
1234             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
1235             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
1236             * should contain the name of the custom protocol.
1237             */
1238            public static final String PROTOCOL = "data5";
1239
1240            public static final String CUSTOM_PROTOCOL = "data6";
1241
1242            /*
1243             * The predefined IM protocol types.
1244             */
1245            public static final int PROTOCOL_CUSTOM = -1;
1246            public static final int PROTOCOL_AIM = 0;
1247            public static final int PROTOCOL_MSN = 1;
1248            public static final int PROTOCOL_YAHOO = 2;
1249            public static final int PROTOCOL_SKYPE = 3;
1250            public static final int PROTOCOL_QQ = 4;
1251            public static final int PROTOCOL_GOOGLE_TALK = 5;
1252            public static final int PROTOCOL_ICQ = 6;
1253            public static final int PROTOCOL_JABBER = 7;
1254            public static final int PROTOCOL_NETMEETING = 8;
1255        }
1256
1257        /**
1258         * Common data definition for organizations.
1259         */
1260        public static final class Organization implements BaseCommonColumns, CommonColumns {
1261            private Organization() {}
1262
1263            /** MIME type used when storing this in data table. */
1264            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
1265
1266            public static final int TYPE_WORK = 1;
1267            public static final int TYPE_OTHER = 2;
1268
1269            /**
1270             * The company as the user entered it.
1271             * <P>Type: TEXT</P>
1272             */
1273            public static final String COMPANY = DATA;
1274
1275            /**
1276             * The position title at this company as the user entered it.
1277             * <P>Type: TEXT</P>
1278             */
1279            public static final String TITLE = "data4";
1280
1281            /**
1282             * The department at this company as the user entered it.
1283             * <P>Type: TEXT</P>
1284             */
1285            public static final String DEPARTMENT = "data5";
1286
1287            /**
1288             * The job description at this company as the user entered it.
1289             * <P>Type: TEXT</P>
1290             */
1291            public static final String JOB_DESCRIPTION = "data6";
1292
1293            /**
1294             * The symbol of this company as the user entered it.
1295             * <P>Type: TEXT</P>
1296             */
1297            public static final String SYMBOL = "data7";
1298
1299            /**
1300             * The phonetic name of this company as the user entered it.
1301             * <P>Type: TEXT</P>
1302             */
1303            public static final String PHONETIC_NAME = "data8";
1304        }
1305
1306        /**
1307         * Common data definition for miscellaneous information.
1308         */
1309        public static final class Miscellaneous implements BaseCommonColumns {
1310            private Miscellaneous() {}
1311
1312            /** MIME type used when storing this in data table. */
1313            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/misc";
1314
1315            /**
1316             * The birthday as the user entered it.
1317             * <P>Type: TEXT</P>
1318             */
1319            public static final String BIRTHDAY = "data1";
1320
1321            /**
1322             * The nickname as the user entered it.
1323             * <P>Type: TEXT</P>
1324             */
1325            public static final String NICKNAME = "data2";
1326        }
1327
1328        /**
1329         * Common data definition for relations.
1330         */
1331        public static final class Relation implements BaseCommonColumns, CommonColumns {
1332            private Relation() {}
1333
1334            /** MIME type used when storing this in data table. */
1335            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
1336
1337            public static final int TYPE_ASSISTANT = 1;
1338            public static final int TYPE_BROTHER = 2;
1339            public static final int TYPE_CHILD = 3;
1340            public static final int TYPE_DOMESTIC_PARTNER = 4;
1341            public static final int TYPE_FATHER = 5;
1342            public static final int TYPE_FRIEND = 6;
1343            public static final int TYPE_MANAGER = 7;
1344            public static final int TYPE_MOTHER = 8;
1345            public static final int TYPE_PARENT = 9;
1346            public static final int TYPE_PARTNER = 10;
1347            public static final int TYPE_REFERRED_BY = 11;
1348            public static final int TYPE_RELATIVE = 12;
1349            public static final int TYPE_SISTER = 13;
1350            public static final int TYPE_SPOUSE = 14;
1351
1352            /**
1353             * The name of the relative as the user entered it.
1354             * <P>Type: TEXT</P>
1355             */
1356            public static final String NAME = DATA;
1357        }
1358
1359        /**
1360         * Common data definition for events.
1361         */
1362        public static final class Event implements BaseCommonColumns, CommonColumns {
1363            private Event() {}
1364
1365            /** MIME type used when storing this in data table. */
1366            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/event";
1367
1368            public static final int TYPE_ANNIVERSARY = 1;
1369            public static final int TYPE_OTHER = 2;
1370
1371            /**
1372             * The event start date as the user entered it.
1373             * <P>Type: TEXT</P>
1374             */
1375            public static final String START_DATE = DATA;
1376        }
1377
1378        /**
1379         * Photo of the contact.
1380         */
1381        public static final class Photo implements BaseCommonColumns {
1382            private Photo() {}
1383
1384            /** MIME type used when storing this in data table. */
1385            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
1386
1387            /**
1388             * Thumbnail photo of the raw contact. This is the raw bytes of an image
1389             * that could be inflated using {@link BitmapFactory}.
1390             * <p>
1391             * Type: BLOB
1392             */
1393            public static final String PHOTO = "data1";
1394        }
1395
1396        /**
1397         * Notes about the contact.
1398         */
1399        public static final class Note implements BaseCommonColumns {
1400            private Note() {}
1401
1402            /** MIME type used when storing this in data table. */
1403            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
1404
1405            /**
1406             * The note text.
1407             * <P>Type: TEXT</P>
1408             */
1409            public static final String NOTE = "data1";
1410        }
1411
1412        /**
1413         * Group Membership.
1414         */
1415        public static final class GroupMembership implements BaseCommonColumns {
1416            private GroupMembership() {}
1417
1418            /** MIME type used when storing this in data table. */
1419            public static final String CONTENT_ITEM_TYPE =
1420                    "vnd.android.cursor.item/group_membership";
1421
1422            /**
1423             * The row id of the group that this group membership refers to. Exactly one of
1424             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
1425             * <P>Type: INTEGER</P>
1426             */
1427            public static final String GROUP_ROW_ID = "data1";
1428
1429            /**
1430             * The sourceid of the group that this group membership refers to.  Exactly one of
1431             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
1432             * <P>Type: TEXT</P>
1433             */
1434            public static final String GROUP_SOURCE_ID = "group_sourceid";
1435        }
1436
1437        /**
1438         * Website related to the contact.
1439         */
1440        public static final class Website implements BaseCommonColumns, CommonColumns {
1441            private Website() {}
1442
1443            /** MIME type used when storing this in data table. */
1444            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
1445
1446            public static final int TYPE_HOMEPAGE = 1;
1447            public static final int TYPE_BLOG = 2;
1448            public static final int TYPE_PROFILE = 3;
1449            public static final int TYPE_HOME = 4;
1450            public static final int TYPE_WORK = 5;
1451            public static final int TYPE_FTP = 6;
1452            public static final int TYPE_OTHER = 7;
1453
1454            /**
1455             * The website URL string.
1456             * <P>Type: TEXT</P>
1457             */
1458            public static final String URL = "data1";
1459        }
1460    }
1461
1462    // TODO: make this private before unhiding
1463    public interface GroupsColumns {
1464        /**
1465         * The display title of this group.
1466         * <p>
1467         * Type: TEXT
1468         */
1469        public static final String TITLE = "title";
1470
1471        /**
1472         * The package name to use when creating {@link Resources} objects for
1473         * this group. This value is only designed for use when building user
1474         * interfaces, and should not be used to infer the owner.
1475         */
1476        public static final String RES_PACKAGE = "res_package";
1477
1478        /**
1479         * The display title of this group to load as a resource from
1480         * {@link #RES_PACKAGE}, which may be localized.
1481         * <P>Type: TEXT</P>
1482         */
1483        public static final String TITLE_RES = "title_res";
1484
1485        /**
1486         * Notes about the group.
1487         * <p>
1488         * Type: TEXT
1489         */
1490        public static final String NOTES = "notes";
1491
1492        /**
1493         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
1494         * to the sync adapter, null otherwise.
1495         * <P>Type: TEXT</P>
1496         */
1497        public static final String SYSTEM_ID = "system_id";
1498
1499        /**
1500         * The total number of {@link Contacts} that have
1501         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
1502         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
1503         * <p>
1504         * Type: INTEGER
1505         */
1506        public static final String SUMMARY_COUNT = "summ_count";
1507
1508        /**
1509         * The total number of {@link Contacts} that have both
1510         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
1511         * Read-only value that is only present when querying
1512         * {@link Groups#CONTENT_SUMMARY_URI}.
1513         * <p>
1514         * Type: INTEGER
1515         */
1516        public static final String SUMMARY_WITH_PHONES = "summ_phones";
1517
1518        /**
1519         * Flag indicating if the contacts belonging to this group should be
1520         * visible in any user interface.
1521         * <p>
1522         * Type: INTEGER (boolean)
1523         */
1524        public static final String GROUP_VISIBLE = "group_visible";
1525
1526        /**
1527         * The "deleted" flag: "0" by default, "1" if the row has been marked
1528         * for deletion. When {@link android.content.ContentResolver#delete} is
1529         * called on a raw contact, it is marked for deletion and removed from its
1530         * aggregate contact. The sync adaptor deletes the raw contact on the server and
1531         * then calls ContactResolver.delete once more, this time setting the the
1532         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
1533         * the data removal.
1534         * <P>Type: INTEGER</P>
1535         */
1536        public static final String DELETED = "deleted";
1537
1538        /**
1539         * Whether this group should be synced if the SYNC_EVERYTHING settings
1540         * is false for this group's account.
1541         * <p>
1542         * Type: INTEGER (boolean)
1543         */
1544        public static final String SHOULD_SYNC = "should_sync";
1545    }
1546
1547    /**
1548     * Constants for the groups table.
1549     */
1550    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
1551        /**
1552         * This utility class cannot be instantiated
1553         */
1554        private Groups() {
1555        }
1556
1557        /**
1558         * The content:// style URI for this table
1559         */
1560        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
1561
1562        /**
1563         * The content:// style URI for this table joined with details data from
1564         * {@link Data}.
1565         */
1566        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
1567                "groups_summary");
1568
1569        /**
1570         * The MIME type of a directory of groups.
1571         */
1572        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
1573
1574        /**
1575         * The MIME type of a single group.
1576         */
1577        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
1578    }
1579
1580    /**
1581     * Constants for the contact aggregation exceptions table, which contains
1582     * aggregation rules overriding those used by automatic aggregation.  This type only
1583     * supports query and update. Neither insert nor delete are supported.
1584     */
1585    public static final class AggregationExceptions implements BaseColumns {
1586        /**
1587         * This utility class cannot be instantiated
1588         */
1589        private AggregationExceptions() {}
1590
1591        /**
1592         * The content:// style URI for this table
1593         */
1594        public static final Uri CONTENT_URI =
1595                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
1596
1597        /**
1598         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
1599         */
1600        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
1601
1602        /**
1603         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
1604         */
1605        public static final String CONTENT_ITEM_TYPE =
1606                "vnd.android.cursor.item/aggregation_exception";
1607
1608        /**
1609         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
1610         * {@link #TYPE_AUTOMATIC}.
1611         *
1612         * <P>Type: INTEGER</P>
1613         */
1614        public static final String TYPE = "type";
1615
1616        /**
1617         * Allows the provider to automatically decide whether the specified raw contacts should
1618         * be included in the same aggregate contact or not.
1619         */
1620        public static final int TYPE_AUTOMATIC = 0;
1621
1622        /**
1623         * Makes sure that the specified raw contacts are included in the same
1624         * aggregate contact.
1625         */
1626        public static final int TYPE_KEEP_TOGETHER = 1;
1627
1628        @Deprecated
1629        public static final int TYPE_KEEP_IN = 1;
1630
1631        /**
1632         * Makes sure that the specified raw contacts are NOT included in the same
1633         * aggregate contact.
1634         */
1635        public static final int TYPE_KEEP_SEPARATE = 2;
1636
1637        @Deprecated
1638        public static final int TYPE_KEEP_OUT = 2;
1639
1640        @Deprecated
1641        public static final String CONTACT_ID = "contact_id";
1642
1643        @Deprecated
1644        public static final String RAW_CONTACT_ID = "raw_contact_id";
1645
1646        /**
1647         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
1648         */
1649        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
1650
1651        /**
1652         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
1653         * applies to.
1654         */
1655        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
1656    }
1657
1658    private interface SettingsColumns {
1659        /**
1660         * The name of the account instance to which this row belongs.
1661         * <P>Type: TEXT</P>
1662         */
1663        public static final String ACCOUNT_NAME = "account_name";
1664
1665        /**
1666         * The type of account to which this row belongs, which when paired with
1667         * {@link #ACCOUNT_NAME} identifies a specific account.
1668         * <P>Type: TEXT</P>
1669         */
1670        public static final String ACCOUNT_TYPE = "account_type";
1671
1672        /**
1673         * Depending on the mode defined by the sync-adapter, this flag controls
1674         * the top-level sync behavior for this data source.
1675         * <p>
1676         * Type: INTEGER (boolean)
1677         */
1678        public static final String SHOULD_SYNC = "should_sync";
1679
1680        /**
1681         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
1682         * entries should be visible in any user interface.
1683         * <p>
1684         * Type: INTEGER (boolean)
1685         */
1686        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
1687
1688        /**
1689         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
1690         * {@link Groups#SHOULD_SYNC} under this account have been marked as
1691         * unsynced.
1692         */
1693        public static final String ANY_UNSYNCED = "any_unsynced";
1694
1695        /**
1696         * Read-only count of {@link Contacts} from a specific source that have
1697         * no {@link CommonDataKinds.GroupMembership} entries.
1698         * <p>
1699         * Type: INTEGER
1700         */
1701        public static final String UNGROUPED_COUNT = "summ_count";
1702
1703        /**
1704         * Read-only count of {@link Contacts} from a specific source that have
1705         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
1706         * <p>
1707         * Type: INTEGER
1708         */
1709        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
1710    }
1711
1712    /**
1713     * Contacts-specific settings for various {@link Account}.
1714     */
1715    public static final class Settings implements SettingsColumns {
1716        /**
1717         * This utility class cannot be instantiated
1718         */
1719        private Settings() {
1720        }
1721
1722        /**
1723         * The content:// style URI for this table
1724         */
1725        public static final Uri CONTENT_URI =
1726                Uri.withAppendedPath(AUTHORITY_URI, "settings");
1727
1728        /**
1729         * The MIME-type of {@link #CONTENT_URI} providing a directory of
1730         * settings.
1731         */
1732        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
1733
1734        /**
1735         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
1736         */
1737        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
1738    }
1739
1740    /**
1741     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
1742     * that involve contacts.
1743     */
1744    public static final class Intents {
1745        /**
1746         * This is the intent that is fired when a search suggestion is clicked on.
1747         */
1748        public static final String SEARCH_SUGGESTION_CLICKED =
1749                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
1750
1751        /**
1752         * This is the intent that is fired when a search suggestion for dialing a number
1753         * is clicked on.
1754         */
1755        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
1756                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
1757
1758        /**
1759         * This is the intent that is fired when a search suggestion for creating a contact
1760         * is clicked on.
1761         */
1762        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
1763                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
1764
1765        /**
1766         * Starts an Activity that lets the user pick a contact to attach an image to.
1767         * After picking the contact it launches the image cropper in face detection mode.
1768         */
1769        public static final String ATTACH_IMAGE =
1770                "com.android.contacts.action.ATTACH_IMAGE";
1771
1772        /**
1773         * Takes as input a data URI with a mailto: or tel: scheme. If a single
1774         * contact exists with the given data it will be shown. If no contact
1775         * exists, a dialog will ask the user if they want to create a new
1776         * contact with the provided details filled in. If multiple contacts
1777         * share the data the user will be prompted to pick which contact they
1778         * want to view.
1779         * <p>
1780         * For <code>mailto:</code> URIs, the scheme specific portion must be a
1781         * raw email address, such as one built using
1782         * {@link Uri#fromParts(String, String, String)}.
1783         * <p>
1784         * For <code>tel:</code> URIs, the scheme specific portion is compared
1785         * to existing numbers using the standard caller ID lookup algorithm.
1786         * The number must be properly encoded, for example using
1787         * {@link Uri#fromParts(String, String, String)}.
1788         * <p>
1789         * Any extras from the {@link Insert} class will be passed along to the
1790         * create activity if there are no contacts to show.
1791         * <p>
1792         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
1793         * prompting the user when the contact doesn't exist.
1794         */
1795        public static final String SHOW_OR_CREATE_CONTACT =
1796                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
1797
1798        /**
1799         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
1800         * contact if no matching contact found. Otherwise, default behavior is
1801         * to prompt user with dialog before creating.
1802         * <p>
1803         * Type: BOOLEAN
1804         */
1805        public static final String EXTRA_FORCE_CREATE =
1806                "com.android.contacts.action.FORCE_CREATE";
1807
1808        /**
1809         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
1810         * description to be shown when prompting user about creating a new
1811         * contact.
1812         * <p>
1813         * Type: STRING
1814         */
1815        public static final String EXTRA_CREATE_DESCRIPTION =
1816            "com.android.contacts.action.CREATE_DESCRIPTION";
1817
1818        /**
1819         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
1820         * dialog location using screen coordinates. When not specified, the
1821         * dialog will be centered.
1822         */
1823        public static final String EXTRA_TARGET_RECT = "target_rect";
1824
1825        /**
1826         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
1827         * desired dialog style, usually a variation on size. One of
1828         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
1829         */
1830        public static final String EXTRA_MODE = "mode";
1831
1832        /**
1833         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
1834         */
1835        public static final int MODE_SMALL = 1;
1836
1837        /**
1838         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
1839         */
1840        public static final int MODE_MEDIUM = 2;
1841
1842        /**
1843         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
1844         */
1845        public static final int MODE_LARGE = 3;
1846
1847        /**
1848         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
1849         * a list of specific MIME-types to exclude and not display. Stored as a
1850         * {@link String} array.
1851         */
1852        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
1853
1854        /**
1855         * Intents related to the Contacts app UI.
1856         */
1857        public static final class UI {
1858            /**
1859             * The action for the default contacts list tab.
1860             */
1861            public static final String LIST_DEFAULT =
1862                    "com.android.contacts.action.LIST_DEFAULT";
1863
1864            /**
1865             * The action for the contacts list tab.
1866             */
1867            public static final String LIST_GROUP_ACTION =
1868                    "com.android.contacts.action.LIST_GROUP";
1869
1870            /**
1871             * When in LIST_GROUP_ACTION mode, this is the group to display.
1872             */
1873            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
1874
1875            /**
1876             * The action for the all contacts list tab.
1877             */
1878            public static final String LIST_ALL_CONTACTS_ACTION =
1879                    "com.android.contacts.action.LIST_ALL_CONTACTS";
1880
1881            /**
1882             * The action for the contacts with phone numbers list tab.
1883             */
1884            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
1885                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
1886
1887            /**
1888             * The action for the starred contacts list tab.
1889             */
1890            public static final String LIST_STARRED_ACTION =
1891                    "com.android.contacts.action.LIST_STARRED";
1892
1893            /**
1894             * The action for the frequent contacts list tab.
1895             */
1896            public static final String LIST_FREQUENT_ACTION =
1897                    "com.android.contacts.action.LIST_FREQUENT";
1898
1899            /**
1900             * The action for the "strequent" contacts list tab. It first lists the starred
1901             * contacts in alphabetical order and then the frequent contacts in descending
1902             * order of the number of times they have been contacted.
1903             */
1904            public static final String LIST_STREQUENT_ACTION =
1905                    "com.android.contacts.action.LIST_STREQUENT";
1906
1907            /**
1908             * A key for to be used as an intent extra to set the activity
1909             * title to a custom String value.
1910             */
1911            public static final String TITLE_EXTRA_KEY =
1912                "com.android.contacts.extra.TITLE_EXTRA";
1913
1914            /**
1915             * Activity Action: Display a filtered list of contacts
1916             * <p>
1917             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
1918             * filtering
1919             * <p>
1920             * Output: Nothing.
1921             */
1922            public static final String FILTER_CONTACTS_ACTION =
1923                "com.android.contacts.action.FILTER_CONTACTS";
1924
1925            /**
1926             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
1927             * intents to supply the text on which to filter.
1928             */
1929            public static final String FILTER_TEXT_EXTRA_KEY =
1930                "com.android.contacts.extra.FILTER_TEXT";
1931        }
1932
1933        /**
1934         * Convenience class that contains string constants used
1935         * to create contact {@link android.content.Intent Intents}.
1936         */
1937        public static final class Insert {
1938            /** The action code to use when adding a contact */
1939            public static final String ACTION = Intent.ACTION_INSERT;
1940
1941            /**
1942             * If present, forces a bypass of quick insert mode.
1943             */
1944            public static final String FULL_MODE = "full_mode";
1945
1946            /**
1947             * The extra field for the contact name.
1948             * <P>Type: String</P>
1949             */
1950            public static final String NAME = "name";
1951
1952            // TODO add structured name values here.
1953
1954            /**
1955             * The extra field for the contact phonetic name.
1956             * <P>Type: String</P>
1957             */
1958            public static final String PHONETIC_NAME = "phonetic_name";
1959
1960            /**
1961             * The extra field for the contact company.
1962             * <P>Type: String</P>
1963             */
1964            public static final String COMPANY = "company";
1965
1966            /**
1967             * The extra field for the contact job title.
1968             * <P>Type: String</P>
1969             */
1970            public static final String JOB_TITLE = "job_title";
1971
1972            /**
1973             * The extra field for the contact notes.
1974             * <P>Type: String</P>
1975             */
1976            public static final String NOTES = "notes";
1977
1978            /**
1979             * The extra field for the contact phone number.
1980             * <P>Type: String</P>
1981             */
1982            public static final String PHONE = "phone";
1983
1984            /**
1985             * The extra field for the contact phone number type.
1986             * <P>Type: Either an integer value from
1987             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1988             *  or a string specifying a custom label.</P>
1989             */
1990            public static final String PHONE_TYPE = "phone_type";
1991
1992            /**
1993             * The extra field for the phone isprimary flag.
1994             * <P>Type: boolean</P>
1995             */
1996            public static final String PHONE_ISPRIMARY = "phone_isprimary";
1997
1998            /**
1999             * The extra field for an optional second contact phone number.
2000             * <P>Type: String</P>
2001             */
2002            public static final String SECONDARY_PHONE = "secondary_phone";
2003
2004            /**
2005             * The extra field for an optional second contact phone number type.
2006             * <P>Type: Either an integer value from
2007             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
2008             *  or a string specifying a custom label.</P>
2009             */
2010            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
2011
2012            /**
2013             * The extra field for an optional third contact phone number.
2014             * <P>Type: String</P>
2015             */
2016            public static final String TERTIARY_PHONE = "tertiary_phone";
2017
2018            /**
2019             * The extra field for an optional third contact phone number type.
2020             * <P>Type: Either an integer value from
2021             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
2022             *  or a string specifying a custom label.</P>
2023             */
2024            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
2025
2026            /**
2027             * The extra field for the contact email address.
2028             * <P>Type: String</P>
2029             */
2030            public static final String EMAIL = "email";
2031
2032            /**
2033             * The extra field for the contact email type.
2034             * <P>Type: Either an integer value from
2035             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2036             *  or a string specifying a custom label.</P>
2037             */
2038            public static final String EMAIL_TYPE = "email_type";
2039
2040            /**
2041             * The extra field for the email isprimary flag.
2042             * <P>Type: boolean</P>
2043             */
2044            public static final String EMAIL_ISPRIMARY = "email_isprimary";
2045
2046            /**
2047             * The extra field for an optional second contact email address.
2048             * <P>Type: String</P>
2049             */
2050            public static final String SECONDARY_EMAIL = "secondary_email";
2051
2052            /**
2053             * The extra field for an optional second contact email type.
2054             * <P>Type: Either an integer value from
2055             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2056             *  or a string specifying a custom label.</P>
2057             */
2058            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
2059
2060            /**
2061             * The extra field for an optional third contact email address.
2062             * <P>Type: String</P>
2063             */
2064            public static final String TERTIARY_EMAIL = "tertiary_email";
2065
2066            /**
2067             * The extra field for an optional third contact email type.
2068             * <P>Type: Either an integer value from
2069             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2070             *  or a string specifying a custom label.</P>
2071             */
2072            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
2073
2074            /**
2075             * The extra field for the contact postal address.
2076             * <P>Type: String</P>
2077             */
2078            public static final String POSTAL = "postal";
2079
2080            /**
2081             * The extra field for the contact postal address type.
2082             * <P>Type: Either an integer value from
2083             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2084             *  or a string specifying a custom label.</P>
2085             */
2086            public static final String POSTAL_TYPE = "postal_type";
2087
2088            /**
2089             * The extra field for the postal isprimary flag.
2090             * <P>Type: boolean</P>
2091             */
2092            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
2093
2094            /**
2095             * The extra field for an IM handle.
2096             * <P>Type: String</P>
2097             */
2098            public static final String IM_HANDLE = "im_handle";
2099
2100            /**
2101             * The extra field for the IM protocol
2102             * <P>Type: the result of {@link CommonDataKinds.Im#encodePredefinedImProtocol(int)}
2103             * or {@link CommonDataKinds.Im#encodeCustomImProtocol(String)}.</P>
2104             */
2105            public static final String IM_PROTOCOL = "im_protocol";
2106
2107            /**
2108             * The extra field for the IM isprimary flag.
2109             * <P>Type: boolean</P>
2110             */
2111            public static final String IM_ISPRIMARY = "im_isprimary";
2112        }
2113    }
2114
2115}
2116