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