androidpackagesynchronizationauthority

How to get all sync adapters (type/authority) for a specific package


I'm trying to determine the list of sync adapters an installed apps provides, but I can't find anything linking a sync authority and the package/app handling it?

Using AccountManager.getAccountsByType only provides account, no authority or package information at all.

Using ContentResolver.getSyncAdapterTypes() provides all sync authorities available, however I'm unable to determine which package/app is handling which.

Is there a way to determine what sync adapters a particular app/package handles or as in the title, what package handles a given sync adapter?

Thanks for any help on this.


Solution

  • Was actually pretty easy, I was just taking the whole thing the wrong way, trying to find out the package from a sync adapter, whereas a package has all components defined in its PackageInfo!

    Below code will find all package provider being a sync adapter for a given package (pkg_name):

                SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
                int J = types.length;
    
                PackageInfo pi = pm.getPackageInfo(pkg_name, PackageManager.GET_PROVIDERS);
                if (pi.providers != null)
                {
                    int I = pi.providers.length;
                    for(int i = 0; i < I; i++)
                    {
                        ProviderInfo p = pi.providers[i];
                        for(int j = 0; j < J; j++)
                        {
                            SyncAdapterType sat = types[j];
    
                            if (p.authority.equals(sat.authority))
                            {
                                // This provider is a sync adapter
    

    Above code requires a specific permission:

    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />