Search in sources :

Example 1 with NativeContactsApi

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());
            }
        }
    }
}
Also used : NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi)

Example 2 with NativeContactsApi

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();
}
Also used : NetworkAgent(com.vodafone360.people.service.agent.NetworkAgent) UserDataProtection(com.vodafone360.people.service.utils.UserDataProtection) MainApplication(com.vodafone360.people.MainApplication)

Example 3 with NativeContactsApi

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));
}
Also used : UpdateNativeContacts(com.vodafone360.people.engine.contactsync.UpdateNativeContacts) NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) Contact(com.vodafone360.people.datatypes.Contact)

Example 4 with NativeContactsApi

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);
}
Also used : UpdateNativeContacts(com.vodafone360.people.engine.contactsync.UpdateNativeContacts) NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 5 with NativeContactsApi

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()]);
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Aggregations

NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)7 UpdateNativeContacts (com.vodafone360.people.engine.contactsync.UpdateNativeContacts)3 Cursor (android.database.Cursor)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 Suppress (android.test.suitebuilder.annotation.Suppress)1 MainApplication (com.vodafone360.people.MainApplication)1 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)1 Name (com.vodafone360.people.datatypes.VCardHelper.Name)1 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)1 NativeContactsApi1 (com.vodafone360.people.engine.contactsync.NativeContactsApi1)1 NativeContactsApi2 (com.vodafone360.people.engine.contactsync.NativeContactsApi2)1 NetworkAgent (com.vodafone360.people.service.agent.NetworkAgent)1 UserDataProtection (com.vodafone360.people.service.utils.UserDataProtection)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1