Example usage for android.content ContentResolver getSyncAdapterTypes

List of usage examples for android.content ContentResolver getSyncAdapterTypes

Introduction

In this page you can find the example usage for android.content ContentResolver getSyncAdapterTypes.

Prototype

public static SyncAdapterType[] getSyncAdapterTypes() 

Source Link

Document

Get information about the SyncAdapters that are known to the system.

Usage

From source file:de.spiritcroc.syncsettings.Util.java

public static ArrayList<String> getAuthorities() {
    SyncAdapterType[] syncAdapterTypes = ContentResolver.getSyncAdapterTypes();
    ArrayList<String> syncAuthorities = new ArrayList<>();
    for (SyncAdapterType type : syncAdapterTypes) {
        if (DEBUG)
            Log.d(LOG_TAG, "Found sync type " + type);
        if (!syncAuthorities.contains(type.authority)) {
            syncAuthorities.add(type.authority);
            if (DEBUG)
                Log.d(LOG_TAG, "Added sync authority " + type.authority);
        }//from ww  w. j  a v  a2  s. c  o m
    }
    return syncAuthorities;
}

From source file:com.odoo.MainActivity.java

private void updateSyncSettings() {
    Log.d(TAG, "MainActivity->updateSyncSettings()");

    PreferenceManager mPref = new PreferenceManager(mContext);
    int sync_interval = mPref.getInt("sync_interval", 1440);

    List<String> default_authorities = new ArrayList<String>();
    default_authorities.add("com.android.calendar");
    default_authorities.add("com.android.contacts");

    SyncAdapterType[] list = ContentResolver.getSyncAdapterTypes();

    Account mAccount = OdooAccountManager.getAccount(mContext, OUser.current(mContext).getAndroidName());

    for (SyncAdapterType lst : list) {
        if (lst.authority.contains("com.odoo") && lst.authority.contains("providers")) {
            default_authorities.add(lst.authority);
        }/*from  w  ww  .  ja va2 s . com*/
    }
    for (String authority : default_authorities) {
        boolean isSyncActive = ContentResolver.getSyncAutomatically(mAccount, authority);
        if (isSyncActive) {
            setSyncPeriodic(authority, sync_interval, 60, 1);
        }
    }
    Toast.makeText(this, R.string.toast_setting_saved, Toast.LENGTH_LONG).show();
}

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Loads account list and corresponding account types (potentially with data sets). Always
 * called on a background thread.//www . ja  v  a2 s  .  c o  m
 */
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 = Maps.newHashMap();

    // 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 = Maps.newHashMap();

    final List<AccountWithDataSet> allAccounts = Lists.newArrayList();
    final List<AccountWithDataSet> contactWritableAccounts = Lists.newArrayList();
    final List<AccountWithDataSet> groupWritableAccounts = Lists.newArrayList();
    final Set<String> extensionPackages = Sets.newHashSet();

    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");

    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) {
                // Add an account-with-data-set entry for each account type that is
                // 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);
}

From source file:com.openerp.MainActivity.java

private void updateSyncSettings() {
    Log.d(TAG, "MainActivity->updateSyncSettings()");

    PreferenceManager mPref = new PreferenceManager(mContext);
    int sync_interval = mPref.getInt("sync_interval", 1440);

    List<String> default_authorities = new ArrayList<String>();
    default_authorities.add("com.android.calendar");
    default_authorities.add("com.android.contacts");

    SyncAdapterType[] list = ContentResolver.getSyncAdapterTypes();

    Account mAccount = OpenERPAccountManager.getAccount(mContext, OEUser.current(mContext).getAndroidName());

    for (SyncAdapterType lst : list) {
        if (lst.authority.contains("com.openerp") && lst.authority.contains("providers")) {
            default_authorities.add(lst.authority);
        }/*  w ww  .  ja v  a  2 s. c o  m*/
    }
    for (String authority : default_authorities) {
        boolean isSyncActive = ContentResolver.getSyncAutomatically(mAccount, authority);
        if (isSyncActive) {
            setSyncPeriodic(authority, sync_interval, 60, 1);
        }
    }
    Toast.makeText(this, R.string.toast_setting_saved, Toast.LENGTH_LONG).show();
}

From source file:edu.cmu.cylab.starslinger.view.SaveActivity.java

@Override
public void onAccountsUpdated(Account[] a) {
    MyLog.i(TAG, "Account list update detected");
    // Clear out any old data to prevent duplicates
    mAccounts.clear();/*from  w w  w  . j a  v a 2 s  .co m*/

    // Get account data from system
    AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();

    // Also, get a list of all sync adapters and find the ones that
    // support contacts:
    SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
    ArrayList<String> contactAccountTypes = new ArrayList<String>();
    for (SyncAdapterType sync : syncs) {
        if (ContactsContract.AUTHORITY.equals(sync.authority) && sync.supportsUploading()) {
            contactAccountTypes.add(sync.accountType);
        }
    }

    // Populate tables
    for (int i = 0; i < a.length; i++) {
        // The user may have multiple accounts with the same name, so we
        // need to construct a
        // meaningful display name for each.
        String systemAccountType = a[i].type;
        AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType, accountTypes);
        if (ad != null) {
            AccountData data = new AccountData(this, a[i].name, ad);

            // filter on accounts that support contacts
            if (contactAccountTypes.contains(a[i].type))
                mAccounts.add(data);
        }
    }

    // unsync account
    AuthenticatorDescription adNull = new AuthenticatorDescription(mUnsyncType, UNSYNC_PKG, 0, 0, 0, 0);
    AccountData aNull = new AccountData(this, mUnsyncName, adNull);
    mAccounts.add(aNull);

    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}

From source file:com.android.contacts.model.AccountTypeManager.java

private synchronized void reloadAccountTypesIfNeeded() {
    if (mTypeProvider == null || mTypeProvider.shouldUpdate(mAccountManager.getAuthenticatorTypes(),
            ContentResolver.getSyncAdapterTypes())) {
        reloadAccountTypes();/*  w  w  w . j a v  a2 s.c  om*/
    }
}