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