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