ContactsContract.java revision 693d50e7aef79f16519bf9786af68124ffaf5cd8
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 java.util.Arrays;
20import java.util.List;
21
22import android.content.Intent;
23import android.graphics.BitmapFactory;
24import android.net.Uri;
25
26/**
27 * The contract between the contacts provider and applications. Contains definitions
28 * for the supported URIs and columns.
29 *
30 * @hide
31 */
32public final class ContactsContract {
33    /** The authority for the contacts provider */
34    public static final String AUTHORITY = "com.android.contacts";
35    /** A content:// style uri to the authority for the contacts provider */
36    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
37
38    public interface AccountsColumns {
39        /**
40         * The name of this account data
41         * <P>Type: TEXT</P>
42         */
43        public static final String NAME = "name";
44        /**
45         * The name of this account data
46         * <P>Type: TEXT</P>
47         */
48        public static final String TYPE = "type";
49        /**
50         * The name of this account data
51         * <P>Type: TEXT</P>
52         */
53        public static final String DATA1 = "data1";
54
55        /**
56         * The value for this account data
57         * <P>Type: INTEGER</P>
58         */
59        public static final String DATA2 = "data2";
60
61        /**
62         * The value for this account data
63         * <P>Type: INTEGER</P>
64         */
65        public static final String DATA3 = "data3";
66
67        /**
68         * The value for this account data
69         * <P>Type: INTEGER</P>
70         */
71        public static final String DATA4 = "data4";
72
73        /**
74         * The value for this account data
75         * <P>Type: INTEGER</P>
76         */
77        public static final String DATA5 = "data5";
78    }
79
80    /**
81     * Constants for the aggregates table, which contains a record per group
82     * of contact representing the same person.
83     */
84    public static final class Accounts implements BaseColumns, AccountsColumns {
85        /**
86         * This utility class cannot be instantiated
87         */
88        private Accounts()  {}
89
90        /**
91         * The content:// style URI for this table
92         */
93        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "accounts");
94
95        /**
96         * The MIME type of {@link #CONTENT_URI} providing a directory of
97         * account data.
98         */
99        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contacts_account";
100
101        /**
102         * The MIME type of a {@link #CONTENT_URI} subdirectory of a account
103         */
104        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contacts_account";
105    }
106
107    public interface AggregatesColumns {
108        /**
109         * The display name for the contact.
110         * <P>Type: TEXT</P>
111         */
112        public static final String DISPLAY_NAME = "display_name";
113
114        /**
115         * The number of times a person has been contacted
116         * <P>Type: INTEGER</P>
117         */
118        public static final String TIMES_CONTACTED = "times_contacted";
119
120        /**
121         * The last time a person was contacted.
122         * <P>Type: INTEGER</P>
123         */
124        public static final String LAST_TIME_CONTACTED = "last_time_contacted";
125
126        /**
127         * Is the contact starred?
128         * <P>Type: INTEGER (boolean)</P>
129         */
130        public static final String STARRED = "starred";
131
132        /**
133         * A custom ringtone associated with a person. Not always present.
134         * <P>Type: TEXT (URI to the ringtone)</P>
135         */
136        public static final String CUSTOM_RINGTONE = "custom_ringtone";
137
138        /**
139         * Whether the person should always be sent to voicemail. Not always
140         * present.
141         * <P>Type: INTEGER (0 for false, 1 for true)</P>
142         */
143        public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
144
145        /**
146         * Reference to the row in the data table holding the primary phone number.
147         * <P>Type: INTEGER REFERENCES data(_id)</P>
148         */
149        public static final String PRIMARY_PHONE_ID = "primary_phone_id";
150
151        /**
152         * Reference to the row in the data table holding the primary email address.
153         * <P>Type: INTEGER REFERENCES data(_id)</P>
154         */
155        public static final String PRIMARY_EMAIL_ID = "primary_email_id";
156
157        /**
158         * Reference to the row in the data table holding the photo.
159         * <P>Type: INTEGER REFERENCES data(_id)</P>
160         */
161        public static final String PHOTO_ID = "photo_id";
162    }
163
164    /**
165     * Constants for the aggregates table, which contains a record per group
166     * of contact representing the same person.
167     */
168    public static final class Aggregates implements BaseColumns, AggregatesColumns {
169        /**
170         * This utility class cannot be instantiated
171         */
172        private Aggregates()  {}
173
174        /**
175         * The content:// style URI for this table
176         */
177        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "aggregates");
178
179        /**
180         * The content:// style URI for this table joined with useful data from
181         * {@link Data} and {@link Presence}.
182         */
183        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
184                "aggregates_summary");
185        /**
186         * The content:// style URI used for "type-to-filter" functionality on the
187         * {@link CONTENT_SUMMARY_URI} URI. The filter string will be used to match
188         * various parts of the aggregate name. The filter argument should be passed
189         * as an additional path segment after this URI.
190         */
191        public static final Uri CONTENT_SUMMARY_FILTER_URI = Uri.withAppendedPath(
192                CONTENT_SUMMARY_URI, "filter");
193        /**
194         * The content:// style URI for this table joined with useful data from
195         * {@link Data} and {@link Presence}, filtered to include only starred aggregates
196         * and the most frequently contacted aggregates.
197         */
198        public static final Uri CONTENT_SUMMARY_STREQUENT_URI = Uri.withAppendedPath(
199                CONTENT_SUMMARY_URI, "strequent");
200        /**
201         * The content:// style URI used for "type-to-filter" functionality on the
202         * {@link CONTENT_SUMMARY_STREQUENT_URI} URI. The filter string will be used to match
203         * various parts of the aggregate name. The filter argument should be passed
204         * as an additional path segment after this URI.
205         */
206        public static final Uri CONTENT_SUMMARY_STREQUENT_FILTER_URI = Uri.withAppendedPath(
207                CONTENT_SUMMARY_STREQUENT_URI, "filter");
208
209        /**
210         * The MIME type of {@link #CONTENT_URI} providing a directory of
211         * people.
212         */
213        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/person_aggregate";
214
215        /**
216         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
217         * person.
218         */
219        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/person_aggregate";
220
221        /**
222         * A sub-directory of a single contact aggregate that contains all of their
223         * {@link Data} rows.
224         */
225        public static final class Data implements BaseColumns, DataColumns {
226            /**
227             * no public constructor since this is a utility class
228             */
229            private Data() {}
230
231            /**
232             * The directory twig for this sub-table
233             */
234            public static final String CONTENT_DIRECTORY = "data";
235        }
236
237        /**
238         * A sub-directory of a single contact aggregate that contains all aggregation suggestions
239         * (other aggregates).  The aggregation suggestions are computed based on approximate
240         * data matches with this aggregate.
241         */
242        public static final class AggregationSuggestions implements BaseColumns, AggregatesColumns {
243            /**
244             * No public constructor since this is a utility class
245             */
246            private AggregationSuggestions() {}
247
248            /**
249             * The directory twig for this sub-table
250             */
251            public static final String CONTENT_DIRECTORY = "suggestions";
252
253            /**
254             * An optional query parameter that can be supplied to limit the number of returned
255             * suggestions.
256             * <p>
257             * Type: INTEGER
258             */
259            public static final String MAX_SUGGESTIONS = "max_suggestions";
260        }
261    }
262
263
264    /**
265     * Constants for the contacts table, which contains the base contact information.
266     */
267    public static final class Contacts implements BaseColumns {
268        /**
269         * This utility class cannot be instantiated
270         */
271        private Contacts()  {}
272
273        /**
274         * The package name that owns this contact and all of its details. This
275         * package has control over the {@link #IS_RESTRICTED} flag, and can
276         * grant {@link RestrictionExceptions} to other packages.
277         */
278        public static final String PACKAGE = "package";
279
280        /**
281         * Flag indicating that this data entry has been restricted by the owner
282         * {@link #PACKAGE}.
283         */
284        public static final String IS_RESTRICTED = "is_restricted";
285
286        /**
287         * A reference to the {@link Accounts#_ID} that this data belongs to.
288         */
289        public static final String ACCOUNTS_ID = "accounts_id";
290
291        /**
292         * A reference to the {@link Aggregates#_ID} that this data belongs to.
293         */
294        public static final String AGGREGATE_ID = "aggregate_id";
295
296        /**
297         * The content:// style URI for this table
298         */
299        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");
300
301        /**
302         * The content:// style URL for filtering people by email address. The
303         * filter argument should be passed as an additional path segment after
304         * this URI.
305         *
306         * @hide
307         */
308        public static final Uri CONTENT_FILTER_EMAIL_URI =
309                Uri.withAppendedPath(CONTENT_URI, "filter_email");
310
311        /**
312         * The MIME type of {@link #CONTENT_URI} providing a directory of
313         * people.
314         */
315        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/person";
316
317        /**
318         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
319         * person.
320         */
321        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/person";
322
323        /**
324         * A string that uniquely identifies this contact to its source, which is referred to
325         * by the {@link #ACCOUNTS_ID}
326         */
327        public static final String SOURCE_ID = "sourceid";
328
329        /**
330         * An integer that is updated whenever this contact or its data changes.
331         */
332        public static final String VERSION = "version";
333
334        /**
335         * Set to 1 whenever the version changes
336         */
337        public static final String DIRTY = "dirty";
338
339        /**
340         * A sub-directory of a single contact that contains all of their {@link Data} rows.
341         * To access this directory append
342         */
343        public static final class Data implements BaseColumns, DataColumns {
344            /**
345             * no public constructor since this is a utility class
346             */
347            private Data() {}
348
349            /**
350             * The directory twig for this sub-table
351             */
352            public static final String CONTENT_DIRECTORY = "data";
353        }
354    }
355
356    private interface DataColumns {
357        /**
358         * The mime-type of the item represented by this row.
359         */
360        public static final String MIMETYPE = "mimetype";
361
362        /**
363         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID}
364         * that this data belongs to.
365         */
366        public static final String CONTACT_ID = "contact_id";
367
368        /**
369         * Whether this is the primary entry of its kind for the contact it belongs to
370         * <P>Type: INTEGER (if set, non-0 means true)</P>
371         */
372        public static final String IS_PRIMARY = "is_primary";
373
374        /**
375         * Whether this is the primary entry of its kind for the aggregate it belongs to. Any data
376         * record that is "super primary" must also be "primary".
377         * <P>Type: INTEGER (if set, non-0 means true)</P>
378         */
379        public static final String IS_SUPER_PRIMARY = "is_super_primary";
380
381        /**
382         * The version of this data record. This is a read-only value. The data column is
383         * guaranteed to not change without the version going up. This value is monotonically
384         * increasing.
385         * <P>Type: INTEGER</P>
386         */
387        public static final String DATA_VERSION = "data_version";
388
389        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
390        public static final String DATA1 = "data1";
391        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
392        public static final String DATA2 = "data2";
393        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
394        public static final String DATA3 = "data3";
395        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
396        public static final String DATA4 = "data4";
397        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
398        public static final String DATA5 = "data5";
399        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
400        public static final String DATA6 = "data6";
401        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
402        public static final String DATA7 = "data7";
403        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
404        public static final String DATA8 = "data8";
405        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
406        public static final String DATA9 = "data9";
407        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
408        public static final String DATA10 = "data10";
409    }
410
411    /**
412     * Constants for the data table, which contains data points tied to a contact.
413     * For example, a phone number or email address. Each row in this table contains a type
414     * definition and some generic columns. Each data type can define the meaning for each of
415     * the generic columns.
416     */
417    public static final class Data implements BaseColumns, DataColumns {
418        /**
419         * This utility class cannot be instantiated
420         */
421        private Data() {}
422
423        /**
424         * The content:// style URI for this table
425         */
426        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
427
428        /**
429         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
430         */
431        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
432    }
433
434    /**
435     * A table that represents the result of looking up a phone number, for example for caller ID.
436     * The table joins that data row for the phone number with the contact that owns the number.
437     * To perform a lookup you must append the number you want to find to {@link #CONTENT_URI}.
438     */
439    public static final class PhoneLookup implements BaseColumns, DataColumns, AggregatesColumns {
440        /**
441         * This utility class cannot be instantiated
442         */
443        private PhoneLookup() {}
444
445        /**
446         * The content:// style URI for this table. Append the phone number you want to lookup
447         * to this URI and query it to perform a lookup. For example:
448         *
449         * {@code
450         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, phoneNumber);
451         * }
452         */
453        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
454                "phone_lookup");
455    }
456
457    /**
458     * Additional data mixed in with {@link Im.CommonPresenceColumns} to link
459     * back to specific {@link ContactsContract.Aggregates#_ID} entries.
460     */
461    private interface PresenceColumns {
462        /**
463         * Reference to the {@link Aggregates#_ID} this presence references.
464         */
465        public static final String AGGREGATE_ID = "aggregate_id";
466
467        /**
468         * Reference to the {@link Data#_ID} entry that owns this presence.
469         */
470        public static final String DATA_ID = "data_id";
471
472        /**
473         * The IM service the presence is coming from. Formatted using either
474         * {@link Contacts.ContactMethods#encodePredefinedImProtocol} or
475         * {@link Contacts.ContactMethods#encodeCustomImProtocol}.
476         * <p>
477         * Type: STRING
478         */
479        public static final String IM_PROTOCOL = "im_protocol";
480
481        /**
482         * The IM handle the presence item is for. The handle is scoped to the
483         * {@link #IM_PROTOCOL}.
484         * <p>
485         * Type: STRING
486         */
487        public static final String IM_HANDLE = "im_handle";
488
489        /**
490         * The IM account for the local user that the presence data came from.
491         * <p>
492         * Type: STRING
493         */
494        public static final String IM_ACCOUNT = "im_account";
495    }
496
497    public static final class Presence implements BaseColumns, PresenceColumns,
498            Im.CommonPresenceColumns {
499        /**
500         * This utility class cannot be instantiated
501         */
502        private Presence() {
503        }
504
505        /**
506         * The content:// style URI for this table
507         */
508        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "presence");
509
510        /**
511         * Gets the resource ID for the proper presence icon.
512         *
513         * @param status the status to get the icon for
514         * @return the resource ID for the proper presence icon
515         */
516        public static final int getPresenceIconResourceId(int status) {
517            switch (status) {
518                case AVAILABLE:
519                    return android.R.drawable.presence_online;
520                case IDLE:
521                case AWAY:
522                    return android.R.drawable.presence_away;
523                case DO_NOT_DISTURB:
524                    return android.R.drawable.presence_busy;
525                case INVISIBLE:
526                    return android.R.drawable.presence_invisible;
527                case OFFLINE:
528                default:
529                    return android.R.drawable.presence_offline;
530            }
531        }
532
533        /**
534         * Returns the precedence of the status code the higher number being the higher precedence.
535         *
536         * @param status The status code.
537         * @return An integer representing the precedence, 0 being the lowest.
538         */
539        public static final int getPresencePrecedence(int status) {
540            // Keep this function here incase we want to enforce a different precedence than the
541            // natural order of the status constants.
542            return status;
543        }
544
545        /**
546         * The MIME type of {@link #CONTENT_URI} providing a directory of
547         * presence details.
548         */
549        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/im-presence";
550
551        /**
552         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
553         * presence detail.
554         */
555        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im-presence";
556    }
557
558    /**
559     * Container for definitions of common data types stored in the {@link Data} table.
560     */
561    public static final class CommonDataKinds {
562        /**
563         * The {@link Data#PACKAGE} value for common data that should be shown
564         * using a default style.
565         */
566        public static final String PACKAGE_COMMON = "common";
567
568        /**
569         * Columns common across the specific types.
570         */
571        private interface BaseCommonColumns {
572            /**
573             * The package name that defines this type of data.
574             */
575            public static final String PACKAGE = "package";
576
577            /**
578             * The mime-type of the item represented by this row.
579             */
580            public static final String MIMETYPE = "mimetype";
581
582            /**
583             * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} that this
584             * data belongs to.
585             */
586            public static final String CONTACT_ID = "contact_id";
587        }
588
589        /**
590         * Columns common across the specific types.
591         */
592        private interface CommonColumns {
593            /**
594             * The type of data, for example Home or Work.
595             * <P>Type: INTEGER</P>
596             */
597            public static final String TYPE = "data1";
598
599            /**
600             * The data for the contact method.
601             * <P>Type: TEXT</P>
602             */
603            public static final String DATA = "data2";
604
605            /**
606             * The user defined label for the the contact method.
607             * <P>Type: TEXT</P>
608             */
609            public static final String LABEL = "data3";
610        }
611
612        /**
613         * The base types that all "Typed" data kinds support.
614         */
615        public interface BaseTypes {
616
617            /**
618             * A custom type. The custom label should be supplied by user.
619             */
620            public static int TYPE_CUSTOM = 0;
621        }
622
623        /**
624         * Parts of the name.
625         */
626        public static final class StructuredName {
627            private StructuredName() {}
628
629            /** Mime-type used when storing this in data table. */
630            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
631
632            /**
633             * The given name for the contact.
634             * <P>Type: TEXT</P>
635             */
636            public static final String GIVEN_NAME = "data1";
637
638            /**
639             * The family name for the contact.
640             * <P>Type: TEXT</P>
641             */
642            public static final String FAMILY_NAME = "data2";
643
644            /**
645             * The contact's honorific prefix, e.g. "Sir"
646             * <P>Type: TEXT</P>
647             */
648            public static final String PREFIX = "data3";
649
650            /**
651             * The contact's middle name
652             * <P>Type: TEXT</P>
653             */
654            public static final String MIDDLE_NAME = "data4";
655
656            /**
657             * The contact's honorific suffix, e.g. "Jr"
658             */
659            public static final String SUFFIX = "data5";
660
661            /**
662             * The phonetic version of the given name for the contact.
663             * <P>Type: TEXT</P>
664             */
665            public static final String PHONETIC_GIVEN_NAME = "data6";
666
667            /**
668             * The phonetic version of the additional name for the contact.
669             * <P>Type: TEXT</P>
670             */
671            public static final String PHONETIC_MIDDLE_NAME = "data7";
672
673            /**
674             * The phonetic version of the family name for the contact.
675             * <P>Type: TEXT</P>
676             */
677            public static final String PHONETIC_FAMILY_NAME = "data8";
678
679            /**
680             * The name that should be used to display the contact.
681             * <P>Type: TEXT</P>
682             */
683            public static final String DISPLAY_NAME = "data9";
684        }
685
686        /**
687         * A nickname.
688         */
689        public static final class Nickname implements BaseTypes {
690            private Nickname() {}
691
692            /** Mime-type used when storing this in data table. */
693            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
694
695            /**
696             * The type of data, for example Home or Work.
697             * <P>Type: INTEGER</P>
698             */
699            public static final String TYPE = "data1";
700
701            public static final int TYPE_DEFAULT = 1;
702            public static final int TYPE_OTHER_NAME = 2;
703            public static final int TYPE_MAINDEN_NAME = 3;
704            public static final int TYPE_SHORT_NAME = 4;
705            public static final int TYPE_INITIALS = 5;
706
707            /**
708             * The name itself
709             */
710            public static final String NAME = "data2";
711
712            /**
713             * The user provided label, only used if TYPE is {@link #TYPE_CUSTOM}.
714             * <P>Type: TEXT</P>
715             */
716            public static final String LABEL = "data3";
717        }
718
719        /**
720         * Common data definition for telephone numbers.
721         */
722        public static final class Phone implements BaseCommonColumns, CommonColumns, BaseTypes {
723            private Phone() {}
724
725            /** Mime-type used when storing this in data table. */
726            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone";
727
728            /**
729             * The MIME type of {@link #CONTENT_URI} providing a directory of
730             * phones.
731             */
732            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone";
733
734            /**
735             * The content:// style URI for all data records of the
736             * {@link Phone.CONTENT_ITEM_TYPE} mimetype, combined with the associated contact
737             * and aggregate data.
738             */
739            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
740                    "phones");
741
742            /**
743             * The content:// style URI for filtering data records of the
744             * {@link Phone.CONTENT_ITEM_TYPE} mimetype, combined with the associated contact
745             * and aggregate data. The filter argument should be passed
746             * as an additional path segment after this URI.
747             */
748            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
749                    "filter");
750
751            public static final int TYPE_HOME = 1;
752            public static final int TYPE_MOBILE = 2;
753            public static final int TYPE_WORK = 3;
754            public static final int TYPE_FAX_WORK = 4;
755            public static final int TYPE_FAX_HOME = 5;
756            public static final int TYPE_PAGER = 6;
757            public static final int TYPE_OTHER = 7;
758
759            /**
760             * The phone number as the user entered it.
761             * <P>Type: TEXT</P>
762             */
763            public static final String NUMBER = "data2";
764        }
765
766        /**
767         * Common data definition for email addresses.
768         */
769        public static final class Email implements BaseCommonColumns, CommonColumns, BaseTypes {
770            private Email() {}
771
772            /** Mime-type used when storing this in data table. */
773            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email";
774
775            public static final int TYPE_HOME = 1;
776            public static final int TYPE_WORK = 2;
777            public static final int TYPE_OTHER = 3;
778        }
779
780        /**
781         * Common data definition for postal addresses.
782         */
783        public static final class Postal implements BaseCommonColumns, CommonColumns, BaseTypes {
784            private Postal() {}
785
786            /** Mime-type used when storing this in data table. */
787            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/postal-address";
788
789            /**
790             * The MIME type of {@link #CONTENT_URI} providing a directory of
791             * postal addresses.
792             */
793            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address";
794
795            /**
796             * The content:// style URI for all data records of the
797             * {@link Postal.CONTENT_ITEM_TYPE} mimetype, combined with the associated contact
798             * and aggregate data.
799             */
800            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
801                    "postals");
802
803            public static final int TYPE_HOME = 1;
804            public static final int TYPE_WORK = 2;
805            public static final int TYPE_OTHER = 3;
806        }
807
808       /**
809        * Common data definition for IM addresses.
810        */
811        public static final class Im implements BaseCommonColumns, CommonColumns, BaseTypes {
812            private Im() {}
813
814            /** Mime-type used when storing this in data table. */
815            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
816
817            public static final int TYPE_HOME = 1;
818            public static final int TYPE_WORK = 2;
819            public static final int TYPE_OTHER = 3;
820
821            public static final String PROTOCOL = "data5";
822
823            /**
824             * The predefined IM protocol types. The protocol can either be non-present, one
825             * of these types, or a free-form string. These cases are encoded in the PROTOCOL
826             * column as:
827             * <ul>
828             * <li>null</li>
829             * <li>pre:&lt;an integer, one of the protocols below&gt;</li>
830             * <li>custom:&lt;a string&gt;</li>
831             * </ul>
832             */
833            public static final int PROTOCOL_AIM = 0;
834            public static final int PROTOCOL_MSN = 1;
835            public static final int PROTOCOL_YAHOO = 2;
836            public static final int PROTOCOL_SKYPE = 3;
837            public static final int PROTOCOL_QQ = 4;
838            public static final int PROTOCOL_GOOGLE_TALK = 5;
839            public static final int PROTOCOL_ICQ = 6;
840            public static final int PROTOCOL_JABBER = 7;
841
842            public static String encodePredefinedImProtocol(int protocol) {
843               return "pre:" + protocol;
844            }
845
846            public static String encodeCustomImProtocol(String protocolString) {
847               return "custom:" + protocolString;
848            }
849
850            public static Object decodeImProtocol(String encodedString) {
851               if (encodedString == null) {
852                   return null;
853               }
854
855               if (encodedString.startsWith("pre:")) {
856                   return Integer.parseInt(encodedString.substring(4));
857               }
858
859               if (encodedString.startsWith("custom:")) {
860                   return encodedString.substring(7);
861               }
862
863               throw new IllegalArgumentException(
864                       "the value is not a valid encoded protocol, " + encodedString);
865            }
866        }
867
868        /**
869         * Common data definition for organizations.
870         */
871        public static final class Organization implements BaseCommonColumns, BaseTypes {
872            private Organization() {}
873
874            /** Mime-type used when storing this in data table. */
875            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
876
877            /**
878             * The type of data, for example Home or Work.
879             * <P>Type: INTEGER</P>
880             */
881            public static final String TYPE = "data1";
882
883            public static final int TYPE_HOME = 1;
884            public static final int TYPE_WORK = 2;
885            public static final int TYPE_OTHER = 3;
886
887            /**
888             * The user provided label, only used if TYPE is {@link #TYPE_CUSTOM}.
889             * <P>Type: TEXT</P>
890             */
891            public static final String LABEL = "data2";
892
893            /**
894             * The company as the user entered it.
895             * <P>Type: TEXT</P>
896             */
897            public static final String COMPANY = "data3";
898
899            /**
900             * The position title at this company as the user entered it.
901             * <P>Type: TEXT</P>
902             */
903            public static final String TITLE = "data4";
904        }
905
906        /**
907         * Photo of the contact.
908         */
909        public static final class Photo implements BaseCommonColumns {
910            private Photo() {}
911
912            /** Mime-type used when storing this in data table. */
913            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
914
915            /**
916             * Thumbnail photo of the contact. This is the raw bytes of an image
917             * that could be inflated using {@link BitmapFactory}.
918             * <p>
919             * Type: BLOB
920             */
921            public static final String PHOTO = "data1";
922        }
923
924        /**
925         * Notes about the contact.
926         */
927        public static final class Note implements BaseCommonColumns {
928            private Note() {}
929
930            /** Mime-type used when storing this in data table. */
931            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
932
933            /**
934             * The note text.
935             * <P>Type: TEXT</P>
936             */
937            public static final String NOTE = "data1";
938        }
939
940        /**
941         * Group Membership.
942         */
943        public static final class GroupMembership implements BaseCommonColumns {
944            private GroupMembership() {}
945
946            /** Mime-type used when storing this in data table. */
947            public static final String CONTENT_ITEM_TYPE =
948                    "vnd.android.cursor.item/group_membership";
949
950            /**
951             * The row id of the group that this group membership refers to. Either this or the
952             * GROUP_SOURCE_ID must be set. If they are both set then they must refer to the same
953             * group.
954             * <P>Type: INTEGER</P>
955             */
956            public static final String GROUP_ROW_ID = "data1";
957
958            /**
959             * The source id of the group that this membership refers to. Either this or the
960             * GROUP_ROW_ID must be set. If they are both set then they must refer to the same
961             * group.
962             * <P>Type: STRING</P>
963             */
964            public static final String GROUP_SOURCE_ID = "data2";
965        }
966    }
967
968    /**
969     * Constants for the contact aggregation exceptions table, which contains
970     * aggregation rules overriding those used by automatic aggregation.  This type only
971     * supports query and update. Neither insert nor delete are supported.
972     */
973    public static final class AggregationExceptions implements BaseColumns {
974        /**
975         * This utility class cannot be instantiated
976         */
977        private AggregationExceptions() {}
978
979        /**
980         * The content:// style URI for this table
981         */
982        public static final Uri CONTENT_URI =
983                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
984
985        /**
986         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
987         */
988        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
989
990        /**
991         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
992         */
993        public static final String CONTENT_ITEM_TYPE =
994                "vnd.android.cursor.item/aggregation_exception";
995
996        /**
997         * The type of exception: {@link #TYPE_KEEP_IN}, {@link #TYPE_KEEP_OUT} or
998         * {@link #TYPE_AUTOMATIC}.
999         *
1000         * <P>Type: INTEGER</P>
1001         */
1002        public static final String TYPE = "type";
1003
1004        /**
1005         * Allows the provider to automatically decide whether the aggregate should include
1006         * a particular contact or not.
1007         */
1008        public static final int TYPE_AUTOMATIC = 0;
1009
1010        /**
1011         * Makes sure that the specified contact is included in the specified aggregate.
1012         */
1013        public static final int TYPE_KEEP_IN = 1;
1014
1015        /**
1016         * Makes sure that the specified contact is NOT included in the specified aggregate.
1017         */
1018        public static final int TYPE_KEEP_OUT = 2;
1019
1020        /**
1021         * A reference to the {@link Aggregates#_ID} of the aggregate that the rule applies to.
1022         */
1023        public static final String AGGREGATE_ID = "aggregate_id";
1024
1025        /**
1026         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} of the
1027         * contact that the rule applies to.
1028         */
1029        public static final String CONTACT_ID = "contact_id";
1030    }
1031
1032    private interface RestrictionExceptionsColumns {
1033        /**
1034         * Package name of a specific data provider, which will be matched
1035         * against {@link Data#PACKAGE}.
1036         * <p>
1037         * Type: STRING
1038         */
1039        public static final String PACKAGE_PROVIDER = "package_provider";
1040
1041        /**
1042         * Package name of a specific data client, which will be matched against
1043         * the incoming {@link android.os.Binder#getCallingUid()} to decide if
1044         * the caller can access values with {@link Data#IS_RESTRICTED} flags.
1045         * <p>
1046         * Type: STRING
1047         */
1048        public static final String PACKAGE_CLIENT = "package_client";
1049
1050        /**
1051         * Flag indicating if {@link #PACKAGE_PROVIDER} allows
1052         * {@link #PACKAGE_CLIENT} to access restricted {@link Data} rows.
1053         * <p>
1054         * Type: INTEGER
1055         */
1056        public static final String ALLOW_ACCESS = "allow_access";
1057    }
1058
1059    /**
1060     * Constants for {@link Data} restriction exceptions. Sync adapters who
1061     * insert restricted data can use this table to specify exceptions about
1062     * which additional packages can access that restricted data.You can only
1063     * modify rules for a {@link RestrictionExceptionsColumns#PACKAGE_PROVIDER}
1064     * that your {@link android.os.Binder#getCallingUid()} owns.
1065     */
1066    public static final class RestrictionExceptions implements RestrictionExceptionsColumns {
1067        /**
1068         * This utility class cannot be instantiated
1069         */
1070        private RestrictionExceptions() {}
1071
1072        /**
1073         * The content:// style URI for this table
1074         */
1075        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI,
1076                "restriction_exceptions");
1077    }
1078
1079    /**
1080     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
1081     * that involve contacts.
1082     */
1083    public static final class Intents {
1084        /**
1085         * This is the intent that is fired when a search suggestion is clicked on.
1086         */
1087        public static final String SEARCH_SUGGESTION_CLICKED =
1088                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
1089
1090        /**
1091         * This is the intent that is fired when a search suggestion for dialing a number
1092         * is clicked on.
1093         */
1094        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
1095                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
1096
1097        /**
1098         * This is the intent that is fired when a search suggestion for creating a contact
1099         * is clicked on.
1100         */
1101        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
1102                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
1103
1104        /**
1105         * Starts an Activity that lets the user pick a contact to attach an image to.
1106         * After picking the contact it launches the image cropper in face detection mode.
1107         */
1108        public static final String ATTACH_IMAGE =
1109                "com.android.contacts.action.ATTACH_IMAGE";
1110
1111        /**
1112         * Takes as input a data URI with a mailto: or tel: scheme. If a single
1113         * contact exists with the given data it will be shown. If no contact
1114         * exists, a dialog will ask the user if they want to create a new
1115         * contact with the provided details filled in. If multiple contacts
1116         * share the data the user will be prompted to pick which contact they
1117         * want to view.
1118         * <p>
1119         * For <code>mailto:</code> URIs, the scheme specific portion must be a
1120         * raw email address, such as one built using
1121         * {@link Uri#fromParts(String, String, String)}.
1122         * <p>
1123         * For <code>tel:</code> URIs, the scheme specific portion is compared
1124         * to existing numbers using the standard caller ID lookup algorithm.
1125         * The number must be properly encoded, for example using
1126         * {@link Uri#fromParts(String, String, String)}.
1127         * <p>
1128         * Any extras from the {@link Insert} class will be passed along to the
1129         * create activity if there are no contacts to show.
1130         * <p>
1131         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
1132         * prompting the user when the contact doesn't exist.
1133         */
1134        public static final String SHOW_OR_CREATE_CONTACT =
1135                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
1136
1137        /**
1138         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
1139         * contact if no matching contact found. Otherwise, default behavior is
1140         * to prompt user with dialog before creating.
1141         * <p>
1142         * Type: BOOLEAN
1143         */
1144        public static final String EXTRA_FORCE_CREATE =
1145                "com.android.contacts.action.FORCE_CREATE";
1146
1147        /**
1148         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
1149         * description to be shown when prompting user about creating a new
1150         * contact.
1151         * <p>
1152         * Type: STRING
1153         */
1154        public static final String EXTRA_CREATE_DESCRIPTION =
1155            "com.android.contacts.action.CREATE_DESCRIPTION";
1156
1157        /**
1158         * Intents related to the Contacts app UI.
1159         */
1160        public static final class UI {
1161            /**
1162             * The action for the default contacts list tab.
1163             */
1164            public static final String LIST_DEFAULT =
1165                    "com.android.contacts.action.LIST_DEFAULT";
1166
1167            /**
1168             * The action for the contacts list tab.
1169             */
1170            public static final String LIST_GROUP_ACTION =
1171                    "com.android.contacts.action.LIST_GROUP";
1172
1173            /**
1174             * When in LIST_GROUP_ACTION mode, this is the group to display.
1175             */
1176            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
1177
1178            /**
1179             * The action for the all contacts list tab.
1180             */
1181            public static final String LIST_ALL_CONTACTS_ACTION =
1182                    "com.android.contacts.action.LIST_ALL_CONTACTS";
1183
1184            /**
1185             * The action for the contacts with phone numbers list tab.
1186             */
1187            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
1188                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
1189
1190            /**
1191             * The action for the starred contacts list tab.
1192             */
1193            public static final String LIST_STARRED_ACTION =
1194                    "com.android.contacts.action.LIST_STARRED";
1195
1196            /**
1197             * The action for the frequent contacts list tab.
1198             */
1199            public static final String LIST_FREQUENT_ACTION =
1200                    "com.android.contacts.action.LIST_FREQUENT";
1201
1202            /**
1203             * The action for the "strequent" contacts list tab. It first lists the starred
1204             * contacts in alphabetical order and then the frequent contacts in descending
1205             * order of the number of times they have been contacted.
1206             */
1207            public static final String LIST_STREQUENT_ACTION =
1208                    "com.android.contacts.action.LIST_STREQUENT";
1209
1210            /**
1211             * A key for to be used as an intent extra to set the activity
1212             * title to a custom String value.
1213             */
1214            public static final String TITLE_EXTRA_KEY =
1215                "com.android.contacts.extra.TITLE_EXTRA";
1216
1217            /**
1218             * Activity Action: Display a filtered list of contacts
1219             * <p>
1220             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
1221             * filtering
1222             * <p>
1223             * Output: Nothing.
1224             */
1225            public static final String FILTER_CONTACTS_ACTION =
1226                "com.android.contacts.action.FILTER_CONTACTS";
1227
1228            /**
1229             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
1230             * intents to supply the text on which to filter.
1231             */
1232            public static final String FILTER_TEXT_EXTRA_KEY =
1233                "com.android.contacts.extra.FILTER_TEXT";
1234        }
1235
1236        /**
1237         * Convenience class that contains string constants used
1238         * to create contact {@link android.content.Intent Intents}.
1239         */
1240        public static final class Insert {
1241            /** The action code to use when adding a contact */
1242            public static final String ACTION = Intent.ACTION_INSERT;
1243
1244            /**
1245             * If present, forces a bypass of quick insert mode.
1246             */
1247            public static final String FULL_MODE = "full_mode";
1248
1249            /**
1250             * The extra field for the contact name.
1251             * <P>Type: String</P>
1252             */
1253            public static final String NAME = "name";
1254
1255            // TODO add structured name values here.
1256
1257            /**
1258             * The extra field for the contact phonetic name.
1259             * <P>Type: String</P>
1260             */
1261            public static final String PHONETIC_NAME = "phonetic_name";
1262
1263            /**
1264             * The extra field for the contact company.
1265             * <P>Type: String</P>
1266             */
1267            public static final String COMPANY = "company";
1268
1269            /**
1270             * The extra field for the contact job title.
1271             * <P>Type: String</P>
1272             */
1273            public static final String JOB_TITLE = "job_title";
1274
1275            /**
1276             * The extra field for the contact notes.
1277             * <P>Type: String</P>
1278             */
1279            public static final String NOTES = "notes";
1280
1281            /**
1282             * The extra field for the contact phone number.
1283             * <P>Type: String</P>
1284             */
1285            public static final String PHONE = "phone";
1286
1287            /**
1288             * The extra field for the contact phone number type.
1289             * <P>Type: Either an integer value from
1290             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1291             *  or a string specifying a custom label.</P>
1292             */
1293            public static final String PHONE_TYPE = "phone_type";
1294
1295            /**
1296             * The extra field for the phone isprimary flag.
1297             * <P>Type: boolean</P>
1298             */
1299            public static final String PHONE_ISPRIMARY = "phone_isprimary";
1300
1301            /**
1302             * The extra field for an optional second contact phone number.
1303             * <P>Type: String</P>
1304             */
1305            public static final String SECONDARY_PHONE = "secondary_phone";
1306
1307            /**
1308             * The extra field for an optional second contact phone number type.
1309             * <P>Type: Either an integer value from
1310             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1311             *  or a string specifying a custom label.</P>
1312             */
1313            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
1314
1315            /**
1316             * The extra field for an optional third contact phone number.
1317             * <P>Type: String</P>
1318             */
1319            public static final String TERTIARY_PHONE = "tertiary_phone";
1320
1321            /**
1322             * The extra field for an optional third contact phone number type.
1323             * <P>Type: Either an integer value from
1324             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
1325             *  or a string specifying a custom label.</P>
1326             */
1327            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
1328
1329            /**
1330             * The extra field for the contact email address.
1331             * <P>Type: String</P>
1332             */
1333            public static final String EMAIL = "email";
1334
1335            /**
1336             * The extra field for the contact email type.
1337             * <P>Type: Either an integer value from
1338             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1339             *  or a string specifying a custom label.</P>
1340             */
1341            public static final String EMAIL_TYPE = "email_type";
1342
1343            /**
1344             * The extra field for the email isprimary flag.
1345             * <P>Type: boolean</P>
1346             */
1347            public static final String EMAIL_ISPRIMARY = "email_isprimary";
1348
1349            /**
1350             * The extra field for an optional second contact email address.
1351             * <P>Type: String</P>
1352             */
1353            public static final String SECONDARY_EMAIL = "secondary_email";
1354
1355            /**
1356             * The extra field for an optional second contact email type.
1357             * <P>Type: Either an integer value from
1358             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1359             *  or a string specifying a custom label.</P>
1360             */
1361            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
1362
1363            /**
1364             * The extra field for an optional third contact email address.
1365             * <P>Type: String</P>
1366             */
1367            public static final String TERTIARY_EMAIL = "tertiary_email";
1368
1369            /**
1370             * The extra field for an optional third contact email type.
1371             * <P>Type: Either an integer value from
1372             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1373             *  or a string specifying a custom label.</P>
1374             */
1375            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
1376
1377            /**
1378             * The extra field for the contact postal address.
1379             * <P>Type: String</P>
1380             */
1381            public static final String POSTAL = "postal";
1382
1383            /**
1384             * The extra field for the contact postal address type.
1385             * <P>Type: Either an integer value from
1386             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
1387             *  or a string specifying a custom label.</P>
1388             */
1389            public static final String POSTAL_TYPE = "postal_type";
1390
1391            /**
1392             * The extra field for the postal isprimary flag.
1393             * <P>Type: boolean</P>
1394             */
1395            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
1396
1397            /**
1398             * The extra field for an IM handle.
1399             * <P>Type: String</P>
1400             */
1401            public static final String IM_HANDLE = "im_handle";
1402
1403            /**
1404             * The extra field for the IM protocol
1405             * <P>Type: the result of {@link Contacts.ContactMethods#encodePredefinedImProtocol}
1406             * or {@link Contacts.ContactMethods#encodeCustomImProtocol}.</P>
1407             */
1408            public static final String IM_PROTOCOL = "im_protocol";
1409
1410            /**
1411             * The extra field for the IM isprimary flag.
1412             * <P>Type: boolean</P>
1413             */
1414            public static final String IM_ISPRIMARY = "im_isprimary";
1415        }
1416    }
1417
1418}
1419