2009-07-05 19:54:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008-2009 Marc Blank
|
|
|
|
* Licensed to The Android Open Source Project.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.exchange.adapter;
|
|
|
|
|
2009-08-14 16:42:24 +00:00
|
|
|
import com.android.email.codec.binary.Base64;
|
2009-07-23 22:31:28 +00:00
|
|
|
import com.android.email.provider.EmailContent.Mailbox;
|
2009-07-27 17:24:58 +00:00
|
|
|
import com.android.email.provider.EmailContent.MailboxColumns;
|
|
|
|
import com.android.exchange.Eas;
|
2009-07-23 22:31:28 +00:00
|
|
|
import com.android.exchange.EasSyncService;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
|
|
|
import android.content.ContentProviderOperation;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.content.ContentProviderResult;
|
|
|
|
import android.content.ContentResolver;
|
2009-07-05 19:54:49 +00:00
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.content.ContentValues;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.content.Entity;
|
|
|
|
import android.content.EntityIterator;
|
|
|
|
import android.content.OperationApplicationException;
|
|
|
|
import android.content.ContentProviderOperation.Builder;
|
|
|
|
import android.content.Entity.NamedContentValues;
|
2009-07-05 19:54:49 +00:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
import android.provider.ContactsContract.Data;
|
2009-08-04 03:25:00 +00:00
|
|
|
import android.provider.ContactsContract.Groups;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.provider.ContactsContract.RawContacts;
|
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Email;
|
2009-08-04 03:25:00 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Im;
|
2009-08-02 22:33:22 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Nickname;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Note;
|
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Organization;
|
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
2009-08-02 22:33:22 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds.Photo;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
|
|
|
|
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
|
2009-08-05 05:39:02 +00:00
|
|
|
import android.text.util.Rfc822Token;
|
|
|
|
import android.text.util.Rfc822Tokenizer;
|
2009-07-27 17:24:58 +00:00
|
|
|
import android.util.Log;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
2009-07-23 22:31:28 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync adapter for EAS Contacts
|
|
|
|
*
|
|
|
|
*/
|
2009-07-31 01:17:52 +00:00
|
|
|
public class ContactsSyncAdapter extends AbstractSyncAdapter {
|
2009-07-05 19:54:49 +00:00
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
private static final String TAG = "EasContactsSyncAdapter";
|
|
|
|
private static final String SERVER_ID_SELECTION = RawContacts.SOURCE_ID + "=?";
|
|
|
|
private static final String[] ID_PROJECTION = new String[] {RawContacts._ID};
|
2009-08-04 03:25:00 +00:00
|
|
|
private static final String[] GROUP_PROJECTION = new String[] {Groups.SOURCE_ID};
|
2009-07-05 19:54:49 +00:00
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
// Note: These constants are likely to change; they are internal to this class now, but
|
|
|
|
// may end up in the provider.
|
|
|
|
private static final int TYPE_EMAIL1 = 20;
|
|
|
|
private static final int TYPE_EMAIL2 = 21;
|
|
|
|
private static final int TYPE_EMAIL3 = 22;
|
|
|
|
|
2009-08-05 05:39:02 +00:00
|
|
|
// We'll split email into two columns, the one that Contacts uses (just for the email address
|
|
|
|
// portion, and another one (the one defined here) for the display name
|
2009-08-05 15:41:16 +00:00
|
|
|
//private static final String EMAIL_DISPLAY_NAME = Data.SYNC1;
|
2009-08-05 05:39:02 +00:00
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
private static final int TYPE_IM1 = 23;
|
|
|
|
private static final int TYPE_IM2 = 24;
|
|
|
|
private static final int TYPE_IM3 = 25;
|
|
|
|
|
|
|
|
private static final int TYPE_WORK2 = 26;
|
|
|
|
private static final int TYPE_HOME2 = 27;
|
|
|
|
private static final int TYPE_CAR = 28;
|
|
|
|
private static final int TYPE_COMPANY_MAIN = 29;
|
|
|
|
private static final int TYPE_MMS = 30;
|
|
|
|
private static final int TYPE_RADIO = 31;
|
2009-08-02 22:33:22 +00:00
|
|
|
private static final int TYPE_ASSISTANT = 32;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
ArrayList<Long> mDeletedIdList = new ArrayList<Long>();
|
2009-07-05 19:54:49 +00:00
|
|
|
ArrayList<Long> mUpdatedIdList = new ArrayList<Long>();
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
public ContactsSyncAdapter(Mailbox mailbox, EasSyncService service) {
|
2009-07-27 17:24:58 +00:00
|
|
|
super(mailbox, service);
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-08-08 20:26:03 +00:00
|
|
|
public boolean parse(InputStream is, EasSyncService service) throws IOException {
|
2009-07-05 19:54:49 +00:00
|
|
|
EasContactsSyncParser p = new EasContactsSyncParser(is, service);
|
|
|
|
return p.parse();
|
|
|
|
}
|
|
|
|
|
2009-08-10 18:11:21 +00:00
|
|
|
// YomiFirstName, YomiLastName, and YomiCompanyName are the names of EAS fields
|
|
|
|
// Yomi is a shortened form of yomigana, which is a Japanese phonetic rendering.
|
2009-08-02 22:33:22 +00:00
|
|
|
public static final class Yomi {
|
|
|
|
private Yomi() {}
|
2009-07-27 17:24:58 +00:00
|
|
|
|
|
|
|
/** MIME type used when storing this in data table. */
|
2009-08-02 22:33:22 +00:00
|
|
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/eas_yomi";
|
|
|
|
public static final String FIRST_NAME = "data2";
|
|
|
|
public static final String LAST_NAME = "data3";
|
|
|
|
public static final String COMPANY_NAME = "data4";
|
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
public static final class EasChildren {
|
|
|
|
private EasChildren() {}
|
|
|
|
|
|
|
|
/** MIME type used when storing this in data table. */
|
|
|
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/eas_children";
|
|
|
|
public static final int MAX_CHILDREN = 8;
|
|
|
|
public static final String[] ROWS =
|
|
|
|
new String[] {"data2", "data3", "data4", "data5", "data6", "data7", "data8", "data9"};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final class EasPersonal {
|
|
|
|
String anniversary;
|
|
|
|
String birthday;
|
|
|
|
String fileAs;
|
|
|
|
String title;
|
|
|
|
String spouse;
|
|
|
|
String webpage;
|
|
|
|
|
|
|
|
/** MIME type used when storing this in data table. */
|
|
|
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/eas_personal";
|
|
|
|
public static final String ANNIVERSARY = "data2";
|
|
|
|
public static final String BIRTHDAY = "data3";
|
|
|
|
public static final String FILE_AS = "data4";
|
|
|
|
public static final String TITLE = "data5";
|
|
|
|
public static final String SPOUSE = "data6";
|
|
|
|
public static final String WEBPAGE = "data7";
|
|
|
|
|
|
|
|
boolean hasData() {
|
|
|
|
return anniversary != null || birthday != null || fileAs != null || title != null
|
|
|
|
|| spouse != null || webpage != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final class EasBusiness {
|
|
|
|
String assistantName;
|
|
|
|
String department;
|
|
|
|
String officeLocation;
|
|
|
|
String managerName;
|
|
|
|
String customerId;
|
|
|
|
String governmentId;
|
|
|
|
String accountName;
|
|
|
|
|
|
|
|
/** MIME type used when storing this in data table. */
|
|
|
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/eas_business";
|
|
|
|
public static final String ASSISTANT_NAME = "data2";
|
|
|
|
public static final String DEPARTMENT = "data3";
|
|
|
|
public static final String OFFICE_LOCATION = "data4";
|
|
|
|
public static final String MANAGER_NAME = "data5";
|
|
|
|
public static final String CUSTOMER_ID = "data6";
|
|
|
|
public static final String GOVERNMENT_ID = "data7";
|
|
|
|
public static final String ACCOUNT_NAME = "data8";
|
|
|
|
|
|
|
|
boolean hasData() {
|
|
|
|
return assistantName != null || department != null || officeLocation != null
|
|
|
|
|| managerName != null || customerId != null || governmentId != null
|
|
|
|
|| accountName != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final class Address {
|
|
|
|
String city;
|
|
|
|
String country;
|
|
|
|
String code;
|
|
|
|
String street;
|
|
|
|
String state;
|
|
|
|
|
|
|
|
boolean hasData() {
|
|
|
|
return city != null || country != null || code != null || state != null
|
|
|
|
|| street != null;
|
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
class EasContactsSyncParser extends AbstractSyncParser {
|
2009-07-05 19:54:49 +00:00
|
|
|
|
|
|
|
String[] mBindArgument = new String[1];
|
|
|
|
String mMailboxIdAsString;
|
2009-07-27 17:24:58 +00:00
|
|
|
Uri mAccountUri;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
|
|
|
public EasContactsSyncParser(InputStream in, EasSyncService service) throws IOException {
|
|
|
|
super(in, service);
|
2009-07-27 17:24:58 +00:00
|
|
|
mAccountUri = uriWithAccount(RawContacts.CONTENT_URI);
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
@Override
|
|
|
|
public void wipe() {
|
2009-07-31 01:17:52 +00:00
|
|
|
// TODO Use the bulk delete when the CP supports it
|
|
|
|
// mContentResolver.delete(mAccountUri.buildUpon()
|
|
|
|
// .appendQueryParameter(ContactsContract.RawContacts.DELETE_PERMANENTLY, "true")
|
|
|
|
// .build(), null, null);
|
|
|
|
Cursor c = mContentResolver.query(mAccountUri, new String[] {"_id"}, null, null, null);
|
|
|
|
try {
|
|
|
|
while (c.moveToNext()) {
|
|
|
|
long id = c.getLong(0);
|
|
|
|
mContentResolver.delete(ContentUris
|
|
|
|
.withAppendedId(mAccountUri, id)
|
|
|
|
.buildUpon().appendQueryParameter(
|
|
|
|
ContactsContract.RawContacts.DELETE_PERMANENTLY, "true")
|
|
|
|
.build(), null, null);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
public void addData(String serverId, ContactOperations ops, Entity entity)
|
2009-07-05 19:54:49 +00:00
|
|
|
throws IOException {
|
|
|
|
String firstName = null;
|
|
|
|
String lastName = null;
|
2009-08-02 22:33:22 +00:00
|
|
|
String middleName = null;
|
|
|
|
String suffix = null;
|
2009-07-05 19:54:49 +00:00
|
|
|
String companyName = null;
|
2009-08-02 22:33:22 +00:00
|
|
|
String yomiFirstName = null;
|
|
|
|
String yomiLastName = null;
|
|
|
|
String yomiCompanyName = null;
|
2009-07-27 17:24:58 +00:00
|
|
|
String title = null;
|
|
|
|
Address home = new Address();
|
|
|
|
Address work = new Address();
|
|
|
|
Address other = new Address();
|
2009-08-02 22:33:22 +00:00
|
|
|
EasBusiness business = new EasBusiness();
|
|
|
|
EasPersonal personal = new EasPersonal();
|
|
|
|
ArrayList<String> children = new ArrayList<String>();
|
2009-07-27 17:24:58 +00:00
|
|
|
|
|
|
|
if (entity == null) {
|
|
|
|
ops.newContact(serverId);
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.SYNC_APPLICATION_DATA) != END) {
|
2009-07-05 19:54:49 +00:00
|
|
|
switch (tag) {
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_FIRST_NAME:
|
2009-07-05 19:54:49 +00:00
|
|
|
firstName = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_LAST_NAME:
|
2009-07-05 19:54:49 +00:00
|
|
|
lastName = getValue();
|
|
|
|
break;
|
2009-08-02 22:33:22 +00:00
|
|
|
case Tags.CONTACTS_MIDDLE_NAME:
|
|
|
|
middleName = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS_SUFFIX:
|
|
|
|
suffix = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_COMPANY_NAME:
|
2009-07-05 19:54:49 +00:00
|
|
|
companyName = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_JOB_TITLE:
|
2009-07-27 17:24:58 +00:00
|
|
|
title = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_EMAIL1_ADDRESS:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addEmail(entity, TYPE_EMAIL1, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_EMAIL2_ADDRESS:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addEmail(entity, TYPE_EMAIL2, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_EMAIL3_ADDRESS:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addEmail(entity, TYPE_EMAIL3, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS2_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, TYPE_WORK2, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, Phone.TYPE_WORK, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS2_MMS:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, TYPE_MMS, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_FAX_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, Phone.TYPE_FAX_WORK, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS2_COMPANY_MAIN_PHONE:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, TYPE_COMPANY_MAIN, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_FAX_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, Phone.TYPE_FAX_HOME, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, Phone.TYPE_HOME, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME2_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, TYPE_HOME2, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_MOBILE_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, Phone.TYPE_MOBILE, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_CAR_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, TYPE_CAR, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_RADIO_TELEPHONE_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, TYPE_RADIO, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_PAGER_NUMBER:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addPhone(entity, Phone.TYPE_PAGER, getValue());
|
|
|
|
break;
|
2009-08-02 22:33:22 +00:00
|
|
|
case Tags.CONTACTS_ASSISTANT_TELEPHONE_NUMBER:
|
|
|
|
ops.addPhone(entity, TYPE_ASSISTANT, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS2_IM_ADDRESS:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addIm(entity, TYPE_IM1, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS2_IM_ADDRESS_2:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addIm(entity, TYPE_IM2, getValue());
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS2_IM_ADDRESS_3:
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.addIm(entity, TYPE_IM3, getValue());
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_ADDRESS_CITY:
|
2009-07-27 17:24:58 +00:00
|
|
|
work.city = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_ADDRESS_COUNTRY:
|
2009-07-27 17:24:58 +00:00
|
|
|
work.country = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_ADDRESS_POSTAL_CODE:
|
2009-07-27 17:24:58 +00:00
|
|
|
work.code = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_ADDRESS_STATE:
|
2009-07-27 17:24:58 +00:00
|
|
|
work.state = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_BUSINESS_ADDRESS_STREET:
|
2009-07-27 17:24:58 +00:00
|
|
|
work.street = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_ADDRESS_CITY:
|
2009-07-27 17:24:58 +00:00
|
|
|
home.city = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_ADDRESS_COUNTRY:
|
2009-07-27 17:24:58 +00:00
|
|
|
home.country = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_ADDRESS_POSTAL_CODE:
|
2009-07-27 17:24:58 +00:00
|
|
|
home.code = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_ADDRESS_STATE:
|
2009-07-27 17:24:58 +00:00
|
|
|
home.state = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_HOME_ADDRESS_STREET:
|
2009-07-27 17:24:58 +00:00
|
|
|
home.street = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_OTHER_ADDRESS_CITY:
|
2009-07-27 17:24:58 +00:00
|
|
|
other.city = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_OTHER_ADDRESS_COUNTRY:
|
2009-07-27 17:24:58 +00:00
|
|
|
other.country = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_OTHER_ADDRESS_POSTAL_CODE:
|
2009-07-27 17:24:58 +00:00
|
|
|
other.code = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_OTHER_ADDRESS_STATE:
|
2009-07-27 17:24:58 +00:00
|
|
|
other.state = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_OTHER_ADDRESS_STREET:
|
2009-07-27 17:24:58 +00:00
|
|
|
other.street = getValue();
|
|
|
|
break;
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_CHILDREN:
|
2009-08-02 22:33:22 +00:00
|
|
|
childrenParser(children);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
case Tags.CONTACTS_YOMI_COMPANY_NAME:
|
|
|
|
yomiCompanyName = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS_YOMI_FIRST_NAME:
|
|
|
|
yomiFirstName = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS_YOMI_LAST_NAME:
|
|
|
|
yomiLastName = getValue();
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
case Tags.CONTACTS2_NICKNAME:
|
|
|
|
ops.addNickname(entity, getValue());
|
|
|
|
break;
|
|
|
|
|
|
|
|
// EAS Business
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_ASSISTANT_NAME:
|
2009-08-02 22:33:22 +00:00
|
|
|
business.assistantName = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_DEPARTMENT:
|
2009-08-02 22:33:22 +00:00
|
|
|
business.department = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS_OFFICE_LOCATION:
|
|
|
|
business.officeLocation = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS2_MANAGER_NAME:
|
|
|
|
business.managerName = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS2_CUSTOMER_ID:
|
|
|
|
business.customerId = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS2_GOVERNMENT_ID:
|
|
|
|
business.governmentId = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS2_ACCOUNT_NAME:
|
|
|
|
business.accountName = getValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// EAS Personal
|
|
|
|
case Tags.CONTACTS_ANNIVERSARY:
|
|
|
|
personal.anniversary = getValue();
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS_BIRTHDAY:
|
|
|
|
personal.birthday = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_FILE_AS:
|
2009-08-02 22:33:22 +00:00
|
|
|
personal.fileAs = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_TITLE:
|
2009-08-02 22:33:22 +00:00
|
|
|
personal.title = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_SPOUSE:
|
2009-08-02 22:33:22 +00:00
|
|
|
personal.spouse = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_WEBPAGE:
|
2009-08-02 22:33:22 +00:00
|
|
|
personal.webpage = getValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tags.CONTACTS_PICTURE:
|
|
|
|
ops.addPhoto(entity, getValue());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tags.BASE_BODY:
|
|
|
|
ops.addNote(entity, bodyParser());
|
|
|
|
break;
|
|
|
|
case Tags.CONTACTS_BODY:
|
|
|
|
ops.addNote(entity, getValue());
|
|
|
|
break;
|
|
|
|
|
|
|
|
// TODO Handle Categories/Category
|
|
|
|
// If we don't handle this properly, we'll lose the information if/when we
|
|
|
|
// upload changes to the server!
|
2009-08-04 03:25:00 +00:00
|
|
|
case Tags.CONTACTS_CATEGORIES:
|
|
|
|
categoriesParser(ops, entity);
|
|
|
|
break;
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_COMPRESSED_RTF:
|
2009-08-02 22:33:22 +00:00
|
|
|
// We don't use this, and it isn't necessary to upload, so we'll ignore it
|
|
|
|
skipTag();
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
2009-08-02 22:33:22 +00:00
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must have first name, last name, or company name
|
|
|
|
String name;
|
|
|
|
if (firstName != null || lastName != null) {
|
|
|
|
if (firstName == null) {
|
|
|
|
name = lastName;
|
|
|
|
} else if (lastName == null) {
|
|
|
|
name = firstName;
|
|
|
|
} else {
|
|
|
|
name = firstName + ' ' + lastName;
|
|
|
|
}
|
|
|
|
} else if (companyName != null) {
|
|
|
|
name = companyName;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2009-08-02 22:33:22 +00:00
|
|
|
|
|
|
|
ops.addName(entity, firstName, lastName, middleName, suffix, name);
|
|
|
|
ops.addYomi(entity, yomiFirstName, yomiLastName, yomiCompanyName);
|
|
|
|
ops.addBusiness(entity, business);
|
|
|
|
ops.addPersonal(entity, personal);
|
|
|
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
ops.addChildren(entity, children);
|
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
if (work.hasData()) {
|
|
|
|
ops.addPostal(entity, StructuredPostal.TYPE_WORK, work.street, work.city,
|
|
|
|
work.state, work.country, work.code);
|
|
|
|
}
|
|
|
|
if (home.hasData()) {
|
|
|
|
ops.addPostal(entity, StructuredPostal.TYPE_HOME, home.street, home.city,
|
|
|
|
home.state, home.country, home.code);
|
|
|
|
}
|
|
|
|
if (other.hasData()) {
|
|
|
|
ops.addPostal(entity, StructuredPostal.TYPE_OTHER, other.street, other.city,
|
|
|
|
other.state, other.country, other.code);
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
if (companyName != null) {
|
|
|
|
ops.addOrganization(entity, Organization.TYPE_WORK, companyName, title);
|
|
|
|
}
|
2009-08-10 18:11:21 +00:00
|
|
|
|
|
|
|
if (entity != null) {
|
|
|
|
// We've been removing rows from the list as they've been found in the xml
|
|
|
|
// Any that are left must have been deleted on the server
|
|
|
|
ArrayList<NamedContentValues> ncvList = entity.getSubValues();
|
|
|
|
for (NamedContentValues ncv: ncvList) {
|
|
|
|
// These rows need to be deleted...
|
|
|
|
Uri u = dataUriFromNamedContentValues(ncv);
|
|
|
|
ops.add(ContentProviderOperation.newDelete(u).build());
|
|
|
|
}
|
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 03:25:00 +00:00
|
|
|
private void categoriesParser(ContactOperations ops, Entity entity) throws IOException {
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.CONTACTS_CATEGORIES) != END) {
|
2009-07-27 17:24:58 +00:00
|
|
|
switch (tag) {
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_CATEGORY:
|
2009-08-04 03:25:00 +00:00
|
|
|
ops.addGroup(entity, getValue());
|
2009-07-27 17:24:58 +00:00
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
private void childrenParser(ArrayList<String> children) throws IOException {
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.CONTACTS_CHILDREN) != END) {
|
2009-07-27 17:24:58 +00:00
|
|
|
switch (tag) {
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.CONTACTS_CHILD:
|
2009-08-02 22:33:22 +00:00
|
|
|
if (children.size() < EasChildren.MAX_CHILDREN) {
|
|
|
|
children.add(getValue());
|
|
|
|
}
|
|
|
|
break;
|
2009-07-27 17:24:58 +00:00
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
private String bodyParser() throws IOException {
|
|
|
|
String body = null;
|
|
|
|
while (nextTag(Tags.BASE_BODY) != END) {
|
|
|
|
switch (tag) {
|
|
|
|
case Tags.BASE_DATA:
|
|
|
|
body = getValue();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
public void addParser(ContactOperations ops) throws IOException {
|
2009-07-05 19:54:49 +00:00
|
|
|
String serverId = null;
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.SYNC_ADD) != END) {
|
2009-07-05 19:54:49 +00:00
|
|
|
switch (tag) {
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.SYNC_SERVER_ID: // same as
|
2009-07-05 19:54:49 +00:00
|
|
|
serverId = getValue();
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.SYNC_APPLICATION_DATA:
|
2009-07-27 17:24:58 +00:00
|
|
|
addData(serverId, ops, null);
|
2009-07-05 19:54:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Cursor getServerIdCursor(String serverId) {
|
|
|
|
mBindArgument[0] = serverId;
|
2009-07-27 17:24:58 +00:00
|
|
|
return mContentResolver.query(mAccountUri, ID_PROJECTION, SERVER_ID_SELECTION,
|
|
|
|
mBindArgument, null);
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
public void deleteParser(ContactOperations ops) throws IOException {
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.SYNC_DELETE) != END) {
|
2009-07-05 19:54:49 +00:00
|
|
|
switch (tag) {
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.SYNC_SERVER_ID:
|
2009-07-05 19:54:49 +00:00
|
|
|
String serverId = getValue();
|
|
|
|
// Find the message in this mailbox with the given serverId
|
|
|
|
Cursor c = getServerIdCursor(serverId);
|
|
|
|
try {
|
|
|
|
if (c.moveToFirst()) {
|
2009-08-13 16:32:58 +00:00
|
|
|
userLog("Deleting ", serverId);
|
2009-07-27 17:24:58 +00:00
|
|
|
ops.delete(c.getLong(0));
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ServerChange {
|
|
|
|
long id;
|
|
|
|
boolean read;
|
|
|
|
|
|
|
|
ServerChange(long _id, boolean _read) {
|
|
|
|
id = _id;
|
|
|
|
read = _read;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-07-27 17:24:58 +00:00
|
|
|
* Changes are handled row by row, and only changed/new rows are acted upon
|
2009-07-05 19:54:49 +00:00
|
|
|
* @param ops the array of pending ContactProviderOperations.
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
2009-07-27 17:24:58 +00:00
|
|
|
public void changeParser(ContactOperations ops) throws IOException {
|
2009-07-05 19:54:49 +00:00
|
|
|
String serverId = null;
|
2009-07-27 17:24:58 +00:00
|
|
|
Entity entity = null;
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.SYNC_CHANGE) != END) {
|
2009-07-05 19:54:49 +00:00
|
|
|
switch (tag) {
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.SYNC_SERVER_ID:
|
2009-07-05 19:54:49 +00:00
|
|
|
serverId = getValue();
|
|
|
|
Cursor c = getServerIdCursor(serverId);
|
|
|
|
try {
|
|
|
|
if (c.moveToFirst()) {
|
2009-07-27 17:24:58 +00:00
|
|
|
// TODO Handle deleted individual rows...
|
|
|
|
try {
|
|
|
|
EntityIterator entityIterator =
|
|
|
|
mContentResolver.queryEntities(ContentUris
|
|
|
|
.withAppendedId(RawContacts.CONTENT_URI, c.getLong(0)),
|
|
|
|
null, null, null);
|
|
|
|
if (entityIterator.hasNext()) {
|
|
|
|
entity = entityIterator.next();
|
|
|
|
}
|
2009-08-13 16:32:58 +00:00
|
|
|
userLog("Changing contact ", serverId);
|
2009-07-27 17:24:58 +00:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
break;
|
2009-07-31 01:17:52 +00:00
|
|
|
case Tags.SYNC_APPLICATION_DATA:
|
2009-07-27 17:24:58 +00:00
|
|
|
addData(serverId, ops, entity);
|
|
|
|
break;
|
2009-07-05 19:54:49 +00:00
|
|
|
default:
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
@Override
|
2009-07-05 19:54:49 +00:00
|
|
|
public void commandsParser() throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
ContactOperations ops = new ContactOperations();
|
2009-07-31 01:17:52 +00:00
|
|
|
while (nextTag(Tags.SYNC_COMMANDS) != END) {
|
|
|
|
if (tag == Tags.SYNC_ADD) {
|
2009-07-05 19:54:49 +00:00
|
|
|
addParser(ops);
|
2009-08-13 16:32:58 +00:00
|
|
|
incrementChangeCount();
|
2009-07-31 01:17:52 +00:00
|
|
|
} else if (tag == Tags.SYNC_DELETE) {
|
2009-07-05 19:54:49 +00:00
|
|
|
deleteParser(ops);
|
2009-08-13 16:32:58 +00:00
|
|
|
incrementChangeCount();
|
2009-07-31 01:17:52 +00:00
|
|
|
} else if (tag == Tags.SYNC_CHANGE) {
|
2009-07-05 19:54:49 +00:00
|
|
|
changeParser(ops);
|
2009-08-13 16:32:58 +00:00
|
|
|
incrementChangeCount();
|
2009-07-05 19:54:49 +00:00
|
|
|
} else
|
|
|
|
skipTag();
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
// Execute these all at once...
|
|
|
|
ops.execute();
|
|
|
|
|
|
|
|
if (ops.mResults != null) {
|
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
cv.put(RawContacts.DIRTY, 0);
|
|
|
|
for (int i = 0; i < ops.mContactIndexCount; i++) {
|
|
|
|
int index = ops.mContactIndexArray[i];
|
|
|
|
Uri u = ops.mResults[index].uri;
|
|
|
|
if (u != null) {
|
|
|
|
String idString = u.getLastPathSegment();
|
2009-08-13 16:32:58 +00:00
|
|
|
mContentResolver.update(RawContacts.CONTENT_URI, cv,
|
2009-07-27 17:24:58 +00:00
|
|
|
RawContacts._ID + "=" + idString, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the sync key in the database
|
2009-08-13 16:32:58 +00:00
|
|
|
userLog("Contacts SyncKey saved as: ", mMailbox.mSyncKey);
|
2009-07-27 17:24:58 +00:00
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
cv.put(MailboxColumns.SYNC_KEY, mMailbox.mSyncKey);
|
|
|
|
Mailbox.update(mContext, Mailbox.CONTENT_URI, mMailbox.mId, cv);
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
|
|
|
|
private Uri uriWithAccount(Uri uri) {
|
|
|
|
return uri.buildUpon()
|
2009-08-13 16:32:58 +00:00
|
|
|
.appendQueryParameter(RawContacts.ACCOUNT_NAME, mAccount.mEmailAddress)
|
2009-07-27 17:24:58 +00:00
|
|
|
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SmartBuilder is a wrapper for the Builder class that is used to create/update rows for a
|
|
|
|
* ContentProvider. It has, in addition to the Builder, ContentValues which, if present,
|
|
|
|
* represent the current values of that row, that can be compared against current values to
|
|
|
|
* see whether an update is even necessary. The methods on SmartBuilder are delegated to
|
|
|
|
* the Builder.
|
|
|
|
*/
|
|
|
|
private class SmartBuilder {
|
|
|
|
Builder builder;
|
|
|
|
ContentValues cv;
|
|
|
|
|
|
|
|
public SmartBuilder(Builder _builder) {
|
|
|
|
builder = _builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SmartBuilder(Builder _builder, NamedContentValues _ncv) {
|
|
|
|
builder = _builder;
|
|
|
|
cv = _ncv.values;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmartBuilder withValues(ContentValues values) {
|
|
|
|
builder.withValues(values);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmartBuilder withValueBackReference(String key, int previousResult) {
|
|
|
|
builder.withValueBackReference(key, previousResult);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentProviderOperation build() {
|
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
SmartBuilder withValue(String key, Object value) {
|
|
|
|
builder.withValue(key, value);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ContactOperations extends ArrayList<ContentProviderOperation> {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private int mCount = 0;
|
|
|
|
private int mContactBackValue = mCount;
|
2009-08-08 20:26:03 +00:00
|
|
|
// Make an array big enough for the PIM window (max items we can get)
|
|
|
|
private int[] mContactIndexArray =
|
|
|
|
new int[Integer.parseInt(EasSyncService.PIM_WINDOW_SIZE)];
|
2009-07-27 17:24:58 +00:00
|
|
|
private int mContactIndexCount = 0;
|
|
|
|
private ContentProviderResult[] mResults = null;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean add(ContentProviderOperation op) {
|
|
|
|
super.add(op);
|
|
|
|
mCount++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void newContact(String serverId) {
|
|
|
|
Builder builder = ContentProviderOperation
|
|
|
|
.newInsert(uriWithAccount(RawContacts.CONTENT_URI));
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(RawContacts.SOURCE_ID, serverId);
|
|
|
|
builder.withValues(values);
|
|
|
|
mContactBackValue = mCount;
|
|
|
|
mContactIndexArray[mContactIndexCount++] = mCount;
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void delete(long id) {
|
2009-07-31 01:17:52 +00:00
|
|
|
add(ContentProviderOperation
|
|
|
|
.newDelete(ContentUris.withAppendedId(RawContacts.CONTENT_URI, id)
|
|
|
|
.buildUpon()
|
|
|
|
.appendQueryParameter(ContactsContract.RawContacts.DELETE_PERMANENTLY,
|
|
|
|
"true")
|
|
|
|
.build())
|
|
|
|
.build());
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void execute() {
|
2009-08-07 18:43:32 +00:00
|
|
|
synchronized (mService.getSynchronizer()) {
|
|
|
|
if (!mService.isStopped()) {
|
|
|
|
try {
|
2009-08-13 16:32:58 +00:00
|
|
|
mService.userLog("Executing ", size(), " CPO's");
|
|
|
|
mResults = mContext.getContentResolver().applyBatch(
|
2009-08-07 18:43:32 +00:00
|
|
|
ContactsContract.AUTHORITY, this);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
// There is nothing sensible to be done here
|
|
|
|
Log.e(TAG, "problem inserting contact during server update", e);
|
|
|
|
} catch (OperationApplicationException e) {
|
|
|
|
// There is nothing sensible to be done here
|
|
|
|
Log.e(TAG, "problem inserting contact during server update", e);
|
|
|
|
}
|
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the list of NamedContentValues for an entity, a mime type, and a subtype,
|
|
|
|
* tries to find a match, returning it
|
|
|
|
* @param list the list of NCV's from the contact entity
|
|
|
|
* @param contentItemType the mime type we're looking for
|
|
|
|
* @param type the subtype (e.g. HOME, WORK, etc.)
|
|
|
|
* @return the matching NCV or null if not found
|
|
|
|
*/
|
|
|
|
private NamedContentValues findExistingData(ArrayList<NamedContentValues> list,
|
2009-08-04 03:25:00 +00:00
|
|
|
String contentItemType, int type, String stringType) {
|
2009-07-27 17:24:58 +00:00
|
|
|
NamedContentValues result = null;
|
|
|
|
|
|
|
|
// Loop through the ncv's, looking for an existing row
|
|
|
|
for (NamedContentValues namedContentValues: list) {
|
|
|
|
Uri uri = namedContentValues.uri;
|
|
|
|
ContentValues cv = namedContentValues.values;
|
|
|
|
if (Data.CONTENT_URI.equals(uri)) {
|
|
|
|
String mimeType = cv.getAsString(Data.MIMETYPE);
|
|
|
|
if (mimeType.equals(contentItemType)) {
|
2009-08-04 03:25:00 +00:00
|
|
|
if (stringType != null) {
|
|
|
|
if (cv.getAsString(GroupMembership.GROUP_ROW_ID).equals(stringType)) {
|
|
|
|
result = namedContentValues;
|
|
|
|
}
|
|
|
|
// Note Email.TYPE could be ANY type column; they are all defined in
|
|
|
|
// the private CommonColumns class in ContactsContract
|
|
|
|
} else if (type < 0 || cv.getAsInteger(Email.TYPE) == type) {
|
2009-07-27 17:24:58 +00:00
|
|
|
result = namedContentValues;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-04 03:25:00 +00:00
|
|
|
// TODO Handle deleted items
|
2009-07-27 17:24:58 +00:00
|
|
|
// If we've found an existing data row, we'll delete it. Any rows left at the
|
|
|
|
// end should be deleted...
|
|
|
|
if (result != null) {
|
|
|
|
list.remove(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the row found (or null)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a wrapper for a builder (insert or update) that also includes the NCV for
|
|
|
|
* an existing row of this type. If the SmartBuilder's cv field is not null, then
|
|
|
|
* it represents the current (old) values of this field. The caller can then check
|
|
|
|
* whether the field is now different and needs to be updated; if it's not different,
|
|
|
|
* the caller will simply return and not generate a new CPO. Otherwise, the builder
|
|
|
|
* should have its content values set, and the built CPO should be added to the
|
|
|
|
* ContactOperations list.
|
|
|
|
*
|
|
|
|
* @param entity the contact entity (or null if this is a new contact)
|
|
|
|
* @param mimeType the mime type of this row
|
|
|
|
* @param type the subtype of this row
|
2009-08-04 03:25:00 +00:00
|
|
|
* @param stringType for groups, the name of the group (type will be ignored), or null
|
2009-07-27 17:24:58 +00:00
|
|
|
* @return the created SmartBuilder
|
|
|
|
*/
|
|
|
|
public SmartBuilder createBuilder(Entity entity, String mimeType, int type) {
|
2009-08-04 03:25:00 +00:00
|
|
|
return createBuilder(entity, mimeType, type, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SmartBuilder createBuilder(Entity entity, String mimeType, int type,
|
|
|
|
String stringType) {
|
2009-07-27 17:24:58 +00:00
|
|
|
int contactId = mContactBackValue;
|
|
|
|
SmartBuilder builder = null;
|
|
|
|
|
|
|
|
if (entity != null) {
|
|
|
|
NamedContentValues ncv =
|
2009-08-04 03:25:00 +00:00
|
|
|
findExistingData(entity.getSubValues(), mimeType, type, stringType);
|
2009-07-27 17:24:58 +00:00
|
|
|
if (ncv != null) {
|
|
|
|
builder = new SmartBuilder(
|
|
|
|
ContentProviderOperation
|
|
|
|
.newUpdate(dataUriFromNamedContentValues(ncv)),
|
|
|
|
ncv);
|
|
|
|
} else {
|
|
|
|
contactId = entity.getEntityValues().getAsInteger(RawContacts._ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builder == null) {
|
|
|
|
builder =
|
|
|
|
new SmartBuilder(ContentProviderOperation.newInsert(Data.CONTENT_URI));
|
|
|
|
if (entity == null) {
|
|
|
|
builder.withValueBackReference(Data.RAW_CONTACT_ID, contactId);
|
|
|
|
} else {
|
|
|
|
builder.withValue(Data.RAW_CONTACT_ID, contactId);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.withValue(Data.MIMETYPE, mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the appropriate builder (insert or update)
|
2009-08-02 22:33:22 +00:00
|
|
|
// Caller will fill in the appropriate values; 4 MIMETYPE is already set
|
2009-07-27 17:24:58 +00:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare a column in a ContentValues with an (old) value, and see if they are the
|
|
|
|
* same. For this purpose, null and an empty string are considered the same.
|
|
|
|
* @param cv a ContentValues object, from a NamedContentValues
|
|
|
|
* @param column a column that might be in the ContentValues
|
|
|
|
* @param oldValue an old value (or null) to check against
|
|
|
|
* @return whether the column's value in the ContentValues matches oldValue
|
|
|
|
*/
|
|
|
|
private boolean cvCompareString(ContentValues cv, String column, String oldValue) {
|
|
|
|
if (cv.containsKey(column)) {
|
|
|
|
if (oldValue != null && cv.getAsString(column).equals(oldValue)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (oldValue == null || oldValue.length() == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addEmail(Entity entity, int type, String email) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Email.CONTENT_ITEM_TYPE, type);
|
2009-08-05 05:39:02 +00:00
|
|
|
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(email);
|
|
|
|
// Can't happen, but belt & suspenders
|
|
|
|
if (tokens.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Rfc822Token token = tokens[0];
|
|
|
|
String addr = token.getAddress();
|
|
|
|
String name = token.getName();
|
2009-07-27 17:24:58 +00:00
|
|
|
ContentValues cv = builder.cv;
|
2009-08-05 05:39:02 +00:00
|
|
|
if (cv != null && cvCompareString(cv, Email.DATA, addr)
|
2009-08-05 15:41:16 +00:00
|
|
|
&& cvCompareString(cv, Email.DISPLAY_NAME, name)) {
|
2009-07-27 17:24:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(Email.TYPE, type);
|
2009-08-05 05:39:02 +00:00
|
|
|
builder.withValue(Email.DATA, addr);
|
2009-08-05 15:41:16 +00:00
|
|
|
builder.withValue(Email.DISPLAY_NAME, name);
|
2009-07-27 17:24:58 +00:00
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
public void addChildren(Entity entity, ArrayList<String> children) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, EasChildren.CONTENT_ITEM_TYPE, -1);
|
|
|
|
int i = 0;
|
|
|
|
for (String child: children) {
|
|
|
|
builder.withValue(EasChildren.ROWS[i++], child);
|
|
|
|
}
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-08-04 03:25:00 +00:00
|
|
|
public void addGroup(Entity entity, String group) {
|
|
|
|
SmartBuilder builder =
|
|
|
|
createBuilder(entity, GroupMembership.CONTENT_ITEM_TYPE, -1, group);
|
|
|
|
builder.withValue(GroupMembership.GROUP_SOURCE_ID, group);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
public void addName(Entity entity, String givenName, String familyName, String middleName,
|
|
|
|
String suffix, String displayName) {
|
2009-07-27 17:24:58 +00:00
|
|
|
SmartBuilder builder = createBuilder(entity, StructuredName.CONTENT_ITEM_TYPE, -1);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, StructuredName.GIVEN_NAME, givenName) &&
|
2009-08-02 22:33:22 +00:00
|
|
|
cvCompareString(cv, StructuredName.FAMILY_NAME, familyName) &&
|
|
|
|
cvCompareString(cv, StructuredName.MIDDLE_NAME, middleName) &&
|
|
|
|
cvCompareString(cv, StructuredName.SUFFIX, suffix)) {
|
2009-07-27 17:24:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(StructuredName.GIVEN_NAME, givenName);
|
|
|
|
builder.withValue(StructuredName.FAMILY_NAME, familyName);
|
2009-08-02 22:33:22 +00:00
|
|
|
builder.withValue(StructuredName.MIDDLE_NAME, middleName);
|
|
|
|
builder.withValue(StructuredName.SUFFIX, suffix);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addYomi(Entity entity, String firstName, String lastName, String companyName) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Yomi.CONTENT_ITEM_TYPE, -1);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, Yomi.FIRST_NAME, firstName) &&
|
|
|
|
cvCompareString(cv, Yomi.LAST_NAME, lastName) &&
|
|
|
|
cvCompareString(cv, Yomi.COMPANY_NAME, companyName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(Yomi.FIRST_NAME, firstName);
|
|
|
|
builder.withValue(Yomi.LAST_NAME, lastName);
|
|
|
|
builder.withValue(Yomi.COMPANY_NAME, companyName);
|
2009-07-27 17:24:58 +00:00
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
public void addPersonal(Entity entity, EasPersonal personal) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, EasPersonal.CONTENT_ITEM_TYPE, -1);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, EasPersonal.ANNIVERSARY, personal.anniversary) &&
|
|
|
|
cvCompareString(cv, EasPersonal.BIRTHDAY, personal.birthday) &&
|
|
|
|
cvCompareString(cv, EasPersonal.FILE_AS , personal.fileAs) &&
|
|
|
|
cvCompareString(cv, EasPersonal.SPOUSE, personal.spouse) &&
|
|
|
|
cvCompareString(cv, EasPersonal.TITLE, personal.title) &&
|
|
|
|
cvCompareString(cv, EasPersonal.WEBPAGE, personal.webpage)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!personal.hasData()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(EasPersonal.BIRTHDAY, personal.birthday);
|
|
|
|
builder.withValue(EasPersonal.FILE_AS, personal.fileAs);
|
|
|
|
builder.withValue(EasPersonal.ANNIVERSARY, personal.anniversary);
|
|
|
|
builder.withValue(EasPersonal.SPOUSE, personal.spouse);
|
|
|
|
builder.withValue(EasPersonal.TITLE, personal.title);
|
|
|
|
builder.withValue(EasPersonal.WEBPAGE, personal.webpage);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addBusiness(Entity entity, EasBusiness business) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, EasPersonal.CONTENT_ITEM_TYPE, -1);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, EasBusiness.ACCOUNT_NAME, business.accountName) &&
|
|
|
|
cvCompareString(cv, EasBusiness.ASSISTANT_NAME, business.assistantName) &&
|
|
|
|
cvCompareString(cv, EasBusiness.CUSTOMER_ID, business.customerId) &&
|
|
|
|
cvCompareString(cv, EasBusiness.DEPARTMENT, business.department) &&
|
|
|
|
cvCompareString(cv, EasBusiness.GOVERNMENT_ID, business.governmentId) &&
|
|
|
|
cvCompareString(cv, EasBusiness.MANAGER_NAME, business.managerName) &&
|
|
|
|
cvCompareString(cv, EasBusiness.OFFICE_LOCATION, business.officeLocation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!business.hasData()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(EasBusiness.ACCOUNT_NAME, business.accountName);
|
|
|
|
builder.withValue(EasBusiness.ASSISTANT_NAME, business.assistantName);
|
|
|
|
builder.withValue(EasBusiness.CUSTOMER_ID, business.customerId);
|
|
|
|
builder.withValue(EasBusiness.DEPARTMENT, business.department);
|
|
|
|
builder.withValue(EasBusiness.GOVERNMENT_ID, business.governmentId);
|
|
|
|
builder.withValue(EasBusiness.MANAGER_NAME, business.managerName);
|
|
|
|
builder.withValue(EasBusiness.OFFICE_LOCATION, business.officeLocation);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addPhoto(Entity entity, String photo) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Photo.CONTENT_ITEM_TYPE, -1);
|
|
|
|
// We're always going to add this; it's not worth trying to figure out whether the
|
|
|
|
// picture is the same as the one stored.
|
2009-08-14 16:42:24 +00:00
|
|
|
byte[] pic = Base64.decodeBase64(photo.getBytes());
|
2009-08-04 03:25:00 +00:00
|
|
|
builder.withValue(Photo.PHOTO, pic);
|
2009-08-02 22:33:22 +00:00
|
|
|
add(builder.build());
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addPhone(Entity entity, int type, String phone) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Phone.CONTENT_ITEM_TYPE, type);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, Phone.NUMBER, phone)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(Phone.TYPE, type);
|
|
|
|
builder.withValue(Phone.NUMBER, phone);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
public void addNickname(Entity entity, String name) {
|
2009-08-09 04:58:54 +00:00
|
|
|
SmartBuilder builder =
|
|
|
|
createBuilder(entity, Nickname.CONTENT_ITEM_TYPE, Nickname.TYPE_DEFAULT);
|
2009-08-02 22:33:22 +00:00
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, Nickname.NAME, name)) {
|
|
|
|
return;
|
|
|
|
}
|
2009-08-09 04:58:54 +00:00
|
|
|
builder.withValue(Nickname.TYPE, Nickname.TYPE_DEFAULT);
|
2009-08-02 22:33:22 +00:00
|
|
|
builder.withValue(Nickname.NAME, name);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
public void addPostal(Entity entity, int type, String street, String city, String state,
|
|
|
|
String country, String code) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, StructuredPostal.CONTENT_ITEM_TYPE,
|
|
|
|
type);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, StructuredPostal.CITY, city) &&
|
|
|
|
cvCompareString(cv, StructuredPostal.STREET, street) &&
|
|
|
|
cvCompareString(cv, StructuredPostal.COUNTRY, country) &&
|
|
|
|
cvCompareString(cv, StructuredPostal.POSTCODE, code) &&
|
|
|
|
cvCompareString(cv, StructuredPostal.REGION, state)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(StructuredPostal.TYPE, type);
|
|
|
|
builder.withValue(StructuredPostal.CITY, city);
|
|
|
|
builder.withValue(StructuredPostal.STREET, street);
|
|
|
|
builder.withValue(StructuredPostal.COUNTRY, country);
|
|
|
|
builder.withValue(StructuredPostal.POSTCODE, code);
|
|
|
|
builder.withValue(StructuredPostal.REGION, state);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addIm(Entity entity, int type, String account) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Im.CONTENT_ITEM_TYPE, type);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, Im.DATA, account)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(Im.TYPE, type);
|
|
|
|
builder.withValue(Im.DATA, account);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addOrganization(Entity entity, int type, String company, String title) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Organization.CONTENT_ITEM_TYPE, type);
|
|
|
|
ContentValues cv = builder.cv;
|
|
|
|
if (cv != null && cvCompareString(cv, Organization.COMPANY, company) &&
|
|
|
|
cvCompareString(cv, Organization.TITLE, title)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.withValue(Organization.TYPE, type);
|
|
|
|
builder.withValue(Organization.COMPANY, company);
|
|
|
|
builder.withValue(Organization.TITLE, title);
|
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
public void addNote(Entity entity, String note) {
|
|
|
|
SmartBuilder builder = createBuilder(entity, Note.CONTENT_ITEM_TYPE, -1);
|
2009-07-27 17:24:58 +00:00
|
|
|
ContentValues cv = builder.cv;
|
2009-08-04 03:25:00 +00:00
|
|
|
if (note != null) {
|
2009-08-05 05:39:02 +00:00
|
|
|
note = note.replaceAll("\r\n", "\n");
|
2009-08-04 03:25:00 +00:00
|
|
|
}
|
2009-08-02 22:33:22 +00:00
|
|
|
if (cv != null && cvCompareString(cv, Note.NOTE, note)) {
|
2009-07-27 17:24:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-02 22:33:22 +00:00
|
|
|
builder.withValue(Note.NOTE, note);
|
2009-07-27 17:24:58 +00:00
|
|
|
add(builder.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-10 18:11:21 +00:00
|
|
|
/**
|
|
|
|
* Generate the uri for the data row associated with this NamedContentValues object
|
|
|
|
* @param ncv the NamedContentValues object
|
|
|
|
* @return a uri that can be used to refer to this row
|
|
|
|
*/
|
|
|
|
public Uri dataUriFromNamedContentValues(NamedContentValues ncv) {
|
|
|
|
long id = ncv.values.getAsLong(RawContacts._ID);
|
|
|
|
Uri dataUri = ContentUris.withAppendedId(ncv.uri, id);
|
|
|
|
return dataUri;
|
|
|
|
}
|
|
|
|
|
2009-07-15 00:21:13 +00:00
|
|
|
@Override
|
|
|
|
public void cleanup(EasSyncService service) {
|
2009-07-27 17:24:58 +00:00
|
|
|
// Mark the changed contacts dirty = 0
|
|
|
|
// TODO Put this in a single batch
|
|
|
|
ContactOperations ops = new ContactOperations();
|
|
|
|
for (Long id: mUpdatedIdList) {
|
|
|
|
ops.add(ContentProviderOperation
|
|
|
|
.newUpdate(ContentUris.withAppendedId(RawContacts.CONTENT_URI, id))
|
|
|
|
.withValue(RawContacts.DIRTY, 0).build());
|
|
|
|
}
|
|
|
|
|
|
|
|
ops.execute();
|
2009-07-15 00:21:13 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
@Override
|
|
|
|
public String getCollectionName() {
|
|
|
|
return "Contacts";
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendEmail(Serializer s, ContentValues cv) throws IOException {
|
2009-08-05 05:39:02 +00:00
|
|
|
// Get both parts of the email address (a newly created one in the UI won't have a name)
|
|
|
|
String addr = cv.getAsString(Email.DATA);
|
2009-08-05 15:41:16 +00:00
|
|
|
String name = cv.getAsString(Email.DISPLAY_NAME);
|
2009-08-05 05:39:02 +00:00
|
|
|
// Don't crash if we don't have a name
|
|
|
|
if (name == null) {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
String value = null;
|
|
|
|
// If there's no addr, just send an empty address (will delete it on the server)
|
|
|
|
// Otherwise compose it from name and addr
|
|
|
|
if (addr != null) {
|
|
|
|
value = '\"' + name + "\" <" + addr + '>';
|
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
switch (cv.getAsInteger(Email.TYPE)) {
|
|
|
|
case TYPE_EMAIL1:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_EMAIL1_ADDRESS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_EMAIL2:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_EMAIL2_ADDRESS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_EMAIL3:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_EMAIL3_ADDRESS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendIm(Serializer s, ContentValues cv) throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
String value = cv.getAsString(Email.DATA);
|
|
|
|
switch (cv.getAsInteger(Email.TYPE)) {
|
|
|
|
case TYPE_IM1:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS2_IM_ADDRESS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_IM2:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS2_IM_ADDRESS_2, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_IM3:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS2_IM_ADDRESS_3, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendOnePostal(Serializer s, ContentValues cv, int[] fieldNames)
|
2009-07-27 17:24:58 +00:00
|
|
|
throws IOException{
|
|
|
|
if (cv.containsKey(StructuredPostal.CITY)) {
|
|
|
|
s.data(fieldNames[0], cv.getAsString(StructuredPostal.CITY));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(StructuredPostal.COUNTRY)) {
|
|
|
|
s.data(fieldNames[1], cv.getAsString(StructuredPostal.COUNTRY));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(StructuredPostal.POSTCODE)) {
|
|
|
|
s.data(fieldNames[2], cv.getAsString(StructuredPostal.POSTCODE));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(StructuredPostal.REGION)) {
|
|
|
|
s.data(fieldNames[3], cv.getAsString(StructuredPostal.REGION));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(StructuredPostal.STREET)) {
|
|
|
|
s.data(fieldNames[4], cv.getAsString(StructuredPostal.STREET));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendStructuredPostal(Serializer s, ContentValues cv) throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
switch (cv.getAsInteger(StructuredPostal.TYPE)) {
|
|
|
|
case StructuredPostal.TYPE_HOME:
|
2009-07-31 01:17:52 +00:00
|
|
|
sendOnePostal(s, cv, new int[] {Tags.CONTACTS_HOME_ADDRESS_CITY,
|
|
|
|
Tags.CONTACTS_HOME_ADDRESS_COUNTRY,
|
|
|
|
Tags.CONTACTS_HOME_ADDRESS_POSTAL_CODE,
|
|
|
|
Tags.CONTACTS_HOME_ADDRESS_STATE,
|
|
|
|
Tags.CONTACTS_HOME_ADDRESS_STREET});
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case StructuredPostal.TYPE_WORK:
|
2009-07-31 01:17:52 +00:00
|
|
|
sendOnePostal(s, cv, new int[] {Tags.CONTACTS_BUSINESS_ADDRESS_CITY,
|
|
|
|
Tags.CONTACTS_BUSINESS_ADDRESS_COUNTRY,
|
|
|
|
Tags.CONTACTS_BUSINESS_ADDRESS_POSTAL_CODE,
|
|
|
|
Tags.CONTACTS_BUSINESS_ADDRESS_STATE,
|
|
|
|
Tags.CONTACTS_BUSINESS_ADDRESS_STREET});
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case StructuredPostal.TYPE_OTHER:
|
2009-07-31 01:17:52 +00:00
|
|
|
sendOnePostal(s, cv, new int[] {Tags.CONTACTS_HOME_ADDRESS_CITY,
|
|
|
|
Tags.CONTACTS_OTHER_ADDRESS_COUNTRY,
|
|
|
|
Tags.CONTACTS_OTHER_ADDRESS_POSTAL_CODE,
|
|
|
|
Tags.CONTACTS_OTHER_ADDRESS_STATE,
|
|
|
|
Tags.CONTACTS_OTHER_ADDRESS_STREET});
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendStructuredName(Serializer s, ContentValues cv) throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
if (cv.containsKey(StructuredName.FAMILY_NAME)) {
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_LAST_NAME, cv.getAsString(StructuredName.FAMILY_NAME));
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
if (cv.containsKey(StructuredName.GIVEN_NAME)) {
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_FIRST_NAME, cv.getAsString(StructuredName.GIVEN_NAME));
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
2009-08-02 22:33:22 +00:00
|
|
|
if (cv.containsKey(StructuredName.MIDDLE_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS_MIDDLE_NAME, cv.getAsString(StructuredName.MIDDLE_NAME));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(StructuredName.SUFFIX)) {
|
|
|
|
s.data(Tags.CONTACTS_SUFFIX, cv.getAsString(StructuredName.SUFFIX));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendBusiness(Serializer s, ContentValues cv) throws IOException {
|
|
|
|
if (cv.containsKey(EasBusiness.ACCOUNT_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS2_ACCOUNT_NAME, cv.getAsString(EasBusiness.ACCOUNT_NAME));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasBusiness.ASSISTANT_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS_ASSISTANT_NAME, cv.getAsString(EasBusiness.ASSISTANT_NAME));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasBusiness.CUSTOMER_ID)) {
|
|
|
|
s.data(Tags.CONTACTS2_CUSTOMER_ID, cv.getAsString(EasBusiness.CUSTOMER_ID));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasBusiness.DEPARTMENT)) {
|
|
|
|
s.data(Tags.CONTACTS_DEPARTMENT, cv.getAsString(EasBusiness.DEPARTMENT));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasBusiness.GOVERNMENT_ID)) {
|
|
|
|
s.data(Tags.CONTACTS2_GOVERNMENT_ID, cv.getAsString(EasBusiness.GOVERNMENT_ID));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasBusiness.MANAGER_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS2_MANAGER_NAME, cv.getAsString(EasBusiness.MANAGER_NAME));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasBusiness.OFFICE_LOCATION)) {
|
|
|
|
s.data(Tags.CONTACTS_OFFICE_LOCATION, cv.getAsString(EasBusiness.OFFICE_LOCATION));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendPersonal(Serializer s, ContentValues cv) throws IOException {
|
|
|
|
if (cv.containsKey(EasPersonal.ANNIVERSARY)) {
|
|
|
|
s.data(Tags.CONTACTS_ANNIVERSARY, cv.getAsString(EasPersonal.ANNIVERSARY));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasPersonal.BIRTHDAY)) {
|
|
|
|
s.data(Tags.CONTACTS_BIRTHDAY, cv.getAsString(EasPersonal.BIRTHDAY));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasPersonal.FILE_AS)) {
|
|
|
|
s.data(Tags.CONTACTS_FILE_AS, cv.getAsString(EasPersonal.FILE_AS));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasPersonal.SPOUSE)) {
|
|
|
|
s.data(Tags.CONTACTS_SPOUSE, cv.getAsString(EasPersonal.SPOUSE));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasPersonal.TITLE)) {
|
|
|
|
s.data(Tags.CONTACTS_TITLE, cv.getAsString(EasPersonal.TITLE));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(EasPersonal.WEBPAGE)) {
|
|
|
|
s.data(Tags.CONTACTS_WEBPAGE, cv.getAsString(EasPersonal.WEBPAGE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendYomi(Serializer s, ContentValues cv) throws IOException {
|
|
|
|
if (cv.containsKey(Yomi.FIRST_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS_YOMI_FIRST_NAME, cv.getAsString(Yomi.FIRST_NAME));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(Yomi.LAST_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS_YOMI_LAST_NAME, cv.getAsString(Yomi.LAST_NAME));
|
|
|
|
}
|
|
|
|
if (cv.containsKey(Yomi.COMPANY_NAME)) {
|
|
|
|
s.data(Tags.CONTACTS_YOMI_COMPANY_NAME, cv.getAsString(Yomi.COMPANY_NAME));
|
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendOrganization(Serializer s, ContentValues cv) throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
if (cv.containsKey(Organization.TITLE)) {
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_JOB_TITLE, cv.getAsString(Organization.TITLE));
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
if (cv.containsKey(Organization.COMPANY)) {
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_COMPANY_NAME, cv.getAsString(Organization.COMPANY));
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
private void sendNickname(Serializer s, ContentValues cv) throws IOException {
|
|
|
|
if (cv.containsKey(Nickname.NAME)) {
|
|
|
|
s.data(Tags.CONTACTS2_NICKNAME, cv.getAsString(Nickname.NAME));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-04 03:25:00 +00:00
|
|
|
private void sendNote(Serializer s, ContentValues cv) throws IOException {
|
|
|
|
if (cv.containsKey(Note.NOTE)) {
|
|
|
|
// EAS won't accept note data with raw newline characters
|
2009-08-05 05:39:02 +00:00
|
|
|
String note = cv.getAsString(Note.NOTE).replaceAll("\n", "\r\n");
|
|
|
|
// Format of upsync data depends on protocol version
|
2009-08-04 03:25:00 +00:00
|
|
|
if (mService.mProtocolVersionDouble >= 12.0) {
|
|
|
|
s.start(Tags.BASE_BODY);
|
|
|
|
s.data(Tags.BASE_TYPE, Eas.BODY_PREFERENCE_TEXT).data(Tags.BASE_DATA, note);
|
|
|
|
s.end();
|
|
|
|
} else {
|
|
|
|
s.data(Tags.CONTACTS_BODY, note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 22:33:22 +00:00
|
|
|
private void sendChildren(Serializer s, ContentValues cv) throws IOException {
|
|
|
|
boolean first = true;
|
|
|
|
for (int i = 0; i < EasChildren.MAX_CHILDREN; i++) {
|
|
|
|
String row = EasChildren.ROWS[i];
|
|
|
|
if (cv.containsKey(row)) {
|
|
|
|
if (first) {
|
|
|
|
s.start(Tags.CONTACTS_CHILDREN);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
s.data(Tags.CONTACTS_CHILD, cv.getAsString(row));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!first) {
|
|
|
|
s.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
private void sendPhone(Serializer s, ContentValues cv) throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
String value = cv.getAsString(Phone.NUMBER);
|
|
|
|
switch (cv.getAsInteger(Phone.TYPE)) {
|
|
|
|
case TYPE_WORK2:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_BUSINESS2_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case Phone.TYPE_WORK:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_BUSINESS_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_MMS:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS2_MMS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case Phone.TYPE_FAX_WORK:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_BUSINESS_FAX_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_COMPANY_MAIN:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS2_COMPANY_MAIN_PHONE, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case Phone.TYPE_HOME:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_HOME_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_HOME2:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_HOME2_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case Phone.TYPE_MOBILE:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_MOBILE_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_CAR:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_CAR_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case Phone.TYPE_PAGER:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_PAGER_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_RADIO:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_RADIO_TELEPHONE_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case Phone.TYPE_FAX_HOME:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_HOME_FAX_NUMBER, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_EMAIL2:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_EMAIL2_ADDRESS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
case TYPE_EMAIL3:
|
2009-07-31 01:17:52 +00:00
|
|
|
s.data(Tags.CONTACTS_EMAIL3_ADDRESS, value);
|
2009-07-27 17:24:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
@Override
|
2009-07-31 01:17:52 +00:00
|
|
|
public boolean sendLocalChanges(Serializer s, EasSyncService service) throws IOException {
|
2009-07-27 17:24:58 +00:00
|
|
|
// First, let's find Contacts that have changed.
|
|
|
|
ContentResolver cr = service.mContentResolver;
|
|
|
|
Uri uri = RawContacts.CONTENT_URI.buildUpon()
|
|
|
|
.appendQueryParameter(RawContacts.ACCOUNT_NAME, service.mAccount.mEmailAddress)
|
|
|
|
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE)
|
|
|
|
.build();
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
if (service.mMailbox.mSyncKey.equals("0")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:24:58 +00:00
|
|
|
try {
|
|
|
|
// Get them all atomically
|
2009-07-31 01:17:52 +00:00
|
|
|
EntityIterator ei = cr.queryEntities(uri, RawContacts.DIRTY + "=1", null, null);
|
2009-08-02 22:29:41 +00:00
|
|
|
try {
|
|
|
|
boolean first = true;
|
|
|
|
while (ei.hasNext()) {
|
|
|
|
Entity entity = ei.next();
|
|
|
|
// For each of these entities, create the change commands
|
|
|
|
ContentValues entityValues = entity.getEntityValues();
|
|
|
|
String serverId = entityValues.getAsString(RawContacts.SOURCE_ID);
|
2009-08-04 03:25:00 +00:00
|
|
|
ArrayList<Integer> groupIds = new ArrayList<Integer>();
|
2009-08-02 22:29:41 +00:00
|
|
|
if (first) {
|
|
|
|
s.start(Tags.SYNC_COMMANDS);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
s.start(Tags.SYNC_CHANGE).data(Tags.SYNC_SERVER_ID, serverId)
|
2009-08-04 03:25:00 +00:00
|
|
|
.start(Tags.SYNC_APPLICATION_DATA);
|
2009-08-02 22:29:41 +00:00
|
|
|
// Write out the data here
|
|
|
|
for (NamedContentValues ncv: entity.getSubValues()) {
|
|
|
|
ContentValues cv = ncv.values;
|
|
|
|
String mimeType = cv.getAsString(Data.MIMETYPE);
|
|
|
|
if (mimeType.equals(Email.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendEmail(s, cv);
|
2009-08-02 22:33:22 +00:00
|
|
|
} else if (mimeType.equals(Nickname.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendNickname(s, cv);
|
|
|
|
} else if (mimeType.equals(EasChildren.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendChildren(s, cv);
|
|
|
|
} else if (mimeType.equals(EasBusiness.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendBusiness(s, cv);
|
|
|
|
} else if (mimeType.equals(EasPersonal.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendPersonal(s, cv);
|
2009-08-02 22:29:41 +00:00
|
|
|
} else if (mimeType.equals(Phone.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendPhone(s, cv);
|
2009-08-02 22:33:22 +00:00
|
|
|
} else if (mimeType.equals(Yomi.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendYomi(s, cv);
|
2009-08-02 22:29:41 +00:00
|
|
|
} else if (mimeType.equals(StructuredName.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendStructuredName(s, cv);
|
|
|
|
} else if (mimeType.equals(StructuredPostal.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendStructuredPostal(s, cv);
|
|
|
|
} else if (mimeType.equals(Organization.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendOrganization(s, cv);
|
|
|
|
} else if (mimeType.equals(Im.CONTENT_ITEM_TYPE)) {
|
|
|
|
sendIm(s, cv);
|
2009-08-04 03:25:00 +00:00
|
|
|
} else if (mimeType.equals(GroupMembership.CONTENT_ITEM_TYPE)) {
|
|
|
|
// We must gather these, and send them together (below)
|
|
|
|
groupIds.add(cv.getAsInteger(GroupMembership.GROUP_ROW_ID));
|
2009-08-02 22:29:41 +00:00
|
|
|
} else if (mimeType.equals(Note.CONTENT_ITEM_TYPE)) {
|
2009-08-04 03:25:00 +00:00
|
|
|
sendNote(s, cv);
|
2009-08-02 22:33:22 +00:00
|
|
|
} else if (mimeType.equals(Photo.CONTENT_ITEM_TYPE)) {
|
2009-08-04 03:25:00 +00:00
|
|
|
// For now, the user can change the photo, but the change won't be
|
|
|
|
// uploaded.
|
2009-08-02 22:29:41 +00:00
|
|
|
} else {
|
2009-08-13 16:32:58 +00:00
|
|
|
userLog("Contacts upsync, unknown data: ", mimeType);
|
2009-08-02 22:29:41 +00:00
|
|
|
}
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
2009-08-04 03:25:00 +00:00
|
|
|
|
|
|
|
// Now, we'll send up groups, if any
|
|
|
|
if (!groupIds.isEmpty()) {
|
|
|
|
boolean groupFirst = true;
|
|
|
|
for (int id: groupIds) {
|
|
|
|
// Since we get id's from the provider, we need to find their names
|
|
|
|
Cursor c = cr.query(ContentUris.withAppendedId(Groups.CONTENT_URI, id),
|
|
|
|
GROUP_PROJECTION, null, null, null);
|
|
|
|
try {
|
|
|
|
// Presumably, this should always succeed, but ...
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
if (groupFirst) {
|
|
|
|
s.start(Tags.CONTACTS_CATEGORIES);
|
|
|
|
groupFirst = false;
|
|
|
|
}
|
|
|
|
s.data(Tags.CONTACTS_CATEGORY, c.getString(0));
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!groupFirst) {
|
|
|
|
s.end();
|
|
|
|
}
|
|
|
|
}
|
2009-08-02 22:29:41 +00:00
|
|
|
s.end().end(); // ApplicationData & Change
|
|
|
|
mUpdatedIdList.add(entityValues.getAsLong(RawContacts._ID));
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
2009-08-02 22:29:41 +00:00
|
|
|
if (!first) {
|
|
|
|
s.end(); // Commands
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
ei.close();
|
2009-07-27 17:24:58 +00:00
|
|
|
}
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
Log.e(TAG, "Could not read dirty contacts.");
|
|
|
|
}
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|