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