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