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