Search in sources :

Example 11 with SyncAdapterType

use of android.content.SyncAdapterType in project platform_frameworks_base by android.

the class AuthenticatorHelper method buildAccountTypeToAuthoritiesMap.

private void buildAccountTypeToAuthoritiesMap() {
    mAccountTypeToAuthorities.clear();
    SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mUserHandle.getIdentifier());
    for (int i = 0, n = syncAdapters.length; i < n; i++) {
        final SyncAdapterType sa = syncAdapters[i];
        ArrayList<String> authorities = mAccountTypeToAuthorities.get(sa.accountType);
        if (authorities == null) {
            authorities = new ArrayList<String>();
            mAccountTypeToAuthorities.put(sa.accountType, authorities);
        }
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "Added authority " + sa.authority + " to accountType " + sa.accountType);
        }
        authorities.add(sa.authority);
    }
}
Also used : SyncAdapterType(android.content.SyncAdapterType)

Example 12 with SyncAdapterType

use of android.content.SyncAdapterType in project platform_frameworks_base by android.

the class SyncManager method whiteListExistingSyncAdaptersIfNeeded.

private void whiteListExistingSyncAdaptersIfNeeded() {
    if (!mSyncStorageEngine.shouldGrantSyncAdaptersAccountAccess()) {
        return;
    }
    List<UserInfo> users = mUserManager.getUsers(true);
    final int userCount = users.size();
    for (int i = 0; i < userCount; i++) {
        UserHandle userHandle = users.get(i).getUserHandle();
        final int userId = userHandle.getIdentifier();
        for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> service : mSyncAdapters.getAllServices(userId)) {
            String packageName = service.componentName.getPackageName();
            for (Account account : mAccountManager.getAccountsByTypeAsUser(service.type.accountType, userHandle)) {
                if (!canAccessAccount(account, packageName, userId)) {
                    mAccountManager.updateAppPermission(account, AccountManager.ACCOUNT_ACCESS_TOKEN_TYPE, service.uid, true);
                }
            }
        }
    }
}
Also used : Account(android.accounts.Account) UserHandle(android.os.UserHandle) UserInfo(android.content.pm.UserInfo) SyncAdapterType(android.content.SyncAdapterType) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 13 with SyncAdapterType

use of android.content.SyncAdapterType in project platform_frameworks_base by android.

the class SyncManager method getIsSyncable.

private int getIsSyncable(Account account, int userId, String providerName) {
    int isSyncable = mSyncStorageEngine.getIsSyncable(account, userId, providerName);
    UserInfo userInfo = UserManager.get(mContext).getUserInfo(userId);
    // If it's not a restricted user, return isSyncable.
    if (userInfo == null || !userInfo.isRestricted())
        return isSyncable;
    // Else check if the sync adapter has opted-in or not.
    RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo = mSyncAdapters.getServiceInfo(SyncAdapterType.newKey(providerName, account.type), userId);
    if (syncAdapterInfo == null)
        return AuthorityInfo.NOT_SYNCABLE;
    PackageInfo pInfo = null;
    try {
        pInfo = AppGlobals.getPackageManager().getPackageInfo(syncAdapterInfo.componentName.getPackageName(), 0, userId);
        if (pInfo == null)
            return AuthorityInfo.NOT_SYNCABLE;
    } catch (RemoteException re) {
        // Shouldn't happen.
        return AuthorityInfo.NOT_SYNCABLE;
    }
    if (pInfo.restrictedAccountType != null && pInfo.restrictedAccountType.equals(account.type)) {
        return isSyncable;
    } else {
        return AuthorityInfo.NOT_SYNCABLE;
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) UserInfo(android.content.pm.UserInfo) SyncAdapterType(android.content.SyncAdapterType) RemoteException(android.os.RemoteException) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 14 with SyncAdapterType

use of android.content.SyncAdapterType in project android_frameworks_base by crdroidandroid.

the class AccountSyncSettingsBackupHelper method serializeAccountSyncSettingsToJSON.

/**
     * Fetch and serialize Account and authority information as a JSON Array.
     */
private JSONObject serializeAccountSyncSettingsToJSON() throws JSONException {
    Account[] accounts = mAccountManager.getAccounts();
    SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mContext.getUserId());
    // Create a map of Account types to authorities. Later this will make it easier for us to
    // generate our JSON.
    HashMap<String, List<String>> accountTypeToAuthorities = new HashMap<String, List<String>>();
    for (SyncAdapterType syncAdapter : syncAdapters) {
        // Skip adapters that aren’t visible to the user.
        if (!syncAdapter.isUserVisible()) {
            continue;
        }
        if (!accountTypeToAuthorities.containsKey(syncAdapter.accountType)) {
            accountTypeToAuthorities.put(syncAdapter.accountType, new ArrayList<String>());
        }
        accountTypeToAuthorities.get(syncAdapter.accountType).add(syncAdapter.authority);
    }
    // Generate JSON.
    JSONObject backupJSON = new JSONObject();
    backupJSON.put(KEY_VERSION, JSON_FORMAT_VERSION);
    backupJSON.put(KEY_MASTER_SYNC_ENABLED, ContentResolver.getMasterSyncAutomatically());
    JSONArray accountJSONArray = new JSONArray();
    for (Account account : accounts) {
        List<String> authorities = accountTypeToAuthorities.get(account.type);
        // settings for us to restore.
        if (authorities == null || authorities.isEmpty()) {
            continue;
        }
        JSONObject accountJSON = new JSONObject();
        accountJSON.put(KEY_ACCOUNT_NAME, account.name);
        accountJSON.put(KEY_ACCOUNT_TYPE, account.type);
        // Add authorities for this Account type and check whether or not sync is enabled.
        JSONArray authoritiesJSONArray = new JSONArray();
        for (String authority : authorities) {
            int syncState = ContentResolver.getIsSyncable(account, authority);
            boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority);
            JSONObject authorityJSON = new JSONObject();
            authorityJSON.put(KEY_AUTHORITY_NAME, authority);
            authorityJSON.put(KEY_AUTHORITY_SYNC_STATE, syncState);
            authorityJSON.put(KEY_AUTHORITY_SYNC_ENABLED, syncEnabled);
            authoritiesJSONArray.put(authorityJSON);
        }
        accountJSON.put(KEY_ACCOUNT_AUTHORITIES, authoritiesJSONArray);
        accountJSONArray.put(accountJSON);
    }
    backupJSON.put(KEY_ACCOUNTS, accountJSONArray);
    return backupJSON;
}
Also used : Account(android.accounts.Account) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) SyncAdapterType(android.content.SyncAdapterType) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with SyncAdapterType

use of android.content.SyncAdapterType in project android_frameworks_base by crdroidandroid.

the class AuthenticatorHelper method buildAccountTypeToAuthoritiesMap.

private void buildAccountTypeToAuthoritiesMap() {
    mAccountTypeToAuthorities.clear();
    SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mUserHandle.getIdentifier());
    for (int i = 0, n = syncAdapters.length; i < n; i++) {
        final SyncAdapterType sa = syncAdapters[i];
        ArrayList<String> authorities = mAccountTypeToAuthorities.get(sa.accountType);
        if (authorities == null) {
            authorities = new ArrayList<String>();
            mAccountTypeToAuthorities.put(sa.accountType, authorities);
        }
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "Added authority " + sa.authority + " to accountType " + sa.accountType);
        }
        authorities.add(sa.authority);
    }
}
Also used : SyncAdapterType(android.content.SyncAdapterType)

Aggregations

SyncAdapterType (android.content.SyncAdapterType)127 Test (org.junit.Test)46 RegisteredServicesCache (android.content.pm.RegisteredServicesCache)33 EndPoint (com.android.server.content.SyncStorageEngine.EndPoint)30 UserInfo (android.content.pm.UserInfo)17 Account (android.accounts.Account)13 PackageManager (android.content.pm.PackageManager)13 ArrayList (java.util.ArrayList)13 AccountAndUser (android.accounts.AccountAndUser)12 RemoteException (android.os.RemoteException)11 UserHandle (android.os.UserHandle)9 Bundle (android.os.Bundle)8 Preference (android.support.v7.preference.Preference)8 HashSet (java.util.HashSet)8 SyncStatusInfo (android.content.SyncStatusInfo)7 PackageInfo (android.content.pm.PackageInfo)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 List (java.util.List)6 AuthenticatorDescription (android.accounts.AuthenticatorDescription)5 RemoteCallback (android.os.RemoteCallback)5