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