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