use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class PeopleActivityTest method setUp.
@Override
public void setUp() {
mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
mContactsProvider = mContext.getContactsProvider();
// The ContactsApplication performs this getType query to warm up the provider - see
// ContactsApplication#DelayedInitialization.doInBackground
mContactsProvider.expectTypeQuery(ContentUris.withAppendedId(Contacts.CONTENT_URI, 1), Contacts.CONTENT_ITEM_TYPE);
mSettingsProvider = mContext.getSettingsProvider();
InjectedServices services = new InjectedServices();
services.setContentResolver(mContext.getContentResolver());
services.setSharedPreferences(new MockSharedPreferences());
ContactPhotoManager.injectContactPhotoManagerForTesting(new MockContactPhotoManager());
AccountType accountType = new BaseAccountType() {
@Override
public boolean areContactsWritable() {
return false;
}
};
accountType.accountType = TEST_ACCOUNT_TYPE;
AccountWithDataSet account = new AccountWithDataSet(TEST_ACCOUNT, TEST_ACCOUNT_TYPE, null);
ContactsApplication.injectServices(services);
final MockAccountTypeManager mockManager = new MockAccountTypeManager(new AccountType[] { accountType }, new AccountWithDataSet[] { account });
AccountTypeManager.setInstanceForTest(mockManager);
}
use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class ContactEditorUtilsTest method setUp.
@Override
protected void setUp() throws Exception {
// Initialize with 0 types, 0 accounts.
mAccountTypes = new MockAccountTypeManager(new AccountType[] {}, new AccountWithDataSet[] {});
mTarget = new ContactEditorUtils(getContext(), mAccountTypes);
// Clear the preferences.
mTarget.cleanupForTest();
}
use of com.android.contacts.common.model.account.AccountType in project android_packages_apps_Dialer by LineageOS.
the class ContactLoader method loadInvitableAccountTypes.
/**
* Sets the "invitable" account types to {@link Contact#mInvitableAccountTypes}.
*/
private void loadInvitableAccountTypes(Contact contactData) {
final ImmutableList.Builder<AccountType> resultListBuilder = new ImmutableList.Builder<AccountType>();
if (!contactData.isUserProfile()) {
Map<AccountTypeWithDataSet, AccountType> invitables = AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes();
if (!invitables.isEmpty()) {
final Map<AccountTypeWithDataSet, AccountType> resultMap = Maps.newHashMap(invitables);
// Remove the ones that already have a raw contact in the current contact
for (RawContact rawContact : contactData.getRawContacts()) {
final AccountTypeWithDataSet type = AccountTypeWithDataSet.get(rawContact.getAccountTypeString(), rawContact.getDataSet());
resultMap.remove(type);
}
resultListBuilder.addAll(resultMap.values());
}
}
// Set to mInvitableAccountTypes
contactData.setInvitableAccountTypes(resultListBuilder.build());
}
use of com.android.contacts.common.model.account.AccountType in project android_packages_apps_Dialer by LineageOS.
the class ContactLoader method postViewNotificationToSyncAdapter.
/**
* Posts a message to the contributing sync adapters that have opted-in, notifying them that the
* contact has just been loaded
*/
private void postViewNotificationToSyncAdapter() {
Context context = getContext();
for (RawContact rawContact : mContact.getRawContacts()) {
final long rawContactId = rawContact.getId();
if (mNotifiedRawContactIds.contains(rawContactId)) {
// Already notified for this raw contact.
continue;
}
mNotifiedRawContactIds.add(rawContactId);
final AccountType accountType = rawContact.getAccountType(context);
final String serviceName = accountType.getViewContactNotifyServiceClassName();
final String servicePackageName = accountType.getViewContactNotifyServicePackageName();
if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(servicePackageName)) {
final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
final Intent intent = new Intent();
intent.setClassName(servicePackageName, serviceName);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startService(intent);
} catch (Exception e) {
LogUtil.e(TAG, "Error sending message to source-app", e);
}
}
}
}
use of com.android.contacts.common.model.account.AccountType in project android_packages_apps_Dialer by LineageOS.
the class AccountTypeManagerImpl method loadAccountsInBackground.
/**
* Loads account list and corresponding account types (potentially with data sets). Always called
* on a background thread.
*/
protected void loadAccountsInBackground() {
if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground start");
}
TimingLogger timings = new TimingLogger(TAG, "loadAccountsInBackground");
final long startTime = SystemClock.currentThreadTimeMillis();
final long startTimeWall = SystemClock.elapsedRealtime();
// Account types, keyed off the account type and data set concatenation.
final Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet = new ArrayMap<>();
// The same AccountTypes, but keyed off {@link RawContacts#ACCOUNT_TYPE}. Since there can
// be multiple account types (with different data sets) for the same type of account, each
// type string may have multiple AccountType entries.
final Map<String, List<AccountType>> accountTypesByType = new ArrayMap<>();
final List<AccountWithDataSet> allAccounts = new ArrayList<>();
final List<AccountWithDataSet> contactWritableAccounts = new ArrayList<>();
final List<AccountWithDataSet> groupWritableAccounts = new ArrayList<>();
final Set<String> extensionPackages = new HashSet<>();
final AccountManager am = mAccountManager;
final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
final AuthenticatorDescription[] auths = am.getAuthenticatorTypes();
// First process sync adapters to find any that provide contact data.
for (SyncAdapterType sync : syncs) {
if (!ContactsContract.AUTHORITY.equals(sync.authority)) {
// Skip sync adapters that don't provide contact data.
continue;
}
// Look for the formatting details provided by each sync
// adapter, using the authenticator to find general resources.
final String type = sync.accountType;
final AuthenticatorDescription auth = findAuthenticator(auths, type);
if (auth == null) {
Log.w(TAG, "No authenticator found for type=" + type + ", ignoring it.");
continue;
}
AccountType accountType;
if (GoogleAccountType.ACCOUNT_TYPE.equals(type)) {
accountType = new GoogleAccountType(mContext, auth.packageName);
} else if (ExchangeAccountType.isExchangeType(type)) {
accountType = new ExchangeAccountType(mContext, auth.packageName, type);
} else if (SamsungAccountType.isSamsungAccountType(mContext, type, auth.packageName)) {
accountType = new SamsungAccountType(mContext, auth.packageName, type);
} else {
Log.d(TAG, "Registering external account type=" + type + ", packageName=" + auth.packageName);
accountType = new ExternalAccountType(mContext, auth.packageName, false);
}
if (!accountType.isInitialized()) {
if (accountType.isEmbedded()) {
throw new IllegalStateException("Problem initializing embedded type " + accountType.getClass().getCanonicalName());
} else {
// Skip external account types that couldn't be initialized.
continue;
}
}
accountType.accountType = auth.type;
accountType.titleRes = auth.labelId;
accountType.iconRes = auth.iconId;
addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
// Check to see if the account type knows of any other non-sync-adapter packages
// that may provide other data sets of contact data.
extensionPackages.addAll(accountType.getExtensionPackageNames());
}
// If any extension packages were specified, process them as well.
if (!extensionPackages.isEmpty()) {
Log.d(TAG, "Registering " + extensionPackages.size() + " extension packages");
for (String extensionPackage : extensionPackages) {
ExternalAccountType accountType = new ExternalAccountType(mContext, extensionPackage, true);
if (!accountType.isInitialized()) {
// Skip external account types that couldn't be initialized.
continue;
}
if (!accountType.hasContactsMetadata()) {
Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " it doesn't have the CONTACTS_STRUCTURE metadata");
continue;
}
if (TextUtils.isEmpty(accountType.accountType)) {
Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " the CONTACTS_STRUCTURE metadata doesn't have the accountType" + " attribute");
continue;
}
Log.d(TAG, "Registering extension package account type=" + accountType.accountType + ", dataSet=" + accountType.dataSet + ", packageName=" + extensionPackage);
addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
}
}
timings.addSplit("Loaded account types");
// Map in accounts to associate the account names with each account type entry.
Account[] accounts = mAccountManager.getAccounts();
for (Account account : accounts) {
boolean syncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0;
if (syncable) {
List<AccountType> accountTypes = accountTypesByType.get(account.type);
if (accountTypes != null) {
// authenticated by this account.
for (AccountType accountType : accountTypes) {
AccountWithDataSet accountWithDataSet = new AccountWithDataSet(account.name, account.type, accountType.dataSet);
allAccounts.add(accountWithDataSet);
if (accountType.areContactsWritable()) {
contactWritableAccounts.add(accountWithDataSet);
}
if (accountType.isGroupMembershipEditable()) {
groupWritableAccounts.add(accountWithDataSet);
}
}
}
}
}
Collections.sort(allAccounts, ACCOUNT_COMPARATOR);
Collections.sort(contactWritableAccounts, ACCOUNT_COMPARATOR);
Collections.sort(groupWritableAccounts, ACCOUNT_COMPARATOR);
timings.addSplit("Loaded accounts");
synchronized (this) {
mAccountTypesWithDataSets = accountTypesByTypeAndDataSet;
mAccounts = allAccounts;
mContactWritableAccounts = contactWritableAccounts;
mGroupWritableAccounts = groupWritableAccounts;
mInvitableAccountTypes = findAllInvitableAccountTypes(mContext, allAccounts, accountTypesByTypeAndDataSet);
}
timings.dumpToLog();
final long endTimeWall = SystemClock.elapsedRealtime();
final long endTime = SystemClock.currentThreadTimeMillis();
Log.i(TAG, "Loaded meta-data for " + mAccountTypesWithDataSets.size() + " account types, " + mAccounts.size() + " accounts in " + (endTimeWall - startTimeWall) + "ms(wall) " + (endTime - startTime) + "ms(cpu)");
if (mInitializationLatch != null) {
mInitializationLatch.countDown();
mInitializationLatch = null;
}
if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground finish");
}
// Check filter validity since filter may become obsolete after account update. It must be
// done from UI thread.
mMainThreadHandler.post(mCheckFilterValidityRunnable);
}
Aggregations