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