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