use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class LoginEngine method setRegistrationComplete.
/**
* Helper function to set the registration complete flag and update the
* database with the new state.
*
* @param value true if registration is completed
*/
private void setRegistrationComplete(boolean value) {
LogUtils.logD("LoginEngine.setRegistrationComplete(" + value + ")");
if (value != mIsRegistrationComplete) {
StateTable.setRegistrationComplete(value, mDb.getWritableDatabase());
mIsRegistrationComplete = value;
if (mIsRegistrationComplete) {
// Create NAB Account at this point (does nothing on 1.X
// devices)
final NativeContactsApi nabApi = NativeContactsApi.getInstance();
if (!nabApi.isPeopleAccountCreated()) {
// TODO: React upon failure to create account
nabApi.addPeopleAccount(LoginPreferences.getUsername());
}
}
}
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class RemoteService method onCreate.
/**
* Creation of RemoteService. Loads properties (i.e. supported features,
* server URLs etc) from SettingsManager. Creates IPeopleServiceImpl,
* NetworkAgent. Connects ConnectionManager creating Connection thread(s)
* and DecoderThread 'Kicks' worker thread.
*/
@Override
public void onCreate() {
LogUtils.logV("RemoteService.onCreate()");
SettingsManager.loadProperties(this);
mIPeopleServiceImpl = new PeopleServiceImpl(this, this);
mNetworkAgent = new NetworkAgent(this, this, this);
// Create NativeContactsApi here to access Application Context
NativeContactsApi.createInstance(getApplicationContext());
EngineManager.createEngineManager(this, mIPeopleServiceImpl);
mNetworkAgent.onCreate();
mIPeopleServiceImpl.setNetworkAgent(mNetworkAgent);
/** The service has now been fully initialised. **/
mIsStarted = true;
kickWorkerThread();
final MainApplication mainApp = (MainApplication) getApplication();
mainApp.setServiceInterface(mIPeopleServiceImpl);
if (VersionUtils.is2XPlatform()) {
mAccountsObjectsHolder = new NativeAccountObjectsHolder(((MainApplication) getApplication()));
}
final UserDataProtection userDataProtection = new UserDataProtection(this, mainApp.getDatabase());
userDataProtection.performStartupChecks();
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method testExportingContactAllDetails.
/**
* Tests the export of a new syncable contact with all the possible details combinations.
*/
public void testExportingContactAllDetails() {
UpdateNativeContacts processor = new UpdateNativeContacts(mContactSyncCallback, mDatabaseHelper);
// check that there are no contacts to sync
long[] syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
// put a contact that need to be synchronized to native side and that contains
// all the possible details that can be synchronized
final Contact contact = feedOneSyncableContact();
// check the count of the contacts to sync
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(1, syncableIds.length);
// run the UpdateNativeContacts processor until it finishes or it times out
runUpdateNativeContactsProcessor(processor);
// check that the contact on native side is equivalent
final NativeContactsApi nca = NativeContactsApi.getInstance();
long[] ids = null;
if (VersionUtils.is2XPlatform()) {
ids = nca.getContactIds(PEOPLE_ACCOUNT);
} else {
ids = nca.getContactIds(null);
}
assertEquals(1, ids.length);
// check that no more contact is syncable as the export is done
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
final ContactChange[] contactChanges = nca.getContact(ids[0]);
assertTrue(compareContactWithContactChange(contact, contactChanges));
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method testExportingDeletedContacts.
/**
* Tests the export of new syncable contacts.
*/
@Suppress
public void testExportingDeletedContacts() {
final int CONTACTS_COUNT = 30;
UpdateNativeContacts processor = new UpdateNativeContacts(mContactSyncCallback, mDatabaseHelper);
// check that there are no contacts to sync
long[] syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
// put some contacts that need to be synchronized to native side
feedSyncableContactsInDatabase(CONTACTS_COUNT);
// check the count of the contacts to sync
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(CONTACTS_COUNT, syncableIds.length);
// run the UpdateNativeContacts processor until it finishes or it times out
runUpdateNativeContactsProcessor(processor);
// check the contacts count on native side
final NativeContactsApi nca = NativeContactsApi.getInstance();
long[] ids = null;
if (VersionUtils.is2XPlatform()) {
ids = nca.getContactIds(PEOPLE_ACCOUNT);
} else {
ids = nca.getContactIds(null);
}
assertEquals(CONTACTS_COUNT, ids.length);
// check that no more contact is syncable as the export is done
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
// delete 6 of the exported contacts
mDatabaseHelper.deleteContact(1);
mDatabaseHelper.deleteContact(3);
mDatabaseHelper.deleteContact(5);
mDatabaseHelper.deleteContact(15);
mDatabaseHelper.deleteContact(20);
mDatabaseHelper.deleteContact(26);
// check the count of the contacts to sync
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(6, syncableIds.length);
// run the UpdateNativeContacts processor until it finishes or it times out
processor = new UpdateNativeContacts(mContactSyncCallback, mDatabaseHelper);
mContactSyncCallback.mProcessorComplete.clear();
runUpdateNativeContactsProcessor(processor);
// check the contacts count on native side
if (VersionUtils.is2XPlatform()) {
ids = nca.getContactIds(PEOPLE_ACCOUNT);
} else {
ids = nca.getContactIds(null);
}
assertEquals(CONTACTS_COUNT - 6, ids.length);
// check that no more contact is syncable as the export is done
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class NativeContactsApi1 method getContact.
/**
* @see NativeContactsApi#getContact(long)
*/
@Override
public ContactChange[] getContact(long nabContactId) {
final List<ContactChange> ccList = new ArrayList<ContactChange>();
final Cursor cursor = mCr.query(ContentUris.withAppendedId(People.CONTENT_URI, nabContactId), PEOPLE_PROJECTION, null, null, null);
try {
if (cursor.moveToNext()) {
final String displayName = CursorUtils.getString(cursor, People.NAME);
if (!TextUtils.isEmpty(displayName)) {
// TODO: Remove if really not necessary
// final Name name = parseRawName(displayName);
final Name name = new Name();
name.firstname = displayName;
final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NAME, VCardHelper.makeName(name), ContactChange.FLAG_NONE);
cc.setNabContactId(nabContactId);
ccList.add(cc);
}
// Note
final String note = CursorUtils.getString(cursor, People.NOTES);
if (!TextUtils.isEmpty(note)) {
final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NOTE, note, ContactChange.FLAG_NONE);
cc.setNabContactId(nabContactId);
ccList.add(cc);
}
// Remaining contact details
readContactPhoneNumbers(ccList, nabContactId);
readContactMethods(ccList, nabContactId);
readContactOrganizations(ccList, nabContactId);
}
} finally {
CursorUtils.closeCursor(cursor);
}
return ccList.toArray(new ContactChange[ccList.size()]);
}
Aggregations