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