ContactsContract.java revision 833a9e58ce7d4d9778edf7573a980928284a5a8a
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.app.Activity;
21import android.content.ActivityNotFoundException;
22import android.content.ContentProviderClient;
23import android.content.ContentProviderOperation;
24import android.content.ContentResolver;
25import android.content.ContentUris;
26import android.content.ContentValues;
27import android.content.Context;
28import android.content.ContextWrapper;
29import android.content.CursorEntityIterator;
30import android.content.Entity;
31import android.content.EntityIterator;
32import android.content.Intent;
33import android.content.res.AssetFileDescriptor;
34import android.content.res.Resources;
35import android.database.Cursor;
36import android.database.DatabaseUtils;
37import android.graphics.Rect;
38import android.net.Uri;
39import android.os.RemoteException;
40import android.text.TextUtils;
41import android.util.DisplayMetrics;
42import android.util.Pair;
43import android.view.View;
44import android.widget.Toast;
45
46import java.io.ByteArrayInputStream;
47import java.io.IOException;
48import java.io.InputStream;
49import java.util.ArrayList;
50
51/**
52 * <p>
53 * The contract between the contacts provider and applications. Contains
54 * definitions for the supported URIs and columns. These APIs supersede
55 * {@link Contacts}.
56 * </p>
57 * <h3>Overview</h3>
58 * <p>
59 * ContactsContract defines an extensible database of contact-related
60 * information. Contact information is stored in a three-tier data model:
61 * </p>
62 * <ul>
63 * <li>
64 * A row in the {@link Data} table can store any kind of personal data, such
65 * as a phone number or email addresses.  The set of data kinds that can be
66 * stored in this table is open-ended. There is a predefined set of common
67 * kinds, but any application can add its own data kinds.
68 * </li>
69 * <li>
70 * A row in the {@link RawContacts} table represents a set of data describing a
71 * person and associated with a single account (for example, one of the user's
72 * Gmail accounts).
73 * </li>
74 * <li>
75 * A row in the {@link Contacts} table represents an aggregate of one or more
76 * RawContacts presumably describing the same person.  When data in or associated with
77 * the RawContacts table is changed, the affected aggregate contacts are updated as
78 * necessary.
79 * </li>
80 * </ul>
81 * <p>
82 * Other tables include:
83 * </p>
84 * <ul>
85 * <li>
86 * {@link Groups}, which contains information about raw contact groups
87 * such as Gmail contact groups.  The
88 * current API does not support the notion of groups spanning multiple accounts.
89 * </li>
90 * <li>
91 * {@link StatusUpdates}, which contains social status updates including IM
92 * availability.
93 * </li>
94 * <li>
95 * {@link AggregationExceptions}, which is used for manual aggregation and
96 * disaggregation of raw contacts
97 * </li>
98 * <li>
99 * {@link Settings}, which contains visibility and sync settings for accounts
100 * and groups.
101 * </li>
102 * <li>
103 * {@link SyncState}, which contains free-form data maintained on behalf of sync
104 * adapters
105 * </li>
106 * <li>
107 * {@link PhoneLookup}, which is used for quick caller-ID lookup</li>
108 * </ul>
109 */
110@SuppressWarnings("unused")
111public final class ContactsContract {
112    /** The authority for the contacts provider */
113    public static final String AUTHORITY = "com.android.contacts";
114    /** A content:// style uri to the authority for the contacts provider */
115    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
116
117    /**
118     * An optional URI parameter for insert, update, or delete queries
119     * that allows the caller
120     * to specify that it is a sync adapter. The default value is false. If true
121     * {@link RawContacts#DIRTY} is not automatically set and the
122     * "syncToNetwork" parameter is set to false when calling
123     * {@link
124     * ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}.
125     * This prevents an unnecessary extra synchronization, see the discussion of
126     * the delete operation in {@link RawContacts}.
127     */
128    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
129
130    /**
131     * Query parameter that should be used by the client to access a specific
132     * {@link Directory}. The parameter value should be the _ID of the corresponding
133     * directory, e.g.
134     * {@code content://com.android.contacts/data/emails/filter/acme?directory=3}
135     */
136    public static final String DIRECTORY_PARAM_KEY = "directory";
137
138    /**
139     * A query parameter that limits the number of results returned. The
140     * parameter value should be an integer.
141     */
142    public static final String LIMIT_PARAM_KEY = "limit";
143
144    /**
145     * A query parameter specifing a primary account. This parameter should be used with
146     * {@link #PRIMARY_ACCOUNT_TYPE}. The contacts provider handling a query may rely on
147     * this information to optimize its query results.
148     *
149     * For example, in an email composition screen, its implementation can specify an account when
150     * obtaining possible recipients, letting the provider know which account is selected during
151     * the composition. The provider may use the "primary account" information to optimize
152     * the search result.
153     */
154    public static final String PRIMARY_ACCOUNT_NAME = "name_for_primary_account";
155
156    /**
157     * A query parameter specifing a primary account. This parameter should be used with
158     * {@link #PRIMARY_ACCOUNT_NAME}. See the doc in {@link #PRIMARY_ACCOUNT_NAME}.
159     */
160    public static final String PRIMARY_ACCOUNT_TYPE = "type_for_primary_account";
161
162    /**
163     * A boolean parameter for {@link Contacts#CONTENT_STREQUENT_URI} and
164     * {@link Contacts#CONTENT_STREQUENT_FILTER_URI}, which requires the ContactsProvider to
165     * return only phone-related results. For example, frequently contacted person list should
166     * include persons contacted via phone (not email, sms, etc.)
167     */
168    public static final String STREQUENT_PHONE_ONLY = "strequent_phone_only";
169
170    /**
171     * A key to a boolean in the "extras" bundle of the cursor.
172     * The boolean indicates that the provider did not create a snippet and that the client asking
173     * for the snippet should do it (true means the snippeting was deferred to the client).
174     *
175     * @hide
176     */
177    public static final String DEFERRED_SNIPPETING = "deferred_snippeting";
178
179    /**
180     * Key to retrieve the original query on the client side.
181     *
182     * @hide
183     */
184    public static final String DEFERRED_SNIPPETING_QUERY = "deferred_snippeting_query";
185
186    /**
187     * A boolean parameter for {@link CommonDataKinds.Phone#CONTENT_URI},
188     * {@link CommonDataKinds.Email#CONTENT_URI}, and
189     * {@link CommonDataKinds.StructuredPostal#CONTENT_URI}.
190     * This enables a content provider to remove duplicate entries in results.
191     */
192    public static final String REMOVE_DUPLICATE_ENTRIES = "remove_duplicate_entries";
193
194    /**
195     * <p>
196     * API for obtaining a pre-authorized version of a URI that normally requires special
197     * permission (beyond READ_CONTACTS) to read.  The caller obtaining the pre-authorized URI
198     * must already have the necessary permissions to access the URI; otherwise a
199     * {@link SecurityException} will be thrown.
200     * </p>
201     * <p>
202     * The authorized URI returned in the bundle contains an expiring token that allows the
203     * caller to execute the query without having the special permissions that would normally
204     * be required.
205     * </p>
206     * <p>
207     * This API does not access disk, and should be safe to invoke from the UI thread.
208     * </p>
209     * <p>
210     * Example usage:
211     * <pre>
212     * Uri profileUri = ContactsContract.Profile.CONTENT_VCARD_URI;
213     * Bundle uriBundle = new Bundle();
214     * uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri);
215     * Bundle authResponse = getContext().getContentResolver().call(
216     *         ContactsContract.AUTHORITY_URI,
217     *         ContactsContract.Authorization.AUTHORIZATION_METHOD,
218     *         null, // String arg, not used.
219     *         uriBundle);
220     * if (authResponse != null) {
221     *     Uri preauthorizedProfileUri = (Uri) authResponse.getParcelable(
222     *             ContactsContract.Authorization.KEY_AUTHORIZED_URI);
223     *     // This pre-authorized URI can be queried by a caller without READ_PROFILE
224     *     // permission.
225     * }
226     * </pre>
227     * </p>
228     * @hide
229     */
230    public static final class Authorization {
231        /**
232         * The method to invoke to create a pre-authorized URI out of the input argument.
233         */
234        public static final String AUTHORIZATION_METHOD = "authorize";
235
236        /**
237         * The key to set in the outbound Bundle with the URI that should be authorized.
238         */
239        public static final String KEY_URI_TO_AUTHORIZE = "uri_to_authorize";
240
241        /**
242         * The key to retrieve from the returned Bundle to obtain the pre-authorized URI.
243         */
244        public static final String KEY_AUTHORIZED_URI = "authorized_uri";
245    }
246
247    public static final class Preferences {
248
249        /**
250         * A key in the {@link android.provider.Settings android.provider.Settings} provider
251         * that stores the preferred sorting order for contacts (by given name vs. by family name).
252         */
253        public static final String SORT_ORDER = "android.contacts.SORT_ORDER";
254
255        /**
256         * The value for the SORT_ORDER key corresponding to sorting by given name first.
257         */
258        public static final int SORT_ORDER_PRIMARY = 1;
259
260        /**
261         * The value for the SORT_ORDER key corresponding to sorting by family name first.
262         */
263        public static final int SORT_ORDER_ALTERNATIVE = 2;
264
265        /**
266         * A key in the {@link android.provider.Settings android.provider.Settings} provider
267         * that stores the preferred display order for contacts (given name first vs. family
268         * name first).
269         */
270        public static final String DISPLAY_ORDER = "android.contacts.DISPLAY_ORDER";
271
272        /**
273         * The value for the DISPLAY_ORDER key corresponding to showing the given name first.
274         */
275        public static final int DISPLAY_ORDER_PRIMARY = 1;
276
277        /**
278         * The value for the DISPLAY_ORDER key corresponding to showing the family name first.
279         */
280        public static final int DISPLAY_ORDER_ALTERNATIVE = 2;
281    }
282
283    /**
284     * A Directory represents a contacts corpus, e.g. Local contacts,
285     * Google Apps Global Address List or Corporate Global Address List.
286     * <p>
287     * A Directory is implemented as a content provider with its unique authority and
288     * the same API as the main Contacts Provider.  However, there is no expectation that
289     * every directory provider will implement this Contract in its entirety.  If a
290     * directory provider does not have an implementation for a specific request, it
291     * should throw an UnsupportedOperationException.
292     * </p>
293     * <p>
294     * The most important use case for Directories is search.  A Directory provider is
295     * expected to support at least {@link ContactsContract.Contacts#CONTENT_FILTER_URI
296     * Contacts.CONTENT_FILTER_URI}.  If a Directory provider wants to participate
297     * in email and phone lookup functionalities, it should also implement
298     * {@link CommonDataKinds.Email#CONTENT_FILTER_URI CommonDataKinds.Email.CONTENT_FILTER_URI}
299     * and
300     * {@link CommonDataKinds.Phone#CONTENT_FILTER_URI CommonDataKinds.Phone.CONTENT_FILTER_URI}.
301     * </p>
302     * <p>
303     * A directory provider should return NULL for every projection field it does not
304     * recognize, rather than throwing an exception.  This way it will not be broken
305     * if ContactsContract is extended with new fields in the future.
306     * </p>
307     * <p>
308     * The client interacts with a directory via Contacts Provider by supplying an
309     * optional {@code directory=} query parameter.
310     * <p>
311     * <p>
312     * When the Contacts Provider receives the request, it transforms the URI and forwards
313     * the request to the corresponding directory content provider.
314     * The URI is transformed in the following fashion:
315     * <ul>
316     * <li>The URI authority is replaced with the corresponding {@link #DIRECTORY_AUTHORITY}.</li>
317     * <li>The {@code accountName=} and {@code accountType=} parameters are added or
318     * replaced using the corresponding {@link #ACCOUNT_TYPE} and {@link #ACCOUNT_NAME} values.</li>
319     * </ul>
320     * </p>
321     * <p>
322     * Clients should send directory requests to Contacts Provider and let it
323     * forward them to the respective providers rather than constructing
324     * directory provider URIs by themselves. This level of indirection allows
325     * Contacts Provider to implement additional system-level features and
326     * optimizations. Access to Contacts Provider is protected by the
327     * READ_CONTACTS permission, but access to the directory provider is protected by
328     * BIND_DIRECTORY_SEARCH. This permission was introduced at the API level 17, for previous
329     * platform versions the provider should perform the following check to make sure the call
330     * is coming from the ContactsProvider:
331     * <pre>
332     * private boolean isCallerAllowed() {
333     *   PackageManager pm = getContext().getPackageManager();
334     *   for (String packageName: pm.getPackagesForUid(Binder.getCallingUid())) {
335     *     if (packageName.equals("com.android.providers.contacts")) {
336     *       return true;
337     *     }
338     *   }
339     *   return false;
340     * }
341     * </pre>
342     * </p>
343     * <p>
344     * The Directory table is read-only and is maintained by the Contacts Provider
345     * automatically.
346     * </p>
347     * <p>It always has at least these two rows:
348     * <ul>
349     * <li>
350     * The local directory. It has {@link Directory#_ID Directory._ID} =
351     * {@link Directory#DEFAULT Directory.DEFAULT}. This directory can be used to access locally
352     * stored contacts. The same can be achieved by omitting the {@code directory=}
353     * parameter altogether.
354     * </li>
355     * <li>
356     * The local invisible contacts. The corresponding directory ID is
357     * {@link Directory#LOCAL_INVISIBLE Directory.LOCAL_INVISIBLE}.
358     * </li>
359     * </ul>
360     * </p>
361     * <p>Custom Directories are discovered by the Contacts Provider following this procedure:
362     * <ul>
363     * <li>It finds all installed content providers with meta data identifying them
364     * as directory providers in AndroidManifest.xml:
365     * <code>
366     * &lt;meta-data android:name="android.content.ContactDirectory"
367     *               android:value="true" /&gt;
368     * </code>
369     * <p>
370     * This tag should be placed inside the corresponding content provider declaration.
371     * </p>
372     * </li>
373     * <li>
374     * Then Contacts Provider sends a {@link Directory#CONTENT_URI Directory.CONTENT_URI}
375     * query to each of the directory authorities.  A directory provider must implement
376     * this query and return a list of directories.  Each directory returned by
377     * the provider must have a unique combination for the {@link #ACCOUNT_NAME} and
378     * {@link #ACCOUNT_TYPE} columns (nulls are allowed).  Since directory IDs are assigned
379     * automatically, the _ID field will not be part of the query projection.
380     * </li>
381     * <li>Contacts Provider compiles directory lists received from all directory
382     * providers into one, assigns each individual directory a globally unique ID and
383     * stores all directory records in the Directory table.
384     * </li>
385     * </ul>
386     * </p>
387     * <p>Contacts Provider automatically interrogates newly installed or replaced packages.
388     * Thus simply installing a package containing a directory provider is sufficient
389     * to have that provider registered.  A package supplying a directory provider does
390     * not have to contain launchable activities.
391     * </p>
392     * <p>
393     * Every row in the Directory table is automatically associated with the corresponding package
394     * (apk).  If the package is later uninstalled, all corresponding directory rows
395     * are automatically removed from the Contacts Provider.
396     * </p>
397     * <p>
398     * When the list of directories handled by a directory provider changes
399     * (for instance when the user adds a new Directory account), the directory provider
400     * should call {@link #notifyDirectoryChange} to notify the Contacts Provider of the change.
401     * In response, the Contacts Provider will requery the directory provider to obtain the
402     * new list of directories.
403     * </p>
404     * <p>
405     * A directory row can be optionally associated with an existing account
406     * (see {@link android.accounts.AccountManager}). If the account is later removed,
407     * the corresponding directory rows are automatically removed from the Contacts Provider.
408     * </p>
409     */
410    public static final class Directory implements BaseColumns {
411
412        /**
413         * Not instantiable.
414         */
415        private Directory() {
416        }
417
418        /**
419         * The content:// style URI for this table.  Requests to this URI can be
420         * performed on the UI thread because they are always unblocking.
421         */
422        public static final Uri CONTENT_URI =
423                Uri.withAppendedPath(AUTHORITY_URI, "directories");
424
425        /**
426         * The MIME-type of {@link #CONTENT_URI} providing a directory of
427         * contact directories.
428         */
429        public static final String CONTENT_TYPE =
430                "vnd.android.cursor.dir/contact_directories";
431
432        /**
433         * The MIME type of a {@link #CONTENT_URI} item.
434         */
435        public static final String CONTENT_ITEM_TYPE =
436                "vnd.android.cursor.item/contact_directory";
437
438        /**
439         * _ID of the default directory, which represents locally stored contacts.
440         */
441        public static final long DEFAULT = 0;
442
443        /**
444         * _ID of the directory that represents locally stored invisible contacts.
445         */
446        public static final long LOCAL_INVISIBLE = 1;
447
448        /**
449         * The name of the package that owns this directory. Contacts Provider
450         * fill it in with the name of the package containing the directory provider.
451         * If the package is later uninstalled, the directories it owns are
452         * automatically removed from this table.
453         *
454         * <p>TYPE: TEXT</p>
455         */
456        public static final String PACKAGE_NAME = "packageName";
457
458        /**
459         * The type of directory captured as a resource ID in the context of the
460         * package {@link #PACKAGE_NAME}, e.g. "Corporate Directory"
461         *
462         * <p>TYPE: INTEGER</p>
463         */
464        public static final String TYPE_RESOURCE_ID = "typeResourceId";
465
466        /**
467         * An optional name that can be used in the UI to represent this directory,
468         * e.g. "Acme Corp"
469         * <p>TYPE: text</p>
470         */
471        public static final String DISPLAY_NAME = "displayName";
472
473        /**
474         * <p>
475         * The authority of the Directory Provider. Contacts Provider will
476         * use this authority to forward requests to the directory provider.
477         * A directory provider can leave this column empty - Contacts Provider will fill it in.
478         * </p>
479         * <p>
480         * Clients of this API should not send requests directly to this authority.
481         * All directory requests must be routed through Contacts Provider.
482         * </p>
483         *
484         * <p>TYPE: text</p>
485         */
486        public static final String DIRECTORY_AUTHORITY = "authority";
487
488        /**
489         * The account type which this directory is associated.
490         *
491         * <p>TYPE: text</p>
492         */
493        public static final String ACCOUNT_TYPE = "accountType";
494
495        /**
496         * The account with which this directory is associated. If the account is later
497         * removed, the directories it owns are automatically removed from this table.
498         *
499         * <p>TYPE: text</p>
500         */
501        public static final String ACCOUNT_NAME = "accountName";
502
503        /**
504         * One of {@link #EXPORT_SUPPORT_NONE}, {@link #EXPORT_SUPPORT_ANY_ACCOUNT},
505         * {@link #EXPORT_SUPPORT_SAME_ACCOUNT_ONLY}. This is the expectation the
506         * directory has for data exported from it.  Clients must obey this setting.
507         */
508        public static final String EXPORT_SUPPORT = "exportSupport";
509
510        /**
511         * An {@link #EXPORT_SUPPORT} setting that indicates that the directory
512         * does not allow any data to be copied out of it.
513         */
514        public static final int EXPORT_SUPPORT_NONE = 0;
515
516        /**
517         * An {@link #EXPORT_SUPPORT} setting that indicates that the directory
518         * allow its data copied only to the account specified by
519         * {@link #ACCOUNT_TYPE}/{@link #ACCOUNT_NAME}.
520         */
521        public static final int EXPORT_SUPPORT_SAME_ACCOUNT_ONLY = 1;
522
523        /**
524         * An {@link #EXPORT_SUPPORT} setting that indicates that the directory
525         * allow its data copied to any contacts account.
526         */
527        public static final int EXPORT_SUPPORT_ANY_ACCOUNT = 2;
528
529        /**
530         * One of {@link #SHORTCUT_SUPPORT_NONE}, {@link #SHORTCUT_SUPPORT_DATA_ITEMS_ONLY},
531         * {@link #SHORTCUT_SUPPORT_FULL}. This is the expectation the directory
532         * has for shortcuts created for its elements. Clients must obey this setting.
533         */
534        public static final String SHORTCUT_SUPPORT = "shortcutSupport";
535
536        /**
537         * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory
538         * does not allow any shortcuts created for its contacts.
539         */
540        public static final int SHORTCUT_SUPPORT_NONE = 0;
541
542        /**
543         * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory
544         * allow creation of shortcuts for data items like email, phone or postal address,
545         * but not the entire contact.
546         */
547        public static final int SHORTCUT_SUPPORT_DATA_ITEMS_ONLY = 1;
548
549        /**
550         * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory
551         * allow creation of shortcuts for contact as well as their constituent elements.
552         */
553        public static final int SHORTCUT_SUPPORT_FULL = 2;
554
555        /**
556         * One of {@link #PHOTO_SUPPORT_NONE}, {@link #PHOTO_SUPPORT_THUMBNAIL_ONLY},
557         * {@link #PHOTO_SUPPORT_FULL}. This is a feature flag indicating the extent
558         * to which the directory supports contact photos.
559         */
560        public static final String PHOTO_SUPPORT = "photoSupport";
561
562        /**
563         * An {@link #PHOTO_SUPPORT} setting that indicates that the directory
564         * does not provide any photos.
565         */
566        public static final int PHOTO_SUPPORT_NONE = 0;
567
568        /**
569         * An {@link #PHOTO_SUPPORT} setting that indicates that the directory
570         * can only produce small size thumbnails of contact photos.
571         */
572        public static final int PHOTO_SUPPORT_THUMBNAIL_ONLY = 1;
573
574        /**
575         * An {@link #PHOTO_SUPPORT} setting that indicates that the directory
576         * has full-size contact photos, but cannot provide scaled thumbnails.
577         */
578        public static final int PHOTO_SUPPORT_FULL_SIZE_ONLY = 2;
579
580        /**
581         * An {@link #PHOTO_SUPPORT} setting that indicates that the directory
582         * can produce thumbnails as well as full-size contact photos.
583         */
584        public static final int PHOTO_SUPPORT_FULL = 3;
585
586        /**
587         * Notifies the system of a change in the list of directories handled by
588         * a particular directory provider. The Contacts provider will turn around
589         * and send a query to the directory provider for the full list of directories,
590         * which will replace the previous list.
591         */
592        public static void notifyDirectoryChange(ContentResolver resolver) {
593            // This is done to trigger a query by Contacts Provider back to the directory provider.
594            // No data needs to be sent back, because the provider can infer the calling
595            // package from binder.
596            ContentValues contentValues = new ContentValues();
597            resolver.update(Directory.CONTENT_URI, contentValues, null, null);
598        }
599    }
600
601    /**
602     * @hide should be removed when users are updated to refer to SyncState
603     * @deprecated use SyncState instead
604     */
605    @Deprecated
606    public interface SyncStateColumns extends SyncStateContract.Columns {
607    }
608
609    /**
610     * A table provided for sync adapters to use for storing private sync state data for contacts.
611     *
612     * @see SyncStateContract
613     */
614    public static final class SyncState implements SyncStateContract.Columns {
615        /**
616         * This utility class cannot be instantiated
617         */
618        private SyncState() {}
619
620        public static final String CONTENT_DIRECTORY =
621                SyncStateContract.Constants.CONTENT_DIRECTORY;
622
623        /**
624         * The content:// style URI for this table
625         */
626        public static final Uri CONTENT_URI =
627                Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY);
628
629        /**
630         * @see android.provider.SyncStateContract.Helpers#get
631         */
632        public static byte[] get(ContentProviderClient provider, Account account)
633                throws RemoteException {
634            return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
635        }
636
637        /**
638         * @see android.provider.SyncStateContract.Helpers#get
639         */
640        public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account)
641                throws RemoteException {
642            return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account);
643        }
644
645        /**
646         * @see android.provider.SyncStateContract.Helpers#set
647         */
648        public static void set(ContentProviderClient provider, Account account, byte[] data)
649                throws RemoteException {
650            SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
651        }
652
653        /**
654         * @see android.provider.SyncStateContract.Helpers#newSetOperation
655         */
656        public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
657            return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
658        }
659    }
660
661
662    /**
663     * A table provided for sync adapters to use for storing private sync state data for the
664     * user's personal profile.
665     *
666     * @see SyncStateContract
667     */
668    public static final class ProfileSyncState implements SyncStateContract.Columns {
669        /**
670         * This utility class cannot be instantiated
671         */
672        private ProfileSyncState() {}
673
674        public static final String CONTENT_DIRECTORY =
675                SyncStateContract.Constants.CONTENT_DIRECTORY;
676
677        /**
678         * The content:// style URI for this table
679         */
680        public static final Uri CONTENT_URI =
681                Uri.withAppendedPath(Profile.CONTENT_URI, CONTENT_DIRECTORY);
682
683        /**
684         * @see android.provider.SyncStateContract.Helpers#get
685         */
686        public static byte[] get(ContentProviderClient provider, Account account)
687                throws RemoteException {
688            return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
689        }
690
691        /**
692         * @see android.provider.SyncStateContract.Helpers#get
693         */
694        public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account)
695                throws RemoteException {
696            return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account);
697        }
698
699        /**
700         * @see android.provider.SyncStateContract.Helpers#set
701         */
702        public static void set(ContentProviderClient provider, Account account, byte[] data)
703                throws RemoteException {
704            SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
705        }
706
707        /**
708         * @see android.provider.SyncStateContract.Helpers#newSetOperation
709         */
710        public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
711            return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
712        }
713    }
714
715    /**
716     * Generic columns for use by sync adapters. The specific functions of
717     * these columns are private to the sync adapter. Other clients of the API
718     * should not attempt to either read or write this column.
719     *
720     * @see RawContacts
721     * @see Groups
722     */
723    protected interface BaseSyncColumns {
724
725        /** Generic column for use by sync adapters. */
726        public static final String SYNC1 = "sync1";
727        /** Generic column for use by sync adapters. */
728        public static final String SYNC2 = "sync2";
729        /** Generic column for use by sync adapters. */
730        public static final String SYNC3 = "sync3";
731        /** Generic column for use by sync adapters. */
732        public static final String SYNC4 = "sync4";
733    }
734
735    /**
736     * Columns that appear when each row of a table belongs to a specific
737     * account, including sync information that an account may need.
738     *
739     * @see RawContacts
740     * @see Groups
741     */
742    protected interface SyncColumns extends BaseSyncColumns {
743        /**
744         * The name of the account instance to which this row belongs, which when paired with
745         * {@link #ACCOUNT_TYPE} identifies a specific account.
746         * <P>Type: TEXT</P>
747         */
748        public static final String ACCOUNT_NAME = "account_name";
749
750        /**
751         * The type of account to which this row belongs, which when paired with
752         * {@link #ACCOUNT_NAME} identifies a specific account.
753         * <P>Type: TEXT</P>
754         */
755        public static final String ACCOUNT_TYPE = "account_type";
756
757        /**
758         * String that uniquely identifies this row to its source account.
759         * <P>Type: TEXT</P>
760         */
761        public static final String SOURCE_ID = "sourceid";
762
763        /**
764         * Version number that is updated whenever this row or its related data
765         * changes.
766         * <P>Type: INTEGER</P>
767         */
768        public static final String VERSION = "version";
769
770        /**
771         * Flag indicating that {@link #VERSION} has changed, and this row needs
772         * to be synchronized by its owning account.
773         * <P>Type: INTEGER (boolean)</P>
774         */
775        public static final String DIRTY = "dirty";
776    }
777
778    /**
779     * Columns of {@link ContactsContract.Contacts} that track the user's
780     * preferences for, or interactions with, the contact.
781     *
782     * @see Contacts
783     * @see RawContacts
784     * @see ContactsContract.Data
785     * @see PhoneLookup
786     * @see ContactsContract.Contacts.AggregationSuggestions
787     */
788    protected interface ContactOptionsColumns {
789        /**
790         * The number of times a contact has been contacted
791         * <P>Type: INTEGER</P>
792         */
793        public static final String TIMES_CONTACTED = "times_contacted";
794
795        /**
796         * The last time a contact was contacted.
797         * <P>Type: INTEGER</P>
798         */
799        public static final String LAST_TIME_CONTACTED = "last_time_contacted";
800
801        /**
802         * Is the contact starred?
803         * <P>Type: INTEGER (boolean)</P>
804         */
805        public static final String STARRED = "starred";
806
807        /**
808         * The position at which the contact is pinned. If {@link PinnedPositions#UNPINNED},
809         * the contact is not pinned. Also see {@link PinnedPositions}.
810         * <P>Type: INTEGER </P>
811         */
812        public static final String PINNED = "pinned";
813
814        /**
815         * URI for a custom ringtone associated with the contact. If null or missing,
816         * the default ringtone is used.
817         * <P>Type: TEXT (URI to the ringtone)</P>
818         */
819        public static final String CUSTOM_RINGTONE = "custom_ringtone";
820
821        /**
822         * Whether the contact should always be sent to voicemail. If missing,
823         * defaults to false.
824         * <P>Type: INTEGER (0 for false, 1 for true)</P>
825         */
826        public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
827    }
828
829    /**
830     * Columns of {@link ContactsContract.Contacts} that refer to intrinsic
831     * properties of the contact, as opposed to the user-specified options
832     * found in {@link ContactOptionsColumns}.
833     *
834     * @see Contacts
835     * @see ContactsContract.Data
836     * @see PhoneLookup
837     * @see ContactsContract.Contacts.AggregationSuggestions
838     */
839    protected interface ContactsColumns {
840        /**
841         * The display name for the contact.
842         * <P>Type: TEXT</P>
843         */
844        public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY;
845
846        /**
847         * Reference to the row in the RawContacts table holding the contact name.
848         * <P>Type: INTEGER REFERENCES raw_contacts(_id)</P>
849         * @hide
850         */
851        public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id";
852
853        /**
854         * Reference to the row in the data table holding the photo.  A photo can
855         * be referred to either by ID (this field) or by URI (see {@link #PHOTO_THUMBNAIL_URI}
856         * and {@link #PHOTO_URI}).
857         * If PHOTO_ID is null, consult {@link #PHOTO_URI} or {@link #PHOTO_THUMBNAIL_URI},
858         * which is a more generic mechanism for referencing the contact photo, especially for
859         * contacts returned by non-local directories (see {@link Directory}).
860         *
861         * <P>Type: INTEGER REFERENCES data(_id)</P>
862         */
863        public static final String PHOTO_ID = "photo_id";
864
865        /**
866         * Photo file ID of the full-size photo.  If present, this will be used to populate
867         * {@link #PHOTO_URI}.  The ID can also be used with
868         * {@link ContactsContract.DisplayPhoto#CONTENT_URI} to create a URI to the photo.
869         * If this is present, {@link #PHOTO_ID} is also guaranteed to be populated.
870         *
871         * <P>Type: INTEGER</P>
872         */
873        public static final String PHOTO_FILE_ID = "photo_file_id";
874
875        /**
876         * A URI that can be used to retrieve the contact's full-size photo.
877         * If PHOTO_FILE_ID is not null, this will be populated with a URI based off
878         * {@link ContactsContract.DisplayPhoto#CONTENT_URI}.  Otherwise, this will
879         * be populated with the same value as {@link #PHOTO_THUMBNAIL_URI}.
880         * A photo can be referred to either by a URI (this field) or by ID
881         * (see {@link #PHOTO_ID}). If either PHOTO_FILE_ID or PHOTO_ID is not null,
882         * PHOTO_URI and PHOTO_THUMBNAIL_URI shall not be null (but not necessarily
883         * vice versa).  Thus using PHOTO_URI is a more robust method of retrieving
884         * contact photos.
885         *
886         * <P>Type: TEXT</P>
887         */
888        public static final String PHOTO_URI = "photo_uri";
889
890        /**
891         * A URI that can be used to retrieve a thumbnail of the contact's photo.
892         * A photo can be referred to either by a URI (this field or {@link #PHOTO_URI})
893         * or by ID (see {@link #PHOTO_ID}). If PHOTO_ID is not null, PHOTO_URI and
894         * PHOTO_THUMBNAIL_URI shall not be null (but not necessarily vice versa).
895         * If the content provider does not differentiate between full-size photos
896         * and thumbnail photos, PHOTO_THUMBNAIL_URI and {@link #PHOTO_URI} can contain
897         * the same value, but either both shall be null or both not null.
898         *
899         * <P>Type: TEXT</P>
900         */
901        public static final String PHOTO_THUMBNAIL_URI = "photo_thumb_uri";
902
903        /**
904         * Flag that reflects the {@link Groups#GROUP_VISIBLE} state of any
905         * {@link CommonDataKinds.GroupMembership} for this contact.
906         */
907        public static final String IN_VISIBLE_GROUP = "in_visible_group";
908
909        /**
910         * Flag that reflects whether this contact represents the user's
911         * personal profile entry.
912         */
913        public static final String IS_USER_PROFILE = "is_user_profile";
914
915        /**
916         * An indicator of whether this contact has at least one phone number. "1" if there is
917         * at least one phone number, "0" otherwise.
918         * <P>Type: INTEGER</P>
919         */
920        public static final String HAS_PHONE_NUMBER = "has_phone_number";
921
922        /**
923         * An opaque value that contains hints on how to find the contact if
924         * its row id changed as a result of a sync or aggregation.
925         */
926        public static final String LOOKUP_KEY = "lookup";
927
928        /**
929         * Timestamp (milliseconds since epoch) of when this contact was last updated.  This
930         * includes updates to all data associated with this contact including raw contacts.  Any
931         * modification (including deletes and inserts) of underlying contact data are also
932         * reflected in this timestamp.
933         */
934        public static final String CONTACT_LAST_UPDATED_TIMESTAMP =
935                "contact_last_updated_timestamp";
936    }
937
938    /**
939     * @see Contacts
940     */
941    protected interface ContactStatusColumns {
942        /**
943         * Contact presence status. See {@link StatusUpdates} for individual status
944         * definitions.
945         * <p>Type: NUMBER</p>
946         */
947        public static final String CONTACT_PRESENCE = "contact_presence";
948
949        /**
950         * Contact Chat Capabilities. See {@link StatusUpdates} for individual
951         * definitions.
952         * <p>Type: NUMBER</p>
953         */
954        public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability";
955
956        /**
957         * Contact's latest status update.
958         * <p>Type: TEXT</p>
959         */
960        public static final String CONTACT_STATUS = "contact_status";
961
962        /**
963         * The absolute time in milliseconds when the latest status was
964         * inserted/updated.
965         * <p>Type: NUMBER</p>
966         */
967        public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts";
968
969        /**
970         * The package containing resources for this status: label and icon.
971         * <p>Type: TEXT</p>
972         */
973        public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package";
974
975        /**
976         * The resource ID of the label describing the source of contact
977         * status, e.g. "Google Talk". This resource is scoped by the
978         * {@link #CONTACT_STATUS_RES_PACKAGE}.
979         * <p>Type: NUMBER</p>
980         */
981        public static final String CONTACT_STATUS_LABEL = "contact_status_label";
982
983        /**
984         * The resource ID of the icon for the source of contact status. This
985         * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.
986         * <p>Type: NUMBER</p>
987         */
988        public static final String CONTACT_STATUS_ICON = "contact_status_icon";
989    }
990
991    /**
992     * Constants for various styles of combining given name, family name etc into
993     * a full name.  For example, the western tradition follows the pattern
994     * 'given name' 'middle name' 'family name' with the alternative pattern being
995     * 'family name', 'given name' 'middle name'.  The CJK tradition is
996     * 'family name' 'middle name' 'given name', with Japanese favoring a space between
997     * the names and Chinese omitting the space.
998     */
999    public interface FullNameStyle {
1000        public static final int UNDEFINED = 0;
1001        public static final int WESTERN = 1;
1002
1003        /**
1004         * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine
1005         * which specific language it belongs to: Chinese, Japanese or Korean.
1006         */
1007        public static final int CJK = 2;
1008
1009        public static final int CHINESE = 3;
1010        public static final int JAPANESE = 4;
1011        public static final int KOREAN = 5;
1012    }
1013
1014    /**
1015     * Constants for various styles of capturing the pronunciation of a person's name.
1016     */
1017    public interface PhoneticNameStyle {
1018        public static final int UNDEFINED = 0;
1019
1020        /**
1021         * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly
1022         * shown in UIs, but used for searches and sorting.
1023         */
1024        public static final int PINYIN = 3;
1025
1026        /**
1027         * Hiragana and Katakana are two common styles of writing out the pronunciation
1028         * of a Japanese names.
1029         */
1030        public static final int JAPANESE = 4;
1031
1032        /**
1033         * Hangul is the Korean phonetic alphabet.
1034         */
1035        public static final int KOREAN = 5;
1036    }
1037
1038    /**
1039     * Types of data used to produce the display name for a contact. In the order
1040     * of increasing priority: {@link #EMAIL}, {@link #PHONE},
1041     * {@link #ORGANIZATION}, {@link #NICKNAME}, {@link #STRUCTURED_NAME}.
1042     */
1043    public interface DisplayNameSources {
1044        public static final int UNDEFINED = 0;
1045        public static final int EMAIL = 10;
1046        public static final int PHONE = 20;
1047        public static final int ORGANIZATION = 30;
1048        public static final int NICKNAME = 35;
1049        public static final int STRUCTURED_NAME = 40;
1050    }
1051
1052    /**
1053     * Contact name and contact name metadata columns in the RawContacts table.
1054     *
1055     * @see Contacts
1056     * @see RawContacts
1057     */
1058    protected interface ContactNameColumns {
1059
1060        /**
1061         * The kind of data that is used as the display name for the contact, such as
1062         * structured name or email address.  See {@link DisplayNameSources}.
1063         */
1064        public static final String DISPLAY_NAME_SOURCE = "display_name_source";
1065
1066        /**
1067         * <p>
1068         * The standard text shown as the contact's display name, based on the best
1069         * available information for the contact (for example, it might be the email address
1070         * if the name is not available).
1071         * The information actually used to compute the name is stored in
1072         * {@link #DISPLAY_NAME_SOURCE}.
1073         * </p>
1074         * <p>
1075         * A contacts provider is free to choose whatever representation makes most
1076         * sense for its target market.
1077         * For example in the default Android Open Source Project implementation,
1078         * if the display name is
1079         * based on the structured name and the structured name follows
1080         * the Western full-name style, then this field contains the "given name first"
1081         * version of the full name.
1082         * <p>
1083         *
1084         * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE
1085         */
1086        public static final String DISPLAY_NAME_PRIMARY = "display_name";
1087
1088        /**
1089         * <p>
1090         * An alternative representation of the display name, such as "family name first"
1091         * instead of "given name first" for Western names.  If an alternative is not
1092         * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}.
1093         * </p>
1094         * <p>
1095         * A contacts provider is free to provide alternatives as necessary for
1096         * its target market.
1097         * For example the default Android Open Source Project contacts provider
1098         * currently provides an
1099         * alternative in a single case:  if the display name is
1100         * based on the structured name and the structured name follows
1101         * the Western full name style, then the field contains the "family name first"
1102         * version of the full name.
1103         * Other cases may be added later.
1104         * </p>
1105         */
1106        public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt";
1107
1108        /**
1109         * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}.  See
1110         * {@link PhoneticNameStyle}.
1111         */
1112        public static final String PHONETIC_NAME_STYLE = "phonetic_name_style";
1113
1114        /**
1115         * <p>
1116         * Pronunciation of the full name in the phonetic alphabet specified by
1117         * {@link #PHONETIC_NAME_STYLE}.
1118         * </p>
1119         * <p>
1120         * The value may be set manually by the user. This capability is of
1121         * interest only in countries with commonly used phonetic alphabets,
1122         * such as Japan and Korea. See {@link PhoneticNameStyle}.
1123         * </p>
1124         */
1125        public static final String PHONETIC_NAME = "phonetic_name";
1126
1127        /**
1128         * Sort key that takes into account locale-based traditions for sorting
1129         * names in address books.  The default
1130         * sort key is {@link #DISPLAY_NAME_PRIMARY}.  For Chinese names
1131         * the sort key is the name's Pinyin spelling, and for Japanese names
1132         * it is the Hiragana version of the phonetic name.
1133         */
1134        public static final String SORT_KEY_PRIMARY = "sort_key";
1135
1136        /**
1137         * Sort key based on the alternative representation of the full name,
1138         * {@link #DISPLAY_NAME_ALTERNATIVE}.  Thus for Western names,
1139         * it is the one using the "family name first" format.
1140         */
1141        public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt";
1142    }
1143
1144    /**
1145     * URI parameter and cursor extras that return counts of rows grouped by the
1146     * address book index, which is usually the first letter of the sort key.
1147     * When this parameter is supplied, the row counts are returned in the
1148     * cursor extras bundle.
1149     *
1150     * @hide
1151     */
1152    public final static class ContactCounts {
1153
1154        /**
1155         * Add this query parameter to a URI to get back row counts grouped by
1156         * the address book index as cursor extras. For most languages it is the
1157         * first letter of the sort key. This parameter does not affect the main
1158         * content of the cursor.
1159         *
1160         * @hide
1161         */
1162        public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras";
1163
1164        /**
1165         * The array of address book index titles, which are returned in the
1166         * same order as the data in the cursor.
1167         * <p>TYPE: String[]</p>
1168         *
1169         * @hide
1170         */
1171        public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles";
1172
1173        /**
1174         * The array of group counts for the corresponding group.  Contains the same number
1175         * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array.
1176         * <p>TYPE: int[]</p>
1177         *
1178         * @hide
1179         */
1180        public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts";
1181    }
1182
1183    /**
1184     * Constants for the contacts table, which contains a record per aggregate
1185     * of raw contacts representing the same person.
1186     * <h3>Operations</h3>
1187     * <dl>
1188     * <dt><b>Insert</b></dt>
1189     * <dd>A Contact cannot be created explicitly. When a raw contact is
1190     * inserted, the provider will first try to find a Contact representing the
1191     * same person. If one is found, the raw contact's
1192     * {@link RawContacts#CONTACT_ID} column gets the _ID of the aggregate
1193     * Contact. If no match is found, the provider automatically inserts a new
1194     * Contact and puts its _ID into the {@link RawContacts#CONTACT_ID} column
1195     * of the newly inserted raw contact.</dd>
1196     * <dt><b>Update</b></dt>
1197     * <dd>Only certain columns of Contact are modifiable:
1198     * {@link #TIMES_CONTACTED}, {@link #LAST_TIME_CONTACTED}, {@link #STARRED},
1199     * {@link #CUSTOM_RINGTONE}, {@link #SEND_TO_VOICEMAIL}. Changing any of
1200     * these columns on the Contact also changes them on all constituent raw
1201     * contacts.</dd>
1202     * <dt><b>Delete</b></dt>
1203     * <dd>Be careful with deleting Contacts! Deleting an aggregate contact
1204     * deletes all constituent raw contacts. The corresponding sync adapters
1205     * will notice the deletions of their respective raw contacts and remove
1206     * them from their back end storage.</dd>
1207     * <dt><b>Query</b></dt>
1208     * <dd>
1209     * <ul>
1210     * <li>If you need to read an individual contact, consider using
1211     * {@link #CONTENT_LOOKUP_URI} instead of {@link #CONTENT_URI}.</li>
1212     * <li>If you need to look up a contact by the phone number, use
1213     * {@link PhoneLookup#CONTENT_FILTER_URI PhoneLookup.CONTENT_FILTER_URI},
1214     * which is optimized for this purpose.</li>
1215     * <li>If you need to look up a contact by partial name, e.g. to produce
1216     * filter-as-you-type suggestions, use the {@link #CONTENT_FILTER_URI} URI.
1217     * <li>If you need to look up a contact by some data element like email
1218     * address, nickname, etc, use a query against the {@link ContactsContract.Data} table.
1219     * The result will contain contact ID, name etc.
1220     * </ul>
1221     * </dd>
1222     * </dl>
1223     * <h2>Columns</h2>
1224     * <table class="jd-sumtable">
1225     * <tr>
1226     * <th colspan='4'>Contacts</th>
1227     * </tr>
1228     * <tr>
1229     * <td>long</td>
1230     * <td>{@link #_ID}</td>
1231     * <td>read-only</td>
1232     * <td>Row ID. Consider using {@link #LOOKUP_KEY} instead.</td>
1233     * </tr>
1234     * <tr>
1235     * <td>String</td>
1236     * <td>{@link #LOOKUP_KEY}</td>
1237     * <td>read-only</td>
1238     * <td>An opaque value that contains hints on how to find the contact if its
1239     * row id changed as a result of a sync or aggregation.</td>
1240     * </tr>
1241     * <tr>
1242     * <td>long</td>
1243     * <td>NAME_RAW_CONTACT_ID</td>
1244     * <td>read-only</td>
1245     * <td>The ID of the raw contact that contributes the display name
1246     * to the aggregate contact. During aggregation one of the constituent
1247     * raw contacts is chosen using a heuristic: a longer name or a name
1248     * with more diacritic marks or more upper case characters is chosen.</td>
1249     * </tr>
1250     * <tr>
1251     * <td>String</td>
1252     * <td>DISPLAY_NAME_PRIMARY</td>
1253     * <td>read-only</td>
1254     * <td>The display name for the contact. It is the display name
1255     * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID
1256     * column.</td>
1257     * </tr>
1258     * <tr>
1259     * <td>long</td>
1260     * <td>{@link #PHOTO_ID}</td>
1261     * <td>read-only</td>
1262     * <td>Reference to the row in the {@link ContactsContract.Data} table holding the photo.
1263     * That row has the mime type
1264     * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field
1265     * is computed automatically based on the
1266     * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of
1267     * that mime type.</td>
1268     * </tr>
1269     * <tr>
1270     * <td>long</td>
1271     * <td>{@link #PHOTO_URI}</td>
1272     * <td>read-only</td>
1273     * <td>A URI that can be used to retrieve the contact's full-size photo. This
1274     * column is the preferred method of retrieving the contact photo.</td>
1275     * </tr>
1276     * <tr>
1277     * <td>long</td>
1278     * <td>{@link #PHOTO_THUMBNAIL_URI}</td>
1279     * <td>read-only</td>
1280     * <td>A URI that can be used to retrieve the thumbnail of contact's photo.  This
1281     * column is the preferred method of retrieving the contact photo.</td>
1282     * </tr>
1283     * <tr>
1284     * <td>int</td>
1285     * <td>{@link #IN_VISIBLE_GROUP}</td>
1286     * <td>read-only</td>
1287     * <td>An indicator of whether this contact is supposed to be visible in the
1288     * UI. "1" if the contact has at least one raw contact that belongs to a
1289     * visible group; "0" otherwise.</td>
1290     * </tr>
1291     * <tr>
1292     * <td>int</td>
1293     * <td>{@link #HAS_PHONE_NUMBER}</td>
1294     * <td>read-only</td>
1295     * <td>An indicator of whether this contact has at least one phone number.
1296     * "1" if there is at least one phone number, "0" otherwise.</td>
1297     * </tr>
1298     * <tr>
1299     * <td>int</td>
1300     * <td>{@link #TIMES_CONTACTED}</td>
1301     * <td>read/write</td>
1302     * <td>The number of times the contact has been contacted. See
1303     * {@link #markAsContacted}. When raw contacts are aggregated, this field is
1304     * computed automatically as the maximum number of times contacted among all
1305     * constituent raw contacts. Setting this field automatically changes the
1306     * corresponding field on all constituent raw contacts.</td>
1307     * </tr>
1308     * <tr>
1309     * <td>long</td>
1310     * <td>{@link #LAST_TIME_CONTACTED}</td>
1311     * <td>read/write</td>
1312     * <td>The timestamp of the last time the contact was contacted. See
1313     * {@link #markAsContacted}. Setting this field also automatically
1314     * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated,
1315     * this field is computed automatically as the latest time contacted of all
1316     * constituent raw contacts. Setting this field automatically changes the
1317     * corresponding field on all constituent raw contacts.</td>
1318     * </tr>
1319     * <tr>
1320     * <td>int</td>
1321     * <td>{@link #STARRED}</td>
1322     * <td>read/write</td>
1323     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
1324     * When raw contacts are aggregated, this field is automatically computed:
1325     * if any constituent raw contacts are starred, then this field is set to
1326     * '1'. Setting this field automatically changes the corresponding field on
1327     * all constituent raw contacts.</td>
1328     * </tr>
1329     * <tr>
1330     * <td>String</td>
1331     * <td>{@link #CUSTOM_RINGTONE}</td>
1332     * <td>read/write</td>
1333     * <td>A custom ringtone associated with a contact. Typically this is the
1334     * URI returned by an activity launched with the
1335     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.</td>
1336     * </tr>
1337     * <tr>
1338     * <td>int</td>
1339     * <td>{@link #SEND_TO_VOICEMAIL}</td>
1340     * <td>read/write</td>
1341     * <td>An indicator of whether calls from this contact should be forwarded
1342     * directly to voice mail ('1') or not ('0'). When raw contacts are
1343     * aggregated, this field is automatically computed: if <i>all</i>
1344     * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set
1345     * to '1'. Setting this field automatically changes the corresponding field
1346     * on all constituent raw contacts.</td>
1347     * </tr>
1348     * <tr>
1349     * <td>int</td>
1350     * <td>{@link #CONTACT_PRESENCE}</td>
1351     * <td>read-only</td>
1352     * <td>Contact IM presence status. See {@link StatusUpdates} for individual
1353     * status definitions. Automatically computed as the highest presence of all
1354     * constituent raw contacts. The provider may choose not to store this value
1355     * in persistent storage. The expectation is that presence status will be
1356     * updated on a regular basis.</td>
1357     * </tr>
1358     * <tr>
1359     * <td>String</td>
1360     * <td>{@link #CONTACT_STATUS}</td>
1361     * <td>read-only</td>
1362     * <td>Contact's latest status update. Automatically computed as the latest
1363     * of all constituent raw contacts' status updates.</td>
1364     * </tr>
1365     * <tr>
1366     * <td>long</td>
1367     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
1368     * <td>read-only</td>
1369     * <td>The absolute time in milliseconds when the latest status was
1370     * inserted/updated.</td>
1371     * </tr>
1372     * <tr>
1373     * <td>String</td>
1374     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
1375     * <td>read-only</td>
1376     * <td> The package containing resources for this status: label and icon.</td>
1377     * </tr>
1378     * <tr>
1379     * <td>long</td>
1380     * <td>{@link #CONTACT_STATUS_LABEL}</td>
1381     * <td>read-only</td>
1382     * <td>The resource ID of the label describing the source of contact status,
1383     * e.g. "Google Talk". This resource is scoped by the
1384     * {@link #CONTACT_STATUS_RES_PACKAGE}.</td>
1385     * </tr>
1386     * <tr>
1387     * <td>long</td>
1388     * <td>{@link #CONTACT_STATUS_ICON}</td>
1389     * <td>read-only</td>
1390     * <td>The resource ID of the icon for the source of contact status. This
1391     * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.</td>
1392     * </tr>
1393     * </table>
1394     */
1395    public static class Contacts implements BaseColumns, ContactsColumns,
1396            ContactOptionsColumns, ContactNameColumns, ContactStatusColumns {
1397        /**
1398         * This utility class cannot be instantiated
1399         */
1400        private Contacts()  {}
1401
1402        /**
1403         * The content:// style URI for this table
1404         */
1405        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");
1406
1407        /**
1408         * A content:// style URI for this table that should be used to create
1409         * shortcuts or otherwise create long-term links to contacts. This URI
1410         * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}.
1411         * It can optionally also have a "/" and last known contact ID appended after
1412         * that. This "complete" format is an important optimization and is highly recommended.
1413         * <p>
1414         * As long as the contact's row ID remains the same, this URI is
1415         * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes
1416         * as a result of a sync or aggregation, this URI will look up the
1417         * contact using indirect information (sync IDs or constituent raw
1418         * contacts).
1419         * <p>
1420         * Lookup key should be appended unencoded - it is stored in the encoded
1421         * form, ready for use in a URI.
1422         */
1423        public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
1424                "lookup");
1425
1426        /**
1427         * Base {@link Uri} for referencing a single {@link Contacts} entry,
1428         * created by appending {@link #LOOKUP_KEY} using
1429         * {@link Uri#withAppendedPath(Uri, String)}. Provides
1430         * {@link OpenableColumns} columns when queried, or returns the
1431         * referenced contact formatted as a vCard when opened through
1432         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
1433         */
1434        public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
1435                "as_vcard");
1436
1437       /**
1438        * Boolean parameter that may be used with {@link #CONTENT_VCARD_URI}
1439        * and {@link #CONTENT_MULTI_VCARD_URI} to indicate that the returned
1440        * vcard should not contain a photo.
1441        *
1442        * @hide
1443        */
1444        public static final String QUERY_PARAMETER_VCARD_NO_PHOTO = "nophoto";
1445
1446        /**
1447         * Base {@link Uri} for referencing multiple {@link Contacts} entry,
1448         * created by appending {@link #LOOKUP_KEY} using
1449         * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be
1450         * joined with the colon (":") separator, and the resulting string encoded.
1451         *
1452         * Provides {@link OpenableColumns} columns when queried, or returns the
1453         * referenced contact formatted as a vCard when opened through
1454         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
1455         *
1456         * <p>
1457         * Usage example:
1458         * <dl>
1459         * <dt>The following code snippet creates a multi-vcard URI that references all the
1460         * contacts in a user's database.</dt>
1461         * <dd>
1462         *
1463         * <pre>
1464         * public Uri getAllContactsVcardUri() {
1465         *     Cursor cursor = getActivity().getContentResolver().query(Contacts.CONTENT_URI,
1466         *         new String[] {Contacts.LOOKUP_KEY}, null, null, null);
1467         *     if (cursor == null) {
1468         *         return null;
1469         *     }
1470         *     try {
1471         *         StringBuilder uriListBuilder = new StringBuilder();
1472         *         int index = 0;
1473         *         while (cursor.moveToNext()) {
1474         *             if (index != 0) uriListBuilder.append(':');
1475         *             uriListBuilder.append(cursor.getString(0));
1476         *             index++;
1477         *         }
1478         *         return Uri.withAppendedPath(Contacts.CONTENT_MULTI_VCARD_URI,
1479         *                 Uri.encode(uriListBuilder.toString()));
1480         *     } finally {
1481         *         cursor.close();
1482         *     }
1483         * }
1484         * </pre>
1485         *
1486         * </p>
1487         */
1488        public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
1489                "as_multi_vcard");
1490
1491        /**
1492         * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the
1493         * requested {@link Contacts} entry.
1494         *
1495         * @param contactUri A {@link #CONTENT_URI} row, or an existing
1496         *            {@link #CONTENT_LOOKUP_URI} to attempt refreshing.
1497         */
1498        public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) {
1499            final Cursor c = resolver.query(contactUri, new String[] {
1500                    Contacts.LOOKUP_KEY, Contacts._ID
1501            }, null, null, null);
1502            if (c == null) {
1503                return null;
1504            }
1505
1506            try {
1507                if (c.moveToFirst()) {
1508                    final String lookupKey = c.getString(0);
1509                    final long contactId = c.getLong(1);
1510                    return getLookupUri(contactId, lookupKey);
1511                }
1512            } finally {
1513                c.close();
1514            }
1515            return null;
1516        }
1517
1518        /**
1519         * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the
1520         * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}.
1521         */
1522        public static Uri getLookupUri(long contactId, String lookupKey) {
1523            return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI,
1524                    lookupKey), contactId);
1525        }
1526
1527        /**
1528         * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI.
1529         * <p>
1530         * Returns null if the contact cannot be found.
1531         */
1532        public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) {
1533            if (lookupUri == null) {
1534                return null;
1535            }
1536
1537            Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null);
1538            if (c == null) {
1539                return null;
1540            }
1541
1542            try {
1543                if (c.moveToFirst()) {
1544                    long contactId = c.getLong(0);
1545                    return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
1546                }
1547            } finally {
1548                c.close();
1549            }
1550            return null;
1551        }
1552
1553        /**
1554         * Mark a contact as having been contacted. Updates two fields:
1555         * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED}. The
1556         * TIMES_CONTACTED field is incremented by 1 and the LAST_TIME_CONTACTED
1557         * field is populated with the current system time.
1558         *
1559         * @param resolver the ContentResolver to use
1560         * @param contactId the person who was contacted
1561         *
1562         * @deprecated The class DataUsageStatUpdater of the Android support library should
1563         *     be used instead.
1564         */
1565        @Deprecated
1566        public static void markAsContacted(ContentResolver resolver, long contactId) {
1567            Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId);
1568            ContentValues values = new ContentValues();
1569            // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified.
1570            values.put(LAST_TIME_CONTACTED, System.currentTimeMillis());
1571            resolver.update(uri, values, null, null);
1572        }
1573
1574        /**
1575         * The content:// style URI used for "type-to-filter" functionality on the
1576         * {@link #CONTENT_URI} URI. The filter string will be used to match
1577         * various parts of the contact name. The filter argument should be passed
1578         * as an additional path segment after this URI.
1579         */
1580        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
1581                CONTENT_URI, "filter");
1582
1583        /**
1584         * The content:// style URI for this table joined with useful data from
1585         * {@link ContactsContract.Data}, filtered to include only starred contacts
1586         * and the most frequently contacted contacts.
1587         */
1588        public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath(
1589                CONTENT_URI, "strequent");
1590
1591        /**
1592         * The content:// style URI for showing frequently contacted person listing.
1593         * @hide
1594         */
1595        public static final Uri CONTENT_FREQUENT_URI = Uri.withAppendedPath(
1596                CONTENT_URI, "frequent");
1597
1598        /**
1599         * The content:// style URI used for "type-to-filter" functionality on the
1600         * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match
1601         * various parts of the contact name. The filter argument should be passed
1602         * as an additional path segment after this URI.
1603         */
1604        public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath(
1605                CONTENT_STREQUENT_URI, "filter");
1606
1607        public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath(
1608                CONTENT_URI, "group");
1609
1610        /**
1611         * The MIME type of {@link #CONTENT_URI} providing a directory of
1612         * people.
1613         */
1614        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact";
1615
1616        /**
1617         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
1618         * person.
1619         */
1620        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact";
1621
1622        /**
1623         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
1624         * person.
1625         */
1626        public static final String CONTENT_VCARD_TYPE = "text/x-vcard";
1627
1628        /**
1629         * A sub-directory of a single contact that contains all of the constituent raw contact
1630         * {@link ContactsContract.Data} rows.  This directory can be used either
1631         * with a {@link #CONTENT_URI} or {@link #CONTENT_LOOKUP_URI}.
1632         */
1633        public static final class Data implements BaseColumns, DataColumns {
1634            /**
1635             * no public constructor since this is a utility class
1636             */
1637            private Data() {}
1638
1639            /**
1640             * The directory twig for this sub-table
1641             */
1642            public static final String CONTENT_DIRECTORY = "data";
1643        }
1644
1645        /**
1646         * <p>
1647         * A sub-directory of a contact that contains all of its
1648         * {@link ContactsContract.RawContacts} as well as
1649         * {@link ContactsContract.Data} rows. To access this directory append
1650         * {@link #CONTENT_DIRECTORY} to the contact URI.
1651         * </p>
1652         * <p>
1653         * Entity has three ID fields: {@link #CONTACT_ID} for the contact,
1654         * {@link #RAW_CONTACT_ID} for the raw contact and {@link #DATA_ID} for
1655         * the data rows. Entity always contains at least one row per
1656         * constituent raw contact, even if there are no actual data rows. In
1657         * this case the {@link #DATA_ID} field will be null.
1658         * </p>
1659         * <p>
1660         * Entity reads all data for the entire contact in one transaction, to
1661         * guarantee consistency.  There is significant data duplication
1662         * in the Entity (each row repeats all Contact columns and all RawContact
1663         * columns), so the benefits of transactional consistency should be weighed
1664         * against the cost of transferring large amounts of denormalized data
1665         * from the Provider.
1666         * </p>
1667         * <p>
1668         * To reduce the amount of data duplication the contacts provider and directory
1669         * providers implementing this protocol are allowed to provide common Contacts
1670         * and RawContacts fields in the first row returned for each raw contact only and
1671         * leave them as null in subsequent rows.
1672         * </p>
1673         */
1674        public static final class Entity implements BaseColumns, ContactsColumns,
1675                ContactNameColumns, RawContactsColumns, BaseSyncColumns, SyncColumns, DataColumns,
1676                StatusColumns, ContactOptionsColumns, ContactStatusColumns {
1677            /**
1678             * no public constructor since this is a utility class
1679             */
1680            private Entity() {
1681            }
1682
1683            /**
1684             * The directory twig for this sub-table
1685             */
1686            public static final String CONTENT_DIRECTORY = "entities";
1687
1688            /**
1689             * The ID of the raw contact row.
1690             * <P>Type: INTEGER</P>
1691             */
1692            public static final String RAW_CONTACT_ID = "raw_contact_id";
1693
1694            /**
1695             * The ID of the data row. The value will be null if this raw contact has no
1696             * data rows.
1697             * <P>Type: INTEGER</P>
1698             */
1699            public static final String DATA_ID = "data_id";
1700        }
1701
1702        /**
1703         * <p>
1704         * A sub-directory of a single contact that contains all of the constituent raw contact
1705         * {@link ContactsContract.StreamItems} rows.  This directory can be used either
1706         * with a {@link #CONTENT_URI} or {@link #CONTENT_LOOKUP_URI}.
1707         * </p>
1708         * <p>
1709         * Querying for social stream data requires android.permission.READ_SOCIAL_STREAM
1710         * permission.
1711         * </p>
1712         */
1713        public static final class StreamItems implements StreamItemsColumns {
1714            /**
1715             * no public constructor since this is a utility class
1716             */
1717            private StreamItems() {}
1718
1719            /**
1720             * The directory twig for this sub-table
1721             */
1722            public static final String CONTENT_DIRECTORY = "stream_items";
1723        }
1724
1725        /**
1726         * <p>
1727         * A <i>read-only</i> sub-directory of a single contact aggregate that
1728         * contains all aggregation suggestions (other contacts). The
1729         * aggregation suggestions are computed based on approximate data
1730         * matches with this contact.
1731         * </p>
1732         * <p>
1733         * <i>Note: this query may be expensive! If you need to use it in bulk,
1734         * make sure the user experience is acceptable when the query runs for a
1735         * long time.</i>
1736         * <p>
1737         * Usage example:
1738         *
1739         * <pre>
1740         * Uri uri = Contacts.CONTENT_URI.buildUpon()
1741         *          .appendEncodedPath(String.valueOf(contactId))
1742         *          .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY)
1743         *          .appendQueryParameter(&quot;limit&quot;, &quot;3&quot;)
1744         *          .build()
1745         * Cursor cursor = getContentResolver().query(suggestionsUri,
1746         *          new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY},
1747         *          null, null, null);
1748         * </pre>
1749         *
1750         * </p>
1751         * <p>
1752         * This directory can be used either with a {@link #CONTENT_URI} or
1753         * {@link #CONTENT_LOOKUP_URI}.
1754         * </p>
1755         */
1756        public static final class AggregationSuggestions implements BaseColumns, ContactsColumns,
1757                ContactOptionsColumns, ContactStatusColumns {
1758            /**
1759             * No public constructor since this is a utility class
1760             */
1761            private AggregationSuggestions() {}
1762
1763            /**
1764             * The directory twig for this sub-table. The URI can be followed by an optional
1765             * type-to-filter, similar to
1766             * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}.
1767             */
1768            public static final String CONTENT_DIRECTORY = "suggestions";
1769
1770            /**
1771             * Used with {@link Builder#addParameter} to specify what kind of data is
1772             * supplied for the suggestion query.
1773             *
1774             * @hide
1775             */
1776            public static final String PARAMETER_MATCH_NAME = "name";
1777
1778            /**
1779             * Used with {@link Builder#addParameter} to specify what kind of data is
1780             * supplied for the suggestion query.
1781             *
1782             * @hide
1783             */
1784            public static final String PARAMETER_MATCH_EMAIL = "email";
1785
1786            /**
1787             * Used with {@link Builder#addParameter} to specify what kind of data is
1788             * supplied for the suggestion query.
1789             *
1790             * @hide
1791             */
1792            public static final String PARAMETER_MATCH_PHONE = "phone";
1793
1794            /**
1795             * Used with {@link Builder#addParameter} to specify what kind of data is
1796             * supplied for the suggestion query.
1797             *
1798             * @hide
1799             */
1800            public static final String PARAMETER_MATCH_NICKNAME = "nickname";
1801
1802            /**
1803             * A convenience builder for aggregation suggestion content URIs.
1804             *
1805             * TODO: change documentation for this class to use the builder.
1806             * @hide
1807             */
1808            public static final class Builder {
1809                private long mContactId;
1810                private ArrayList<String> mKinds = new ArrayList<String>();
1811                private ArrayList<String> mValues = new ArrayList<String>();
1812                private int mLimit;
1813
1814                /**
1815                 * Optional existing contact ID.  If it is not provided, the search
1816                 * will be based exclusively on the values supplied with {@link #addParameter}.
1817                 */
1818                public Builder setContactId(long contactId) {
1819                    this.mContactId = contactId;
1820                    return this;
1821                }
1822
1823                /**
1824                 * A value that can be used when searching for an aggregation
1825                 * suggestion.
1826                 *
1827                 * @param kind can be one of
1828                 *            {@link AggregationSuggestions#PARAMETER_MATCH_NAME},
1829                 *            {@link AggregationSuggestions#PARAMETER_MATCH_EMAIL},
1830                 *            {@link AggregationSuggestions#PARAMETER_MATCH_NICKNAME},
1831                 *            {@link AggregationSuggestions#PARAMETER_MATCH_PHONE}
1832                 */
1833                public Builder addParameter(String kind, String value) {
1834                    if (!TextUtils.isEmpty(value)) {
1835                        mKinds.add(kind);
1836                        mValues.add(value);
1837                    }
1838                    return this;
1839                }
1840
1841                public Builder setLimit(int limit) {
1842                    mLimit = limit;
1843                    return this;
1844                }
1845
1846                public Uri build() {
1847                    android.net.Uri.Builder builder = Contacts.CONTENT_URI.buildUpon();
1848                    builder.appendEncodedPath(String.valueOf(mContactId));
1849                    builder.appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY);
1850                    if (mLimit != 0) {
1851                        builder.appendQueryParameter("limit", String.valueOf(mLimit));
1852                    }
1853
1854                    int count = mKinds.size();
1855                    for (int i = 0; i < count; i++) {
1856                        builder.appendQueryParameter("query", mKinds.get(i) + ":" + mValues.get(i));
1857                    }
1858
1859                    return builder.build();
1860                }
1861            }
1862
1863            /**
1864             * @hide
1865             */
1866            public static final Builder builder() {
1867                return new Builder();
1868            }
1869        }
1870
1871        /**
1872         * A <i>read-only</i> sub-directory of a single contact that contains
1873         * the contact's primary photo.  The photo may be stored in up to two ways -
1874         * the default "photo" is a thumbnail-sized image stored directly in the data
1875         * row, while the "display photo", if present, is a larger version stored as
1876         * a file.
1877         * <p>
1878         * Usage example:
1879         * <dl>
1880         * <dt>Retrieving the thumbnail-sized photo</dt>
1881         * <dd>
1882         * <pre>
1883         * public InputStream openPhoto(long contactId) {
1884         *     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
1885         *     Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
1886         *     Cursor cursor = getContentResolver().query(photoUri,
1887         *          new String[] {Contacts.Photo.PHOTO}, null, null, null);
1888         *     if (cursor == null) {
1889         *         return null;
1890         *     }
1891         *     try {
1892         *         if (cursor.moveToFirst()) {
1893         *             byte[] data = cursor.getBlob(0);
1894         *             if (data != null) {
1895         *                 return new ByteArrayInputStream(data);
1896         *             }
1897         *         }
1898         *     } finally {
1899         *         cursor.close();
1900         *     }
1901         *     return null;
1902         * }
1903         * </pre>
1904         * </dd>
1905         * <dt>Retrieving the larger photo version</dt>
1906         * <dd>
1907         * <pre>
1908         * public InputStream openDisplayPhoto(long contactId) {
1909         *     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
1910         *     Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
1911         *     try {
1912         *         AssetFileDescriptor fd =
1913         *             getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
1914         *         return fd.createInputStream();
1915         *     } catch (IOException e) {
1916         *         return null;
1917         *     }
1918         * }
1919         * </pre>
1920         * </dd>
1921         * </dl>
1922         *
1923         * </p>
1924         * <p>You may also consider using the convenience method
1925         * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri, boolean)}
1926         * to retrieve the raw photo contents of either the thumbnail-sized or the full-sized photo.
1927         * </p>
1928         * <p>
1929         * This directory can be used either with a {@link #CONTENT_URI} or
1930         * {@link #CONTENT_LOOKUP_URI}.
1931         * </p>
1932         */
1933        public static final class Photo implements BaseColumns, DataColumnsWithJoins {
1934            /**
1935             * no public constructor since this is a utility class
1936             */
1937            private Photo() {}
1938
1939            /**
1940             * The directory twig for this sub-table
1941             */
1942            public static final String CONTENT_DIRECTORY = "photo";
1943
1944            /**
1945             * The directory twig for retrieving the full-size display photo.
1946             */
1947            public static final String DISPLAY_PHOTO = "display_photo";
1948
1949            /**
1950             * Full-size photo file ID of the raw contact.
1951             * See {@link ContactsContract.DisplayPhoto}.
1952             * <p>
1953             * Type: NUMBER
1954             */
1955            public static final String PHOTO_FILE_ID = DATA14;
1956
1957            /**
1958             * Thumbnail photo of the raw contact. This is the raw bytes of an image
1959             * that could be inflated using {@link android.graphics.BitmapFactory}.
1960             * <p>
1961             * Type: BLOB
1962             */
1963            public static final String PHOTO = DATA15;
1964        }
1965
1966        /**
1967         * Opens an InputStream for the contacts's photo and returns the
1968         * photo as a byte stream.
1969         * @param cr The content resolver to use for querying
1970         * @param contactUri the contact whose photo should be used. This can be used with
1971         * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI.
1972         * @param preferHighres If this is true and the contact has a higher resolution photo
1973         * available, it is returned. If false, this function always tries to get the thumbnail
1974         * @return an InputStream of the photo, or null if no photo is present
1975         */
1976        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri,
1977                boolean preferHighres) {
1978            if (preferHighres) {
1979                final Uri displayPhotoUri = Uri.withAppendedPath(contactUri,
1980                        Contacts.Photo.DISPLAY_PHOTO);
1981                InputStream inputStream;
1982                try {
1983                    AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r");
1984                    return fd.createInputStream();
1985                } catch (IOException e) {
1986                    // fallback to the thumbnail code
1987                }
1988           }
1989
1990            Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
1991            if (photoUri == null) {
1992                return null;
1993            }
1994            Cursor cursor = cr.query(photoUri,
1995                    new String[] {
1996                        ContactsContract.CommonDataKinds.Photo.PHOTO
1997                    }, null, null, null);
1998            try {
1999                if (cursor == null || !cursor.moveToNext()) {
2000                    return null;
2001                }
2002                byte[] data = cursor.getBlob(0);
2003                if (data == null) {
2004                    return null;
2005                }
2006                return new ByteArrayInputStream(data);
2007            } finally {
2008                if (cursor != null) {
2009                    cursor.close();
2010                }
2011            }
2012        }
2013
2014        /**
2015         * Opens an InputStream for the contacts's thumbnail photo and returns the
2016         * photo as a byte stream.
2017         * @param cr The content resolver to use for querying
2018         * @param contactUri the contact whose photo should be used. This can be used with
2019         * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI.
2020         * @return an InputStream of the photo, or null if no photo is present
2021         * @see #openContactPhotoInputStream(ContentResolver, Uri, boolean), if instead
2022         * of the thumbnail the high-res picture is preferred
2023         */
2024        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
2025            return openContactPhotoInputStream(cr, contactUri, false);
2026        }
2027    }
2028
2029    /**
2030     * <p>
2031     * Constants for the user's profile data, which is represented as a single contact on
2032     * the device that represents the user.  The profile contact is not aggregated
2033     * together automatically in the same way that normal contacts are; instead, each
2034     * account (including data set, if applicable) on the device may contribute a single
2035     * raw contact representing the user's personal profile data from that source.
2036     * </p>
2037     * <p>
2038     * Access to the profile entry through these URIs (or incidental access to parts of
2039     * the profile if retrieved directly via ID) requires additional permissions beyond
2040     * the read/write contact permissions required by the provider.  Querying for profile
2041     * data requires android.permission.READ_PROFILE permission, and inserting or
2042     * updating profile data requires android.permission.WRITE_PROFILE permission.
2043     * </p>
2044     * <h3>Operations</h3>
2045     * <dl>
2046     * <dt><b>Insert</b></dt>
2047     * <dd>The user's profile entry cannot be created explicitly (attempting to do so
2048     * will throw an exception). When a raw contact is inserted into the profile, the
2049     * provider will check for the existence of a profile on the device.  If one is
2050     * found, the raw contact's {@link RawContacts#CONTACT_ID} column gets the _ID of
2051     * the profile Contact. If no match is found, the profile Contact is created and
2052     * its _ID is put into the {@link RawContacts#CONTACT_ID} column of the newly
2053     * inserted raw contact.</dd>
2054     * <dt><b>Update</b></dt>
2055     * <dd>The profile Contact has the same update restrictions as Contacts in general,
2056     * but requires the android.permission.WRITE_PROFILE permission.</dd>
2057     * <dt><b>Delete</b></dt>
2058     * <dd>The profile Contact cannot be explicitly deleted.  It will be removed
2059     * automatically if all of its constituent raw contact entries are deleted.</dd>
2060     * <dt><b>Query</b></dt>
2061     * <dd>
2062     * <ul>
2063     * <li>The {@link #CONTENT_URI} for profiles behaves in much the same way as
2064     * retrieving a contact by ID, except that it will only ever return the user's
2065     * profile contact.
2066     * </li>
2067     * <li>
2068     * The profile contact supports all of the same sub-paths as an individual contact
2069     * does - the content of the profile contact can be retrieved as entities or
2070     * data rows.  Similarly, specific raw contact entries can be retrieved by appending
2071     * the desired raw contact ID within the profile.
2072     * </li>
2073     * </ul>
2074     * </dd>
2075     * </dl>
2076     */
2077    public static final class Profile implements BaseColumns, ContactsColumns,
2078            ContactOptionsColumns, ContactNameColumns, ContactStatusColumns {
2079        /**
2080         * This utility class cannot be instantiated
2081         */
2082        private Profile() {
2083        }
2084
2085        /**
2086         * The content:// style URI for this table, which requests the contact entry
2087         * representing the user's personal profile data.
2088         */
2089        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "profile");
2090
2091        /**
2092         * {@link Uri} for referencing the user's profile {@link Contacts} entry,
2093         * Provides {@link OpenableColumns} columns when queried, or returns the
2094         * user's profile contact formatted as a vCard when opened through
2095         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
2096         */
2097        public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
2098                "as_vcard");
2099
2100        /**
2101         * {@link Uri} for referencing the raw contacts that make up the user's profile
2102         * {@link Contacts} entry.  An individual raw contact entry within the profile
2103         * can be addressed by appending the raw contact ID.  The entities or data within
2104         * that specific raw contact can be requested by appending the entity or data
2105         * path as well.
2106         */
2107        public static final Uri CONTENT_RAW_CONTACTS_URI = Uri.withAppendedPath(CONTENT_URI,
2108                "raw_contacts");
2109
2110        /**
2111         * The minimum ID for any entity that belongs to the profile.  This essentially
2112         * defines an ID-space in which profile data is stored, and is used by the provider
2113         * to determine whether a request via a non-profile-specific URI should be directed
2114         * to the profile data rather than general contacts data, along with all the special
2115         * permission checks that entails.
2116         *
2117         * Callers may use {@link #isProfileId} to check whether a specific ID falls into
2118         * the set of data intended for the profile.
2119         */
2120        public static final long MIN_ID = Long.MAX_VALUE - (long) Integer.MAX_VALUE;
2121    }
2122
2123    /**
2124     * This method can be used to identify whether the given ID is associated with profile
2125     * data.  It does not necessarily indicate that the ID is tied to valid data, merely
2126     * that accessing data using this ID will result in profile access checks and will only
2127     * return data from the profile.
2128     *
2129     * @param id The ID to check.
2130     * @return Whether the ID is associated with profile data.
2131     */
2132    public static boolean isProfileId(long id) {
2133        return id >= Profile.MIN_ID;
2134    }
2135
2136    protected interface DeletedContactsColumns {
2137
2138        /**
2139         * A reference to the {@link ContactsContract.Contacts#_ID} that was deleted.
2140         * <P>Type: INTEGER</P>
2141         */
2142        public static final String CONTACT_ID = "contact_id";
2143
2144        /**
2145         * Time (milliseconds since epoch) that the contact was deleted.
2146         */
2147        public static final String CONTACT_DELETED_TIMESTAMP = "contact_deleted_timestamp";
2148    }
2149
2150    /**
2151     * Constants for the deleted contact table.  This table holds a log of deleted contacts.
2152     * <p>
2153     * Log older than {@link #DAYS_KEPT_MILLISECONDS} may be deleted.
2154     */
2155    public static final class DeletedContacts implements DeletedContactsColumns {
2156
2157        /**
2158         * This utility class cannot be instantiated
2159         */
2160        private DeletedContacts() {
2161        }
2162
2163        /**
2164         * The content:// style URI for this table, which requests a directory of raw contact rows
2165         * matching the selection criteria.
2166         */
2167        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI,
2168                "deleted_contacts");
2169
2170        /**
2171         * Number of days that the delete log will be kept.  After this time, delete records may be
2172         * deleted.
2173         *
2174         * @hide
2175         */
2176        private static final int DAYS_KEPT = 30;
2177
2178        /**
2179         * Milliseconds that the delete log will be kept.  After this time, delete records may be
2180         * deleted.
2181         */
2182        public static final long DAYS_KEPT_MILLISECONDS = 1000L * 60L * 60L * 24L * (long)DAYS_KEPT;
2183    }
2184
2185
2186    protected interface RawContactsColumns {
2187        /**
2188         * A reference to the {@link ContactsContract.Contacts#_ID} that this
2189         * data belongs to.
2190         * <P>Type: INTEGER</P>
2191         */
2192        public static final String CONTACT_ID = "contact_id";
2193
2194        /**
2195         * The data set within the account that this row belongs to.  This allows
2196         * multiple sync adapters for the same account type to distinguish between
2197         * each others' data.
2198         *
2199         * This is empty by default, and is completely optional.  It only needs to
2200         * be populated if multiple sync adapters are entering distinct data for
2201         * the same account type and account name.
2202         * <P>Type: TEXT</P>
2203         */
2204        public static final String DATA_SET = "data_set";
2205
2206        /**
2207         * A concatenation of the account type and data set (delimited by a forward
2208         * slash) - if the data set is empty, this will be the same as the account
2209         * type.  For applications that need to be aware of the data set, this can
2210         * be used instead of account type to distinguish sets of data.  This is
2211         * never intended to be used for specifying accounts.
2212         * @hide
2213         */
2214        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
2215
2216        /**
2217         * The aggregation mode for this contact.
2218         * <P>Type: INTEGER</P>
2219         */
2220        public static final String AGGREGATION_MODE = "aggregation_mode";
2221
2222        /**
2223         * The "deleted" flag: "0" by default, "1" if the row has been marked
2224         * for deletion. When {@link android.content.ContentResolver#delete} is
2225         * called on a raw contact, it is marked for deletion and removed from its
2226         * aggregate contact. The sync adaptor deletes the raw contact on the server and
2227         * then calls ContactResolver.delete once more, this time passing the
2228         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
2229         * the data removal.
2230         * <P>Type: INTEGER</P>
2231         */
2232        public static final String DELETED = "deleted";
2233
2234        /**
2235         * The "name_verified" flag: "1" means that the name fields on this raw
2236         * contact can be trusted and therefore should be used for the entire
2237         * aggregated contact.
2238         * <p>
2239         * If an aggregated contact contains more than one raw contact with a
2240         * verified name, one of those verified names is chosen at random.
2241         * If an aggregated contact contains no verified names, the
2242         * name is chosen randomly from the constituent raw contacts.
2243         * </p>
2244         * <p>
2245         * Updating this flag from "0" to "1" automatically resets it to "0" on
2246         * all other raw contacts in the same aggregated contact.
2247         * </p>
2248         * <p>
2249         * Sync adapters should only specify a value for this column when
2250         * inserting a raw contact and leave it out when doing an update.
2251         * </p>
2252         * <p>
2253         * The default value is "0"
2254         * </p>
2255         * <p>Type: INTEGER</p>
2256         *
2257         * @hide
2258         */
2259        public static final String NAME_VERIFIED = "name_verified";
2260
2261        /**
2262         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
2263         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
2264         * <P>Type: INTEGER</P>
2265         */
2266        public static final String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only";
2267
2268        /**
2269         * Flag that reflects whether this raw contact belongs to the user's
2270         * personal profile entry.
2271         */
2272        public static final String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile";
2273    }
2274
2275    /**
2276     * Constants for the raw contacts table, which contains one row of contact
2277     * information for each person in each synced account. Sync adapters and
2278     * contact management apps
2279     * are the primary consumers of this API.
2280     *
2281     * <h3>Aggregation</h3>
2282     * <p>
2283     * As soon as a raw contact is inserted or whenever its constituent data
2284     * changes, the provider will check if the raw contact matches other
2285     * existing raw contacts and if so will aggregate it with those. The
2286     * aggregation is reflected in the {@link RawContacts} table by the change of the
2287     * {@link #CONTACT_ID} field, which is the reference to the aggregate contact.
2288     * </p>
2289     * <p>
2290     * Changes to the structured name, organization, phone number, email address,
2291     * or nickname trigger a re-aggregation.
2292     * </p>
2293     * <p>
2294     * See also {@link AggregationExceptions} for a mechanism to control
2295     * aggregation programmatically.
2296     * </p>
2297     *
2298     * <h3>Operations</h3>
2299     * <dl>
2300     * <dt><b>Insert</b></dt>
2301     * <dd>
2302     * <p>
2303     * Raw contacts can be inserted incrementally or in a batch.
2304     * The incremental method is more traditional but less efficient.
2305     * It should be used
2306     * only if no {@link Data} values are available at the time the raw contact is created:
2307     * <pre>
2308     * ContentValues values = new ContentValues();
2309     * values.put(RawContacts.ACCOUNT_TYPE, accountType);
2310     * values.put(RawContacts.ACCOUNT_NAME, accountName);
2311     * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
2312     * long rawContactId = ContentUris.parseId(rawContactUri);
2313     * </pre>
2314     * </p>
2315     * <p>
2316     * Once {@link Data} values become available, insert those.
2317     * For example, here's how you would insert a name:
2318     *
2319     * <pre>
2320     * values.clear();
2321     * values.put(Data.RAW_CONTACT_ID, rawContactId);
2322     * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
2323     * values.put(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;);
2324     * getContentResolver().insert(Data.CONTENT_URI, values);
2325     * </pre>
2326     * </p>
2327     * <p>
2328     * The batch method is by far preferred.  It inserts the raw contact and its
2329     * constituent data rows in a single database transaction
2330     * and causes at most one aggregation pass.
2331     * <pre>
2332     * ArrayList&lt;ContentProviderOperation&gt; ops =
2333     *          new ArrayList&lt;ContentProviderOperation&gt;();
2334     * ...
2335     * int rawContactInsertIndex = ops.size();
2336     * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
2337     *          .withValue(RawContacts.ACCOUNT_TYPE, accountType)
2338     *          .withValue(RawContacts.ACCOUNT_NAME, accountName)
2339     *          .build());
2340     *
2341     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
2342     *          .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
2343     *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
2344     *          .withValue(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;)
2345     *          .build());
2346     *
2347     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2348     * </pre>
2349     * </p>
2350     * <p>
2351     * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)}
2352     * to refer to the as-yet-unknown index value of the raw contact inserted in the
2353     * first operation.
2354     * </p>
2355     *
2356     * <dt><b>Update</b></dt>
2357     * <dd><p>
2358     * Raw contacts can be updated incrementally or in a batch.
2359     * Batch mode should be used whenever possible.
2360     * The procedures and considerations are analogous to those documented above for inserts.
2361     * </p></dd>
2362     * <dt><b>Delete</b></dt>
2363     * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates,
2364     * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw
2365     * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row
2366     * itself is also deleted automatically.
2367     * </p>
2368     * <p>
2369     * The invocation of {@code resolver.delete(...)}, does not immediately delete
2370     * a raw contacts row.
2371     * Instead, it sets the {@link #DELETED} flag on the raw contact and
2372     * removes the raw contact from its aggregate contact.
2373     * The sync adapter then deletes the raw contact from the server and
2374     * finalizes phone-side deletion by calling {@code resolver.delete(...)}
2375     * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p>
2376     * <p>Some sync adapters are read-only, meaning that they only sync server-side
2377     * changes to the phone, but not the reverse.  If one of those raw contacts
2378     * is marked for deletion, it will remain on the phone.  However it will be
2379     * effectively invisible, because it will not be part of any aggregate contact.
2380     * </dd>
2381     *
2382     * <dt><b>Query</b></dt>
2383     * <dd>
2384     * <p>
2385     * It is easy to find all raw contacts in a Contact:
2386     * <pre>
2387     * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
2388     *          new String[]{RawContacts._ID},
2389     *          RawContacts.CONTACT_ID + "=?",
2390     *          new String[]{String.valueOf(contactId)}, null);
2391     * </pre>
2392     * </p>
2393     * <p>
2394     * To find raw contacts within a specific account,
2395     * you can either put the account name and type in the selection or pass them as query
2396     * parameters.  The latter approach is preferable, especially when you can reuse the
2397     * URI:
2398     * <pre>
2399     * Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
2400     *          .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
2401     *          .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType)
2402     *          .build();
2403     * Cursor c1 = getContentResolver().query(rawContactUri,
2404     *          RawContacts.STARRED + "&lt;&gt;0", null, null, null);
2405     * ...
2406     * Cursor c2 = getContentResolver().query(rawContactUri,
2407     *          RawContacts.DELETED + "&lt;&gt;0", null, null, null);
2408     * </pre>
2409     * </p>
2410     * <p>The best way to read a raw contact along with all the data associated with it is
2411     * by using the {@link Entity} directory. If the raw contact has data rows,
2412     * the Entity cursor will contain a row for each data row.  If the raw contact has no
2413     * data rows, the cursor will still contain one row with the raw contact-level information.
2414     * <pre>
2415     * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
2416     * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
2417     * Cursor c = getContentResolver().query(entityUri,
2418     *          new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
2419     *          null, null, null);
2420     * try {
2421     *     while (c.moveToNext()) {
2422     *         String sourceId = c.getString(0);
2423     *         if (!c.isNull(1)) {
2424     *             String mimeType = c.getString(2);
2425     *             String data = c.getString(3);
2426     *             ...
2427     *         }
2428     *     }
2429     * } finally {
2430     *     c.close();
2431     * }
2432     * </pre>
2433     * </p>
2434     * </dd>
2435     * </dl>
2436     * <h2>Columns</h2>
2437     *
2438     * <table class="jd-sumtable">
2439     * <tr>
2440     * <th colspan='4'>RawContacts</th>
2441     * </tr>
2442     * <tr>
2443     * <td>long</td>
2444     * <td>{@link #_ID}</td>
2445     * <td>read-only</td>
2446     * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words,
2447     * it is much better for a sync adapter to update a raw contact rather than to delete and
2448     * re-insert it.</td>
2449     * </tr>
2450     * <tr>
2451     * <td>long</td>
2452     * <td>{@link #CONTACT_ID}</td>
2453     * <td>read-only</td>
2454     * <td>The ID of the row in the {@link ContactsContract.Contacts} table
2455     * that this raw contact belongs
2456     * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled
2457     * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td>
2458     * </tr>
2459     * <tr>
2460     * <td>int</td>
2461     * <td>{@link #AGGREGATION_MODE}</td>
2462     * <td>read/write</td>
2463     * <td>A mechanism that allows programmatic control of the aggregation process. The allowed
2464     * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED}
2465     * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td>
2466     * </tr>
2467     * <tr>
2468     * <td>int</td>
2469     * <td>{@link #DELETED}</td>
2470     * <td>read/write</td>
2471     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
2472     * for deletion. When {@link android.content.ContentResolver#delete} is
2473     * called on a raw contact, it is marked for deletion and removed from its
2474     * aggregate contact. The sync adaptor deletes the raw contact on the server and
2475     * then calls ContactResolver.delete once more, this time passing the
2476     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
2477     * the data removal.</td>
2478     * </tr>
2479     * <tr>
2480     * <td>int</td>
2481     * <td>{@link #TIMES_CONTACTED}</td>
2482     * <td>read/write</td>
2483     * <td>The number of times the contact has been contacted. To have an effect
2484     * on the corresponding value of the aggregate contact, this field
2485     * should be set at the time the raw contact is inserted.
2486     * After that, this value is typically updated via
2487     * {@link ContactsContract.Contacts#markAsContacted}.</td>
2488     * </tr>
2489     * <tr>
2490     * <td>long</td>
2491     * <td>{@link #LAST_TIME_CONTACTED}</td>
2492     * <td>read/write</td>
2493     * <td>The timestamp of the last time the contact was contacted. To have an effect
2494     * on the corresponding value of the aggregate contact, this field
2495     * should be set at the time the raw contact is inserted.
2496     * After that, this value is typically updated via
2497     * {@link ContactsContract.Contacts#markAsContacted}.
2498     * </td>
2499     * </tr>
2500     * <tr>
2501     * <td>int</td>
2502     * <td>{@link #STARRED}</td>
2503     * <td>read/write</td>
2504     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
2505     * Changing this field immediately affects the corresponding aggregate contact:
2506     * if any raw contacts in that aggregate contact are starred, then the contact
2507     * itself is marked as starred.</td>
2508     * </tr>
2509     * <tr>
2510     * <td>String</td>
2511     * <td>{@link #CUSTOM_RINGTONE}</td>
2512     * <td>read/write</td>
2513     * <td>A custom ringtone associated with a raw contact. Typically this is the
2514     * URI returned by an activity launched with the
2515     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.
2516     * To have an effect on the corresponding value of the aggregate contact, this field
2517     * should be set at the time the raw contact is inserted. To set a custom
2518     * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE
2519     * Contacts.CUSTOM_RINGTONE}
2520     * instead.</td>
2521     * </tr>
2522     * <tr>
2523     * <td>int</td>
2524     * <td>{@link #SEND_TO_VOICEMAIL}</td>
2525     * <td>read/write</td>
2526     * <td>An indicator of whether calls from this raw contact should be forwarded
2527     * directly to voice mail ('1') or not ('0'). To have an effect
2528     * on the corresponding value of the aggregate contact, this field
2529     * should be set at the time the raw contact is inserted.</td>
2530     * </tr>
2531     * <tr>
2532     * <td>String</td>
2533     * <td>{@link #ACCOUNT_NAME}</td>
2534     * <td>read/write-once</td>
2535     * <td>The name of the account instance to which this row belongs, which when paired with
2536     * {@link #ACCOUNT_TYPE} identifies a specific account.
2537     * For example, this will be the Gmail address if it is a Google account.
2538     * It should be set at the time the raw contact is inserted and never
2539     * changed afterwards.</td>
2540     * </tr>
2541     * <tr>
2542     * <td>String</td>
2543     * <td>{@link #ACCOUNT_TYPE}</td>
2544     * <td>read/write-once</td>
2545     * <td>
2546     * <p>
2547     * The type of account to which this row belongs, which when paired with
2548     * {@link #ACCOUNT_NAME} identifies a specific account.
2549     * It should be set at the time the raw contact is inserted and never
2550     * changed afterwards.
2551     * </p>
2552     * <p>
2553     * To ensure uniqueness, new account types should be chosen according to the
2554     * Java package naming convention.  Thus a Google account is of type "com.google".
2555     * </p>
2556     * </td>
2557     * </tr>
2558     * <tr>
2559     * <td>String</td>
2560     * <td>{@link #DATA_SET}</td>
2561     * <td>read/write-once</td>
2562     * <td>
2563     * <p>
2564     * The data set within the account that this row belongs to.  This allows
2565     * multiple sync adapters for the same account type to distinguish between
2566     * each others' data.  The combination of {@link #ACCOUNT_TYPE},
2567     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
2568     * that is associated with a single sync adapter.
2569     * </p>
2570     * <p>
2571     * This is empty by default, and is completely optional.  It only needs to
2572     * be populated if multiple sync adapters are entering distinct data for
2573     * the same account type and account name.
2574     * </p>
2575     * <p>
2576     * It should be set at the time the raw contact is inserted and never
2577     * changed afterwards.
2578     * </p>
2579     * </td>
2580     * </tr>
2581     * <tr>
2582     * <td>String</td>
2583     * <td>{@link #SOURCE_ID}</td>
2584     * <td>read/write</td>
2585     * <td>String that uniquely identifies this row to its source account.
2586     * Typically it is set at the time the raw contact is inserted and never
2587     * changed afterwards. The one notable exception is a new raw contact: it
2588     * will have an account name and type (and possibly a data set), but no
2589     * source id. This indicates to the sync adapter that a new contact needs
2590     * to be created server-side and its ID stored in the corresponding
2591     * SOURCE_ID field on the phone.
2592     * </td>
2593     * </tr>
2594     * <tr>
2595     * <td>int</td>
2596     * <td>{@link #VERSION}</td>
2597     * <td>read-only</td>
2598     * <td>Version number that is updated whenever this row or its related data
2599     * changes. This field can be used for optimistic locking of a raw contact.
2600     * </td>
2601     * </tr>
2602     * <tr>
2603     * <td>int</td>
2604     * <td>{@link #DIRTY}</td>
2605     * <td>read/write</td>
2606     * <td>Flag indicating that {@link #VERSION} has changed, and this row needs
2607     * to be synchronized by its owning account.  The value is set to "1" automatically
2608     * whenever the raw contact changes, unless the URI has the
2609     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified.
2610     * The sync adapter should always supply this query parameter to prevent
2611     * unnecessary synchronization: user changes some data on the server,
2612     * the sync adapter updates the contact on the phone (without the
2613     * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag,
2614     * which triggers a sync to bring the changes to the server.
2615     * </td>
2616     * </tr>
2617     * <tr>
2618     * <td>String</td>
2619     * <td>{@link #SYNC1}</td>
2620     * <td>read/write</td>
2621     * <td>Generic column provided for arbitrary use by sync adapters.
2622     * The content provider
2623     * stores this information on behalf of the sync adapter but does not
2624     * interpret it in any way.
2625     * </td>
2626     * </tr>
2627     * <tr>
2628     * <td>String</td>
2629     * <td>{@link #SYNC2}</td>
2630     * <td>read/write</td>
2631     * <td>Generic column for use by sync adapters.
2632     * </td>
2633     * </tr>
2634     * <tr>
2635     * <td>String</td>
2636     * <td>{@link #SYNC3}</td>
2637     * <td>read/write</td>
2638     * <td>Generic column for use by sync adapters.
2639     * </td>
2640     * </tr>
2641     * <tr>
2642     * <td>String</td>
2643     * <td>{@link #SYNC4}</td>
2644     * <td>read/write</td>
2645     * <td>Generic column for use by sync adapters.
2646     * </td>
2647     * </tr>
2648     * </table>
2649     */
2650    public static final class RawContacts implements BaseColumns, RawContactsColumns,
2651            ContactOptionsColumns, ContactNameColumns, SyncColumns  {
2652        /**
2653         * This utility class cannot be instantiated
2654         */
2655        private RawContacts() {
2656        }
2657
2658        /**
2659         * The content:// style URI for this table, which requests a directory of
2660         * raw contact rows matching the selection criteria.
2661         */
2662        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts");
2663
2664        /**
2665         * The MIME type of the results from {@link #CONTENT_URI} when a specific
2666         * ID value is not provided, and multiple raw contacts may be returned.
2667         */
2668        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact";
2669
2670        /**
2671         * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI},
2672         * yielding a subdirectory of a single person.
2673         */
2674        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact";
2675
2676        /**
2677         * Aggregation mode: aggregate immediately after insert or update operation(s) are complete.
2678         */
2679        public static final int AGGREGATION_MODE_DEFAULT = 0;
2680
2681        /**
2682         * Aggregation mode: aggregate at the time the raw contact is inserted/updated.
2683         * @deprecated Aggregation is synchronous, this historic value is a no-op
2684         */
2685        @Deprecated
2686        public static final int AGGREGATION_MODE_IMMEDIATE = 1;
2687
2688        /**
2689         * <p>
2690         * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later.
2691         * Changes to the raw contact will update the associated aggregate contact but will not
2692         * result in any change in how the contact is aggregated. Similar to
2693         * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding
2694         * {@link Contacts} aggregate.
2695         * </p>
2696         * <p>
2697         * This can be used to postpone aggregation until after a series of updates, for better
2698         * performance and/or user experience.
2699         * </p>
2700         * <p>
2701         * Note that changing
2702         * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to
2703         * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any
2704         * subsequent
2705         * change to the raw contact's data will.
2706         * </p>
2707         */
2708        public static final int AGGREGATION_MODE_SUSPENDED = 2;
2709
2710        /**
2711         * <p>
2712         * Aggregation mode: never aggregate this raw contact.  The raw contact will not
2713         * have a corresponding {@link Contacts} aggregate and therefore will not be included in
2714         * {@link Contacts} query results.
2715         * </p>
2716         * <p>
2717         * For example, this mode can be used for a raw contact that is marked for deletion while
2718         * waiting for the deletion to occur on the server side.
2719         * </p>
2720         *
2721         * @see #AGGREGATION_MODE_SUSPENDED
2722         */
2723        public static final int AGGREGATION_MODE_DISABLED = 3;
2724
2725        /**
2726         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
2727         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
2728         * entry of the given {@link RawContacts} entry.
2729         */
2730        public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) {
2731            // TODO: use a lighter query by joining rawcontacts with contacts in provider
2732            final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY);
2733            final Cursor cursor = resolver.query(dataUri, new String[] {
2734                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
2735            }, null, null, null);
2736
2737            Uri lookupUri = null;
2738            try {
2739                if (cursor != null && cursor.moveToFirst()) {
2740                    final long contactId = cursor.getLong(0);
2741                    final String lookupKey = cursor.getString(1);
2742                    return Contacts.getLookupUri(contactId, lookupKey);
2743                }
2744            } finally {
2745                if (cursor != null) cursor.close();
2746            }
2747            return lookupUri;
2748        }
2749
2750        /**
2751         * A sub-directory of a single raw contact that contains all of its
2752         * {@link ContactsContract.Data} rows. To access this directory
2753         * append {@link Data#CONTENT_DIRECTORY} to the raw contact URI.
2754         */
2755        public static final class Data implements BaseColumns, DataColumns {
2756            /**
2757             * no public constructor since this is a utility class
2758             */
2759            private Data() {
2760            }
2761
2762            /**
2763             * The directory twig for this sub-table
2764             */
2765            public static final String CONTENT_DIRECTORY = "data";
2766        }
2767
2768        /**
2769         * <p>
2770         * A sub-directory of a single raw contact that contains all of its
2771         * {@link ContactsContract.Data} rows. To access this directory append
2772         * {@link RawContacts.Entity#CONTENT_DIRECTORY} to the raw contact URI. See
2773         * {@link RawContactsEntity} for a stand-alone table containing the same
2774         * data.
2775         * </p>
2776         * <p>
2777         * Entity has two ID fields: {@link #_ID} for the raw contact
2778         * and {@link #DATA_ID} for the data rows.
2779         * Entity always contains at least one row, even if there are no
2780         * actual data rows. In this case the {@link #DATA_ID} field will be
2781         * null.
2782         * </p>
2783         * <p>
2784         * Using Entity should be preferred to using two separate queries:
2785         * RawContacts followed by Data. The reason is that Entity reads all
2786         * data for a raw contact in one transaction, so there is no possibility
2787         * of the data changing between the two queries.
2788         */
2789        public static final class Entity implements BaseColumns, DataColumns {
2790            /**
2791             * no public constructor since this is a utility class
2792             */
2793            private Entity() {
2794            }
2795
2796            /**
2797             * The directory twig for this sub-table
2798             */
2799            public static final String CONTENT_DIRECTORY = "entity";
2800
2801            /**
2802             * The ID of the data row. The value will be null if this raw contact has no
2803             * data rows.
2804             * <P>Type: INTEGER</P>
2805             */
2806            public static final String DATA_ID = "data_id";
2807        }
2808
2809        /**
2810         * <p>
2811         * A sub-directory of a single raw contact that contains all of its
2812         * {@link ContactsContract.StreamItems} rows. To access this directory append
2813         * {@link RawContacts.StreamItems#CONTENT_DIRECTORY} to the raw contact URI. See
2814         * {@link ContactsContract.StreamItems} for a stand-alone table containing the
2815         * same data.
2816         * </p>
2817         * <p>
2818         * Access to the social stream through this sub-directory requires additional permissions
2819         * beyond the read/write contact permissions required by the provider.  Querying for
2820         * social stream data requires android.permission.READ_SOCIAL_STREAM permission, and
2821         * inserting or updating social stream items requires android.permission.WRITE_SOCIAL_STREAM
2822         * permission.
2823         * </p>
2824         */
2825        public static final class StreamItems implements BaseColumns, StreamItemsColumns {
2826            /**
2827             * No public constructor since this is a utility class
2828             */
2829            private StreamItems() {
2830            }
2831
2832            /**
2833             * The directory twig for this sub-table
2834             */
2835            public static final String CONTENT_DIRECTORY = "stream_items";
2836        }
2837
2838        /**
2839         * <p>
2840         * A sub-directory of a single raw contact that represents its primary
2841         * display photo.  To access this directory append
2842         * {@link RawContacts.DisplayPhoto#CONTENT_DIRECTORY} to the raw contact URI.
2843         * The resulting URI represents an image file, and should be interacted with
2844         * using ContentResolver.openAssetFileDescriptor.
2845         * <p>
2846         * <p>
2847         * Note that this sub-directory also supports opening the photo as an asset file
2848         * in write mode.  Callers can create or replace the primary photo associated
2849         * with this raw contact by opening the asset file and writing the full-size
2850         * photo contents into it.  When the file is closed, the image will be parsed,
2851         * sized down if necessary for the full-size display photo and thumbnail
2852         * dimensions, and stored.
2853         * </p>
2854         * <p>
2855         * Usage example:
2856         * <pre>
2857         * public void writeDisplayPhoto(long rawContactId, byte[] photo) {
2858         *     Uri rawContactPhotoUri = Uri.withAppendedPath(
2859         *             ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
2860         *             RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
2861         *     try {
2862         *         AssetFileDescriptor fd =
2863         *             getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw");
2864         *         OutputStream os = fd.createOutputStream();
2865         *         os.write(photo);
2866         *         os.close();
2867         *         fd.close();
2868         *     } catch (IOException e) {
2869         *         // Handle error cases.
2870         *     }
2871         * }
2872         * </pre>
2873         * </p>
2874         */
2875        public static final class DisplayPhoto {
2876            /**
2877             * No public constructor since this is a utility class
2878             */
2879            private DisplayPhoto() {
2880            }
2881
2882            /**
2883             * The directory twig for this sub-table
2884             */
2885            public static final String CONTENT_DIRECTORY = "display_photo";
2886        }
2887
2888        /**
2889         * TODO: javadoc
2890         * @param cursor
2891         * @return
2892         */
2893        public static EntityIterator newEntityIterator(Cursor cursor) {
2894            return new EntityIteratorImpl(cursor);
2895        }
2896
2897        private static class EntityIteratorImpl extends CursorEntityIterator {
2898            private static final String[] DATA_KEYS = new String[]{
2899                    Data.DATA1,
2900                    Data.DATA2,
2901                    Data.DATA3,
2902                    Data.DATA4,
2903                    Data.DATA5,
2904                    Data.DATA6,
2905                    Data.DATA7,
2906                    Data.DATA8,
2907                    Data.DATA9,
2908                    Data.DATA10,
2909                    Data.DATA11,
2910                    Data.DATA12,
2911                    Data.DATA13,
2912                    Data.DATA14,
2913                    Data.DATA15,
2914                    Data.SYNC1,
2915                    Data.SYNC2,
2916                    Data.SYNC3,
2917                    Data.SYNC4};
2918
2919            public EntityIteratorImpl(Cursor cursor) {
2920                super(cursor);
2921            }
2922
2923            @Override
2924            public android.content.Entity getEntityAndIncrementCursor(Cursor cursor)
2925                    throws RemoteException {
2926                final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID);
2927                final long rawContactId = cursor.getLong(columnRawContactId);
2928
2929                // we expect the cursor is already at the row we need to read from
2930                ContentValues cv = new ContentValues();
2931                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
2932                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
2933                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DATA_SET);
2934                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID);
2935                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
2936                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION);
2937                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID);
2938                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1);
2939                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2);
2940                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3);
2941                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4);
2942                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED);
2943                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID);
2944                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED);
2945                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED);
2946                android.content.Entity contact = new android.content.Entity(cv);
2947
2948                // read data rows until the contact id changes
2949                do {
2950                    if (rawContactId != cursor.getLong(columnRawContactId)) {
2951                        break;
2952                    }
2953                    // add the data to to the contact
2954                    cv = new ContentValues();
2955                    cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID)));
2956                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
2957                            Data.RES_PACKAGE);
2958                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE);
2959                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY);
2960                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
2961                            Data.IS_SUPER_PRIMARY);
2962                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION);
2963                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
2964                            CommonDataKinds.GroupMembership.GROUP_SOURCE_ID);
2965                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
2966                            Data.DATA_VERSION);
2967                    for (String key : DATA_KEYS) {
2968                        final int columnIndex = cursor.getColumnIndexOrThrow(key);
2969                        switch (cursor.getType(columnIndex)) {
2970                            case Cursor.FIELD_TYPE_NULL:
2971                                // don't put anything
2972                                break;
2973                            case Cursor.FIELD_TYPE_INTEGER:
2974                            case Cursor.FIELD_TYPE_FLOAT:
2975                            case Cursor.FIELD_TYPE_STRING:
2976                                cv.put(key, cursor.getString(columnIndex));
2977                                break;
2978                            case Cursor.FIELD_TYPE_BLOB:
2979                                cv.put(key, cursor.getBlob(columnIndex));
2980                                break;
2981                            default:
2982                                throw new IllegalStateException("Invalid or unhandled data type");
2983                        }
2984                    }
2985                    contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv);
2986                } while (cursor.moveToNext());
2987
2988                return contact;
2989            }
2990
2991        }
2992    }
2993
2994    /**
2995     * Social status update columns.
2996     *
2997     * @see StatusUpdates
2998     * @see ContactsContract.Data
2999     */
3000    protected interface StatusColumns {
3001        /**
3002         * Contact's latest presence level.
3003         * <P>Type: INTEGER (one of the values below)</P>
3004         */
3005        public static final String PRESENCE = "mode";
3006
3007        /**
3008         * @deprecated use {@link #PRESENCE}
3009         */
3010        @Deprecated
3011        public static final String PRESENCE_STATUS = PRESENCE;
3012
3013        /**
3014         * An allowed value of {@link #PRESENCE}.
3015         */
3016        int OFFLINE = 0;
3017
3018        /**
3019         * An allowed value of {@link #PRESENCE}.
3020         */
3021        int INVISIBLE = 1;
3022
3023        /**
3024         * An allowed value of {@link #PRESENCE}.
3025         */
3026        int AWAY = 2;
3027
3028        /**
3029         * An allowed value of {@link #PRESENCE}.
3030         */
3031        int IDLE = 3;
3032
3033        /**
3034         * An allowed value of {@link #PRESENCE}.
3035         */
3036        int DO_NOT_DISTURB = 4;
3037
3038        /**
3039         * An allowed value of {@link #PRESENCE}.
3040         */
3041        int AVAILABLE = 5;
3042
3043        /**
3044         * Contact latest status update.
3045         * <p>Type: TEXT</p>
3046         */
3047        public static final String STATUS = "status";
3048
3049        /**
3050         * @deprecated use {@link #STATUS}
3051         */
3052        @Deprecated
3053        public static final String PRESENCE_CUSTOM_STATUS = STATUS;
3054
3055        /**
3056         * The absolute time in milliseconds when the latest status was inserted/updated.
3057         * <p>Type: NUMBER</p>
3058         */
3059        public static final String STATUS_TIMESTAMP = "status_ts";
3060
3061        /**
3062         * The package containing resources for this status: label and icon.
3063         * <p>Type: TEXT</p>
3064         */
3065        public static final String STATUS_RES_PACKAGE = "status_res_package";
3066
3067        /**
3068         * The resource ID of the label describing the source of the status update, e.g. "Google
3069         * Talk".  This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
3070         * <p>Type: NUMBER</p>
3071         */
3072        public static final String STATUS_LABEL = "status_label";
3073
3074        /**
3075         * The resource ID of the icon for the source of the status update.
3076         * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
3077         * <p>Type: NUMBER</p>
3078         */
3079        public static final String STATUS_ICON = "status_icon";
3080
3081        /**
3082         * Contact's audio/video chat capability level.
3083         * <P>Type: INTEGER (one of the values below)</P>
3084         */
3085        public static final String CHAT_CAPABILITY = "chat_capability";
3086
3087        /**
3088         * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability (microphone
3089         * and speaker)
3090         */
3091        public static final int CAPABILITY_HAS_VOICE = 1;
3092
3093        /**
3094         * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can
3095         * display a video feed.
3096         */
3097        public static final int CAPABILITY_HAS_VIDEO = 2;
3098
3099        /**
3100         * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a
3101         * camera that can be used for video chat (e.g. a front-facing camera on a phone).
3102         */
3103        public static final int CAPABILITY_HAS_CAMERA = 4;
3104    }
3105
3106    /**
3107     * <p>
3108     * Constants for the stream_items table, which contains social stream updates from
3109     * the user's contact list.
3110     * </p>
3111     * <p>
3112     * Only a certain number of stream items will ever be stored under a given raw contact.
3113     * Users of this API can query {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} to
3114     * determine this limit, and should restrict the number of items inserted in any given
3115     * transaction correspondingly.  Insertion of more items beyond the limit will
3116     * automatically lead to deletion of the oldest items, by {@link StreamItems#TIMESTAMP}.
3117     * </p>
3118     * <p>
3119     * Access to the social stream through these URIs requires additional permissions beyond the
3120     * read/write contact permissions required by the provider.  Querying for social stream data
3121     * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating social
3122     * stream items requires android.permission.WRITE_SOCIAL_STREAM permission.
3123     * </p>
3124     * <h3>Account check</h3>
3125     * <p>
3126     * The content URIs to the insert, update and delete operations are required to have the account
3127     * information matching that of the owning raw contact as query parameters, namely
3128     * {@link RawContacts#ACCOUNT_TYPE} and {@link RawContacts#ACCOUNT_NAME}.
3129     * {@link RawContacts#DATA_SET} isn't required.
3130     * </p>
3131     * <h3>Operations</h3>
3132     * <dl>
3133     * <dt><b>Insert</b></dt>
3134     * <dd>
3135     * <p>Social stream updates are always associated with a raw contact.  There are a couple
3136     * of ways to insert these entries.
3137     * <dl>
3138     * <dt>Via the {@link RawContacts.StreamItems#CONTENT_DIRECTORY} sub-path of a raw contact:</dt>
3139     * <dd>
3140     * <pre>
3141     * ContentValues values = new ContentValues();
3142     * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys");
3143     * values.put(StreamItems.TIMESTAMP, timestamp);
3144     * values.put(StreamItems.COMMENTS, "3 people reshared this");
3145     * Uri.Builder builder = RawContacts.CONTENT_URI.buildUpon();
3146     * ContentUris.appendId(builder, rawContactId);
3147     * builder.appendEncodedPath(RawContacts.StreamItems.CONTENT_DIRECTORY);
3148     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3149     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3150     * Uri streamItemUri = getContentResolver().insert(builder.build(), values);
3151     * long streamItemId = ContentUris.parseId(streamItemUri);
3152     * </pre>
3153     * </dd>
3154     * <dt>Via {@link StreamItems#CONTENT_URI}:</dt>
3155     * <dd>
3156     *<pre>
3157     * ContentValues values = new ContentValues();
3158     * values.put(StreamItems.RAW_CONTACT_ID, rawContactId);
3159     * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys");
3160     * values.put(StreamItems.TIMESTAMP, timestamp);
3161     * values.put(StreamItems.COMMENTS, "3 people reshared this");
3162     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3163     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3164     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3165     * Uri streamItemUri = getContentResolver().insert(builder.build(), values);
3166     * long streamItemId = ContentUris.parseId(streamItemUri);
3167     *</pre>
3168     * </dd>
3169     * </dl>
3170     * </dd>
3171     * </p>
3172     * <p>
3173     * Once a {@link StreamItems} entry has been inserted, photos associated with that
3174     * social update can be inserted.  For example, after one of the insertions above,
3175     * photos could be added to the stream item in one of the following ways:
3176     * <dl>
3177     * <dt>Via a URI including the stream item ID:</dt>
3178     * <dd>
3179     * <pre>
3180     * values.clear();
3181     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3182     * values.put(StreamItemPhotos.PHOTO, photoData);
3183     * getContentResolver().insert(Uri.withAppendedPath(
3184     *     ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId),
3185     *     StreamItems.StreamItemPhotos.CONTENT_DIRECTORY), values);
3186     * </pre>
3187     * </dd>
3188     * <dt>Via {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI}:</dt>
3189     * <dd>
3190     * <pre>
3191     * values.clear();
3192     * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
3193     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3194     * values.put(StreamItemPhotos.PHOTO, photoData);
3195     * getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values);
3196     * </pre>
3197     * <p>Note that this latter form allows the insertion of a stream item and its
3198     * photos in a single transaction, by using {@link ContentProviderOperation} with
3199     * back references to populate the stream item ID in the {@link ContentValues}.
3200     * </dd>
3201     * </dl>
3202     * </p>
3203     * </dd>
3204     * <dt><b>Update</b></dt>
3205     * <dd>Updates can be performed by appending the stream item ID to the
3206     * {@link StreamItems#CONTENT_URI} URI.  Only social stream entries that were
3207     * created by the calling package can be updated.</dd>
3208     * <dt><b>Delete</b></dt>
3209     * <dd>Deletes can be performed by appending the stream item ID to the
3210     * {@link StreamItems#CONTENT_URI} URI.  Only social stream entries that were
3211     * created by the calling package can be deleted.</dd>
3212     * <dt><b>Query</b></dt>
3213     * <dl>
3214     * <dt>Finding all social stream updates for a given contact</dt>
3215     * <dd>By Contact ID:
3216     * <pre>
3217     * Cursor c = getContentResolver().query(Uri.withAppendedPath(
3218     *          ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId),
3219     *          Contacts.StreamItems.CONTENT_DIRECTORY),
3220     *          null, null, null, null);
3221     * </pre>
3222     * </dd>
3223     * <dd>By lookup key:
3224     * <pre>
3225     * Cursor c = getContentResolver().query(Contacts.CONTENT_URI.buildUpon()
3226     *          .appendPath(lookupKey)
3227     *          .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(),
3228     *          null, null, null, null);
3229     * </pre>
3230     * </dd>
3231     * <dt>Finding all social stream updates for a given raw contact</dt>
3232     * <dd>
3233     * <pre>
3234     * Cursor c = getContentResolver().query(Uri.withAppendedPath(
3235     *          ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
3236     *          RawContacts.StreamItems.CONTENT_DIRECTORY)),
3237     *          null, null, null, null);
3238     * </pre>
3239     * </dd>
3240     * <dt>Querying for a specific stream item by ID</dt>
3241     * <dd>
3242     * <pre>
3243     * Cursor c = getContentResolver().query(ContentUris.withAppendedId(
3244     *          StreamItems.CONTENT_URI, streamItemId),
3245     *          null, null, null, null);
3246     * </pre>
3247     * </dd>
3248     * </dl>
3249     */
3250    public static final class StreamItems implements BaseColumns, StreamItemsColumns {
3251        /**
3252         * This utility class cannot be instantiated
3253         */
3254        private StreamItems() {
3255        }
3256
3257        /**
3258         * The content:// style URI for this table, which handles social network stream
3259         * updates for the user's contacts.
3260         */
3261        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "stream_items");
3262
3263        /**
3264         * <p>
3265         * A content:// style URI for the photos stored in a sub-table underneath
3266         * stream items.  This is only used for inserts, and updates - queries and deletes
3267         * for photos should be performed by appending
3268         * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} path to URIs for a
3269         * specific stream item.
3270         * </p>
3271         * <p>
3272         * When using this URI, the stream item ID for the photo(s) must be identified
3273         * in the {@link ContentValues} passed in.
3274         * </p>
3275         */
3276        public static final Uri CONTENT_PHOTO_URI = Uri.withAppendedPath(CONTENT_URI, "photo");
3277
3278        /**
3279         * This URI allows the caller to query for the maximum number of stream items
3280         * that will be stored under any single raw contact.
3281         */
3282        public static final Uri CONTENT_LIMIT_URI =
3283                Uri.withAppendedPath(AUTHORITY_URI, "stream_items_limit");
3284
3285        /**
3286         * The MIME type of a directory of stream items.
3287         */
3288        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item";
3289
3290        /**
3291         * The MIME type of a single stream item.
3292         */
3293        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/stream_item";
3294
3295        /**
3296         * Queries to {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} will
3297         * contain this column, with the value indicating the maximum number of
3298         * stream items that will be stored under any single raw contact.
3299         */
3300        public static final String MAX_ITEMS = "max_items";
3301
3302        /**
3303         * <p>
3304         * A sub-directory of a single stream item entry that contains all of its
3305         * photo rows. To access this
3306         * directory append {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} to
3307         * an individual stream item URI.
3308         * </p>
3309         * <p>
3310         * Access to social stream photos requires additional permissions beyond the read/write
3311         * contact permissions required by the provider.  Querying for social stream photos
3312         * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating
3313         * social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission.
3314         * </p>
3315         */
3316        public static final class StreamItemPhotos
3317                implements BaseColumns, StreamItemPhotosColumns {
3318            /**
3319             * No public constructor since this is a utility class
3320             */
3321            private StreamItemPhotos() {
3322            }
3323
3324            /**
3325             * The directory twig for this sub-table
3326             */
3327            public static final String CONTENT_DIRECTORY = "photo";
3328
3329            /**
3330             * The MIME type of a directory of stream item photos.
3331             */
3332            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item_photo";
3333
3334            /**
3335             * The MIME type of a single stream item photo.
3336             */
3337            public static final String CONTENT_ITEM_TYPE
3338                    = "vnd.android.cursor.item/stream_item_photo";
3339        }
3340    }
3341
3342    /**
3343     * Columns in the StreamItems table.
3344     *
3345     * @see ContactsContract.StreamItems
3346     */
3347    protected interface StreamItemsColumns {
3348        /**
3349         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID}
3350         * that this stream item belongs to.
3351         *
3352         * <p>Type: INTEGER</p>
3353         * <p>read-only</p>
3354         */
3355        public static final String CONTACT_ID = "contact_id";
3356
3357        /**
3358         * A reference to the {@link android.provider.ContactsContract.Contacts#LOOKUP_KEY}
3359         * that this stream item belongs to.
3360         *
3361         * <p>Type: TEXT</p>
3362         * <p>read-only</p>
3363         */
3364        public static final String CONTACT_LOOKUP_KEY = "contact_lookup";
3365
3366        /**
3367         * A reference to the {@link RawContacts#_ID}
3368         * that this stream item belongs to.
3369         * <p>Type: INTEGER</p>
3370         */
3371        public static final String RAW_CONTACT_ID = "raw_contact_id";
3372
3373        /**
3374         * The package name to use when creating {@link Resources} objects for
3375         * this stream item. This value is only designed for use when building
3376         * user interfaces, and should not be used to infer the owner.
3377         * <P>Type: TEXT</P>
3378         */
3379        public static final String RES_PACKAGE = "res_package";
3380
3381        /**
3382         * The account type to which the raw_contact of this item is associated. See
3383         * {@link RawContacts#ACCOUNT_TYPE}
3384         *
3385         * <p>Type: TEXT</p>
3386         * <p>read-only</p>
3387         */
3388        public static final String ACCOUNT_TYPE = "account_type";
3389
3390        /**
3391         * The account name to which the raw_contact of this item is associated. See
3392         * {@link RawContacts#ACCOUNT_NAME}
3393         *
3394         * <p>Type: TEXT</p>
3395         * <p>read-only</p>
3396         */
3397        public static final String ACCOUNT_NAME = "account_name";
3398
3399        /**
3400         * The data set within the account that the raw_contact of this row belongs to. This allows
3401         * multiple sync adapters for the same account type to distinguish between
3402         * each others' data.
3403         * {@link RawContacts#DATA_SET}
3404         *
3405         * <P>Type: TEXT</P>
3406         * <p>read-only</p>
3407         */
3408        public static final String DATA_SET = "data_set";
3409
3410        /**
3411         * The source_id of the raw_contact that this row belongs to.
3412         * {@link RawContacts#SOURCE_ID}
3413         *
3414         * <P>Type: TEXT</P>
3415         * <p>read-only</p>
3416         */
3417        public static final String RAW_CONTACT_SOURCE_ID = "raw_contact_source_id";
3418
3419        /**
3420         * The resource name of the icon for the source of the stream item.
3421         * This resource should be scoped by the {@link #RES_PACKAGE}. As this can only reference
3422         * drawables, the "@drawable/" prefix must be omitted.
3423         * <P>Type: TEXT</P>
3424         */
3425        public static final String RES_ICON = "icon";
3426
3427        /**
3428         * The resource name of the label describing the source of the status update, e.g. "Google
3429         * Talk". This resource should be scoped by the {@link #RES_PACKAGE}. As this can only
3430         * reference strings, the "@string/" prefix must be omitted.
3431         * <p>Type: TEXT</p>
3432         */
3433        public static final String RES_LABEL = "label";
3434
3435        /**
3436         * <P>
3437         * The main textual contents of the item. Typically this is content
3438         * that was posted by the source of this stream item, but it can also
3439         * be a textual representation of an action (e.g. ”Checked in at Joe's”).
3440         * This text is displayed to the user and allows formatting and embedded
3441         * resource images via HTML (as parseable via
3442         * {@link android.text.Html#fromHtml}).
3443         * </P>
3444         * <P>
3445         * Long content may be truncated and/or ellipsized - the exact behavior
3446         * is unspecified, but it should not break tags.
3447         * </P>
3448         * <P>Type: TEXT</P>
3449         */
3450        public static final String TEXT = "text";
3451
3452        /**
3453         * The absolute time (milliseconds since epoch) when this stream item was
3454         * inserted/updated.
3455         * <P>Type: NUMBER</P>
3456         */
3457        public static final String TIMESTAMP = "timestamp";
3458
3459        /**
3460         * <P>
3461         * Summary information about the stream item, for example to indicate how
3462         * many people have reshared it, how many have liked it, how many thumbs
3463         * up and/or thumbs down it has, what the original source was, etc.
3464         * </P>
3465         * <P>
3466         * This text is displayed to the user and allows simple formatting via
3467         * HTML, in the same manner as {@link #TEXT} allows.
3468         * </P>
3469         * <P>
3470         * Long content may be truncated and/or ellipsized - the exact behavior
3471         * is unspecified, but it should not break tags.
3472         * </P>
3473         * <P>Type: TEXT</P>
3474         */
3475        public static final String COMMENTS = "comments";
3476
3477        /** Generic column for use by sync adapters. */
3478        public static final String SYNC1 = "stream_item_sync1";
3479        /** Generic column for use by sync adapters. */
3480        public static final String SYNC2 = "stream_item_sync2";
3481        /** Generic column for use by sync adapters. */
3482        public static final String SYNC3 = "stream_item_sync3";
3483        /** Generic column for use by sync adapters. */
3484        public static final String SYNC4 = "stream_item_sync4";
3485    }
3486
3487    /**
3488     * <p>
3489     * Constants for the stream_item_photos table, which contains photos associated with
3490     * social stream updates.
3491     * </p>
3492     * <p>
3493     * Access to social stream photos requires additional permissions beyond the read/write
3494     * contact permissions required by the provider.  Querying for social stream photos
3495     * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating
3496     * social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission.
3497     * </p>
3498     * <h3>Account check</h3>
3499     * <p>
3500     * The content URIs to the insert, update and delete operations are required to have the account
3501     * information matching that of the owning raw contact as query parameters, namely
3502     * {@link RawContacts#ACCOUNT_TYPE} and {@link RawContacts#ACCOUNT_NAME}.
3503     * {@link RawContacts#DATA_SET} isn't required.
3504     * </p>
3505     * <h3>Operations</h3>
3506     * <dl>
3507     * <dt><b>Insert</b></dt>
3508     * <dd>
3509     * <p>Social stream photo entries are associated with a social stream item.  Photos
3510     * can be inserted into a social stream item in a couple of ways:
3511     * <dl>
3512     * <dt>
3513     * Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a
3514     * stream item:
3515     * </dt>
3516     * <dd>
3517     * <pre>
3518     * ContentValues values = new ContentValues();
3519     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3520     * values.put(StreamItemPhotos.PHOTO, photoData);
3521     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3522     * ContentUris.appendId(builder, streamItemId);
3523     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3524     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3525     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3526     * Uri photoUri = getContentResolver().insert(builder.build(), values);
3527     * long photoId = ContentUris.parseId(photoUri);
3528     * </pre>
3529     * </dd>
3530     * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt>
3531     * <dd>
3532     * <pre>
3533     * ContentValues values = new ContentValues();
3534     * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
3535     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3536     * values.put(StreamItemPhotos.PHOTO, photoData);
3537     * Uri.Builder builder = StreamItems.CONTENT_PHOTO_URI.buildUpon();
3538     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3539     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3540     * Uri photoUri = getContentResolver().insert(builder.build(), values);
3541     * long photoId = ContentUris.parseId(photoUri);
3542     * </pre>
3543     * </dd>
3544     * </dl>
3545     * </p>
3546     * </dd>
3547     * <dt><b>Update</b></dt>
3548     * <dd>
3549     * <p>Updates can only be made against a specific {@link StreamItemPhotos} entry,
3550     * identified by both the stream item ID it belongs to and the stream item photo ID.
3551     * This can be specified in two ways.
3552     * <dl>
3553     * <dt>Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a
3554     * stream item:
3555     * </dt>
3556     * <dd>
3557     * <pre>
3558     * ContentValues values = new ContentValues();
3559     * values.put(StreamItemPhotos.PHOTO, newPhotoData);
3560     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3561     * ContentUris.appendId(builder, streamItemId);
3562     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3563     * ContentUris.appendId(builder, streamItemPhotoId);
3564     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3565     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3566     * getContentResolver().update(builder.build(), values, null, null);
3567     * </pre>
3568     * </dd>
3569     * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt>
3570     * <dd>
3571     * <pre>
3572     * ContentValues values = new ContentValues();
3573     * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
3574     * values.put(StreamItemPhotos.PHOTO, newPhotoData);
3575     * Uri.Builder builder = StreamItems.CONTENT_PHOTO_URI.buildUpon();
3576     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3577     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3578     * getContentResolver().update(builder.build(), values);
3579     * </pre>
3580     * </dd>
3581     * </dl>
3582     * </p>
3583     * </dd>
3584     * <dt><b>Delete</b></dt>
3585     * <dd>Deletes can be made against either a specific photo item in a stream item, or
3586     * against all or a selected subset of photo items under a stream item.
3587     * For example:
3588     * <dl>
3589     * <dt>Deleting a single photo via the
3590     * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a stream item:
3591     * </dt>
3592     * <dd>
3593     * <pre>
3594     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3595     * ContentUris.appendId(builder, streamItemId);
3596     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3597     * ContentUris.appendId(builder, streamItemPhotoId);
3598     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3599     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3600     * getContentResolver().delete(builder.build(), null, null);
3601     * </pre>
3602     * </dd>
3603     * <dt>Deleting all photos under a stream item</dt>
3604     * <dd>
3605     * <pre>
3606     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3607     * ContentUris.appendId(builder, streamItemId);
3608     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3609     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3610     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3611     * getContentResolver().delete(builder.build(), null, null);
3612     * </pre>
3613     * </dd>
3614     * </dl>
3615     * </dd>
3616     * <dt><b>Query</b></dt>
3617     * <dl>
3618     * <dt>Querying for a specific photo in a stream item</dt>
3619     * <dd>
3620     * <pre>
3621     * Cursor c = getContentResolver().query(
3622     *     ContentUris.withAppendedId(
3623     *         Uri.withAppendedPath(
3624     *             ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
3625     *             StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
3626     *         streamItemPhotoId), null, null, null, null);
3627     * </pre>
3628     * </dd>
3629     * <dt>Querying for all photos in a stream item</dt>
3630     * <dd>
3631     * <pre>
3632     * Cursor c = getContentResolver().query(
3633     *     Uri.withAppendedPath(
3634     *         ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
3635     *         StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
3636     *     null, null, null, StreamItemPhotos.SORT_INDEX);
3637     * </pre>
3638     * </dl>
3639     * The record will contain both a {@link StreamItemPhotos#PHOTO_FILE_ID} and a
3640     * {@link StreamItemPhotos#PHOTO_URI}.  The {@link StreamItemPhotos#PHOTO_FILE_ID}
3641     * can be used in conjunction with the {@link ContactsContract.DisplayPhoto} API to
3642     * retrieve photo content, or you can open the {@link StreamItemPhotos#PHOTO_URI} as
3643     * an asset file, as follows:
3644     * <pre>
3645     * public InputStream openDisplayPhoto(String photoUri) {
3646     *     try {
3647     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(photoUri, "r");
3648     *         return fd.createInputStream();
3649     *     } catch (IOException e) {
3650     *         return null;
3651     *     }
3652     * }
3653     * <pre>
3654     * </dd>
3655     * </dl>
3656     */
3657    public static final class StreamItemPhotos implements BaseColumns, StreamItemPhotosColumns {
3658        /**
3659         * No public constructor since this is a utility class
3660         */
3661        private StreamItemPhotos() {
3662        }
3663
3664        /**
3665         * <p>
3666         * The binary representation of the photo.  Any size photo can be inserted;
3667         * the provider will resize it appropriately for storage and display.
3668         * </p>
3669         * <p>
3670         * This is only intended for use when inserting or updating a stream item photo.
3671         * To retrieve the photo that was stored, open {@link StreamItemPhotos#PHOTO_URI}
3672         * as an asset file.
3673         * </p>
3674         * <P>Type: BLOB</P>
3675         */
3676        public static final String PHOTO = "photo";
3677    }
3678
3679    /**
3680     * Columns in the StreamItemPhotos table.
3681     *
3682     * @see ContactsContract.StreamItemPhotos
3683     */
3684    protected interface StreamItemPhotosColumns {
3685        /**
3686         * A reference to the {@link StreamItems#_ID} this photo is associated with.
3687         * <P>Type: NUMBER</P>
3688         */
3689        public static final String STREAM_ITEM_ID = "stream_item_id";
3690
3691        /**
3692         * An integer to use for sort order for photos in the stream item.  If not
3693         * specified, the {@link StreamItemPhotos#_ID} will be used for sorting.
3694         * <P>Type: NUMBER</P>
3695         */
3696        public static final String SORT_INDEX = "sort_index";
3697
3698        /**
3699         * Photo file ID for the photo.
3700         * See {@link ContactsContract.DisplayPhoto}.
3701         * <P>Type: NUMBER</P>
3702         */
3703        public static final String PHOTO_FILE_ID = "photo_file_id";
3704
3705        /**
3706         * URI for retrieving the photo content, automatically populated.  Callers
3707         * may retrieve the photo content by opening this URI as an asset file.
3708         * <P>Type: TEXT</P>
3709         */
3710        public static final String PHOTO_URI = "photo_uri";
3711
3712        /** Generic column for use by sync adapters. */
3713        public static final String SYNC1 = "stream_item_photo_sync1";
3714        /** Generic column for use by sync adapters. */
3715        public static final String SYNC2 = "stream_item_photo_sync2";
3716        /** Generic column for use by sync adapters. */
3717        public static final String SYNC3 = "stream_item_photo_sync3";
3718        /** Generic column for use by sync adapters. */
3719        public static final String SYNC4 = "stream_item_photo_sync4";
3720    }
3721
3722    /**
3723     * <p>
3724     * Constants for the photo files table, which tracks metadata for hi-res photos
3725     * stored in the file system.
3726     * </p>
3727     *
3728     * @hide
3729     */
3730    public static final class PhotoFiles implements BaseColumns, PhotoFilesColumns {
3731        /**
3732         * No public constructor since this is a utility class
3733         */
3734        private PhotoFiles() {
3735        }
3736    }
3737
3738    /**
3739     * Columns in the PhotoFiles table.
3740     *
3741     * @see ContactsContract.PhotoFiles
3742     *
3743     * @hide
3744     */
3745    protected interface PhotoFilesColumns {
3746
3747        /**
3748         * The height, in pixels, of the photo this entry is associated with.
3749         * <P>Type: NUMBER</P>
3750         */
3751        public static final String HEIGHT = "height";
3752
3753        /**
3754         * The width, in pixels, of the photo this entry is associated with.
3755         * <P>Type: NUMBER</P>
3756         */
3757        public static final String WIDTH = "width";
3758
3759        /**
3760         * The size, in bytes, of the photo stored on disk.
3761         * <P>Type: NUMBER</P>
3762         */
3763        public static final String FILESIZE = "filesize";
3764    }
3765
3766    /**
3767     * Columns in the Data table.
3768     *
3769     * @see ContactsContract.Data
3770     */
3771    protected interface DataColumns {
3772        /**
3773         * The package name to use when creating {@link Resources} objects for
3774         * this data row. This value is only designed for use when building user
3775         * interfaces, and should not be used to infer the owner.
3776         *
3777         * @hide
3778         */
3779        public static final String RES_PACKAGE = "res_package";
3780
3781        /**
3782         * The MIME type of the item represented by this row.
3783         */
3784        public static final String MIMETYPE = "mimetype";
3785
3786        /**
3787         * A reference to the {@link RawContacts#_ID}
3788         * that this data belongs to.
3789         */
3790        public static final String RAW_CONTACT_ID = "raw_contact_id";
3791
3792        /**
3793         * Whether this is the primary entry of its kind for the raw contact it belongs to.
3794         * <P>Type: INTEGER (if set, non-0 means true)</P>
3795         */
3796        public static final String IS_PRIMARY = "is_primary";
3797
3798        /**
3799         * Whether this is the primary entry of its kind for the aggregate
3800         * contact it belongs to. Any data record that is "super primary" must
3801         * also be "primary".
3802         * <P>Type: INTEGER (if set, non-0 means true)</P>
3803         */
3804        public static final String IS_SUPER_PRIMARY = "is_super_primary";
3805
3806        /**
3807         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
3808         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
3809         * <P>Type: INTEGER</P>
3810         */
3811        public static final String IS_READ_ONLY = "is_read_only";
3812
3813        /**
3814         * The version of this data record. This is a read-only value. The data column is
3815         * guaranteed to not change without the version going up. This value is monotonically
3816         * increasing.
3817         * <P>Type: INTEGER</P>
3818         */
3819        public static final String DATA_VERSION = "data_version";
3820
3821        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3822        public static final String DATA1 = "data1";
3823        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3824        public static final String DATA2 = "data2";
3825        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3826        public static final String DATA3 = "data3";
3827        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3828        public static final String DATA4 = "data4";
3829        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3830        public static final String DATA5 = "data5";
3831        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3832        public static final String DATA6 = "data6";
3833        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3834        public static final String DATA7 = "data7";
3835        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3836        public static final String DATA8 = "data8";
3837        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3838        public static final String DATA9 = "data9";
3839        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3840        public static final String DATA10 = "data10";
3841        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3842        public static final String DATA11 = "data11";
3843        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3844        public static final String DATA12 = "data12";
3845        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3846        public static final String DATA13 = "data13";
3847        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
3848        public static final String DATA14 = "data14";
3849        /**
3850         * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention,
3851         * this field is used to store BLOBs (binary data).
3852         */
3853        public static final String DATA15 = "data15";
3854
3855        /** Generic column for use by sync adapters. */
3856        public static final String SYNC1 = "data_sync1";
3857        /** Generic column for use by sync adapters. */
3858        public static final String SYNC2 = "data_sync2";
3859        /** Generic column for use by sync adapters. */
3860        public static final String SYNC3 = "data_sync3";
3861        /** Generic column for use by sync adapters. */
3862        public static final String SYNC4 = "data_sync4";
3863    }
3864
3865    /**
3866     * Columns in the Data_Usage_Stat table
3867     */
3868    protected interface DataUsageStatColumns {
3869        /** The last time (in milliseconds) this {@link Data} was used. */
3870        public static final String LAST_TIME_USED = "last_time_used";
3871
3872        /** The number of times the referenced {@link Data} has been used. */
3873        public static final String TIMES_USED = "times_used";
3874    }
3875
3876    /**
3877     * Combines all columns returned by {@link ContactsContract.Data} table queries.
3878     *
3879     * @see ContactsContract.Data
3880     */
3881    protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns,
3882            RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns,
3883            ContactStatusColumns, DataUsageStatColumns {
3884    }
3885
3886    /**
3887     * <p>
3888     * Constants for the data table, which contains data points tied to a raw
3889     * contact.  Each row of the data table is typically used to store a single
3890     * piece of contact
3891     * information (such as a phone number) and its
3892     * associated metadata (such as whether it is a work or home number).
3893     * </p>
3894     * <h3>Data kinds</h3>
3895     * <p>
3896     * Data is a generic table that can hold any kind of contact data.
3897     * The kind of data stored in a given row is specified by the row's
3898     * {@link #MIMETYPE} value, which determines the meaning of the
3899     * generic columns {@link #DATA1} through
3900     * {@link #DATA15}.
3901     * For example, if the data kind is
3902     * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column
3903     * {@link #DATA1} stores the
3904     * phone number, but if the data kind is
3905     * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1}
3906     * stores the email address.
3907     * Sync adapters and applications can introduce their own data kinds.
3908     * </p>
3909     * <p>
3910     * ContactsContract defines a small number of pre-defined data kinds, e.g.
3911     * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a
3912     * convenience, these classes define data kind specific aliases for DATA1 etc.
3913     * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as
3914     * {@link ContactsContract.Data Data.DATA1}.
3915     * </p>
3916     * <p>
3917     * {@link #DATA1} is an indexed column and should be used for the data element that is
3918     * expected to be most frequently used in query selections. For example, in the
3919     * case of a row representing email addresses {@link #DATA1} should probably
3920     * be used for the email address itself, while {@link #DATA2} etc can be
3921     * used for auxiliary information like type of email address.
3922     * <p>
3923     * <p>
3924     * By convention, {@link #DATA15} is used for storing BLOBs (binary data).
3925     * </p>
3926     * <p>
3927     * The sync adapter for a given account type must correctly handle every data type
3928     * used in the corresponding raw contacts.  Otherwise it could result in lost or
3929     * corrupted data.
3930     * </p>
3931     * <p>
3932     * Similarly, you should refrain from introducing new kinds of data for an other
3933     * party's account types. For example, if you add a data row for
3934     * "favorite song" to a raw contact owned by a Google account, it will not
3935     * get synced to the server, because the Google sync adapter does not know
3936     * how to handle this data kind. Thus new data kinds are typically
3937     * introduced along with new account types, i.e. new sync adapters.
3938     * </p>
3939     * <h3>Batch operations</h3>
3940     * <p>
3941     * Data rows can be inserted/updated/deleted using the traditional
3942     * {@link ContentResolver#insert}, {@link ContentResolver#update} and
3943     * {@link ContentResolver#delete} methods, however the newer mechanism based
3944     * on a batch of {@link ContentProviderOperation} will prove to be a better
3945     * choice in almost all cases. All operations in a batch are executed in a
3946     * single transaction, which ensures that the phone-side and server-side
3947     * state of a raw contact are always consistent. Also, the batch-based
3948     * approach is far more efficient: not only are the database operations
3949     * faster when executed in a single transaction, but also sending a batch of
3950     * commands to the content provider saves a lot of time on context switching
3951     * between your process and the process in which the content provider runs.
3952     * </p>
3953     * <p>
3954     * The flip side of using batched operations is that a large batch may lock
3955     * up the database for a long time preventing other applications from
3956     * accessing data and potentially causing ANRs ("Application Not Responding"
3957     * dialogs.)
3958     * </p>
3959     * <p>
3960     * To avoid such lockups of the database, make sure to insert "yield points"
3961     * in the batch. A yield point indicates to the content provider that before
3962     * executing the next operation it can commit the changes that have already
3963     * been made, yield to other requests, open another transaction and continue
3964     * processing operations. A yield point will not automatically commit the
3965     * transaction, but only if there is another request waiting on the
3966     * database. Normally a sync adapter should insert a yield point at the
3967     * beginning of each raw contact operation sequence in the batch. See
3968     * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}.
3969     * </p>
3970     * <h3>Operations</h3>
3971     * <dl>
3972     * <dt><b>Insert</b></dt>
3973     * <dd>
3974     * <p>
3975     * An individual data row can be inserted using the traditional
3976     * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows
3977     * should always be inserted as a batch.
3978     * </p>
3979     * <p>
3980     * An example of a traditional insert:
3981     * <pre>
3982     * ContentValues values = new ContentValues();
3983     * values.put(Data.RAW_CONTACT_ID, rawContactId);
3984     * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
3985     * values.put(Phone.NUMBER, "1-800-GOOG-411");
3986     * values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
3987     * values.put(Phone.LABEL, "free directory assistance");
3988     * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);
3989     * </pre>
3990     * <p>
3991     * The same done using ContentProviderOperations:
3992     * <pre>
3993     * ArrayList&lt;ContentProviderOperation&gt; ops =
3994     *          new ArrayList&lt;ContentProviderOperation&gt;();
3995     *
3996     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3997     *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3998     *          .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
3999     *          .withValue(Phone.NUMBER, "1-800-GOOG-411")
4000     *          .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
4001     *          .withValue(Phone.LABEL, "free directory assistance")
4002     *          .build());
4003     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
4004     * </pre>
4005     * </p>
4006     * <dt><b>Update</b></dt>
4007     * <dd>
4008     * <p>
4009     * Just as with insert, update can be done incrementally or as a batch,
4010     * the batch mode being the preferred method:
4011     * <pre>
4012     * ArrayList&lt;ContentProviderOperation&gt; ops =
4013     *          new ArrayList&lt;ContentProviderOperation&gt;();
4014     *
4015     * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
4016     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
4017     *          .withValue(Email.DATA, "somebody@android.com")
4018     *          .build());
4019     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
4020     * </pre>
4021     * </p>
4022     * </dd>
4023     * <dt><b>Delete</b></dt>
4024     * <dd>
4025     * <p>
4026     * Just as with insert and update, deletion can be done either using the
4027     * {@link ContentResolver#delete} method or using a ContentProviderOperation:
4028     * <pre>
4029     * ArrayList&lt;ContentProviderOperation&gt; ops =
4030     *          new ArrayList&lt;ContentProviderOperation&gt;();
4031     *
4032     * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
4033     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
4034     *          .build());
4035     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
4036     * </pre>
4037     * </p>
4038     * </dd>
4039     * <dt><b>Query</b></dt>
4040     * <dd>
4041     * <p>
4042     * <dl>
4043     * <dt>Finding all Data of a given type for a given contact</dt>
4044     * <dd>
4045     * <pre>
4046     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
4047     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
4048     *          Data.CONTACT_ID + &quot;=?&quot; + " AND "
4049     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
4050     *          new String[] {String.valueOf(contactId)}, null);
4051     * </pre>
4052     * </p>
4053     * <p>
4054     * </dd>
4055     * <dt>Finding all Data of a given type for a given raw contact</dt>
4056     * <dd>
4057     * <pre>
4058     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
4059     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
4060     *          Data.RAW_CONTACT_ID + &quot;=?&quot; + " AND "
4061     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
4062     *          new String[] {String.valueOf(rawContactId)}, null);
4063     * </pre>
4064     * </dd>
4065     * <dt>Finding all Data for a given raw contact</dt>
4066     * <dd>
4067     * Most sync adapters will want to read all data rows for a raw contact
4068     * along with the raw contact itself.  For that you should use the
4069     * {@link RawContactsEntity}. See also {@link RawContacts}.
4070     * </dd>
4071     * </dl>
4072     * </p>
4073     * </dd>
4074     * </dl>
4075     * <h2>Columns</h2>
4076     * <p>
4077     * Many columns are available via a {@link Data#CONTENT_URI} query.  For best performance you
4078     * should explicitly specify a projection to only those columns that you need.
4079     * </p>
4080     * <table class="jd-sumtable">
4081     * <tr>
4082     * <th colspan='4'>Data</th>
4083     * </tr>
4084     * <tr>
4085     * <td style="width: 7em;">long</td>
4086     * <td style="width: 20em;">{@link #_ID}</td>
4087     * <td style="width: 5em;">read-only</td>
4088     * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words,
4089     * it would be a bad idea to delete and reinsert a data row. A sync adapter should
4090     * always do an update instead.</td>
4091     * </tr>
4092     * <tr>
4093     * <td>String</td>
4094     * <td>{@link #MIMETYPE}</td>
4095     * <td>read/write-once</td>
4096     * <td>
4097     * <p>The MIME type of the item represented by this row. Examples of common
4098     * MIME types are:
4099     * <ul>
4100     * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li>
4101     * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li>
4102     * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li>
4103     * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li>
4104     * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li>
4105     * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li>
4106     * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li>
4107     * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li>
4108     * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li>
4109     * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li>
4110     * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li>
4111     * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li>
4112     * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li>
4113     * <li>{@link CommonDataKinds.SipAddress SipAddress.CONTENT_ITEM_TYPE}</li>
4114     * </ul>
4115     * </p>
4116     * </td>
4117     * </tr>
4118     * <tr>
4119     * <td>long</td>
4120     * <td>{@link #RAW_CONTACT_ID}</td>
4121     * <td>read/write-once</td>
4122     * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td>
4123     * </tr>
4124     * <tr>
4125     * <td>int</td>
4126     * <td>{@link #IS_PRIMARY}</td>
4127     * <td>read/write</td>
4128     * <td>Whether this is the primary entry of its kind for the raw contact it belongs to.
4129     * "1" if true, "0" if false.
4130     * </td>
4131     * </tr>
4132     * <tr>
4133     * <td>int</td>
4134     * <td>{@link #IS_SUPER_PRIMARY}</td>
4135     * <td>read/write</td>
4136     * <td>Whether this is the primary entry of its kind for the aggregate
4137     * contact it belongs to. Any data record that is "super primary" must
4138     * also be "primary".  For example, the super-primary entry may be
4139     * interpreted as the default contact value of its kind (for example,
4140     * the default phone number to use for the contact).</td>
4141     * </tr>
4142     * <tr>
4143     * <td>int</td>
4144     * <td>{@link #DATA_VERSION}</td>
4145     * <td>read-only</td>
4146     * <td>The version of this data record. Whenever the data row changes
4147     * the version goes up. This value is monotonically increasing.</td>
4148     * </tr>
4149     * <tr>
4150     * <td>Any type</td>
4151     * <td>
4152     * {@link #DATA1}<br>
4153     * {@link #DATA2}<br>
4154     * {@link #DATA3}<br>
4155     * {@link #DATA4}<br>
4156     * {@link #DATA5}<br>
4157     * {@link #DATA6}<br>
4158     * {@link #DATA7}<br>
4159     * {@link #DATA8}<br>
4160     * {@link #DATA9}<br>
4161     * {@link #DATA10}<br>
4162     * {@link #DATA11}<br>
4163     * {@link #DATA12}<br>
4164     * {@link #DATA13}<br>
4165     * {@link #DATA14}<br>
4166     * {@link #DATA15}
4167     * </td>
4168     * <td>read/write</td>
4169     * <td>
4170     * <p>
4171     * Generic data columns.  The meaning of each column is determined by the
4172     * {@link #MIMETYPE}.  By convention, {@link #DATA15} is used for storing
4173     * BLOBs (binary data).
4174     * </p>
4175     * <p>
4176     * Data columns whose meaning is not explicitly defined for a given MIMETYPE
4177     * should not be used.  There is no guarantee that any sync adapter will
4178     * preserve them.  Sync adapters themselves should not use such columns either,
4179     * but should instead use {@link #SYNC1}-{@link #SYNC4}.
4180     * </p>
4181     * </td>
4182     * </tr>
4183     * <tr>
4184     * <td>Any type</td>
4185     * <td>
4186     * {@link #SYNC1}<br>
4187     * {@link #SYNC2}<br>
4188     * {@link #SYNC3}<br>
4189     * {@link #SYNC4}
4190     * </td>
4191     * <td>read/write</td>
4192     * <td>Generic columns for use by sync adapters. For example, a Photo row
4193     * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error)
4194     * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td>
4195     * </tr>
4196     * </table>
4197     *
4198     * <p>
4199     * Some columns from the most recent associated status update are also available
4200     * through an implicit join.
4201     * </p>
4202     * <table class="jd-sumtable">
4203     * <tr>
4204     * <th colspan='4'>Join with {@link StatusUpdates}</th>
4205     * </tr>
4206     * <tr>
4207     * <td style="width: 7em;">int</td>
4208     * <td style="width: 20em;">{@link #PRESENCE}</td>
4209     * <td style="width: 5em;">read-only</td>
4210     * <td>IM presence status linked to this data row. Compare with
4211     * {@link #CONTACT_PRESENCE}, which contains the contact's presence across
4212     * all IM rows. See {@link StatusUpdates} for individual status definitions.
4213     * The provider may choose not to store this value
4214     * in persistent storage. The expectation is that presence status will be
4215     * updated on a regular basis.
4216     * </td>
4217     * </tr>
4218     * <tr>
4219     * <td>String</td>
4220     * <td>{@link #STATUS}</td>
4221     * <td>read-only</td>
4222     * <td>Latest status update linked with this data row.</td>
4223     * </tr>
4224     * <tr>
4225     * <td>long</td>
4226     * <td>{@link #STATUS_TIMESTAMP}</td>
4227     * <td>read-only</td>
4228     * <td>The absolute time in milliseconds when the latest status was
4229     * inserted/updated for this data row.</td>
4230     * </tr>
4231     * <tr>
4232     * <td>String</td>
4233     * <td>{@link #STATUS_RES_PACKAGE}</td>
4234     * <td>read-only</td>
4235     * <td>The package containing resources for this status: label and icon.</td>
4236     * </tr>
4237     * <tr>
4238     * <td>long</td>
4239     * <td>{@link #STATUS_LABEL}</td>
4240     * <td>read-only</td>
4241     * <td>The resource ID of the label describing the source of status update linked
4242     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
4243     * </tr>
4244     * <tr>
4245     * <td>long</td>
4246     * <td>{@link #STATUS_ICON}</td>
4247     * <td>read-only</td>
4248     * <td>The resource ID of the icon for the source of the status update linked
4249     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
4250     * </tr>
4251     * </table>
4252     *
4253     * <p>
4254     * Some columns from the associated raw contact are also available through an
4255     * implicit join.  The other columns are excluded as uninteresting in this
4256     * context.
4257     * </p>
4258     *
4259     * <table class="jd-sumtable">
4260     * <tr>
4261     * <th colspan='4'>Join with {@link ContactsContract.RawContacts}</th>
4262     * </tr>
4263     * <tr>
4264     * <td style="width: 7em;">long</td>
4265     * <td style="width: 20em;">{@link #CONTACT_ID}</td>
4266     * <td style="width: 5em;">read-only</td>
4267     * <td>The id of the row in the {@link Contacts} table that this data belongs
4268     * to.</td>
4269     * </tr>
4270     * <tr>
4271     * <td>int</td>
4272     * <td>{@link #AGGREGATION_MODE}</td>
4273     * <td>read-only</td>
4274     * <td>See {@link RawContacts}.</td>
4275     * </tr>
4276     * <tr>
4277     * <td>int</td>
4278     * <td>{@link #DELETED}</td>
4279     * <td>read-only</td>
4280     * <td>See {@link RawContacts}.</td>
4281     * </tr>
4282     * </table>
4283     *
4284     * <p>
4285     * The ID column for the associated aggregated contact table
4286     * {@link ContactsContract.Contacts} is available
4287     * via the implicit join to the {@link RawContacts} table, see above.
4288     * The remaining columns from this table are also
4289     * available, through an implicit join.  This
4290     * facilitates lookup by
4291     * the value of a single data element, such as the email address.
4292     * </p>
4293     *
4294     * <table class="jd-sumtable">
4295     * <tr>
4296     * <th colspan='4'>Join with {@link ContactsContract.Contacts}</th>
4297     * </tr>
4298     * <tr>
4299     * <td style="width: 7em;">String</td>
4300     * <td style="width: 20em;">{@link #LOOKUP_KEY}</td>
4301     * <td style="width: 5em;">read-only</td>
4302     * <td>See {@link ContactsContract.Contacts}</td>
4303     * </tr>
4304     * <tr>
4305     * <td>String</td>
4306     * <td>{@link #DISPLAY_NAME}</td>
4307     * <td>read-only</td>
4308     * <td>See {@link ContactsContract.Contacts}</td>
4309     * </tr>
4310     * <tr>
4311     * <td>long</td>
4312     * <td>{@link #PHOTO_ID}</td>
4313     * <td>read-only</td>
4314     * <td>See {@link ContactsContract.Contacts}.</td>
4315     * </tr>
4316     * <tr>
4317     * <td>int</td>
4318     * <td>{@link #IN_VISIBLE_GROUP}</td>
4319     * <td>read-only</td>
4320     * <td>See {@link ContactsContract.Contacts}.</td>
4321     * </tr>
4322     * <tr>
4323     * <td>int</td>
4324     * <td>{@link #HAS_PHONE_NUMBER}</td>
4325     * <td>read-only</td>
4326     * <td>See {@link ContactsContract.Contacts}.</td>
4327     * </tr>
4328     * <tr>
4329     * <td>int</td>
4330     * <td>{@link #TIMES_CONTACTED}</td>
4331     * <td>read-only</td>
4332     * <td>See {@link ContactsContract.Contacts}.</td>
4333     * </tr>
4334     * <tr>
4335     * <td>long</td>
4336     * <td>{@link #LAST_TIME_CONTACTED}</td>
4337     * <td>read-only</td>
4338     * <td>See {@link ContactsContract.Contacts}.</td>
4339     * </tr>
4340     * <tr>
4341     * <td>int</td>
4342     * <td>{@link #STARRED}</td>
4343     * <td>read-only</td>
4344     * <td>See {@link ContactsContract.Contacts}.</td>
4345     * </tr>
4346     * <tr>
4347     * <td>String</td>
4348     * <td>{@link #CUSTOM_RINGTONE}</td>
4349     * <td>read-only</td>
4350     * <td>See {@link ContactsContract.Contacts}.</td>
4351     * </tr>
4352     * <tr>
4353     * <td>int</td>
4354     * <td>{@link #SEND_TO_VOICEMAIL}</td>
4355     * <td>read-only</td>
4356     * <td>See {@link ContactsContract.Contacts}.</td>
4357     * </tr>
4358     * <tr>
4359     * <td>int</td>
4360     * <td>{@link #CONTACT_PRESENCE}</td>
4361     * <td>read-only</td>
4362     * <td>See {@link ContactsContract.Contacts}.</td>
4363     * </tr>
4364     * <tr>
4365     * <td>String</td>
4366     * <td>{@link #CONTACT_STATUS}</td>
4367     * <td>read-only</td>
4368     * <td>See {@link ContactsContract.Contacts}.</td>
4369     * </tr>
4370     * <tr>
4371     * <td>long</td>
4372     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
4373     * <td>read-only</td>
4374     * <td>See {@link ContactsContract.Contacts}.</td>
4375     * </tr>
4376     * <tr>
4377     * <td>String</td>
4378     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
4379     * <td>read-only</td>
4380     * <td>See {@link ContactsContract.Contacts}.</td>
4381     * </tr>
4382     * <tr>
4383     * <td>long</td>
4384     * <td>{@link #CONTACT_STATUS_LABEL}</td>
4385     * <td>read-only</td>
4386     * <td>See {@link ContactsContract.Contacts}.</td>
4387     * </tr>
4388     * <tr>
4389     * <td>long</td>
4390     * <td>{@link #CONTACT_STATUS_ICON}</td>
4391     * <td>read-only</td>
4392     * <td>See {@link ContactsContract.Contacts}.</td>
4393     * </tr>
4394     * </table>
4395     */
4396    public final static class Data implements DataColumnsWithJoins {
4397        /**
4398         * This utility class cannot be instantiated
4399         */
4400        private Data() {}
4401
4402        /**
4403         * The content:// style URI for this table, which requests a directory
4404         * of data rows matching the selection criteria.
4405         */
4406        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
4407
4408        /**
4409         * A boolean parameter for {@link Data#CONTENT_URI}.
4410         * This specifies whether or not the returned data items should be filtered to show
4411         * data items belonging to visible contacts only.
4412         */
4413        public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
4414
4415        /**
4416         * The MIME type of the results from {@link #CONTENT_URI}.
4417         */
4418        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
4419
4420        /**
4421         * <p>
4422         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
4423         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
4424         * entry of the given {@link ContactsContract.Data} entry.
4425         * </p>
4426         * <p>
4427         * Returns the Uri for the contact in the first entry returned by
4428         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
4429         * for the provided {@code dataUri}.  If the query returns null or empty
4430         * results, silently returns null.
4431         * </p>
4432         */
4433        public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) {
4434            final Cursor cursor = resolver.query(dataUri, new String[] {
4435                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
4436            }, null, null, null);
4437
4438            Uri lookupUri = null;
4439            try {
4440                if (cursor != null && cursor.moveToFirst()) {
4441                    final long contactId = cursor.getLong(0);
4442                    final String lookupKey = cursor.getString(1);
4443                    return Contacts.getLookupUri(contactId, lookupKey);
4444                }
4445            } finally {
4446                if (cursor != null) cursor.close();
4447            }
4448            return lookupUri;
4449        }
4450    }
4451
4452    /**
4453     * <p>
4454     * Constants for the raw contacts entities table, which can be thought of as
4455     * an outer join of the raw_contacts table with the data table.  It is a strictly
4456     * read-only table.
4457     * </p>
4458     * <p>
4459     * If a raw contact has data rows, the RawContactsEntity cursor will contain
4460     * a one row for each data row. If the raw contact has no data rows, the
4461     * cursor will still contain one row with the raw contact-level information
4462     * and nulls for data columns.
4463     *
4464     * <pre>
4465     * Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId);
4466     * Cursor c = getContentResolver().query(entityUri,
4467     *          new String[]{
4468     *              RawContactsEntity.SOURCE_ID,
4469     *              RawContactsEntity.DATA_ID,
4470     *              RawContactsEntity.MIMETYPE,
4471     *              RawContactsEntity.DATA1
4472     *          }, null, null, null);
4473     * try {
4474     *     while (c.moveToNext()) {
4475     *         String sourceId = c.getString(0);
4476     *         if (!c.isNull(1)) {
4477     *             String mimeType = c.getString(2);
4478     *             String data = c.getString(3);
4479     *             ...
4480     *         }
4481     *     }
4482     * } finally {
4483     *     c.close();
4484     * }
4485     * </pre>
4486     *
4487     * <h3>Columns</h3>
4488     * RawContactsEntity has a combination of RawContact and Data columns.
4489     *
4490     * <table class="jd-sumtable">
4491     * <tr>
4492     * <th colspan='4'>RawContacts</th>
4493     * </tr>
4494     * <tr>
4495     * <td style="width: 7em;">long</td>
4496     * <td style="width: 20em;">{@link #_ID}</td>
4497     * <td style="width: 5em;">read-only</td>
4498     * <td>Raw contact row ID. See {@link RawContacts}.</td>
4499     * </tr>
4500     * <tr>
4501     * <td>long</td>
4502     * <td>{@link #CONTACT_ID}</td>
4503     * <td>read-only</td>
4504     * <td>See {@link RawContacts}.</td>
4505     * </tr>
4506     * <tr>
4507     * <td>int</td>
4508     * <td>{@link #AGGREGATION_MODE}</td>
4509     * <td>read-only</td>
4510     * <td>See {@link RawContacts}.</td>
4511     * </tr>
4512     * <tr>
4513     * <td>int</td>
4514     * <td>{@link #DELETED}</td>
4515     * <td>read-only</td>
4516     * <td>See {@link RawContacts}.</td>
4517     * </tr>
4518     * </table>
4519     *
4520     * <table class="jd-sumtable">
4521     * <tr>
4522     * <th colspan='4'>Data</th>
4523     * </tr>
4524     * <tr>
4525     * <td style="width: 7em;">long</td>
4526     * <td style="width: 20em;">{@link #DATA_ID}</td>
4527     * <td style="width: 5em;">read-only</td>
4528     * <td>Data row ID. It will be null if the raw contact has no data rows.</td>
4529     * </tr>
4530     * <tr>
4531     * <td>String</td>
4532     * <td>{@link #MIMETYPE}</td>
4533     * <td>read-only</td>
4534     * <td>See {@link ContactsContract.Data}.</td>
4535     * </tr>
4536     * <tr>
4537     * <td>int</td>
4538     * <td>{@link #IS_PRIMARY}</td>
4539     * <td>read-only</td>
4540     * <td>See {@link ContactsContract.Data}.</td>
4541     * </tr>
4542     * <tr>
4543     * <td>int</td>
4544     * <td>{@link #IS_SUPER_PRIMARY}</td>
4545     * <td>read-only</td>
4546     * <td>See {@link ContactsContract.Data}.</td>
4547     * </tr>
4548     * <tr>
4549     * <td>int</td>
4550     * <td>{@link #DATA_VERSION}</td>
4551     * <td>read-only</td>
4552     * <td>See {@link ContactsContract.Data}.</td>
4553     * </tr>
4554     * <tr>
4555     * <td>Any type</td>
4556     * <td>
4557     * {@link #DATA1}<br>
4558     * {@link #DATA2}<br>
4559     * {@link #DATA3}<br>
4560     * {@link #DATA4}<br>
4561     * {@link #DATA5}<br>
4562     * {@link #DATA6}<br>
4563     * {@link #DATA7}<br>
4564     * {@link #DATA8}<br>
4565     * {@link #DATA9}<br>
4566     * {@link #DATA10}<br>
4567     * {@link #DATA11}<br>
4568     * {@link #DATA12}<br>
4569     * {@link #DATA13}<br>
4570     * {@link #DATA14}<br>
4571     * {@link #DATA15}
4572     * </td>
4573     * <td>read-only</td>
4574     * <td>See {@link ContactsContract.Data}.</td>
4575     * </tr>
4576     * <tr>
4577     * <td>Any type</td>
4578     * <td>
4579     * {@link #SYNC1}<br>
4580     * {@link #SYNC2}<br>
4581     * {@link #SYNC3}<br>
4582     * {@link #SYNC4}
4583     * </td>
4584     * <td>read-only</td>
4585     * <td>See {@link ContactsContract.Data}.</td>
4586     * </tr>
4587     * </table>
4588     */
4589    public final static class RawContactsEntity
4590            implements BaseColumns, DataColumns, RawContactsColumns {
4591        /**
4592         * This utility class cannot be instantiated
4593         */
4594        private RawContactsEntity() {}
4595
4596        /**
4597         * The content:// style URI for this table
4598         */
4599        public static final Uri CONTENT_URI =
4600                Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities");
4601
4602        /**
4603         * The content:// style URI for this table, specific to the user's profile.
4604         */
4605        public static final Uri PROFILE_CONTENT_URI =
4606                Uri.withAppendedPath(Profile.CONTENT_URI, "raw_contact_entities");
4607
4608        /**
4609         * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities.
4610         */
4611        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity";
4612
4613        /**
4614         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
4615         * Data.CONTENT_URI contains only exportable data.
4616         *
4617         * This flag is useful (currently) only for vCard exporter in Contacts app, which
4618         * needs to exclude "un-exportable" data from available data to export, while
4619         * Contacts app itself has priviledge to access all data including "un-expotable"
4620         * ones and providers return all of them regardless of the callers' intention.
4621         * <P>Type: INTEGER</p>
4622         *
4623         * @hide Maybe available only in Eclair and not really ready for public use.
4624         * TODO: remove, or implement this feature completely. As of now (Eclair),
4625         * we only use this flag in queryEntities(), not query().
4626         */
4627        public static final String FOR_EXPORT_ONLY = "for_export_only";
4628
4629        /**
4630         * The ID of the data column. The value will be null if this raw contact has no data rows.
4631         * <P>Type: INTEGER</P>
4632         */
4633        public static final String DATA_ID = "data_id";
4634    }
4635
4636    /**
4637     * @see PhoneLookup
4638     */
4639    protected interface PhoneLookupColumns {
4640        /**
4641         * The phone number as the user entered it.
4642         * <P>Type: TEXT</P>
4643         */
4644        public static final String NUMBER = "number";
4645
4646        /**
4647         * The type of phone number, for example Home or Work.
4648         * <P>Type: INTEGER</P>
4649         */
4650        public static final String TYPE = "type";
4651
4652        /**
4653         * The user defined label for the phone number.
4654         * <P>Type: TEXT</P>
4655         */
4656        public static final String LABEL = "label";
4657
4658        /**
4659         * The phone number's E164 representation.
4660         * <P>Type: TEXT</P>
4661         */
4662        public static final String NORMALIZED_NUMBER = "normalized_number";
4663    }
4664
4665    /**
4666     * A table that represents the result of looking up a phone number, for
4667     * example for caller ID. To perform a lookup you must append the number you
4668     * want to find to {@link #CONTENT_FILTER_URI}.  This query is highly
4669     * optimized.
4670     * <pre>
4671     * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
4672     * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
4673     * </pre>
4674     *
4675     * <h3>Columns</h3>
4676     *
4677     * <table class="jd-sumtable">
4678     * <tr>
4679     * <th colspan='4'>PhoneLookup</th>
4680     * </tr>
4681     * <tr>
4682     * <td>String</td>
4683     * <td>{@link #NUMBER}</td>
4684     * <td>read-only</td>
4685     * <td>Phone number.</td>
4686     * </tr>
4687     * <tr>
4688     * <td>String</td>
4689     * <td>{@link #TYPE}</td>
4690     * <td>read-only</td>
4691     * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td>
4692     * </tr>
4693     * <tr>
4694     * <td>String</td>
4695     * <td>{@link #LABEL}</td>
4696     * <td>read-only</td>
4697     * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td>
4698     * </tr>
4699     * </table>
4700     * <p>
4701     * Columns from the Contacts table are also available through a join.
4702     * </p>
4703     * <table class="jd-sumtable">
4704     * <tr>
4705     * <th colspan='4'>Join with {@link Contacts}</th>
4706     * </tr>
4707     * <tr>
4708     * <td>long</td>
4709     * <td>{@link #_ID}</td>
4710     * <td>read-only</td>
4711     * <td>Contact ID.</td>
4712     * </tr>
4713     * <tr>
4714     * <td>String</td>
4715     * <td>{@link #LOOKUP_KEY}</td>
4716     * <td>read-only</td>
4717     * <td>See {@link ContactsContract.Contacts}</td>
4718     * </tr>
4719     * <tr>
4720     * <td>String</td>
4721     * <td>{@link #DISPLAY_NAME}</td>
4722     * <td>read-only</td>
4723     * <td>See {@link ContactsContract.Contacts}</td>
4724     * </tr>
4725     * <tr>
4726     * <td>long</td>
4727     * <td>{@link #PHOTO_ID}</td>
4728     * <td>read-only</td>
4729     * <td>See {@link ContactsContract.Contacts}.</td>
4730     * </tr>
4731     * <tr>
4732     * <td>int</td>
4733     * <td>{@link #IN_VISIBLE_GROUP}</td>
4734     * <td>read-only</td>
4735     * <td>See {@link ContactsContract.Contacts}.</td>
4736     * </tr>
4737     * <tr>
4738     * <td>int</td>
4739     * <td>{@link #HAS_PHONE_NUMBER}</td>
4740     * <td>read-only</td>
4741     * <td>See {@link ContactsContract.Contacts}.</td>
4742     * </tr>
4743     * <tr>
4744     * <td>int</td>
4745     * <td>{@link #TIMES_CONTACTED}</td>
4746     * <td>read-only</td>
4747     * <td>See {@link ContactsContract.Contacts}.</td>
4748     * </tr>
4749     * <tr>
4750     * <td>long</td>
4751     * <td>{@link #LAST_TIME_CONTACTED}</td>
4752     * <td>read-only</td>
4753     * <td>See {@link ContactsContract.Contacts}.</td>
4754     * </tr>
4755     * <tr>
4756     * <td>int</td>
4757     * <td>{@link #STARRED}</td>
4758     * <td>read-only</td>
4759     * <td>See {@link ContactsContract.Contacts}.</td>
4760     * </tr>
4761     * <tr>
4762     * <td>String</td>
4763     * <td>{@link #CUSTOM_RINGTONE}</td>
4764     * <td>read-only</td>
4765     * <td>See {@link ContactsContract.Contacts}.</td>
4766     * </tr>
4767     * <tr>
4768     * <td>int</td>
4769     * <td>{@link #SEND_TO_VOICEMAIL}</td>
4770     * <td>read-only</td>
4771     * <td>See {@link ContactsContract.Contacts}.</td>
4772     * </tr>
4773     * </table>
4774     */
4775    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
4776            ContactsColumns, ContactOptionsColumns {
4777        /**
4778         * This utility class cannot be instantiated
4779         */
4780        private PhoneLookup() {}
4781
4782        /**
4783         * The content:// style URI for this table. Append the phone number you want to lookup
4784         * to this URI and query it to perform a lookup. For example:
4785         * <pre>
4786         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
4787         *         Uri.encode(phoneNumber));
4788         * </pre>
4789         */
4790        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
4791                "phone_lookup");
4792
4793        /**
4794         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
4795         *
4796         * @hide
4797         */
4798        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
4799
4800        /**
4801         * If this boolean parameter is set to true, then the appended query is treated as a
4802         * SIP address and the lookup will be performed against SIP addresses in the user's
4803         * contacts.
4804         */
4805        public static final String QUERY_PARAMETER_SIP_ADDRESS = "sip";
4806    }
4807
4808    /**
4809     * Additional data mixed in with {@link StatusColumns} to link
4810     * back to specific {@link ContactsContract.Data#_ID} entries.
4811     *
4812     * @see StatusUpdates
4813     */
4814    protected interface PresenceColumns {
4815
4816        /**
4817         * Reference to the {@link Data#_ID} entry that owns this presence.
4818         * <P>Type: INTEGER</P>
4819         */
4820        public static final String DATA_ID = "presence_data_id";
4821
4822        /**
4823         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
4824         * <p>Type: NUMBER</p>
4825         */
4826        public static final String PROTOCOL = "protocol";
4827
4828        /**
4829         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
4830         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
4831         * omitted if {@link #PROTOCOL} value is not
4832         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
4833         *
4834         * <p>Type: NUMBER</p>
4835         */
4836        public static final String CUSTOM_PROTOCOL = "custom_protocol";
4837
4838        /**
4839         * The IM handle the presence item is for. The handle is scoped to
4840         * {@link #PROTOCOL}.
4841         * <P>Type: TEXT</P>
4842         */
4843        public static final String IM_HANDLE = "im_handle";
4844
4845        /**
4846         * The IM account for the local user that the presence data came from.
4847         * <P>Type: TEXT</P>
4848         */
4849        public static final String IM_ACCOUNT = "im_account";
4850    }
4851
4852    /**
4853     * <p>
4854     * A status update is linked to a {@link ContactsContract.Data} row and captures
4855     * the user's latest status update via the corresponding source, e.g.
4856     * "Having lunch" via "Google Talk".
4857     * </p>
4858     * <p>
4859     * There are two ways a status update can be inserted: by explicitly linking
4860     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
4861     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
4862     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
4863     * either.
4864     * </p>
4865     * <p>
4866     * Inserting or updating a status update for the user's profile requires either using
4867     * the {@link #DATA_ID} to identify the data row to attach the update to, or
4868     * {@link StatusUpdates#PROFILE_CONTENT_URI} to ensure that the change is scoped to the
4869     * profile.
4870     * </p>
4871     * <p>
4872     * You cannot use {@link ContentResolver#update} to change a status, but
4873     * {@link ContentResolver#insert} will replace the latests status if it already
4874     * exists.
4875     * </p>
4876     * <p>
4877     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
4878     * for multiple contacts at once.
4879     * </p>
4880     *
4881     * <h3>Columns</h3>
4882     * <table class="jd-sumtable">
4883     * <tr>
4884     * <th colspan='4'>StatusUpdates</th>
4885     * </tr>
4886     * <tr>
4887     * <td>long</td>
4888     * <td>{@link #DATA_ID}</td>
4889     * <td>read/write</td>
4890     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
4891     * field is <i>not</i> specified, the provider will attempt to find a data row
4892     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
4893     * {@link #IM_HANDLE} columns.
4894     * </td>
4895     * </tr>
4896     * <tr>
4897     * <td>long</td>
4898     * <td>{@link #PROTOCOL}</td>
4899     * <td>read/write</td>
4900     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
4901     * </tr>
4902     * <tr>
4903     * <td>String</td>
4904     * <td>{@link #CUSTOM_PROTOCOL}</td>
4905     * <td>read/write</td>
4906     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
4907     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
4908     * omitted if {@link #PROTOCOL} value is not
4909     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
4910     * </tr>
4911     * <tr>
4912     * <td>String</td>
4913     * <td>{@link #IM_HANDLE}</td>
4914     * <td>read/write</td>
4915     * <td> The IM handle the presence item is for. The handle is scoped to
4916     * {@link #PROTOCOL}.</td>
4917     * </tr>
4918     * <tr>
4919     * <td>String</td>
4920     * <td>{@link #IM_ACCOUNT}</td>
4921     * <td>read/write</td>
4922     * <td>The IM account for the local user that the presence data came from.</td>
4923     * </tr>
4924     * <tr>
4925     * <td>int</td>
4926     * <td>{@link #PRESENCE}</td>
4927     * <td>read/write</td>
4928     * <td>Contact IM presence status. The allowed values are:
4929     * <p>
4930     * <ul>
4931     * <li>{@link #OFFLINE}</li>
4932     * <li>{@link #INVISIBLE}</li>
4933     * <li>{@link #AWAY}</li>
4934     * <li>{@link #IDLE}</li>
4935     * <li>{@link #DO_NOT_DISTURB}</li>
4936     * <li>{@link #AVAILABLE}</li>
4937     * </ul>
4938     * </p>
4939     * <p>
4940     * Since presence status is inherently volatile, the content provider
4941     * may choose not to store this field in long-term storage.
4942     * </p>
4943     * </td>
4944     * </tr>
4945     * <tr>
4946     * <td>int</td>
4947     * <td>{@link #CHAT_CAPABILITY}</td>
4948     * <td>read/write</td>
4949     * <td>Contact IM chat compatibility value. The allowed values combinations of the following
4950     * flags. If None of these flags is set, the device can only do text messaging.
4951     * <p>
4952     * <ul>
4953     * <li>{@link #CAPABILITY_HAS_VIDEO}</li>
4954     * <li>{@link #CAPABILITY_HAS_VOICE}</li>
4955     * <li>{@link #CAPABILITY_HAS_CAMERA}</li>
4956     * </ul>
4957     * </p>
4958     * <p>
4959     * Since chat compatibility is inherently volatile as the contact's availability moves from
4960     * one device to another, the content provider may choose not to store this field in long-term
4961     * storage.
4962     * </p>
4963     * </td>
4964     * </tr>
4965     * <tr>
4966     * <td>String</td>
4967     * <td>{@link #STATUS}</td>
4968     * <td>read/write</td>
4969     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
4970     * </tr>
4971     * <tr>
4972     * <td>long</td>
4973     * <td>{@link #STATUS_TIMESTAMP}</td>
4974     * <td>read/write</td>
4975     * <td>The absolute time in milliseconds when the status was
4976     * entered by the user. If this value is not provided, the provider will follow
4977     * this logic: if there was no prior status update, the value will be left as null.
4978     * If there was a prior status update, the provider will default this field
4979     * to the current time.</td>
4980     * </tr>
4981     * <tr>
4982     * <td>String</td>
4983     * <td>{@link #STATUS_RES_PACKAGE}</td>
4984     * <td>read/write</td>
4985     * <td> The package containing resources for this status: label and icon.</td>
4986     * </tr>
4987     * <tr>
4988     * <td>long</td>
4989     * <td>{@link #STATUS_LABEL}</td>
4990     * <td>read/write</td>
4991     * <td>The resource ID of the label describing the source of contact status,
4992     * e.g. "Google Talk". This resource is scoped by the
4993     * {@link #STATUS_RES_PACKAGE}.</td>
4994     * </tr>
4995     * <tr>
4996     * <td>long</td>
4997     * <td>{@link #STATUS_ICON}</td>
4998     * <td>read/write</td>
4999     * <td>The resource ID of the icon for the source of contact status. This
5000     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
5001     * </tr>
5002     * </table>
5003     */
5004    public static class StatusUpdates implements StatusColumns, PresenceColumns {
5005
5006        /**
5007         * This utility class cannot be instantiated
5008         */
5009        private StatusUpdates() {}
5010
5011        /**
5012         * The content:// style URI for this table
5013         */
5014        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
5015
5016        /**
5017         * The content:// style URI for this table, specific to the user's profile.
5018         */
5019        public static final Uri PROFILE_CONTENT_URI =
5020                Uri.withAppendedPath(Profile.CONTENT_URI, "status_updates");
5021
5022        /**
5023         * Gets the resource ID for the proper presence icon.
5024         *
5025         * @param status the status to get the icon for
5026         * @return the resource ID for the proper presence icon
5027         */
5028        public static final int getPresenceIconResourceId(int status) {
5029            switch (status) {
5030                case AVAILABLE:
5031                    return android.R.drawable.presence_online;
5032                case IDLE:
5033                case AWAY:
5034                    return android.R.drawable.presence_away;
5035                case DO_NOT_DISTURB:
5036                    return android.R.drawable.presence_busy;
5037                case INVISIBLE:
5038                    return android.R.drawable.presence_invisible;
5039                case OFFLINE:
5040                default:
5041                    return android.R.drawable.presence_offline;
5042            }
5043        }
5044
5045        /**
5046         * Returns the precedence of the status code the higher number being the higher precedence.
5047         *
5048         * @param status The status code.
5049         * @return An integer representing the precedence, 0 being the lowest.
5050         */
5051        public static final int getPresencePrecedence(int status) {
5052            // Keep this function here incase we want to enforce a different precedence than the
5053            // natural order of the status constants.
5054            return status;
5055        }
5056
5057        /**
5058         * The MIME type of {@link #CONTENT_URI} providing a directory of
5059         * status update details.
5060         */
5061        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
5062
5063        /**
5064         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
5065         * status update detail.
5066         */
5067        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
5068    }
5069
5070    /**
5071     * @deprecated This old name was never meant to be made public. Do not use.
5072     */
5073    @Deprecated
5074    public static final class Presence extends StatusUpdates {
5075
5076    }
5077
5078    /**
5079     * Additional column returned by the {@link Contacts#CONTENT_FILTER_URI} providing the
5080     * explanation of why the filter matched the contact.  Specifically, it contains the
5081     * data elements that matched the query.  The overall number of words in the snippet
5082     * can be capped.
5083     *
5084     * @hide
5085     */
5086    public static class SearchSnippetColumns {
5087
5088        /**
5089         * The search snippet constructed according to the SQLite rules, see
5090         * http://www.sqlite.org/fts3.html#snippet
5091         * <p>
5092         * The snippet may contain (parts of) several data elements comprising
5093         * the contact.
5094         *
5095         * @hide
5096         */
5097        public static final String SNIPPET = "snippet";
5098
5099
5100        /**
5101         * Comma-separated parameters for the generation of the snippet:
5102         * <ul>
5103         * <li>The "start match" text. Default is &lt;b&gt;</li>
5104         * <li>The "end match" text. Default is &lt;/b&gt;</li>
5105         * <li>The "ellipsis" text. Default is &lt;b&gt;...&lt;/b&gt;</li>
5106         * <li>Maximum number of tokens to include in the snippet. Can be either
5107         * a positive or a negative number: A positive number indicates how many
5108         * tokens can be returned in total. A negative number indicates how many
5109         * tokens can be returned per occurrence of the search terms.</li>
5110         * </ul>
5111         *
5112         * @hide
5113         */
5114        public static final String SNIPPET_ARGS_PARAM_KEY = "snippet_args";
5115
5116        /**
5117         * A key to ask the provider to defer the snippeting to the client if possible.
5118         * Value of 1 implies true, 0 implies false when 0 is the default.
5119         * When a cursor is returned to the client, it should check for an extra with the name
5120         * {@link ContactsContract#DEFERRED_SNIPPETING} in the cursor. If it exists, the client
5121         * should do its own snippeting. If it doesn't exist, the snippet column in the cursor
5122         * should already contain a snippetized string.
5123         *
5124         * @hide
5125         */
5126        public static final String DEFERRED_SNIPPETING_KEY = "deferred_snippeting";
5127    }
5128
5129    /**
5130     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
5131     * table.
5132     */
5133    public static final class CommonDataKinds {
5134        /**
5135         * This utility class cannot be instantiated
5136         */
5137        private CommonDataKinds() {}
5138
5139        /**
5140         * The {@link Data#RES_PACKAGE} value for common data that should be
5141         * shown using a default style.
5142         *
5143         * @hide RES_PACKAGE is hidden
5144         */
5145        public static final String PACKAGE_COMMON = "common";
5146
5147        /**
5148         * The base types that all "Typed" data kinds support.
5149         */
5150        public interface BaseTypes {
5151            /**
5152             * A custom type. The custom label should be supplied by user.
5153             */
5154            public static int TYPE_CUSTOM = 0;
5155        }
5156
5157        /**
5158         * Columns common across the specific types.
5159         */
5160        protected interface CommonColumns extends BaseTypes {
5161            /**
5162             * The data for the contact method.
5163             * <P>Type: TEXT</P>
5164             */
5165            public static final String DATA = DataColumns.DATA1;
5166
5167            /**
5168             * The type of data, for example Home or Work.
5169             * <P>Type: INTEGER</P>
5170             */
5171            public static final String TYPE = DataColumns.DATA2;
5172
5173            /**
5174             * The user defined label for the the contact method.
5175             * <P>Type: TEXT</P>
5176             */
5177            public static final String LABEL = DataColumns.DATA3;
5178        }
5179
5180        /**
5181         * A data kind representing the contact's proper name. You can use all
5182         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
5183         *
5184         * <h2>Column aliases</h2>
5185         * <table class="jd-sumtable">
5186         * <tr>
5187         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5188         * </tr>
5189         * <tr>
5190         * <td>String</td>
5191         * <td>{@link #DISPLAY_NAME}</td>
5192         * <td>{@link #DATA1}</td>
5193         * <td></td>
5194         * </tr>
5195         * <tr>
5196         * <td>String</td>
5197         * <td>{@link #GIVEN_NAME}</td>
5198         * <td>{@link #DATA2}</td>
5199         * <td></td>
5200         * </tr>
5201         * <tr>
5202         * <td>String</td>
5203         * <td>{@link #FAMILY_NAME}</td>
5204         * <td>{@link #DATA3}</td>
5205         * <td></td>
5206         * </tr>
5207         * <tr>
5208         * <td>String</td>
5209         * <td>{@link #PREFIX}</td>
5210         * <td>{@link #DATA4}</td>
5211         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
5212         * </tr>
5213         * <tr>
5214         * <td>String</td>
5215         * <td>{@link #MIDDLE_NAME}</td>
5216         * <td>{@link #DATA5}</td>
5217         * <td></td>
5218         * </tr>
5219         * <tr>
5220         * <td>String</td>
5221         * <td>{@link #SUFFIX}</td>
5222         * <td>{@link #DATA6}</td>
5223         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
5224         * </tr>
5225         * <tr>
5226         * <td>String</td>
5227         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
5228         * <td>{@link #DATA7}</td>
5229         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
5230         * </tr>
5231         * <tr>
5232         * <td>String</td>
5233         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
5234         * <td>{@link #DATA8}</td>
5235         * <td></td>
5236         * </tr>
5237         * <tr>
5238         * <td>String</td>
5239         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
5240         * <td>{@link #DATA9}</td>
5241         * <td></td>
5242         * </tr>
5243         * </table>
5244         */
5245        public static final class StructuredName implements DataColumnsWithJoins {
5246            /**
5247             * This utility class cannot be instantiated
5248             */
5249            private StructuredName() {}
5250
5251            /** MIME type used when storing this in data table. */
5252            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
5253
5254            /**
5255             * The name that should be used to display the contact.
5256             * <i>Unstructured component of the name should be consistent with
5257             * its structured representation.</i>
5258             * <p>
5259             * Type: TEXT
5260             */
5261            public static final String DISPLAY_NAME = DATA1;
5262
5263            /**
5264             * The given name for the contact.
5265             * <P>Type: TEXT</P>
5266             */
5267            public static final String GIVEN_NAME = DATA2;
5268
5269            /**
5270             * The family name for the contact.
5271             * <P>Type: TEXT</P>
5272             */
5273            public static final String FAMILY_NAME = DATA3;
5274
5275            /**
5276             * The contact's honorific prefix, e.g. "Sir"
5277             * <P>Type: TEXT</P>
5278             */
5279            public static final String PREFIX = DATA4;
5280
5281            /**
5282             * The contact's middle name
5283             * <P>Type: TEXT</P>
5284             */
5285            public static final String MIDDLE_NAME = DATA5;
5286
5287            /**
5288             * The contact's honorific suffix, e.g. "Jr"
5289             */
5290            public static final String SUFFIX = DATA6;
5291
5292            /**
5293             * The phonetic version of the given name for the contact.
5294             * <P>Type: TEXT</P>
5295             */
5296            public static final String PHONETIC_GIVEN_NAME = DATA7;
5297
5298            /**
5299             * The phonetic version of the additional name for the contact.
5300             * <P>Type: TEXT</P>
5301             */
5302            public static final String PHONETIC_MIDDLE_NAME = DATA8;
5303
5304            /**
5305             * The phonetic version of the family name for the contact.
5306             * <P>Type: TEXT</P>
5307             */
5308            public static final String PHONETIC_FAMILY_NAME = DATA9;
5309
5310            /**
5311             * The style used for combining given/middle/family name into a full name.
5312             * See {@link ContactsContract.FullNameStyle}.
5313             */
5314            public static final String FULL_NAME_STYLE = DATA10;
5315
5316            /**
5317             * The alphabet used for capturing the phonetic name.
5318             * See ContactsContract.PhoneticNameStyle.
5319             * @hide
5320             */
5321            public static final String PHONETIC_NAME_STYLE = DATA11;
5322        }
5323
5324        /**
5325         * <p>A data kind representing the contact's nickname. For example, for
5326         * Bob Parr ("Mr. Incredible"):
5327         * <pre>
5328         * ArrayList&lt;ContentProviderOperation&gt; ops =
5329         *          new ArrayList&lt;ContentProviderOperation&gt;();
5330         *
5331         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5332         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5333         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
5334         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
5335         *          .build());
5336         *
5337         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5338         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5339         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
5340         *          .withValue(Nickname.NAME, "Mr. Incredible")
5341         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
5342         *          .withValue(Nickname.LABEL, "Superhero")
5343         *          .build());
5344         *
5345         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
5346         * </pre>
5347         * </p>
5348         * <p>
5349         * You can use all columns defined for {@link ContactsContract.Data} as well as the
5350         * following aliases.
5351         * </p>
5352         *
5353         * <h2>Column aliases</h2>
5354         * <table class="jd-sumtable">
5355         * <tr>
5356         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5357         * </tr>
5358         * <tr>
5359         * <td>String</td>
5360         * <td>{@link #NAME}</td>
5361         * <td>{@link #DATA1}</td>
5362         * <td></td>
5363         * </tr>
5364         * <tr>
5365         * <td>int</td>
5366         * <td>{@link #TYPE}</td>
5367         * <td>{@link #DATA2}</td>
5368         * <td>
5369         * Allowed values are:
5370         * <p>
5371         * <ul>
5372         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5373         * <li>{@link #TYPE_DEFAULT}</li>
5374         * <li>{@link #TYPE_OTHER_NAME}</li>
5375         * <li>{@link #TYPE_MAIDEN_NAME}</li>
5376         * <li>{@link #TYPE_SHORT_NAME}</li>
5377         * <li>{@link #TYPE_INITIALS}</li>
5378         * </ul>
5379         * </p>
5380         * </td>
5381         * </tr>
5382         * <tr>
5383         * <td>String</td>
5384         * <td>{@link #LABEL}</td>
5385         * <td>{@link #DATA3}</td>
5386         * <td></td>
5387         * </tr>
5388         * </table>
5389         */
5390        public static final class Nickname implements DataColumnsWithJoins, CommonColumns {
5391            /**
5392             * This utility class cannot be instantiated
5393             */
5394            private Nickname() {}
5395
5396            /** MIME type used when storing this in data table. */
5397            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
5398
5399            public static final int TYPE_DEFAULT = 1;
5400            public static final int TYPE_OTHER_NAME = 2;
5401            public static final int TYPE_MAIDEN_NAME = 3;
5402            /** @deprecated Use TYPE_MAIDEN_NAME instead. */
5403            @Deprecated
5404            public static final int TYPE_MAINDEN_NAME = 3;
5405            public static final int TYPE_SHORT_NAME = 4;
5406            public static final int TYPE_INITIALS = 5;
5407
5408            /**
5409             * The name itself
5410             */
5411            public static final String NAME = DATA;
5412        }
5413
5414        /**
5415         * <p>
5416         * A data kind representing a telephone number.
5417         * </p>
5418         * <p>
5419         * You can use all columns defined for {@link ContactsContract.Data} as
5420         * well as the following aliases.
5421         * </p>
5422         * <h2>Column aliases</h2>
5423         * <table class="jd-sumtable">
5424         * <tr>
5425         * <th>Type</th>
5426         * <th>Alias</th><th colspan='2'>Data column</th>
5427         * </tr>
5428         * <tr>
5429         * <td>String</td>
5430         * <td>{@link #NUMBER}</td>
5431         * <td>{@link #DATA1}</td>
5432         * <td></td>
5433         * </tr>
5434         * <tr>
5435         * <td>int</td>
5436         * <td>{@link #TYPE}</td>
5437         * <td>{@link #DATA2}</td>
5438         * <td>Allowed values are:
5439         * <p>
5440         * <ul>
5441         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5442         * <li>{@link #TYPE_HOME}</li>
5443         * <li>{@link #TYPE_MOBILE}</li>
5444         * <li>{@link #TYPE_WORK}</li>
5445         * <li>{@link #TYPE_FAX_WORK}</li>
5446         * <li>{@link #TYPE_FAX_HOME}</li>
5447         * <li>{@link #TYPE_PAGER}</li>
5448         * <li>{@link #TYPE_OTHER}</li>
5449         * <li>{@link #TYPE_CALLBACK}</li>
5450         * <li>{@link #TYPE_CAR}</li>
5451         * <li>{@link #TYPE_COMPANY_MAIN}</li>
5452         * <li>{@link #TYPE_ISDN}</li>
5453         * <li>{@link #TYPE_MAIN}</li>
5454         * <li>{@link #TYPE_OTHER_FAX}</li>
5455         * <li>{@link #TYPE_RADIO}</li>
5456         * <li>{@link #TYPE_TELEX}</li>
5457         * <li>{@link #TYPE_TTY_TDD}</li>
5458         * <li>{@link #TYPE_WORK_MOBILE}</li>
5459         * <li>{@link #TYPE_WORK_PAGER}</li>
5460         * <li>{@link #TYPE_ASSISTANT}</li>
5461         * <li>{@link #TYPE_MMS}</li>
5462         * </ul>
5463         * </p>
5464         * </td>
5465         * </tr>
5466         * <tr>
5467         * <td>String</td>
5468         * <td>{@link #LABEL}</td>
5469         * <td>{@link #DATA3}</td>
5470         * <td></td>
5471         * </tr>
5472         * </table>
5473         */
5474        public static final class Phone implements DataColumnsWithJoins, CommonColumns {
5475            /**
5476             * This utility class cannot be instantiated
5477             */
5478            private Phone() {}
5479
5480            /** MIME type used when storing this in data table. */
5481            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
5482
5483            /**
5484             * The MIME type of {@link #CONTENT_URI} providing a directory of
5485             * phones.
5486             */
5487            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
5488
5489            /**
5490             * The content:// style URI for all data records of the
5491             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5492             * associated raw contact and aggregate contact data.
5493             */
5494            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5495                    "phones");
5496
5497            /**
5498             * The content:// style URL for phone lookup using a filter. The filter returns
5499             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
5500             * to display names as well as phone numbers. The filter argument should be passed
5501             * as an additional path segment after this URI.
5502             */
5503            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
5504                    "filter");
5505
5506            /**
5507             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5508             * If "1" or "true", display names are searched.  If "0" or "false", display names
5509             * are not searched.  Default is "1".
5510             */
5511            public static final String SEARCH_DISPLAY_NAME_KEY = "search_display_name";
5512
5513            /**
5514             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5515             * If "1" or "true", phone numbers are searched.  If "0" or "false", phone numbers
5516             * are not searched.  Default is "1".
5517             */
5518            public static final String SEARCH_PHONE_NUMBER_KEY = "search_phone_number";
5519
5520            public static final int TYPE_HOME = 1;
5521            public static final int TYPE_MOBILE = 2;
5522            public static final int TYPE_WORK = 3;
5523            public static final int TYPE_FAX_WORK = 4;
5524            public static final int TYPE_FAX_HOME = 5;
5525            public static final int TYPE_PAGER = 6;
5526            public static final int TYPE_OTHER = 7;
5527            public static final int TYPE_CALLBACK = 8;
5528            public static final int TYPE_CAR = 9;
5529            public static final int TYPE_COMPANY_MAIN = 10;
5530            public static final int TYPE_ISDN = 11;
5531            public static final int TYPE_MAIN = 12;
5532            public static final int TYPE_OTHER_FAX = 13;
5533            public static final int TYPE_RADIO = 14;
5534            public static final int TYPE_TELEX = 15;
5535            public static final int TYPE_TTY_TDD = 16;
5536            public static final int TYPE_WORK_MOBILE = 17;
5537            public static final int TYPE_WORK_PAGER = 18;
5538            public static final int TYPE_ASSISTANT = 19;
5539            public static final int TYPE_MMS = 20;
5540
5541            /**
5542             * The phone number as the user entered it.
5543             * <P>Type: TEXT</P>
5544             */
5545            public static final String NUMBER = DATA;
5546
5547            /**
5548             * The phone number's E164 representation. This value can be omitted in which
5549             * case the provider will try to automatically infer it.  (It'll be left null if the
5550             * provider fails to infer.)
5551             * If present, {@link #NUMBER} has to be set as well (it will be ignored otherwise).
5552             * <P>Type: TEXT</P>
5553             */
5554            public static final String NORMALIZED_NUMBER = DATA4;
5555
5556            /**
5557             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5558             * @hide
5559             */
5560            @Deprecated
5561            public static final CharSequence getDisplayLabel(Context context, int type,
5562                    CharSequence label, CharSequence[] labelArray) {
5563                return getTypeLabel(context.getResources(), type, label);
5564            }
5565
5566            /**
5567             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5568             * @hide
5569             */
5570            @Deprecated
5571            public static final CharSequence getDisplayLabel(Context context, int type,
5572                    CharSequence label) {
5573                return getTypeLabel(context.getResources(), type, label);
5574            }
5575
5576            /**
5577             * Return the string resource that best describes the given
5578             * {@link #TYPE}. Will always return a valid resource.
5579             */
5580            public static final int getTypeLabelResource(int type) {
5581                switch (type) {
5582                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
5583                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
5584                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
5585                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
5586                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
5587                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
5588                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
5589                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
5590                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
5591                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
5592                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
5593                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
5594                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
5595                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
5596                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
5597                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
5598                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
5599                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
5600                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
5601                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
5602                    default: return com.android.internal.R.string.phoneTypeCustom;
5603                }
5604            }
5605
5606            /**
5607             * Return a {@link CharSequence} that best describes the given type,
5608             * possibly substituting the given {@link #LABEL} value
5609             * for {@link #TYPE_CUSTOM}.
5610             */
5611            public static final CharSequence getTypeLabel(Resources res, int type,
5612                    CharSequence label) {
5613                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
5614                    return label;
5615                } else {
5616                    final int labelRes = getTypeLabelResource(type);
5617                    return res.getText(labelRes);
5618                }
5619            }
5620        }
5621
5622        /**
5623         * <p>
5624         * A data kind representing an email address.
5625         * </p>
5626         * <p>
5627         * You can use all columns defined for {@link ContactsContract.Data} as
5628         * well as the following aliases.
5629         * </p>
5630         * <h2>Column aliases</h2>
5631         * <table class="jd-sumtable">
5632         * <tr>
5633         * <th>Type</th>
5634         * <th>Alias</th><th colspan='2'>Data column</th>
5635         * </tr>
5636         * <tr>
5637         * <td>String</td>
5638         * <td>{@link #ADDRESS}</td>
5639         * <td>{@link #DATA1}</td>
5640         * <td>Email address itself.</td>
5641         * </tr>
5642         * <tr>
5643         * <td>int</td>
5644         * <td>{@link #TYPE}</td>
5645         * <td>{@link #DATA2}</td>
5646         * <td>Allowed values are:
5647         * <p>
5648         * <ul>
5649         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5650         * <li>{@link #TYPE_HOME}</li>
5651         * <li>{@link #TYPE_WORK}</li>
5652         * <li>{@link #TYPE_OTHER}</li>
5653         * <li>{@link #TYPE_MOBILE}</li>
5654         * </ul>
5655         * </p>
5656         * </td>
5657         * </tr>
5658         * <tr>
5659         * <td>String</td>
5660         * <td>{@link #LABEL}</td>
5661         * <td>{@link #DATA3}</td>
5662         * <td></td>
5663         * </tr>
5664         * </table>
5665         */
5666        public static final class Email implements DataColumnsWithJoins, CommonColumns {
5667            /**
5668             * This utility class cannot be instantiated
5669             */
5670            private Email() {}
5671
5672            /** MIME type used when storing this in data table. */
5673            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
5674
5675            /**
5676             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
5677             */
5678            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
5679
5680            /**
5681             * The content:// style URI for all data records of the
5682             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5683             * associated raw contact and aggregate contact data.
5684             */
5685            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5686                    "emails");
5687
5688            /**
5689             * <p>
5690             * The content:// style URL for looking up data rows by email address. The
5691             * lookup argument, an email address, should be passed as an additional path segment
5692             * after this URI.
5693             * </p>
5694             * <p>Example:
5695             * <pre>
5696             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
5697             * Cursor c = getContentResolver().query(uri,
5698             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
5699             *          null, null, null);
5700             * </pre>
5701             * </p>
5702             */
5703            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
5704                    "lookup");
5705
5706            /**
5707             * <p>
5708             * The content:// style URL for email lookup using a filter. The filter returns
5709             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
5710             * to display names as well as email addresses. The filter argument should be passed
5711             * as an additional path segment after this URI.
5712             * </p>
5713             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
5714             * as well as "Bob Parr (incredible@android.com)".
5715             * <pre>
5716             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
5717             * Cursor c = getContentResolver().query(uri,
5718             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
5719             *          null, null, null);
5720             * </pre>
5721             * </p>
5722             */
5723            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
5724                    "filter");
5725
5726            /**
5727             * The email address.
5728             * <P>Type: TEXT</P>
5729             */
5730            public static final String ADDRESS = DATA1;
5731
5732            public static final int TYPE_HOME = 1;
5733            public static final int TYPE_WORK = 2;
5734            public static final int TYPE_OTHER = 3;
5735            public static final int TYPE_MOBILE = 4;
5736
5737            /**
5738             * The display name for the email address
5739             * <P>Type: TEXT</P>
5740             */
5741            public static final String DISPLAY_NAME = DATA4;
5742
5743            /**
5744             * Return the string resource that best describes the given
5745             * {@link #TYPE}. Will always return a valid resource.
5746             */
5747            public static final int getTypeLabelResource(int type) {
5748                switch (type) {
5749                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
5750                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
5751                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
5752                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
5753                    default: return com.android.internal.R.string.emailTypeCustom;
5754                }
5755            }
5756
5757            /**
5758             * Return a {@link CharSequence} that best describes the given type,
5759             * possibly substituting the given {@link #LABEL} value
5760             * for {@link #TYPE_CUSTOM}.
5761             */
5762            public static final CharSequence getTypeLabel(Resources res, int type,
5763                    CharSequence label) {
5764                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
5765                    return label;
5766                } else {
5767                    final int labelRes = getTypeLabelResource(type);
5768                    return res.getText(labelRes);
5769                }
5770            }
5771        }
5772
5773        /**
5774         * <p>
5775         * A data kind representing a postal addresses.
5776         * </p>
5777         * <p>
5778         * You can use all columns defined for {@link ContactsContract.Data} as
5779         * well as the following aliases.
5780         * </p>
5781         * <h2>Column aliases</h2>
5782         * <table class="jd-sumtable">
5783         * <tr>
5784         * <th>Type</th>
5785         * <th>Alias</th><th colspan='2'>Data column</th>
5786         * </tr>
5787         * <tr>
5788         * <td>String</td>
5789         * <td>{@link #FORMATTED_ADDRESS}</td>
5790         * <td>{@link #DATA1}</td>
5791         * <td></td>
5792         * </tr>
5793         * <tr>
5794         * <td>int</td>
5795         * <td>{@link #TYPE}</td>
5796         * <td>{@link #DATA2}</td>
5797         * <td>Allowed values are:
5798         * <p>
5799         * <ul>
5800         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5801         * <li>{@link #TYPE_HOME}</li>
5802         * <li>{@link #TYPE_WORK}</li>
5803         * <li>{@link #TYPE_OTHER}</li>
5804         * </ul>
5805         * </p>
5806         * </td>
5807         * </tr>
5808         * <tr>
5809         * <td>String</td>
5810         * <td>{@link #LABEL}</td>
5811         * <td>{@link #DATA3}</td>
5812         * <td></td>
5813         * </tr>
5814         * <tr>
5815         * <td>String</td>
5816         * <td>{@link #STREET}</td>
5817         * <td>{@link #DATA4}</td>
5818         * <td></td>
5819         * </tr>
5820         * <tr>
5821         * <td>String</td>
5822         * <td>{@link #POBOX}</td>
5823         * <td>{@link #DATA5}</td>
5824         * <td>Post Office Box number</td>
5825         * </tr>
5826         * <tr>
5827         * <td>String</td>
5828         * <td>{@link #NEIGHBORHOOD}</td>
5829         * <td>{@link #DATA6}</td>
5830         * <td></td>
5831         * </tr>
5832         * <tr>
5833         * <td>String</td>
5834         * <td>{@link #CITY}</td>
5835         * <td>{@link #DATA7}</td>
5836         * <td></td>
5837         * </tr>
5838         * <tr>
5839         * <td>String</td>
5840         * <td>{@link #REGION}</td>
5841         * <td>{@link #DATA8}</td>
5842         * <td></td>
5843         * </tr>
5844         * <tr>
5845         * <td>String</td>
5846         * <td>{@link #POSTCODE}</td>
5847         * <td>{@link #DATA9}</td>
5848         * <td></td>
5849         * </tr>
5850         * <tr>
5851         * <td>String</td>
5852         * <td>{@link #COUNTRY}</td>
5853         * <td>{@link #DATA10}</td>
5854         * <td></td>
5855         * </tr>
5856         * </table>
5857         */
5858        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns {
5859            /**
5860             * This utility class cannot be instantiated
5861             */
5862            private StructuredPostal() {
5863            }
5864
5865            /** MIME type used when storing this in data table. */
5866            public static final String CONTENT_ITEM_TYPE =
5867                    "vnd.android.cursor.item/postal-address_v2";
5868
5869            /**
5870             * The MIME type of {@link #CONTENT_URI} providing a directory of
5871             * postal addresses.
5872             */
5873            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
5874
5875            /**
5876             * The content:// style URI for all data records of the
5877             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
5878             */
5879            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5880                    "postals");
5881
5882            public static final int TYPE_HOME = 1;
5883            public static final int TYPE_WORK = 2;
5884            public static final int TYPE_OTHER = 3;
5885
5886            /**
5887             * The full, unstructured postal address. <i>This field must be
5888             * consistent with any structured data.</i>
5889             * <p>
5890             * Type: TEXT
5891             */
5892            public static final String FORMATTED_ADDRESS = DATA;
5893
5894            /**
5895             * Can be street, avenue, road, etc. This element also includes the
5896             * house number and room/apartment/flat/floor number.
5897             * <p>
5898             * Type: TEXT
5899             */
5900            public static final String STREET = DATA4;
5901
5902            /**
5903             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
5904             * usually but not always mutually exclusive with street.
5905             * <p>
5906             * Type: TEXT
5907             */
5908            public static final String POBOX = DATA5;
5909
5910            /**
5911             * This is used to disambiguate a street address when a city
5912             * contains more than one street with the same name, or to specify a
5913             * small place whose mail is routed through a larger postal town. In
5914             * China it could be a county or a minor city.
5915             * <p>
5916             * Type: TEXT
5917             */
5918            public static final String NEIGHBORHOOD = DATA6;
5919
5920            /**
5921             * Can be city, village, town, borough, etc. This is the postal town
5922             * and not necessarily the place of residence or place of business.
5923             * <p>
5924             * Type: TEXT
5925             */
5926            public static final String CITY = DATA7;
5927
5928            /**
5929             * A state, province, county (in Ireland), Land (in Germany),
5930             * departement (in France), etc.
5931             * <p>
5932             * Type: TEXT
5933             */
5934            public static final String REGION = DATA8;
5935
5936            /**
5937             * Postal code. Usually country-wide, but sometimes specific to the
5938             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
5939             * <p>
5940             * Type: TEXT
5941             */
5942            public static final String POSTCODE = DATA9;
5943
5944            /**
5945             * The name or code of the country.
5946             * <p>
5947             * Type: TEXT
5948             */
5949            public static final String COUNTRY = DATA10;
5950
5951            /**
5952             * Return the string resource that best describes the given
5953             * {@link #TYPE}. Will always return a valid resource.
5954             */
5955            public static final int getTypeLabelResource(int type) {
5956                switch (type) {
5957                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
5958                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
5959                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
5960                    default: return com.android.internal.R.string.postalTypeCustom;
5961                }
5962            }
5963
5964            /**
5965             * Return a {@link CharSequence} that best describes the given type,
5966             * possibly substituting the given {@link #LABEL} value
5967             * for {@link #TYPE_CUSTOM}.
5968             */
5969            public static final CharSequence getTypeLabel(Resources res, int type,
5970                    CharSequence label) {
5971                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
5972                    return label;
5973                } else {
5974                    final int labelRes = getTypeLabelResource(type);
5975                    return res.getText(labelRes);
5976                }
5977            }
5978        }
5979
5980        /**
5981         * <p>
5982         * A data kind representing an IM address
5983         * </p>
5984         * <p>
5985         * You can use all columns defined for {@link ContactsContract.Data} as
5986         * well as the following aliases.
5987         * </p>
5988         * <h2>Column aliases</h2>
5989         * <table class="jd-sumtable">
5990         * <tr>
5991         * <th>Type</th>
5992         * <th>Alias</th><th colspan='2'>Data column</th>
5993         * </tr>
5994         * <tr>
5995         * <td>String</td>
5996         * <td>{@link #DATA}</td>
5997         * <td>{@link #DATA1}</td>
5998         * <td></td>
5999         * </tr>
6000         * <tr>
6001         * <td>int</td>
6002         * <td>{@link #TYPE}</td>
6003         * <td>{@link #DATA2}</td>
6004         * <td>Allowed values are:
6005         * <p>
6006         * <ul>
6007         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6008         * <li>{@link #TYPE_HOME}</li>
6009         * <li>{@link #TYPE_WORK}</li>
6010         * <li>{@link #TYPE_OTHER}</li>
6011         * </ul>
6012         * </p>
6013         * </td>
6014         * </tr>
6015         * <tr>
6016         * <td>String</td>
6017         * <td>{@link #LABEL}</td>
6018         * <td>{@link #DATA3}</td>
6019         * <td></td>
6020         * </tr>
6021         * <tr>
6022         * <td>String</td>
6023         * <td>{@link #PROTOCOL}</td>
6024         * <td>{@link #DATA5}</td>
6025         * <td>
6026         * <p>
6027         * Allowed values:
6028         * <ul>
6029         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
6030         * as {@link #CUSTOM_PROTOCOL}.</li>
6031         * <li>{@link #PROTOCOL_AIM}</li>
6032         * <li>{@link #PROTOCOL_MSN}</li>
6033         * <li>{@link #PROTOCOL_YAHOO}</li>
6034         * <li>{@link #PROTOCOL_SKYPE}</li>
6035         * <li>{@link #PROTOCOL_QQ}</li>
6036         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
6037         * <li>{@link #PROTOCOL_ICQ}</li>
6038         * <li>{@link #PROTOCOL_JABBER}</li>
6039         * <li>{@link #PROTOCOL_NETMEETING}</li>
6040         * </ul>
6041         * </p>
6042         * </td>
6043         * </tr>
6044         * <tr>
6045         * <td>String</td>
6046         * <td>{@link #CUSTOM_PROTOCOL}</td>
6047         * <td>{@link #DATA6}</td>
6048         * <td></td>
6049         * </tr>
6050         * </table>
6051         */
6052        public static final class Im implements DataColumnsWithJoins, CommonColumns {
6053            /**
6054             * This utility class cannot be instantiated
6055             */
6056            private Im() {}
6057
6058            /** MIME type used when storing this in data table. */
6059            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
6060
6061            public static final int TYPE_HOME = 1;
6062            public static final int TYPE_WORK = 2;
6063            public static final int TYPE_OTHER = 3;
6064
6065            /**
6066             * This column should be populated with one of the defined
6067             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
6068             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
6069             * should contain the name of the custom protocol.
6070             */
6071            public static final String PROTOCOL = DATA5;
6072
6073            public static final String CUSTOM_PROTOCOL = DATA6;
6074
6075            /*
6076             * The predefined IM protocol types.
6077             */
6078            public static final int PROTOCOL_CUSTOM = -1;
6079            public static final int PROTOCOL_AIM = 0;
6080            public static final int PROTOCOL_MSN = 1;
6081            public static final int PROTOCOL_YAHOO = 2;
6082            public static final int PROTOCOL_SKYPE = 3;
6083            public static final int PROTOCOL_QQ = 4;
6084            public static final int PROTOCOL_GOOGLE_TALK = 5;
6085            public static final int PROTOCOL_ICQ = 6;
6086            public static final int PROTOCOL_JABBER = 7;
6087            public static final int PROTOCOL_NETMEETING = 8;
6088
6089            /**
6090             * Return the string resource that best describes the given
6091             * {@link #TYPE}. Will always return a valid resource.
6092             */
6093            public static final int getTypeLabelResource(int type) {
6094                switch (type) {
6095                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
6096                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
6097                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
6098                    default: return com.android.internal.R.string.imTypeCustom;
6099                }
6100            }
6101
6102            /**
6103             * Return a {@link CharSequence} that best describes the given type,
6104             * possibly substituting the given {@link #LABEL} value
6105             * for {@link #TYPE_CUSTOM}.
6106             */
6107            public static final CharSequence getTypeLabel(Resources res, int type,
6108                    CharSequence label) {
6109                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6110                    return label;
6111                } else {
6112                    final int labelRes = getTypeLabelResource(type);
6113                    return res.getText(labelRes);
6114                }
6115            }
6116
6117            /**
6118             * Return the string resource that best describes the given
6119             * {@link #PROTOCOL}. Will always return a valid resource.
6120             */
6121            public static final int getProtocolLabelResource(int type) {
6122                switch (type) {
6123                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
6124                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
6125                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
6126                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
6127                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
6128                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
6129                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
6130                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
6131                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
6132                    default: return com.android.internal.R.string.imProtocolCustom;
6133                }
6134            }
6135
6136            /**
6137             * Return a {@link CharSequence} that best describes the given
6138             * protocol, possibly substituting the given
6139             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
6140             */
6141            public static final CharSequence getProtocolLabel(Resources res, int type,
6142                    CharSequence label) {
6143                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
6144                    return label;
6145                } else {
6146                    final int labelRes = getProtocolLabelResource(type);
6147                    return res.getText(labelRes);
6148                }
6149            }
6150        }
6151
6152        /**
6153         * <p>
6154         * A data kind representing an organization.
6155         * </p>
6156         * <p>
6157         * You can use all columns defined for {@link ContactsContract.Data} as
6158         * well as the following aliases.
6159         * </p>
6160         * <h2>Column aliases</h2>
6161         * <table class="jd-sumtable">
6162         * <tr>
6163         * <th>Type</th>
6164         * <th>Alias</th><th colspan='2'>Data column</th>
6165         * </tr>
6166         * <tr>
6167         * <td>String</td>
6168         * <td>{@link #COMPANY}</td>
6169         * <td>{@link #DATA1}</td>
6170         * <td></td>
6171         * </tr>
6172         * <tr>
6173         * <td>int</td>
6174         * <td>{@link #TYPE}</td>
6175         * <td>{@link #DATA2}</td>
6176         * <td>Allowed values are:
6177         * <p>
6178         * <ul>
6179         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6180         * <li>{@link #TYPE_WORK}</li>
6181         * <li>{@link #TYPE_OTHER}</li>
6182         * </ul>
6183         * </p>
6184         * </td>
6185         * </tr>
6186         * <tr>
6187         * <td>String</td>
6188         * <td>{@link #LABEL}</td>
6189         * <td>{@link #DATA3}</td>
6190         * <td></td>
6191         * </tr>
6192         * <tr>
6193         * <td>String</td>
6194         * <td>{@link #TITLE}</td>
6195         * <td>{@link #DATA4}</td>
6196         * <td></td>
6197         * </tr>
6198         * <tr>
6199         * <td>String</td>
6200         * <td>{@link #DEPARTMENT}</td>
6201         * <td>{@link #DATA5}</td>
6202         * <td></td>
6203         * </tr>
6204         * <tr>
6205         * <td>String</td>
6206         * <td>{@link #JOB_DESCRIPTION}</td>
6207         * <td>{@link #DATA6}</td>
6208         * <td></td>
6209         * </tr>
6210         * <tr>
6211         * <td>String</td>
6212         * <td>{@link #SYMBOL}</td>
6213         * <td>{@link #DATA7}</td>
6214         * <td></td>
6215         * </tr>
6216         * <tr>
6217         * <td>String</td>
6218         * <td>{@link #PHONETIC_NAME}</td>
6219         * <td>{@link #DATA8}</td>
6220         * <td></td>
6221         * </tr>
6222         * <tr>
6223         * <td>String</td>
6224         * <td>{@link #OFFICE_LOCATION}</td>
6225         * <td>{@link #DATA9}</td>
6226         * <td></td>
6227         * </tr>
6228         * <tr>
6229         * <td>String</td>
6230         * <td>PHONETIC_NAME_STYLE</td>
6231         * <td>{@link #DATA10}</td>
6232         * <td></td>
6233         * </tr>
6234         * </table>
6235         */
6236        public static final class Organization implements DataColumnsWithJoins, CommonColumns {
6237            /**
6238             * This utility class cannot be instantiated
6239             */
6240            private Organization() {}
6241
6242            /** MIME type used when storing this in data table. */
6243            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
6244
6245            public static final int TYPE_WORK = 1;
6246            public static final int TYPE_OTHER = 2;
6247
6248            /**
6249             * The company as the user entered it.
6250             * <P>Type: TEXT</P>
6251             */
6252            public static final String COMPANY = DATA;
6253
6254            /**
6255             * The position title at this company as the user entered it.
6256             * <P>Type: TEXT</P>
6257             */
6258            public static final String TITLE = DATA4;
6259
6260            /**
6261             * The department at this company as the user entered it.
6262             * <P>Type: TEXT</P>
6263             */
6264            public static final String DEPARTMENT = DATA5;
6265
6266            /**
6267             * The job description at this company as the user entered it.
6268             * <P>Type: TEXT</P>
6269             */
6270            public static final String JOB_DESCRIPTION = DATA6;
6271
6272            /**
6273             * The symbol of this company as the user entered it.
6274             * <P>Type: TEXT</P>
6275             */
6276            public static final String SYMBOL = DATA7;
6277
6278            /**
6279             * The phonetic name of this company as the user entered it.
6280             * <P>Type: TEXT</P>
6281             */
6282            public static final String PHONETIC_NAME = DATA8;
6283
6284            /**
6285             * The office location of this organization.
6286             * <P>Type: TEXT</P>
6287             */
6288            public static final String OFFICE_LOCATION = DATA9;
6289
6290            /**
6291             * The alphabet used for capturing the phonetic name.
6292             * See {@link ContactsContract.PhoneticNameStyle}.
6293             * @hide
6294             */
6295            public static final String PHONETIC_NAME_STYLE = DATA10;
6296
6297            /**
6298             * Return the string resource that best describes the given
6299             * {@link #TYPE}. Will always return a valid resource.
6300             */
6301            public static final int getTypeLabelResource(int type) {
6302                switch (type) {
6303                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
6304                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
6305                    default: return com.android.internal.R.string.orgTypeCustom;
6306                }
6307            }
6308
6309            /**
6310             * Return a {@link CharSequence} that best describes the given type,
6311             * possibly substituting the given {@link #LABEL} value
6312             * for {@link #TYPE_CUSTOM}.
6313             */
6314            public static final CharSequence getTypeLabel(Resources res, int type,
6315                    CharSequence label) {
6316                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6317                    return label;
6318                } else {
6319                    final int labelRes = getTypeLabelResource(type);
6320                    return res.getText(labelRes);
6321                }
6322            }
6323        }
6324
6325        /**
6326         * <p>
6327         * A data kind representing a relation.
6328         * </p>
6329         * <p>
6330         * You can use all columns defined for {@link ContactsContract.Data} as
6331         * well as the following aliases.
6332         * </p>
6333         * <h2>Column aliases</h2>
6334         * <table class="jd-sumtable">
6335         * <tr>
6336         * <th>Type</th>
6337         * <th>Alias</th><th colspan='2'>Data column</th>
6338         * </tr>
6339         * <tr>
6340         * <td>String</td>
6341         * <td>{@link #NAME}</td>
6342         * <td>{@link #DATA1}</td>
6343         * <td></td>
6344         * </tr>
6345         * <tr>
6346         * <td>int</td>
6347         * <td>{@link #TYPE}</td>
6348         * <td>{@link #DATA2}</td>
6349         * <td>Allowed values are:
6350         * <p>
6351         * <ul>
6352         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6353         * <li>{@link #TYPE_ASSISTANT}</li>
6354         * <li>{@link #TYPE_BROTHER}</li>
6355         * <li>{@link #TYPE_CHILD}</li>
6356         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
6357         * <li>{@link #TYPE_FATHER}</li>
6358         * <li>{@link #TYPE_FRIEND}</li>
6359         * <li>{@link #TYPE_MANAGER}</li>
6360         * <li>{@link #TYPE_MOTHER}</li>
6361         * <li>{@link #TYPE_PARENT}</li>
6362         * <li>{@link #TYPE_PARTNER}</li>
6363         * <li>{@link #TYPE_REFERRED_BY}</li>
6364         * <li>{@link #TYPE_RELATIVE}</li>
6365         * <li>{@link #TYPE_SISTER}</li>
6366         * <li>{@link #TYPE_SPOUSE}</li>
6367         * </ul>
6368         * </p>
6369         * </td>
6370         * </tr>
6371         * <tr>
6372         * <td>String</td>
6373         * <td>{@link #LABEL}</td>
6374         * <td>{@link #DATA3}</td>
6375         * <td></td>
6376         * </tr>
6377         * </table>
6378         */
6379        public static final class Relation implements DataColumnsWithJoins, CommonColumns {
6380            /**
6381             * This utility class cannot be instantiated
6382             */
6383            private Relation() {}
6384
6385            /** MIME type used when storing this in data table. */
6386            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
6387
6388            public static final int TYPE_ASSISTANT = 1;
6389            public static final int TYPE_BROTHER = 2;
6390            public static final int TYPE_CHILD = 3;
6391            public static final int TYPE_DOMESTIC_PARTNER = 4;
6392            public static final int TYPE_FATHER = 5;
6393            public static final int TYPE_FRIEND = 6;
6394            public static final int TYPE_MANAGER = 7;
6395            public static final int TYPE_MOTHER = 8;
6396            public static final int TYPE_PARENT = 9;
6397            public static final int TYPE_PARTNER = 10;
6398            public static final int TYPE_REFERRED_BY = 11;
6399            public static final int TYPE_RELATIVE = 12;
6400            public static final int TYPE_SISTER = 13;
6401            public static final int TYPE_SPOUSE = 14;
6402
6403            /**
6404             * The name of the relative as the user entered it.
6405             * <P>Type: TEXT</P>
6406             */
6407            public static final String NAME = DATA;
6408
6409            /**
6410             * Return the string resource that best describes the given
6411             * {@link #TYPE}. Will always return a valid resource.
6412             */
6413            public static final int getTypeLabelResource(int type) {
6414                switch (type) {
6415                    case TYPE_ASSISTANT: return com.android.internal.R.string.relationTypeAssistant;
6416                    case TYPE_BROTHER: return com.android.internal.R.string.relationTypeBrother;
6417                    case TYPE_CHILD: return com.android.internal.R.string.relationTypeChild;
6418                    case TYPE_DOMESTIC_PARTNER:
6419                            return com.android.internal.R.string.relationTypeDomesticPartner;
6420                    case TYPE_FATHER: return com.android.internal.R.string.relationTypeFather;
6421                    case TYPE_FRIEND: return com.android.internal.R.string.relationTypeFriend;
6422                    case TYPE_MANAGER: return com.android.internal.R.string.relationTypeManager;
6423                    case TYPE_MOTHER: return com.android.internal.R.string.relationTypeMother;
6424                    case TYPE_PARENT: return com.android.internal.R.string.relationTypeParent;
6425                    case TYPE_PARTNER: return com.android.internal.R.string.relationTypePartner;
6426                    case TYPE_REFERRED_BY:
6427                            return com.android.internal.R.string.relationTypeReferredBy;
6428                    case TYPE_RELATIVE: return com.android.internal.R.string.relationTypeRelative;
6429                    case TYPE_SISTER: return com.android.internal.R.string.relationTypeSister;
6430                    case TYPE_SPOUSE: return com.android.internal.R.string.relationTypeSpouse;
6431                    default: return com.android.internal.R.string.orgTypeCustom;
6432                }
6433            }
6434
6435            /**
6436             * Return a {@link CharSequence} that best describes the given type,
6437             * possibly substituting the given {@link #LABEL} value
6438             * for {@link #TYPE_CUSTOM}.
6439             */
6440            public static final CharSequence getTypeLabel(Resources res, int type,
6441                    CharSequence label) {
6442                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6443                    return label;
6444                } else {
6445                    final int labelRes = getTypeLabelResource(type);
6446                    return res.getText(labelRes);
6447                }
6448            }
6449        }
6450
6451        /**
6452         * <p>
6453         * A data kind representing an event.
6454         * </p>
6455         * <p>
6456         * You can use all columns defined for {@link ContactsContract.Data} as
6457         * well as the following aliases.
6458         * </p>
6459         * <h2>Column aliases</h2>
6460         * <table class="jd-sumtable">
6461         * <tr>
6462         * <th>Type</th>
6463         * <th>Alias</th><th colspan='2'>Data column</th>
6464         * </tr>
6465         * <tr>
6466         * <td>String</td>
6467         * <td>{@link #START_DATE}</td>
6468         * <td>{@link #DATA1}</td>
6469         * <td></td>
6470         * </tr>
6471         * <tr>
6472         * <td>int</td>
6473         * <td>{@link #TYPE}</td>
6474         * <td>{@link #DATA2}</td>
6475         * <td>Allowed values are:
6476         * <p>
6477         * <ul>
6478         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6479         * <li>{@link #TYPE_ANNIVERSARY}</li>
6480         * <li>{@link #TYPE_OTHER}</li>
6481         * <li>{@link #TYPE_BIRTHDAY}</li>
6482         * </ul>
6483         * </p>
6484         * </td>
6485         * </tr>
6486         * <tr>
6487         * <td>String</td>
6488         * <td>{@link #LABEL}</td>
6489         * <td>{@link #DATA3}</td>
6490         * <td></td>
6491         * </tr>
6492         * </table>
6493         */
6494        public static final class Event implements DataColumnsWithJoins, CommonColumns {
6495            /**
6496             * This utility class cannot be instantiated
6497             */
6498            private Event() {}
6499
6500            /** MIME type used when storing this in data table. */
6501            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
6502
6503            public static final int TYPE_ANNIVERSARY = 1;
6504            public static final int TYPE_OTHER = 2;
6505            public static final int TYPE_BIRTHDAY = 3;
6506
6507            /**
6508             * The event start date as the user entered it.
6509             * <P>Type: TEXT</P>
6510             */
6511            public static final String START_DATE = DATA;
6512
6513            /**
6514             * Return the string resource that best describes the given
6515             * {@link #TYPE}. Will always return a valid resource.
6516             */
6517            public static int getTypeResource(Integer type) {
6518                if (type == null) {
6519                    return com.android.internal.R.string.eventTypeOther;
6520                }
6521                switch (type) {
6522                    case TYPE_ANNIVERSARY:
6523                        return com.android.internal.R.string.eventTypeAnniversary;
6524                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
6525                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
6526                    default: return com.android.internal.R.string.eventTypeCustom;
6527                }
6528            }
6529        }
6530
6531        /**
6532         * <p>
6533         * A data kind representing a photo for the contact.
6534         * </p>
6535         * <p>
6536         * Some sync adapters will choose to download photos in a separate
6537         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
6538         * through {@link ContactsContract.Data#SYNC4} to store temporary
6539         * data, e.g. the image URL or ID, state of download, server-side version
6540         * of the image.  It is allowed for the {@link #PHOTO} to be null.
6541         * </p>
6542         * <p>
6543         * You can use all columns defined for {@link ContactsContract.Data} as
6544         * well as the following aliases.
6545         * </p>
6546         * <h2>Column aliases</h2>
6547         * <table class="jd-sumtable">
6548         * <tr>
6549         * <th>Type</th>
6550         * <th>Alias</th><th colspan='2'>Data column</th>
6551         * </tr>
6552         * <tr>
6553         * <td>NUMBER</td>
6554         * <td>{@link #PHOTO_FILE_ID}</td>
6555         * <td>{@link #DATA14}</td>
6556         * <td>ID of the hi-res photo file.</td>
6557         * </tr>
6558         * <tr>
6559         * <td>BLOB</td>
6560         * <td>{@link #PHOTO}</td>
6561         * <td>{@link #DATA15}</td>
6562         * <td>By convention, binary data is stored in DATA15.  The thumbnail of the
6563         * photo is stored in this column.</td>
6564         * </tr>
6565         * </table>
6566         */
6567        public static final class Photo implements DataColumnsWithJoins {
6568            /**
6569             * This utility class cannot be instantiated
6570             */
6571            private Photo() {}
6572
6573            /** MIME type used when storing this in data table. */
6574            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
6575
6576            /**
6577             * Photo file ID for the display photo of the raw contact.
6578             * See {@link ContactsContract.DisplayPhoto}.
6579             * <p>
6580             * Type: NUMBER
6581             */
6582            public static final String PHOTO_FILE_ID = DATA14;
6583
6584            /**
6585             * Thumbnail photo of the raw contact. This is the raw bytes of an image
6586             * that could be inflated using {@link android.graphics.BitmapFactory}.
6587             * <p>
6588             * Type: BLOB
6589             */
6590            public static final String PHOTO = DATA15;
6591        }
6592
6593        /**
6594         * <p>
6595         * Notes about the contact.
6596         * </p>
6597         * <p>
6598         * You can use all columns defined for {@link ContactsContract.Data} as
6599         * well as the following aliases.
6600         * </p>
6601         * <h2>Column aliases</h2>
6602         * <table class="jd-sumtable">
6603         * <tr>
6604         * <th>Type</th>
6605         * <th>Alias</th><th colspan='2'>Data column</th>
6606         * </tr>
6607         * <tr>
6608         * <td>String</td>
6609         * <td>{@link #NOTE}</td>
6610         * <td>{@link #DATA1}</td>
6611         * <td></td>
6612         * </tr>
6613         * </table>
6614         */
6615        public static final class Note implements DataColumnsWithJoins {
6616            /**
6617             * This utility class cannot be instantiated
6618             */
6619            private Note() {}
6620
6621            /** MIME type used when storing this in data table. */
6622            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
6623
6624            /**
6625             * The note text.
6626             * <P>Type: TEXT</P>
6627             */
6628            public static final String NOTE = DATA1;
6629        }
6630
6631        /**
6632         * <p>
6633         * Group Membership.
6634         * </p>
6635         * <p>
6636         * You can use all columns defined for {@link ContactsContract.Data} as
6637         * well as the following aliases.
6638         * </p>
6639         * <h2>Column aliases</h2>
6640         * <table class="jd-sumtable">
6641         * <tr>
6642         * <th>Type</th>
6643         * <th>Alias</th><th colspan='2'>Data column</th>
6644         * </tr>
6645         * <tr>
6646         * <td>long</td>
6647         * <td>{@link #GROUP_ROW_ID}</td>
6648         * <td>{@link #DATA1}</td>
6649         * <td></td>
6650         * </tr>
6651         * <tr>
6652         * <td>String</td>
6653         * <td>{@link #GROUP_SOURCE_ID}</td>
6654         * <td>none</td>
6655         * <td>
6656         * <p>
6657         * The sourceid of the group that this group membership refers to.
6658         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
6659         * inserting a row.
6660         * </p>
6661         * <p>
6662         * If this field is specified, the provider will first try to
6663         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
6664         * is found, it will use the corresponding row id.  If the group is not
6665         * found, it will create one.
6666         * </td>
6667         * </tr>
6668         * </table>
6669         */
6670        public static final class GroupMembership implements DataColumnsWithJoins {
6671            /**
6672             * This utility class cannot be instantiated
6673             */
6674            private GroupMembership() {}
6675
6676            /** MIME type used when storing this in data table. */
6677            public static final String CONTENT_ITEM_TYPE =
6678                    "vnd.android.cursor.item/group_membership";
6679
6680            /**
6681             * The row id of the group that this group membership refers to. Exactly one of
6682             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
6683             * <P>Type: INTEGER</P>
6684             */
6685            public static final String GROUP_ROW_ID = DATA1;
6686
6687            /**
6688             * The sourceid of the group that this group membership refers to.  Exactly one of
6689             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
6690             * <P>Type: TEXT</P>
6691             */
6692            public static final String GROUP_SOURCE_ID = "group_sourceid";
6693        }
6694
6695        /**
6696         * <p>
6697         * A data kind representing a website related to the contact.
6698         * </p>
6699         * <p>
6700         * You can use all columns defined for {@link ContactsContract.Data} as
6701         * well as the following aliases.
6702         * </p>
6703         * <h2>Column aliases</h2>
6704         * <table class="jd-sumtable">
6705         * <tr>
6706         * <th>Type</th>
6707         * <th>Alias</th><th colspan='2'>Data column</th>
6708         * </tr>
6709         * <tr>
6710         * <td>String</td>
6711         * <td>{@link #URL}</td>
6712         * <td>{@link #DATA1}</td>
6713         * <td></td>
6714         * </tr>
6715         * <tr>
6716         * <td>int</td>
6717         * <td>{@link #TYPE}</td>
6718         * <td>{@link #DATA2}</td>
6719         * <td>Allowed values are:
6720         * <p>
6721         * <ul>
6722         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6723         * <li>{@link #TYPE_HOMEPAGE}</li>
6724         * <li>{@link #TYPE_BLOG}</li>
6725         * <li>{@link #TYPE_PROFILE}</li>
6726         * <li>{@link #TYPE_HOME}</li>
6727         * <li>{@link #TYPE_WORK}</li>
6728         * <li>{@link #TYPE_FTP}</li>
6729         * <li>{@link #TYPE_OTHER}</li>
6730         * </ul>
6731         * </p>
6732         * </td>
6733         * </tr>
6734         * <tr>
6735         * <td>String</td>
6736         * <td>{@link #LABEL}</td>
6737         * <td>{@link #DATA3}</td>
6738         * <td></td>
6739         * </tr>
6740         * </table>
6741         */
6742        public static final class Website implements DataColumnsWithJoins, CommonColumns {
6743            /**
6744             * This utility class cannot be instantiated
6745             */
6746            private Website() {}
6747
6748            /** MIME type used when storing this in data table. */
6749            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
6750
6751            public static final int TYPE_HOMEPAGE = 1;
6752            public static final int TYPE_BLOG = 2;
6753            public static final int TYPE_PROFILE = 3;
6754            public static final int TYPE_HOME = 4;
6755            public static final int TYPE_WORK = 5;
6756            public static final int TYPE_FTP = 6;
6757            public static final int TYPE_OTHER = 7;
6758
6759            /**
6760             * The website URL string.
6761             * <P>Type: TEXT</P>
6762             */
6763            public static final String URL = DATA;
6764        }
6765
6766        /**
6767         * <p>
6768         * A data kind representing a SIP address for the contact.
6769         * </p>
6770         * <p>
6771         * You can use all columns defined for {@link ContactsContract.Data} as
6772         * well as the following aliases.
6773         * </p>
6774         * <h2>Column aliases</h2>
6775         * <table class="jd-sumtable">
6776         * <tr>
6777         * <th>Type</th>
6778         * <th>Alias</th><th colspan='2'>Data column</th>
6779         * </tr>
6780         * <tr>
6781         * <td>String</td>
6782         * <td>{@link #SIP_ADDRESS}</td>
6783         * <td>{@link #DATA1}</td>
6784         * <td></td>
6785         * </tr>
6786         * <tr>
6787         * <td>int</td>
6788         * <td>{@link #TYPE}</td>
6789         * <td>{@link #DATA2}</td>
6790         * <td>Allowed values are:
6791         * <p>
6792         * <ul>
6793         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6794         * <li>{@link #TYPE_HOME}</li>
6795         * <li>{@link #TYPE_WORK}</li>
6796         * <li>{@link #TYPE_OTHER}</li>
6797         * </ul>
6798         * </p>
6799         * </td>
6800         * </tr>
6801         * <tr>
6802         * <td>String</td>
6803         * <td>{@link #LABEL}</td>
6804         * <td>{@link #DATA3}</td>
6805         * <td></td>
6806         * </tr>
6807         * </table>
6808         */
6809        public static final class SipAddress implements DataColumnsWithJoins, CommonColumns {
6810            /**
6811             * This utility class cannot be instantiated
6812             */
6813            private SipAddress() {}
6814
6815            /** MIME type used when storing this in data table. */
6816            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
6817
6818            public static final int TYPE_HOME = 1;
6819            public static final int TYPE_WORK = 2;
6820            public static final int TYPE_OTHER = 3;
6821
6822            /**
6823             * The SIP address.
6824             * <P>Type: TEXT</P>
6825             */
6826            public static final String SIP_ADDRESS = DATA1;
6827            // ...and TYPE and LABEL come from the CommonColumns interface.
6828
6829            /**
6830             * Return the string resource that best describes the given
6831             * {@link #TYPE}. Will always return a valid resource.
6832             */
6833            public static final int getTypeLabelResource(int type) {
6834                switch (type) {
6835                    case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome;
6836                    case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork;
6837                    case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther;
6838                    default: return com.android.internal.R.string.sipAddressTypeCustom;
6839                }
6840            }
6841
6842            /**
6843             * Return a {@link CharSequence} that best describes the given type,
6844             * possibly substituting the given {@link #LABEL} value
6845             * for {@link #TYPE_CUSTOM}.
6846             */
6847            public static final CharSequence getTypeLabel(Resources res, int type,
6848                    CharSequence label) {
6849                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6850                    return label;
6851                } else {
6852                    final int labelRes = getTypeLabelResource(type);
6853                    return res.getText(labelRes);
6854                }
6855            }
6856        }
6857
6858        /**
6859         * A data kind representing an Identity related to the contact.
6860         * <p>
6861         * This can be used as a signal by the aggregator to combine raw contacts into
6862         * contacts, e.g. if two contacts have Identity rows with
6863         * the same NAMESPACE and IDENTITY values the aggregator can know that they refer
6864         * to the same person.
6865         * </p>
6866         */
6867        public static final class Identity implements DataColumnsWithJoins {
6868            /**
6869             * This utility class cannot be instantiated
6870             */
6871            private Identity() {}
6872
6873            /** MIME type used when storing this in data table. */
6874            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/identity";
6875
6876            /**
6877             * The identity string.
6878             * <P>Type: TEXT</P>
6879             */
6880            public static final String IDENTITY = DataColumns.DATA1;
6881
6882            /**
6883             * The namespace of the identity string, e.g. "com.google"
6884             * <P>Type: TEXT</P>
6885             */
6886            public static final String NAMESPACE = DataColumns.DATA2;
6887        }
6888
6889        /**
6890         * <p>
6891         * Convenient functionalities for "callable" data. Note that, this is NOT a separate data
6892         * kind.
6893         * </p>
6894         * <p>
6895         * This URI allows the ContactsProvider to return a unified result for "callable" data
6896         * that users can use for calling purposes. {@link Phone} and {@link SipAddress} are the
6897         * current examples for "callable", but may be expanded to the other types.
6898         * </p>
6899         * <p>
6900         * Each returned row may have a different MIMETYPE and thus different interpretation for
6901         * each column. For example the meaning for {@link Phone}'s type is different than
6902         * {@link SipAddress}'s.
6903         * </p>
6904         */
6905        public static final class Callable implements DataColumnsWithJoins, CommonColumns {
6906            /**
6907             * Similar to {@link Phone#CONTENT_URI}, but returns callable data instead of only
6908             * phone numbers.
6909             */
6910            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6911                    "callables");
6912            /**
6913             * Similar to {@link Phone#CONTENT_FILTER_URI}, but allows users to filter callable
6914             * data.
6915             */
6916            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
6917                    "filter");
6918        }
6919
6920        /**
6921         * A special class of data items, used to refer to types of data that can be used to attempt
6922         * to start communicating with a person ({@link Phone} and {@link Email}). Note that this
6923         * is NOT a separate data kind.
6924         *
6925         * This URI allows the ContactsProvider to return a unified result for data items that users
6926         * can use to initiate communications with another contact. {@link Phone} and {@link Email}
6927         * are the current data types in this category.
6928         */
6929        public static final class Contactables implements DataColumnsWithJoins, CommonColumns {
6930            /**
6931             * The content:// style URI for these data items, which requests a directory of data
6932             * rows matching the selection criteria.
6933             */
6934            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6935                    "contactables");
6936
6937            /**
6938             * The content:// style URI for these data items, which allows for a query parameter to
6939             * be appended onto the end to filter for data items matching the query.
6940             */
6941            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
6942                    Contactables.CONTENT_URI, "filter");
6943
6944            /**
6945             * A boolean parameter for {@link Data#CONTENT_URI}.
6946             * This specifies whether or not the returned data items should be filtered to show
6947             * data items belonging to visible contacts only.
6948             */
6949            public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
6950        }
6951    }
6952
6953    /**
6954     * @see Groups
6955     */
6956    protected interface GroupsColumns {
6957        /**
6958         * The data set within the account that this group belongs to.  This allows
6959         * multiple sync adapters for the same account type to distinguish between
6960         * each others' group data.
6961         *
6962         * This is empty by default, and is completely optional.  It only needs to
6963         * be populated if multiple sync adapters are entering distinct group data
6964         * for the same account type and account name.
6965         * <P>Type: TEXT</P>
6966         */
6967        public static final String DATA_SET = "data_set";
6968
6969        /**
6970         * A concatenation of the account type and data set (delimited by a forward
6971         * slash) - if the data set is empty, this will be the same as the account
6972         * type.  For applications that need to be aware of the data set, this can
6973         * be used instead of account type to distinguish sets of data.  This is
6974         * never intended to be used for specifying accounts.
6975         * @hide
6976         */
6977        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
6978
6979        /**
6980         * The display title of this group.
6981         * <p>
6982         * Type: TEXT
6983         */
6984        public static final String TITLE = "title";
6985
6986        /**
6987         * The package name to use when creating {@link Resources} objects for
6988         * this group. This value is only designed for use when building user
6989         * interfaces, and should not be used to infer the owner.
6990         *
6991         * @hide
6992         */
6993        public static final String RES_PACKAGE = "res_package";
6994
6995        /**
6996         * The display title of this group to load as a resource from
6997         * {@link #RES_PACKAGE}, which may be localized.
6998         * <P>Type: TEXT</P>
6999         *
7000         * @hide
7001         */
7002        public static final String TITLE_RES = "title_res";
7003
7004        /**
7005         * Notes about the group.
7006         * <p>
7007         * Type: TEXT
7008         */
7009        public static final String NOTES = "notes";
7010
7011        /**
7012         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
7013         * to the sync adapter, null otherwise.
7014         * <P>Type: TEXT</P>
7015         */
7016        public static final String SYSTEM_ID = "system_id";
7017
7018        /**
7019         * The total number of {@link Contacts} that have
7020         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
7021         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
7022         * <p>
7023         * Type: INTEGER
7024         */
7025        public static final String SUMMARY_COUNT = "summ_count";
7026
7027        /**
7028         * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}.
7029         * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}.
7030         *
7031         * @hide
7032         */
7033        public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT =
7034                "return_group_count_per_account";
7035
7036        /**
7037         * The total number of groups of the account that a group belongs to.
7038         * This column is available only when the parameter
7039         * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in
7040         * {@link Groups#CONTENT_SUMMARY_URI}.
7041         *
7042         * For example, when the account "A" has two groups "group1" and "group2", and the account
7043         * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for
7044         * "group3" returns "1" for this column.
7045         *
7046         * Note: This counts only non-favorites, non-auto-add, and not deleted groups.
7047         *
7048         * Type: INTEGER
7049         * @hide
7050         */
7051        public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account";
7052
7053        /**
7054         * The total number of {@link Contacts} that have both
7055         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
7056         * Read-only value that is only present when querying
7057         * {@link Groups#CONTENT_SUMMARY_URI}.
7058         * <p>
7059         * Type: INTEGER
7060         */
7061        public static final String SUMMARY_WITH_PHONES = "summ_phones";
7062
7063        /**
7064         * Flag indicating if the contacts belonging to this group should be
7065         * visible in any user interface.
7066         * <p>
7067         * Type: INTEGER (boolean)
7068         */
7069        public static final String GROUP_VISIBLE = "group_visible";
7070
7071        /**
7072         * The "deleted" flag: "0" by default, "1" if the row has been marked
7073         * for deletion. When {@link android.content.ContentResolver#delete} is
7074         * called on a group, it is marked for deletion. The sync adaptor
7075         * deletes the group on the server and then calls ContactResolver.delete
7076         * once more, this time setting the the
7077         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
7078         * finalize the data removal.
7079         * <P>Type: INTEGER</P>
7080         */
7081        public static final String DELETED = "deleted";
7082
7083        /**
7084         * Whether this group should be synced if the SYNC_EVERYTHING settings
7085         * is false for this group's account.
7086         * <p>
7087         * Type: INTEGER (boolean)
7088         */
7089        public static final String SHOULD_SYNC = "should_sync";
7090
7091        /**
7092         * Any newly created contacts will automatically be added to groups that have this
7093         * flag set to true.
7094         * <p>
7095         * Type: INTEGER (boolean)
7096         */
7097        public static final String AUTO_ADD = "auto_add";
7098
7099        /**
7100         * When a contacts is marked as a favorites it will be automatically added
7101         * to the groups that have this flag set, and when it is removed from favorites
7102         * it will be removed from these groups.
7103         * <p>
7104         * Type: INTEGER (boolean)
7105         */
7106        public static final String FAVORITES = "favorites";
7107
7108        /**
7109         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
7110         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
7111         * <P>Type: INTEGER</P>
7112         */
7113        public static final String GROUP_IS_READ_ONLY = "group_is_read_only";
7114    }
7115
7116    /**
7117     * Constants for the groups table. Only per-account groups are supported.
7118     * <h2>Columns</h2>
7119     * <table class="jd-sumtable">
7120     * <tr>
7121     * <th colspan='4'>Groups</th>
7122     * </tr>
7123     * <tr>
7124     * <td>long</td>
7125     * <td>{@link #_ID}</td>
7126     * <td>read-only</td>
7127     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
7128     * In other words, it would be a really bad idea to delete and reinsert a
7129     * group. A sync adapter should always do an update instead.</td>
7130     * </tr>
7131     # <tr>
7132     * <td>String</td>
7133     * <td>{@link #DATA_SET}</td>
7134     * <td>read/write-once</td>
7135     * <td>
7136     * <p>
7137     * The data set within the account that this group belongs to.  This allows
7138     * multiple sync adapters for the same account type to distinguish between
7139     * each others' group data.  The combination of {@link #ACCOUNT_TYPE},
7140     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
7141     * that is associated with a single sync adapter.
7142     * </p>
7143     * <p>
7144     * This is empty by default, and is completely optional.  It only needs to
7145     * be populated if multiple sync adapters are entering distinct data for
7146     * the same account type and account name.
7147     * </p>
7148     * <p>
7149     * It should be set at the time the group is inserted and never changed
7150     * afterwards.
7151     * </p>
7152     * </td>
7153     * </tr>
7154     * <tr>
7155     * <td>String</td>
7156     * <td>{@link #TITLE}</td>
7157     * <td>read/write</td>
7158     * <td>The display title of this group.</td>
7159     * </tr>
7160     * <tr>
7161     * <td>String</td>
7162     * <td>{@link #NOTES}</td>
7163     * <td>read/write</td>
7164     * <td>Notes about the group.</td>
7165     * </tr>
7166     * <tr>
7167     * <td>String</td>
7168     * <td>{@link #SYSTEM_ID}</td>
7169     * <td>read/write</td>
7170     * <td>The ID of this group if it is a System Group, i.e. a group that has a
7171     * special meaning to the sync adapter, null otherwise.</td>
7172     * </tr>
7173     * <tr>
7174     * <td>int</td>
7175     * <td>{@link #SUMMARY_COUNT}</td>
7176     * <td>read-only</td>
7177     * <td>The total number of {@link Contacts} that have
7178     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
7179     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
7180     * </tr>
7181     * <tr>
7182     * <td>int</td>
7183     * <td>{@link #SUMMARY_WITH_PHONES}</td>
7184     * <td>read-only</td>
7185     * <td>The total number of {@link Contacts} that have both
7186     * {@link CommonDataKinds.GroupMembership} in this group, and also have
7187     * phone numbers. Read-only value that is only present when querying
7188     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
7189     * </tr>
7190     * <tr>
7191     * <td>int</td>
7192     * <td>{@link #GROUP_VISIBLE}</td>
7193     * <td>read-only</td>
7194     * <td>Flag indicating if the contacts belonging to this group should be
7195     * visible in any user interface. Allowed values: 0 and 1.</td>
7196     * </tr>
7197     * <tr>
7198     * <td>int</td>
7199     * <td>{@link #DELETED}</td>
7200     * <td>read/write</td>
7201     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
7202     * for deletion. When {@link android.content.ContentResolver#delete} is
7203     * called on a group, it is marked for deletion. The sync adaptor deletes
7204     * the group on the server and then calls ContactResolver.delete once more,
7205     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
7206     * query parameter to finalize the data removal.</td>
7207     * </tr>
7208     * <tr>
7209     * <td>int</td>
7210     * <td>{@link #SHOULD_SYNC}</td>
7211     * <td>read/write</td>
7212     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
7213     * is false for this group's account.</td>
7214     * </tr>
7215     * </table>
7216     */
7217    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
7218        /**
7219         * This utility class cannot be instantiated
7220         */
7221        private Groups() {
7222        }
7223
7224        /**
7225         * The content:// style URI for this table
7226         */
7227        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
7228
7229        /**
7230         * The content:// style URI for this table joined with details data from
7231         * {@link ContactsContract.Data}.
7232         */
7233        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
7234                "groups_summary");
7235
7236        /**
7237         * The MIME type of a directory of groups.
7238         */
7239        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
7240
7241        /**
7242         * The MIME type of a single group.
7243         */
7244        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
7245
7246        public static EntityIterator newEntityIterator(Cursor cursor) {
7247            return new EntityIteratorImpl(cursor);
7248        }
7249
7250        private static class EntityIteratorImpl extends CursorEntityIterator {
7251            public EntityIteratorImpl(Cursor cursor) {
7252                super(cursor);
7253            }
7254
7255            @Override
7256            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
7257                // we expect the cursor is already at the row we need to read from
7258                final ContentValues values = new ContentValues();
7259                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
7260                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
7261                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
7262                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
7263                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
7264                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
7265                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
7266                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
7267                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
7268                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
7269                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
7270                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
7271                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
7272                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
7273                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
7274                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
7275                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
7276                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
7277                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
7278                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
7279                cursor.moveToNext();
7280                return new Entity(values);
7281            }
7282        }
7283    }
7284
7285    /**
7286     * <p>
7287     * Constants for the contact aggregation exceptions table, which contains
7288     * aggregation rules overriding those used by automatic aggregation. This
7289     * type only supports query and update. Neither insert nor delete are
7290     * supported.
7291     * </p>
7292     * <h2>Columns</h2>
7293     * <table class="jd-sumtable">
7294     * <tr>
7295     * <th colspan='4'>AggregationExceptions</th>
7296     * </tr>
7297     * <tr>
7298     * <td>int</td>
7299     * <td>{@link #TYPE}</td>
7300     * <td>read/write</td>
7301     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
7302     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
7303     * </tr>
7304     * <tr>
7305     * <td>long</td>
7306     * <td>{@link #RAW_CONTACT_ID1}</td>
7307     * <td>read/write</td>
7308     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
7309     * the rule applies to.</td>
7310     * </tr>
7311     * <tr>
7312     * <td>long</td>
7313     * <td>{@link #RAW_CONTACT_ID2}</td>
7314     * <td>read/write</td>
7315     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
7316     * that the rule applies to.</td>
7317     * </tr>
7318     * </table>
7319     */
7320    public static final class AggregationExceptions implements BaseColumns {
7321        /**
7322         * This utility class cannot be instantiated
7323         */
7324        private AggregationExceptions() {}
7325
7326        /**
7327         * The content:// style URI for this table
7328         */
7329        public static final Uri CONTENT_URI =
7330                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
7331
7332        /**
7333         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
7334         */
7335        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
7336
7337        /**
7338         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
7339         */
7340        public static final String CONTENT_ITEM_TYPE =
7341                "vnd.android.cursor.item/aggregation_exception";
7342
7343        /**
7344         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
7345         * {@link #TYPE_AUTOMATIC}.
7346         *
7347         * <P>Type: INTEGER</P>
7348         */
7349        public static final String TYPE = "type";
7350
7351        /**
7352         * Allows the provider to automatically decide whether the specified raw contacts should
7353         * be included in the same aggregate contact or not.
7354         */
7355        public static final int TYPE_AUTOMATIC = 0;
7356
7357        /**
7358         * Makes sure that the specified raw contacts are included in the same
7359         * aggregate contact.
7360         */
7361        public static final int TYPE_KEEP_TOGETHER = 1;
7362
7363        /**
7364         * Makes sure that the specified raw contacts are NOT included in the same
7365         * aggregate contact.
7366         */
7367        public static final int TYPE_KEEP_SEPARATE = 2;
7368
7369        /**
7370         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
7371         */
7372        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
7373
7374        /**
7375         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
7376         * applies to.
7377         */
7378        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
7379    }
7380
7381    /**
7382     * @see Settings
7383     */
7384    protected interface SettingsColumns {
7385        /**
7386         * The name of the account instance to which this row belongs.
7387         * <P>Type: TEXT</P>
7388         */
7389        public static final String ACCOUNT_NAME = "account_name";
7390
7391        /**
7392         * The type of account to which this row belongs, which when paired with
7393         * {@link #ACCOUNT_NAME} identifies a specific account.
7394         * <P>Type: TEXT</P>
7395         */
7396        public static final String ACCOUNT_TYPE = "account_type";
7397
7398        /**
7399         * The data set within the account that this row belongs to.  This allows
7400         * multiple sync adapters for the same account type to distinguish between
7401         * each others' data.
7402         *
7403         * This is empty by default, and is completely optional.  It only needs to
7404         * be populated if multiple sync adapters are entering distinct data for
7405         * the same account type and account name.
7406         * <P>Type: TEXT</P>
7407         */
7408        public static final String DATA_SET = "data_set";
7409
7410        /**
7411         * Depending on the mode defined by the sync-adapter, this flag controls
7412         * the top-level sync behavior for this data source.
7413         * <p>
7414         * Type: INTEGER (boolean)
7415         */
7416        public static final String SHOULD_SYNC = "should_sync";
7417
7418        /**
7419         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
7420         * entries should be visible in any user interface.
7421         * <p>
7422         * Type: INTEGER (boolean)
7423         */
7424        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
7425
7426        /**
7427         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7428         * {@link Groups#SHOULD_SYNC} under this account have been marked as
7429         * unsynced.
7430         */
7431        public static final String ANY_UNSYNCED = "any_unsynced";
7432
7433        /**
7434         * Read-only count of {@link Contacts} from a specific source that have
7435         * no {@link CommonDataKinds.GroupMembership} entries.
7436         * <p>
7437         * Type: INTEGER
7438         */
7439        public static final String UNGROUPED_COUNT = "summ_count";
7440
7441        /**
7442         * Read-only count of {@link Contacts} from a specific source that have
7443         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
7444         * <p>
7445         * Type: INTEGER
7446         */
7447        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
7448    }
7449
7450    /**
7451     * <p>
7452     * Contacts-specific settings for various {@link Account}'s.
7453     * </p>
7454     * <h2>Columns</h2>
7455     * <table class="jd-sumtable">
7456     * <tr>
7457     * <th colspan='4'>Settings</th>
7458     * </tr>
7459     * <tr>
7460     * <td>String</td>
7461     * <td>{@link #ACCOUNT_NAME}</td>
7462     * <td>read/write-once</td>
7463     * <td>The name of the account instance to which this row belongs.</td>
7464     * </tr>
7465     * <tr>
7466     * <td>String</td>
7467     * <td>{@link #ACCOUNT_TYPE}</td>
7468     * <td>read/write-once</td>
7469     * <td>The type of account to which this row belongs, which when paired with
7470     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
7471     * </tr>
7472     * <tr>
7473     * <td>int</td>
7474     * <td>{@link #SHOULD_SYNC}</td>
7475     * <td>read/write</td>
7476     * <td>Depending on the mode defined by the sync-adapter, this flag controls
7477     * the top-level sync behavior for this data source.</td>
7478     * </tr>
7479     * <tr>
7480     * <td>int</td>
7481     * <td>{@link #UNGROUPED_VISIBLE}</td>
7482     * <td>read/write</td>
7483     * <td>Flag indicating if contacts without any
7484     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
7485     * user interface.</td>
7486     * </tr>
7487     * <tr>
7488     * <td>int</td>
7489     * <td>{@link #ANY_UNSYNCED}</td>
7490     * <td>read-only</td>
7491     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7492     * {@link Groups#SHOULD_SYNC} under this account have been marked as
7493     * unsynced.</td>
7494     * </tr>
7495     * <tr>
7496     * <td>int</td>
7497     * <td>{@link #UNGROUPED_COUNT}</td>
7498     * <td>read-only</td>
7499     * <td>Read-only count of {@link Contacts} from a specific source that have
7500     * no {@link CommonDataKinds.GroupMembership} entries.</td>
7501     * </tr>
7502     * <tr>
7503     * <td>int</td>
7504     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
7505     * <td>read-only</td>
7506     * <td>Read-only count of {@link Contacts} from a specific source that have
7507     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
7508     * numbers.</td>
7509     * </tr>
7510     * </table>
7511     */
7512    public static final class Settings implements SettingsColumns {
7513        /**
7514         * This utility class cannot be instantiated
7515         */
7516        private Settings() {
7517        }
7518
7519        /**
7520         * The content:// style URI for this table
7521         */
7522        public static final Uri CONTENT_URI =
7523                Uri.withAppendedPath(AUTHORITY_URI, "settings");
7524
7525        /**
7526         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7527         * settings.
7528         */
7529        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
7530
7531        /**
7532         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
7533         */
7534        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
7535    }
7536
7537    /**
7538     * Private API for inquiring about the general status of the provider.
7539     *
7540     * @hide
7541     */
7542    public static final class ProviderStatus {
7543
7544        /**
7545         * Not instantiable.
7546         */
7547        private ProviderStatus() {
7548        }
7549
7550        /**
7551         * The content:// style URI for this table.  Requests to this URI can be
7552         * performed on the UI thread because they are always unblocking.
7553         *
7554         * @hide
7555         */
7556        public static final Uri CONTENT_URI =
7557                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
7558
7559        /**
7560         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7561         * settings.
7562         *
7563         * @hide
7564         */
7565        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
7566
7567        /**
7568         * An integer representing the current status of the provider.
7569         *
7570         * @hide
7571         */
7572        public static final String STATUS = "status";
7573
7574        /**
7575         * Default status of the provider.
7576         *
7577         * @hide
7578         */
7579        public static final int STATUS_NORMAL = 0;
7580
7581        /**
7582         * The status used when the provider is in the process of upgrading.  Contacts
7583         * are temporarily unaccessible.
7584         *
7585         * @hide
7586         */
7587        public static final int STATUS_UPGRADING = 1;
7588
7589        /**
7590         * The status used if the provider was in the process of upgrading but ran
7591         * out of storage. The DATA1 column will contain the estimated amount of
7592         * storage required (in bytes). Update status to STATUS_NORMAL to force
7593         * the provider to retry the upgrade.
7594         *
7595         * @hide
7596         */
7597        public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2;
7598
7599        /**
7600         * The status used during a locale change.
7601         *
7602         * @hide
7603         */
7604        public static final int STATUS_CHANGING_LOCALE = 3;
7605
7606        /**
7607         * The status that indicates that there are no accounts and no contacts
7608         * on the device.
7609         *
7610         * @hide
7611         */
7612        public static final int STATUS_NO_ACCOUNTS_NO_CONTACTS = 4;
7613
7614        /**
7615         * Additional data associated with the status.
7616         *
7617         * @hide
7618         */
7619        public static final String DATA1 = "data1";
7620    }
7621
7622    /**
7623     * <p>
7624     * API allowing applications to send usage information for each {@link Data} row to the
7625     * Contacts Provider.  Applications can also clear all usage information.
7626     * </p>
7627     * <p>
7628     * With the feedback, Contacts Provider may return more contextually appropriate results for
7629     * Data listing, typically supplied with
7630     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI},
7631     * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI},
7632     * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit
7633     * from better ranked (sorted) lists in applications that show auto-complete list.
7634     * </p>
7635     * <p>
7636     * There is no guarantee for how this feedback is used, or even whether it is used at all.
7637     * The ranking algorithm will make best efforts to use the feedback data, but the exact
7638     * implementation, the storage data structures as well as the resulting sort order is device
7639     * and version specific and can change over time.
7640     * </p>
7641     * <p>
7642     * When updating usage information, users of this API need to use
7643     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed
7644     * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as
7645     * its last path. They also need to append a query parameter to the Uri, to specify the type of
7646     * the communication, which enables the Contacts Provider to differentiate between kinds of
7647     * interactions using the same contact data field (for example a phone number can be used to
7648     * make phone calls or send SMS).
7649     * </p>
7650     * <p>
7651     * Selection and selectionArgs are ignored and must be set to null. To get data ids,
7652     * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)}
7653     * toward {@link Data#CONTENT_URI}.
7654     * </p>
7655     * <p>
7656     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive
7657     * integer when successful, and returns 0 if no contact with that id was found.
7658     * </p>
7659     * <p>
7660     * Example:
7661     * <pre>
7662     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
7663     *         .appendPath(TextUtils.join(",", dataIds))
7664     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
7665     *                 DataUsageFeedback.USAGE_TYPE_CALL)
7666     *         .build();
7667     * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
7668     * </pre>
7669     * </p>
7670     * <p>
7671     * Applications can also clear all usage information with:
7672     * <pre>
7673     * boolean successful = resolver.delete(DataUsageFeedback.DELETE_USAGE_URI, null, null) > 0;
7674     * </pre>
7675     * </p>
7676     */
7677    public static final class DataUsageFeedback {
7678
7679        /**
7680         * The content:// style URI for sending usage feedback.
7681         * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}.
7682         */
7683        public static final Uri FEEDBACK_URI =
7684                Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback");
7685
7686        /**
7687         * The content:// style URI for deleting all usage information.
7688         * Must be used with {@link ContentResolver#delete(Uri, String, String[])}.
7689         * The {@code where} and {@code selectionArgs} parameters are ignored.
7690         */
7691        public static final Uri DELETE_USAGE_URI =
7692                Uri.withAppendedPath(Contacts.CONTENT_URI, "delete_usage");
7693
7694        /**
7695         * <p>
7696         * Name for query parameter specifying the type of data usage.
7697         * </p>
7698         */
7699        public static final String USAGE_TYPE = "type";
7700
7701        /**
7702         * <p>
7703         * Type of usage for voice interaction, which includes phone call, voice chat, and
7704         * video chat.
7705         * </p>
7706         */
7707        public static final String USAGE_TYPE_CALL = "call";
7708
7709        /**
7710         * <p>
7711         * Type of usage for text interaction involving longer messages, which includes email.
7712         * </p>
7713         */
7714        public static final String USAGE_TYPE_LONG_TEXT = "long_text";
7715
7716        /**
7717         * <p>
7718         * Type of usage for text interaction involving shorter messages, which includes SMS,
7719         * text chat with email addresses.
7720         * </p>
7721         */
7722        public static final String USAGE_TYPE_SHORT_TEXT = "short_text";
7723    }
7724
7725    /**
7726     * <p>
7727     * API allowing applications to send pinning information for specified contacts to the
7728     * Contacts Provider.
7729     * </p>
7730     *
7731     * <p>
7732     * This pinning information can be used by individual applications to customize how
7733     * they order particular pinned contacts. For example, a Dialer application could
7734     * use pinned information to order user-pinned contacts in a top row of favorites.
7735     * </p>
7736     *
7737     * <p>
7738     * It is possible for two or more contacts to occupy the same pinned position (due
7739     * to aggregation and sync), so this pinning information should be used on a best-effort
7740     * basis to order contacts in-application rather than an absolute guide on where a contact
7741     * should be positioned. Contacts returned by the ContactsProvider will not be ordered based
7742     * on this information, so it is up to the client application to reorder these contacts within
7743     * their own UI adhering to (or ignoring as appropriate) information stored in the pinned
7744     * column.
7745     * </p>
7746     *
7747     * <p>
7748     * By default, unpinned contacts will have a pinned position of
7749     * {@link PinnedPositions#UNPINNED}, or {@link Integer#MAX_VALUE} (2^31 - 1). Client-provided
7750     * pinned positions can be positive integers that range anywhere from 0 to
7751     * {@link PinnedPositions#UNPINNED}.
7752     * </p>
7753     *
7754     * <p>
7755     * When using {@link PinnedPositions#UPDATE_URI} to update the pinned positions of
7756     * certain contacts, it may make sense for your application to star any pinned contacts
7757     * by default. To specify this behavior, set the boolean query parameter
7758     * {@link PinnedPositions#STAR_WHEN_PINNING} to true to force all pinned and unpinned
7759     * contacts to be automatically starred and unstarred.
7760     * </p>
7761     */
7762    public static final class PinnedPositions {
7763
7764        /**
7765         * <p>
7766         * This URI allows applications to update pinned positions for a provided set of contacts.
7767         * </p>
7768         *
7769         * <p>
7770         * The list of contactIds to pin and their corresponding pinned positions should be
7771         * provided in key-value pairs stored in a {@link ContentValues} object where the key
7772         * is a valid contactId, while each pinned position is a positive integer.
7773         * </p>
7774         *
7775         * <p>
7776         * Example:
7777         * <pre>
7778         * ContentValues values = new ContentValues();
7779         * values.put("10", 20);
7780         * values.put("12", 2);
7781         * values.put("15", PinnedPositions.UNPINNED);
7782         * int count = resolver.update(PinnedPositions.UPDATE_URI, values, null, null);
7783         * </pre>
7784         *
7785         * This pins the contact with id 10 at position 20, the contact with id 12 at position 2,
7786         * and unpins the contact with id 15.
7787         * </p>
7788         */
7789        public static final Uri UPDATE_URI = Uri.withAppendedPath(AUTHORITY_URI,
7790                "pinned_position_update");
7791
7792        /**
7793         * Default value for the pinned position of an unpinned contact. Also equal to
7794         * {@link Integer#MAX_VALUE}.
7795         */
7796        public static final int UNPINNED = 0x7FFFFFFF;
7797
7798        /**
7799         * Value of pinned position for a contact that a user has indicated should be considered
7800         * of the lowest priority. It is up to the client application to determine how to present
7801         * such a contact - for example all the way at the bottom of a contact list, or simply
7802         * just hidden from view.
7803         */
7804        public static final int DEMOTED = -1;
7805
7806        /**
7807         * <p> Clients can provide this value as a pinned position to undemote a formerly demoted
7808         * contact. If the contact was formerly demoted, it will be restored to an
7809         * {@link #UNPINNED} position. If it was otherwise already pinned at another position,
7810         * it will not be affected.
7811         * </p>
7812         *
7813         * <p>
7814         * Example:
7815         * <pre>
7816         * ContentValues values = new ContentValues();
7817         * values.put("15", PinnedPositions.UNDEMOTE);
7818         * int count = resolver.update(ContactsContract.PinnedPositions.UPDATE_URI.buildUpon()
7819         *          .build(), values, null, null);
7820         * </pre>
7821         *
7822         * This restores the contact with id 15 to an {@link #UNPINNED} position, meaning that
7823         * other apps (e.g. the Dialer) that were formerly hiding this contact from view based on
7824         * its {@link #DEMOTED} position will start displaying it again.
7825         * </p>
7826         */
7827        public static final String UNDEMOTE = "undemote";
7828
7829        /**
7830         * <p>
7831         * A boolean query parameter that can be used with {@link #UPDATE_URI}.
7832         * If "1" or "true", any contact that is pinned or unpinned will be correspondingly
7833         * starred or unstarred. Otherwise, starring information will not be affected by pinned
7834         * updates. This is false by default.
7835         * </p>
7836         *
7837         * <p>
7838         * Example:
7839         * <pre>
7840         * ContentValues values = new ContentValues();
7841         * values.put("10", 20);
7842         * values.put("15", PinnedPositions.UNPINNED);
7843         * int count = resolver.update(ContactsContract.PinnedPositions.UPDATE_URI.buildUpon()
7844         *          .appendQueryParameter(PinnedPositions.FORCE_STAR_WHEN_PINNING, "true").build(),
7845         *          values, null, null);
7846         * </pre>
7847         *
7848         * This will pin the contact with id 10 at position 20 and star it automatically if not
7849         * already starred, and unpin the contact with id 15, and unstar it automatically if not
7850         * already unstarred.
7851         * </p>
7852         */
7853        public static final String STAR_WHEN_PINNING = "star_when_pinning";
7854    }
7855
7856    /**
7857     * Helper methods to display QuickContact dialogs that allow users to pivot on
7858     * a specific {@link Contacts} entry.
7859     */
7860    public static final class QuickContact {
7861        /**
7862         * Action used to trigger person pivot dialog.
7863         * @hide
7864         */
7865        public static final String ACTION_QUICK_CONTACT =
7866                "com.android.contacts.action.QUICK_CONTACT";
7867
7868        /**
7869         * Extra used to specify pivot dialog location in screen coordinates.
7870         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
7871         * @hide
7872         */
7873        @Deprecated
7874        public static final String EXTRA_TARGET_RECT = "target_rect";
7875
7876        /**
7877         * Extra used to specify size of pivot dialog.
7878         * @hide
7879         */
7880        public static final String EXTRA_MODE = "mode";
7881
7882        /**
7883         * Extra used to indicate a list of specific MIME-types to exclude and
7884         * not display. Stored as a {@link String} array.
7885         * @hide
7886         */
7887        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
7888
7889        /**
7890         * Small QuickContact mode, usually presented with minimal actions.
7891         */
7892        public static final int MODE_SMALL = 1;
7893
7894        /**
7895         * Medium QuickContact mode, includes actions and light summary describing
7896         * the {@link Contacts} entry being shown. This may include social
7897         * status and presence details.
7898         */
7899        public static final int MODE_MEDIUM = 2;
7900
7901        /**
7902         * Large QuickContact mode, includes actions and larger, card-like summary
7903         * of the {@link Contacts} entry being shown. This may include detailed
7904         * information, such as a photo.
7905         */
7906        public static final int MODE_LARGE = 3;
7907
7908        /**
7909         * Constructs the QuickContacts intent with a view's rect.
7910         * @hide
7911         */
7912        public static Intent composeQuickContactsIntent(Context context, View target, Uri lookupUri,
7913                int mode, String[] excludeMimes) {
7914            // Find location and bounds of target view, adjusting based on the
7915            // assumed local density.
7916            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
7917            final int[] pos = new int[2];
7918            target.getLocationOnScreen(pos);
7919
7920            final Rect rect = new Rect();
7921            rect.left = (int) (pos[0] * appScale + 0.5f);
7922            rect.top = (int) (pos[1] * appScale + 0.5f);
7923            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
7924            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
7925
7926            return composeQuickContactsIntent(context, rect, lookupUri, mode, excludeMimes);
7927        }
7928
7929        /**
7930         * Constructs the QuickContacts intent.
7931         * @hide
7932         */
7933        public static Intent composeQuickContactsIntent(Context context, Rect target,
7934                Uri lookupUri, int mode, String[] excludeMimes) {
7935            // When launching from an Activiy, we don't want to start a new task, but otherwise
7936            // we *must* start a new task.  (Otherwise startActivity() would crash.)
7937            Context actualContext = context;
7938            while ((actualContext instanceof ContextWrapper)
7939                    && !(actualContext instanceof Activity)) {
7940                actualContext = ((ContextWrapper) actualContext).getBaseContext();
7941            }
7942            final int intentFlags = (actualContext instanceof Activity)
7943                    ? Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
7944                    : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK;
7945
7946            // Launch pivot dialog through intent for now
7947            final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags);
7948
7949            intent.setData(lookupUri);
7950            intent.setSourceBounds(target);
7951            intent.putExtra(EXTRA_MODE, mode);
7952            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
7953            return intent;
7954        }
7955
7956        /**
7957         * Trigger a dialog that lists the various methods of interacting with
7958         * the requested {@link Contacts} entry. This may be based on available
7959         * {@link ContactsContract.Data} rows under that contact, and may also
7960         * include social status and presence details.
7961         *
7962         * @param context The parent {@link Context} that may be used as the
7963         *            parent for this dialog.
7964         * @param target Specific {@link View} from your layout that this dialog
7965         *            should be centered around. In particular, if the dialog
7966         *            has a "callout" arrow, it will be pointed and centered
7967         *            around this {@link View}.
7968         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
7969         *            {@link Uri} that describes a specific contact to feature
7970         *            in this dialog.
7971         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
7972         *            {@link #MODE_LARGE}, indicating the desired dialog size,
7973         *            when supported.
7974         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
7975         *            to exclude when showing this dialog. For example, when
7976         *            already viewing the contact details card, this can be used
7977         *            to omit the details entry from the dialog.
7978         */
7979        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
7980                String[] excludeMimes) {
7981            // Trigger with obtained rectangle
7982            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
7983                    excludeMimes);
7984            startActivityWithErrorToast(context, intent);
7985        }
7986
7987        /**
7988         * Trigger a dialog that lists the various methods of interacting with
7989         * the requested {@link Contacts} entry. This may be based on available
7990         * {@link ContactsContract.Data} rows under that contact, and may also
7991         * include social status and presence details.
7992         *
7993         * @param context The parent {@link Context} that may be used as the
7994         *            parent for this dialog.
7995         * @param target Specific {@link Rect} that this dialog should be
7996         *            centered around, in screen coordinates. In particular, if
7997         *            the dialog has a "callout" arrow, it will be pointed and
7998         *            centered around this {@link Rect}. If you are running at a
7999         *            non-native density, you need to manually adjust using
8000         *            {@link DisplayMetrics#density} before calling.
8001         * @param lookupUri A
8002         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8003         *            {@link Uri} that describes a specific contact to feature
8004         *            in this dialog.
8005         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8006         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8007         *            when supported.
8008         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8009         *            to exclude when showing this dialog. For example, when
8010         *            already viewing the contact details card, this can be used
8011         *            to omit the details entry from the dialog.
8012         */
8013        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
8014                String[] excludeMimes) {
8015            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8016                    excludeMimes);
8017            startActivityWithErrorToast(context, intent);
8018        }
8019
8020        private static void startActivityWithErrorToast(Context context, Intent intent) {
8021            try {
8022              context.startActivity(intent);
8023            } catch (ActivityNotFoundException e) {
8024                Toast.makeText(context, com.android.internal.R.string.quick_contacts_not_available,
8025                                Toast.LENGTH_SHORT).show();
8026            }
8027        }
8028    }
8029
8030    /**
8031     * Helper class for accessing full-size photos by photo file ID.
8032     * <p>
8033     * Usage example:
8034     * <dl>
8035     * <dt>Retrieving a full-size photo by photo file ID (see
8036     * {@link ContactsContract.ContactsColumns#PHOTO_FILE_ID})
8037     * </dt>
8038     * <dd>
8039     * <pre>
8040     * public InputStream openDisplayPhoto(long photoFileId) {
8041     *     Uri displayPhotoUri = ContentUris.withAppendedId(DisplayPhoto.CONTENT_URI, photoKey);
8042     *     try {
8043     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
8044     *             displayPhotoUri, "r");
8045     *         return fd.createInputStream();
8046     *     } catch (IOException e) {
8047     *         return null;
8048     *     }
8049     * }
8050     * </pre>
8051     * </dd>
8052     * </dl>
8053     * </p>
8054     */
8055    public static final class DisplayPhoto {
8056        /**
8057         * no public constructor since this is a utility class
8058         */
8059        private DisplayPhoto() {}
8060
8061        /**
8062         * The content:// style URI for this class, which allows access to full-size photos,
8063         * given a key.
8064         */
8065        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "display_photo");
8066
8067        /**
8068         * This URI allows the caller to query for the maximum dimensions of a display photo
8069         * or thumbnail.  Requests to this URI can be performed on the UI thread because
8070         * they are always unblocking.
8071         */
8072        public static final Uri CONTENT_MAX_DIMENSIONS_URI =
8073                Uri.withAppendedPath(AUTHORITY_URI, "photo_dimensions");
8074
8075        /**
8076         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8077         * contain this column, populated with the maximum height and width (in pixels)
8078         * that will be stored for a display photo.  Larger photos will be down-sized to
8079         * fit within a square of this many pixels.
8080         */
8081        public static final String DISPLAY_MAX_DIM = "display_max_dim";
8082
8083        /**
8084         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8085         * contain this column, populated with the height and width (in pixels) for photo
8086         * thumbnails.
8087         */
8088        public static final String THUMBNAIL_MAX_DIM = "thumbnail_max_dim";
8089    }
8090
8091    /**
8092     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
8093     * that involve contacts.
8094     */
8095    public static final class Intents {
8096        /**
8097         * This is the intent that is fired when a search suggestion is clicked on.
8098         */
8099        public static final String SEARCH_SUGGESTION_CLICKED =
8100                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
8101
8102        /**
8103         * This is the intent that is fired when a search suggestion for dialing a number
8104         * is clicked on.
8105         */
8106        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
8107                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
8108
8109        /**
8110         * This is the intent that is fired when a search suggestion for creating a contact
8111         * is clicked on.
8112         */
8113        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
8114                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
8115
8116        /**
8117         * This is the intent that is fired when the contacts database is created. <p> The
8118         * READ_CONTACT permission is required to receive these broadcasts.
8119         */
8120        public static final String CONTACTS_DATABASE_CREATED =
8121                "android.provider.Contacts.DATABASE_CREATED";
8122
8123        /**
8124         * Starts an Activity that lets the user pick a contact to attach an image to.
8125         * After picking the contact it launches the image cropper in face detection mode.
8126         */
8127        public static final String ATTACH_IMAGE =
8128                "com.android.contacts.action.ATTACH_IMAGE";
8129
8130        /**
8131         * This is the intent that is fired when the user clicks the "invite to the network" button
8132         * on a contact.  Only sent to an activity which is explicitly registered by a contact
8133         * provider which supports the "invite to the network" feature.
8134         * <p>
8135         * {@link Intent#getData()} contains the lookup URI for the contact.
8136         */
8137        public static final String INVITE_CONTACT =
8138                "com.android.contacts.action.INVITE_CONTACT";
8139
8140        /**
8141         * Takes as input a data URI with a mailto: or tel: scheme. If a single
8142         * contact exists with the given data it will be shown. If no contact
8143         * exists, a dialog will ask the user if they want to create a new
8144         * contact with the provided details filled in. If multiple contacts
8145         * share the data the user will be prompted to pick which contact they
8146         * want to view.
8147         * <p>
8148         * For <code>mailto:</code> URIs, the scheme specific portion must be a
8149         * raw email address, such as one built using
8150         * {@link Uri#fromParts(String, String, String)}.
8151         * <p>
8152         * For <code>tel:</code> URIs, the scheme specific portion is compared
8153         * to existing numbers using the standard caller ID lookup algorithm.
8154         * The number must be properly encoded, for example using
8155         * {@link Uri#fromParts(String, String, String)}.
8156         * <p>
8157         * Any extras from the {@link Insert} class will be passed along to the
8158         * create activity if there are no contacts to show.
8159         * <p>
8160         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
8161         * prompting the user when the contact doesn't exist.
8162         */
8163        public static final String SHOW_OR_CREATE_CONTACT =
8164                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
8165
8166        /**
8167         * Starts an Activity that lets the user select the multiple phones from a
8168         * list of phone numbers which come from the contacts or
8169         * {@link #EXTRA_PHONE_URIS}.
8170         * <p>
8171         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
8172         * could belong to the contacts or not, and will be selected by default.
8173         * <p>
8174         * The user's selection will be returned from
8175         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
8176         * if the resultCode is
8177         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
8178         * numbers are in the Intent's
8179         * {@link #EXTRA_PHONE_URIS}; otherwise, the
8180         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
8181         * left the Activity without changing the selection.
8182         *
8183         * @hide
8184         */
8185        public static final String ACTION_GET_MULTIPLE_PHONES =
8186                "com.android.contacts.action.GET_MULTIPLE_PHONES";
8187
8188        /**
8189         * A broadcast action which is sent when any change has been made to the profile, such
8190         * as the profile name or the picture.  A receiver must have
8191         * the android.permission.READ_PROFILE permission.
8192         *
8193         * @hide
8194         */
8195        public static final String ACTION_PROFILE_CHANGED =
8196                "android.provider.Contacts.PROFILE_CHANGED";
8197
8198        /**
8199         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
8200         * contact if no matching contact found. Otherwise, default behavior is
8201         * to prompt user with dialog before creating.
8202         * <p>
8203         * Type: BOOLEAN
8204         */
8205        public static final String EXTRA_FORCE_CREATE =
8206                "com.android.contacts.action.FORCE_CREATE";
8207
8208        /**
8209         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
8210         * description to be shown when prompting user about creating a new
8211         * contact.
8212         * <p>
8213         * Type: STRING
8214         */
8215        public static final String EXTRA_CREATE_DESCRIPTION =
8216            "com.android.contacts.action.CREATE_DESCRIPTION";
8217
8218        /**
8219         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
8220         * <p>
8221         * The phone numbers want to be picked by default should be passed in as
8222         * input value. These phone numbers could belong to the contacts or not.
8223         * <p>
8224         * The phone numbers which were picked by the user are returned as output
8225         * value.
8226         * <p>
8227         * Type: array of URIs, the tel URI is used for the phone numbers which don't
8228         * belong to any contact, the content URI is used for phone id in contacts.
8229         *
8230         * @hide
8231         */
8232        public static final String EXTRA_PHONE_URIS =
8233            "com.android.contacts.extra.PHONE_URIS";
8234
8235        /**
8236         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8237         * dialog location using screen coordinates. When not specified, the
8238         * dialog will be centered.
8239         *
8240         * @hide
8241         */
8242        @Deprecated
8243        public static final String EXTRA_TARGET_RECT = "target_rect";
8244
8245        /**
8246         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8247         * desired dialog style, usually a variation on size. One of
8248         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8249         *
8250         * @hide
8251         */
8252        @Deprecated
8253        public static final String EXTRA_MODE = "mode";
8254
8255        /**
8256         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
8257         *
8258         * @hide
8259         */
8260        @Deprecated
8261        public static final int MODE_SMALL = 1;
8262
8263        /**
8264         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
8265         *
8266         * @hide
8267         */
8268        @Deprecated
8269        public static final int MODE_MEDIUM = 2;
8270
8271        /**
8272         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
8273         *
8274         * @hide
8275         */
8276        @Deprecated
8277        public static final int MODE_LARGE = 3;
8278
8279        /**
8280         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
8281         * a list of specific MIME-types to exclude and not display. Stored as a
8282         * {@link String} array.
8283         *
8284         * @hide
8285         */
8286        @Deprecated
8287        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
8288
8289        /**
8290         * Intents related to the Contacts app UI.
8291         *
8292         * @hide
8293         */
8294        public static final class UI {
8295            /**
8296             * The action for the default contacts list tab.
8297             */
8298            public static final String LIST_DEFAULT =
8299                    "com.android.contacts.action.LIST_DEFAULT";
8300
8301            /**
8302             * The action for the contacts list tab.
8303             */
8304            public static final String LIST_GROUP_ACTION =
8305                    "com.android.contacts.action.LIST_GROUP";
8306
8307            /**
8308             * When in LIST_GROUP_ACTION mode, this is the group to display.
8309             */
8310            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
8311
8312            /**
8313             * The action for the all contacts list tab.
8314             */
8315            public static final String LIST_ALL_CONTACTS_ACTION =
8316                    "com.android.contacts.action.LIST_ALL_CONTACTS";
8317
8318            /**
8319             * The action for the contacts with phone numbers list tab.
8320             */
8321            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
8322                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
8323
8324            /**
8325             * The action for the starred contacts list tab.
8326             */
8327            public static final String LIST_STARRED_ACTION =
8328                    "com.android.contacts.action.LIST_STARRED";
8329
8330            /**
8331             * The action for the frequent contacts list tab.
8332             */
8333            public static final String LIST_FREQUENT_ACTION =
8334                    "com.android.contacts.action.LIST_FREQUENT";
8335
8336            /**
8337             * The action for the "strequent" contacts list tab. It first lists the starred
8338             * contacts in alphabetical order and then the frequent contacts in descending
8339             * order of the number of times they have been contacted.
8340             */
8341            public static final String LIST_STREQUENT_ACTION =
8342                    "com.android.contacts.action.LIST_STREQUENT";
8343
8344            /**
8345             * A key for to be used as an intent extra to set the activity
8346             * title to a custom String value.
8347             */
8348            public static final String TITLE_EXTRA_KEY =
8349                    "com.android.contacts.extra.TITLE_EXTRA";
8350
8351            /**
8352             * Activity Action: Display a filtered list of contacts
8353             * <p>
8354             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
8355             * filtering
8356             * <p>
8357             * Output: Nothing.
8358             */
8359            public static final String FILTER_CONTACTS_ACTION =
8360                    "com.android.contacts.action.FILTER_CONTACTS";
8361
8362            /**
8363             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
8364             * intents to supply the text on which to filter.
8365             */
8366            public static final String FILTER_TEXT_EXTRA_KEY =
8367                    "com.android.contacts.extra.FILTER_TEXT";
8368        }
8369
8370        /**
8371         * Convenience class that contains string constants used
8372         * to create contact {@link android.content.Intent Intents}.
8373         */
8374        public static final class Insert {
8375            /** The action code to use when adding a contact */
8376            public static final String ACTION = Intent.ACTION_INSERT;
8377
8378            /**
8379             * If present, forces a bypass of quick insert mode.
8380             */
8381            public static final String FULL_MODE = "full_mode";
8382
8383            /**
8384             * The extra field for the contact name.
8385             * <P>Type: String</P>
8386             */
8387            public static final String NAME = "name";
8388
8389            // TODO add structured name values here.
8390
8391            /**
8392             * The extra field for the contact phonetic name.
8393             * <P>Type: String</P>
8394             */
8395            public static final String PHONETIC_NAME = "phonetic_name";
8396
8397            /**
8398             * The extra field for the contact company.
8399             * <P>Type: String</P>
8400             */
8401            public static final String COMPANY = "company";
8402
8403            /**
8404             * The extra field for the contact job title.
8405             * <P>Type: String</P>
8406             */
8407            public static final String JOB_TITLE = "job_title";
8408
8409            /**
8410             * The extra field for the contact notes.
8411             * <P>Type: String</P>
8412             */
8413            public static final String NOTES = "notes";
8414
8415            /**
8416             * The extra field for the contact phone number.
8417             * <P>Type: String</P>
8418             */
8419            public static final String PHONE = "phone";
8420
8421            /**
8422             * The extra field for the contact phone number type.
8423             * <P>Type: Either an integer value from
8424             * {@link CommonDataKinds.Phone},
8425             *  or a string specifying a custom label.</P>
8426             */
8427            public static final String PHONE_TYPE = "phone_type";
8428
8429            /**
8430             * The extra field for the phone isprimary flag.
8431             * <P>Type: boolean</P>
8432             */
8433            public static final String PHONE_ISPRIMARY = "phone_isprimary";
8434
8435            /**
8436             * The extra field for an optional second contact phone number.
8437             * <P>Type: String</P>
8438             */
8439            public static final String SECONDARY_PHONE = "secondary_phone";
8440
8441            /**
8442             * The extra field for an optional second contact phone number type.
8443             * <P>Type: Either an integer value from
8444             * {@link CommonDataKinds.Phone},
8445             *  or a string specifying a custom label.</P>
8446             */
8447            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
8448
8449            /**
8450             * The extra field for an optional third contact phone number.
8451             * <P>Type: String</P>
8452             */
8453            public static final String TERTIARY_PHONE = "tertiary_phone";
8454
8455            /**
8456             * The extra field for an optional third contact phone number type.
8457             * <P>Type: Either an integer value from
8458             * {@link CommonDataKinds.Phone},
8459             *  or a string specifying a custom label.</P>
8460             */
8461            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
8462
8463            /**
8464             * The extra field for the contact email address.
8465             * <P>Type: String</P>
8466             */
8467            public static final String EMAIL = "email";
8468
8469            /**
8470             * The extra field for the contact email type.
8471             * <P>Type: Either an integer value from
8472             * {@link CommonDataKinds.Email}
8473             *  or a string specifying a custom label.</P>
8474             */
8475            public static final String EMAIL_TYPE = "email_type";
8476
8477            /**
8478             * The extra field for the email isprimary flag.
8479             * <P>Type: boolean</P>
8480             */
8481            public static final String EMAIL_ISPRIMARY = "email_isprimary";
8482
8483            /**
8484             * The extra field for an optional second contact email address.
8485             * <P>Type: String</P>
8486             */
8487            public static final String SECONDARY_EMAIL = "secondary_email";
8488
8489            /**
8490             * The extra field for an optional second contact email type.
8491             * <P>Type: Either an integer value from
8492             * {@link CommonDataKinds.Email}
8493             *  or a string specifying a custom label.</P>
8494             */
8495            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
8496
8497            /**
8498             * The extra field for an optional third contact email address.
8499             * <P>Type: String</P>
8500             */
8501            public static final String TERTIARY_EMAIL = "tertiary_email";
8502
8503            /**
8504             * The extra field for an optional third contact email type.
8505             * <P>Type: Either an integer value from
8506             * {@link CommonDataKinds.Email}
8507             *  or a string specifying a custom label.</P>
8508             */
8509            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
8510
8511            /**
8512             * The extra field for the contact postal address.
8513             * <P>Type: String</P>
8514             */
8515            public static final String POSTAL = "postal";
8516
8517            /**
8518             * The extra field for the contact postal address type.
8519             * <P>Type: Either an integer value from
8520             * {@link CommonDataKinds.StructuredPostal}
8521             *  or a string specifying a custom label.</P>
8522             */
8523            public static final String POSTAL_TYPE = "postal_type";
8524
8525            /**
8526             * The extra field for the postal isprimary flag.
8527             * <P>Type: boolean</P>
8528             */
8529            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
8530
8531            /**
8532             * The extra field for an IM handle.
8533             * <P>Type: String</P>
8534             */
8535            public static final String IM_HANDLE = "im_handle";
8536
8537            /**
8538             * The extra field for the IM protocol
8539             */
8540            public static final String IM_PROTOCOL = "im_protocol";
8541
8542            /**
8543             * The extra field for the IM isprimary flag.
8544             * <P>Type: boolean</P>
8545             */
8546            public static final String IM_ISPRIMARY = "im_isprimary";
8547
8548            /**
8549             * The extra field that allows the client to supply multiple rows of
8550             * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT}
8551             * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of
8552             * {@link ContentValues}, one per data row. Supplying this extra is
8553             * similar to inserting multiple rows into the {@link Data} table,
8554             * except the user gets a chance to see and edit them before saving.
8555             * Each ContentValues object must have a value for {@link Data#MIMETYPE}.
8556             * If supplied values are not visible in the editor UI, they will be
8557             * dropped.  Duplicate data will dropped.  Some fields
8558             * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically
8559             * adjusted to comply with the constraints of the specific account type.
8560             * For example, an Exchange contact can only have one phone numbers of type Home,
8561             * so the contact editor may choose a different type for this phone number to
8562             * avoid dropping the valueable part of the row, which is the phone number.
8563             * <p>
8564             * Example:
8565             * <pre>
8566             *  ArrayList&lt;ContentValues&gt; data = new ArrayList&lt;ContentValues&gt;();
8567             *
8568             *  ContentValues row1 = new ContentValues();
8569             *  row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
8570             *  row1.put(Organization.COMPANY, "Android");
8571             *  data.add(row1);
8572             *
8573             *  ContentValues row2 = new ContentValues();
8574             *  row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
8575             *  row2.put(Email.TYPE, Email.TYPE_CUSTOM);
8576             *  row2.put(Email.LABEL, "Green Bot");
8577             *  row2.put(Email.ADDRESS, "android@android.com");
8578             *  data.add(row2);
8579             *
8580             *  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
8581             *  intent.putParcelableArrayListExtra(Insert.DATA, data);
8582             *
8583             *  startActivity(intent);
8584             * </pre>
8585             */
8586            public static final String DATA = "data";
8587
8588            /**
8589             * Used to specify the account in which to create the new contact.
8590             * <p>
8591             * If this value is not provided, the user is presented with a disambiguation
8592             * dialog to chose an account
8593             * <p>
8594             * Type: {@link Account}
8595             *
8596             * @hide
8597             */
8598            public static final String ACCOUNT = "com.android.contacts.extra.ACCOUNT";
8599
8600            /**
8601             * Used to specify the data set within the account in which to create the
8602             * new contact.
8603             * <p>
8604             * This value is optional - if it is not specified, the contact will be
8605             * created in the base account, with no data set.
8606             * <p>
8607             * Type: String
8608             *
8609             * @hide
8610             */
8611            public static final String DATA_SET = "com.android.contacts.extra.DATA_SET";
8612        }
8613    }
8614}
8615