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