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