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