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