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