use of com.vodafone360.people.engine.contactsync.NativeContactsApi.Account in project 360-Engine-for-Android by 360.
the class MainApplication method removeUserData.
/**
* Remove all user data from People client, this includes all account
* information (downloaded contacts, login credentials etc.) and all cached
* settings.
*/
public synchronized void removeUserData() {
EngineManager mEngineManager = EngineManager.getInstance();
if (mEngineManager != null) {
// Resets all the engines, the call will block until every engines
// have been reset.
mEngineManager.resetAllEngines();
}
// Remove NAB Account at this point (does nothing on 1.X)
NativeContactsApi.getInstance().removePeopleAccount();
// the same action as in NetworkSettingsActivity onChecked()
setInternetAvail(InternetAvail.ALWAYS_CONNECT, false);
mDatabaseHelper.removeUserData();
// Before clearing the Application cache, kick the widget update. Pref's
// file contain the widget ID.
WidgetUtils.kickWidgetUpdateNow(this);
mApplicationCache.clearCachedData(this);
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi.Account in project 360-Engine-for-Android by 360.
the class NativeContactsApiTest method testAccountDataType.
/**
* Tests the plain Account inner class
*/
@SmallTest
public void testAccountDataType() {
// Account with null name and type
Account emptyAccount = new Account(null, null);
assertNotNull(emptyAccount);
assertNull(emptyAccount.getName());
assertNull(emptyAccount.getType());
emptyAccount = null;
// Array of accounts
final int NUM_OBJS_TO_CREATE = 4;
final String baseName = "AccountBaseName";
final String baseType = "AccountBaseType";
for (int i = 0; i < NUM_OBJS_TO_CREATE; i++) {
Account account = new Account(baseName + i, baseType + i);
assertNotNull(account);
assertNotNull(account.getName());
assertNotNull(account.getType());
assertNotNull(account.toString());
assertEquals("Account: name=" + baseName + i + ", type=" + baseType + i, account.toString());
assertEquals(baseName + i, account.getName());
assertEquals(baseType + i, account.getType());
assertFalse(account.isPeopleAccount());
}
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi.Account in project 360-Engine-for-Android by 360.
the class NativeContactsApiTest method testUpdateContacts.
@MediumTest
@Suppress
public void testUpdateContacts() {
Account account = null;
if (mUsing2xApi) {
// Add Account for the case where we are in 2.X
mNabApi.addPeopleAccount(PEOPLE_USERNAME);
account = s360PeopleAccount;
threadWait(100);
}
long[] ids = getContactIdsForAllAccounts();
assertNull(ids);
final int numRandomContacts = 10;
for (int i = 0; i < numRandomContacts; i++) {
long id = i;
final ContactChange[] newContactCcList = ContactChangeHelper.randomContact(id, id, -1);
mNabApi.addContact(account, newContactCcList);
//expectedContactId = newIds[0].getNabContactId() + 1;
// GET CONTACT
ids = getContactIdsForAllAccounts();
assertNotNull(ids);
assertEquals(i + 1, ids.length);
final ContactChange[] fetchedContactCcList = mNabApi.getContact(ids[i]);
assertNotNull(fetchedContactCcList);
// UPDATE
final ContactChange[] updateCcList = ContactChangeHelper.randomContactUpdate(fetchedContactCcList);
assertNotNull(updateCcList);
assertTrue(updateCcList.length > 0);
final ContactChange[] updatedIdsCcList = mNabApi.updateContact(updateCcList);
verifyUpdateContactIds(fetchedContactCcList, updateCcList, updatedIdsCcList);
final ContactChange[] updatedContactCcList = ContactChangeHelper.generatedUpdatedContact(newContactCcList, updateCcList);
ids = getContactIdsForAllAccounts();
assertNotNull(ids);
assertEquals(i + 1, ids.length);
final ContactChange[] fetchedUpdatedContactCcList = mNabApi.getContact(ids[i]);
assertNotNull(fetchedUpdatedContactCcList);
if (!ContactChangeHelper.areUnsortedChangeListsEqual(updatedContactCcList, fetchedUpdatedContactCcList, false)) {
// Print update
Log.e(LOG_TAG, "UPDATE FAILED: Print of initial contact follows");
ContactChangeHelper.printContactChangeList(fetchedContactCcList);
Log.e(LOG_TAG, "UPDATE FAILED: Print of failed update follows:");
ContactChangeHelper.printContactChangeList(updateCcList);
// fail test at this point
assertFalse(true);
}
}
// DELETE
final int idCount = ids.length;
for (int i = 0; i < idCount; i++) {
mNabApi.removeContact(ids[i]);
}
ids = getContactIdsForAllAccounts();
assertNull(ids);
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi.Account in project 360-Engine-for-Android by 360.
the class NativeImporter method initAccounts.
/**
* Sets the accounts used to import the native contacs.
*/
private void initAccounts(boolean firstTimeImport) {
if (VersionUtils.is2XPlatform()) {
// accounts otherwise
if (firstTimeImport) {
ArrayList<Account> accountList = new ArrayList<Account>();
/**
* PAND-2125
* The decision has been made to stop the import of Google contacts on 2.x devices.
* From now on, we will only import native addressbook contacts.
*/
/*
Account googleAccounts[] = mNativeContactsApi.getAccountsByType(NativeContactsApi.GOOGLE_ACCOUNT_TYPE);
if (googleAccounts!=null ){
for (Account account : googleAccounts) {
accountList.add(account);
}
}
*/
Account[] phoneAccounts = mNativeContactsApi.getAccountsByType(NativeContactsApi.PHONE_ACCOUNT_TYPE);
if (phoneAccounts != null) {
for (Account account : phoneAccounts) {
accountList.add(account);
}
}
mAccounts = accountList.toArray(new Account[0]);
} else {
mAccounts = mNativeContactsApi.getAccountsByType(NativeContactsApi.PEOPLE_ACCOUNT_TYPE);
}
if (firstTimeImport)
mIsFirstImportOn2X = true;
}
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi.Account in project 360-Engine-for-Android by 360.
the class NativeImporter method getIdsLists.
/**
* Gets the list of native and people contacts ids.
*/
private void getIdsLists() {
LogUtils.logD("NativeImporter.getIdsLists()");
// Get the list of native ids for the contacts
if (mAccounts == null || 0 == mAccounts.length) {
// default account
LogUtils.logD("NativeImporter.getIdsLists() - using default account");
mNativeContactsIds = mNativeContactsApi.getContactIds(null);
} else if (mAccounts.length == 1) {
// one account
LogUtils.logD("NativeImporter.getIdsLists() - one account found: " + mAccounts[0]);
mNativeContactsIds = mNativeContactsApi.getContactIds(mAccounts[0]);
} else {
// we need to merge the ids from different accounts and sort them
final DynamicArrayLong allIds = new DynamicArrayLong();
LogUtils.logD("NativeImporter.getIdsLists() - more than one account found.");
for (int i = 0; i < mAccounts.length; i++) {
LogUtils.logD("NativeImporter.getIdsLists() - account=" + mAccounts[i]);
final long[] ids = mNativeContactsApi.getContactIds(mAccounts[i]);
if (ids != null) {
allIds.add(ids);
}
}
mNativeContactsIds = allIds.toArray();
// which is faster than sorting them afterwards
if (mNativeContactsIds != null) {
Arrays.sort(mNativeContactsIds);
}
}
// check if we have some work to do
if (mNativeContactsIds == null) {
complete(RESULT_OK);
return;
}
// Get a list of native ids for the contacts we have in the People
// database
mPeopleNativeContactsIds = mPeopleContactsApi.getNativeContactsIds();
mTotalIds = mNativeContactsIds.length;
if (mPeopleNativeContactsIds != null) {
mTotalIds += mPeopleNativeContactsIds.length;
}
mState = STATE_ITERATE_THROUGH_IDS;
}
Aggregations