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