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