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