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