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