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