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