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