Search in sources :

Example 21 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project Android-AccountChooser by frakbot.

the class ChooseTypeAndAccountActivity method getReleventAccountTypes.

/**
     * Return a set of account types speficied by the intent as well as supported by the
     * AccountManager.
     */
private Set<String> getReleventAccountTypes(final Intent intent) {
    // An account type is relevant iff it is allowed by the caller and supported by the account
    // manager.
    Set<String> setOfRelevantAccountTypes = null;
    final String[] allowedAccountTypes = intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
    if (allowedAccountTypes != null) {
        setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes);
        AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
        Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
        for (AuthenticatorDescription desc : descs) {
            supportedAccountTypes.add(desc.type);
        }
        setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
    }
    return setOfRelevantAccountTypes;
}
Also used : AuthenticatorDescription(android.accounts.AuthenticatorDescription) HashSet(java.util.HashSet)

Example 22 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project platform_frameworks_base by android.

the class AccountAuthenticatorCache method parseServiceAttributes.

public AuthenticatorDescription parseServiceAttributes(Resources res, String packageName, AttributeSet attrs) {
    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AccountAuthenticator);
    try {
        final String accountType = sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
        final int labelId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_label, 0);
        final int iconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_icon, 0);
        final int smallIconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0);
        final int prefId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0);
        final boolean customTokens = sa.getBoolean(com.android.internal.R.styleable.AccountAuthenticator_customTokens, false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, labelId, iconId, smallIconId, prefId, customTokens);
    } finally {
        sa.recycle();
    }
}
Also used : AuthenticatorDescription(android.accounts.AuthenticatorDescription) TypedArray(android.content.res.TypedArray)

Example 23 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project android_frameworks_base by ParanoidAndroid.

the class AccountAuthenticatorCache method parseServiceAttributes.

public AuthenticatorDescription parseServiceAttributes(Resources res, String packageName, AttributeSet attrs) {
    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AccountAuthenticator);
    try {
        final String accountType = sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
        final int labelId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_label, 0);
        final int iconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_icon, 0);
        final int smallIconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0);
        final int prefId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0);
        final boolean customTokens = sa.getBoolean(com.android.internal.R.styleable.AccountAuthenticator_customTokens, false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, labelId, iconId, smallIconId, prefId, customTokens);
    } finally {
        sa.recycle();
    }
}
Also used : AuthenticatorDescription(android.accounts.AuthenticatorDescription) TypedArray(android.content.res.TypedArray)

Example 24 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project platform_frameworks_base by android.

the class AuthenticatorHelper method getLabelForType.

/**
     * Gets the label associated with a particular account type. If none found, return null.
     * @param accountType the type of account
     * @return a CharSequence for the label or null if one cannot be found.
     */
public CharSequence getLabelForType(Context context, final String accountType) {
    CharSequence label = null;
    if (mTypeToAuthDescription.containsKey(accountType)) {
        try {
            AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
            Context authContext = context.createPackageContextAsUser(desc.packageName, 0, mUserHandle);
            label = authContext.getResources().getText(desc.labelId);
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "No label name for account type " + accountType);
        } catch (Resources.NotFoundException e) {
            Log.w(TAG, "No label icon for account type " + accountType);
        }
    }
    return label;
}
Also used : Context(android.content.Context) AuthenticatorDescription(android.accounts.AuthenticatorDescription) PackageManager(android.content.pm.PackageManager) Resources(android.content.res.Resources)

Example 25 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project platform_frameworks_base by android.

the class AuthenticatorHelper method getDrawableForType.

/**
     * Gets an icon associated with a particular account type. If none found, return null.
     * @param accountType the type of account
     * @return a drawable for the icon or a default icon returned by
     * {@link PackageManager#getDefaultActivityIcon} if one cannot be found.
     */
public Drawable getDrawableForType(Context context, final String accountType) {
    Drawable icon = null;
    synchronized (mAccTypeIconCache) {
        if (mAccTypeIconCache.containsKey(accountType)) {
            return mAccTypeIconCache.get(accountType);
        }
    }
    if (mTypeToAuthDescription.containsKey(accountType)) {
        try {
            AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
            Context authContext = context.createPackageContextAsUser(desc.packageName, 0, mUserHandle);
            icon = mContext.getPackageManager().getUserBadgedIcon(authContext.getDrawable(desc.iconId), mUserHandle);
            synchronized (mAccTypeIconCache) {
                mAccTypeIconCache.put(accountType, icon);
            }
        } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
        // Ignore
        }
    }
    if (icon == null) {
        icon = context.getPackageManager().getDefaultActivityIcon();
    }
    return icon;
}
Also used : Context(android.content.Context) AuthenticatorDescription(android.accounts.AuthenticatorDescription) Drawable(android.graphics.drawable.Drawable)

Aggregations

AuthenticatorDescription (android.accounts.AuthenticatorDescription)37 Context (android.content.Context)17 PackageManager (android.content.pm.PackageManager)12 Resources (android.content.res.Resources)11 Account (android.accounts.Account)10 Drawable (android.graphics.drawable.Drawable)9 RegisteredServicesCache (android.content.pm.RegisteredServicesCache)7 TypedArray (android.content.res.TypedArray)7 Bundle (android.os.Bundle)7 RemoteException (android.os.RemoteException)7 AccountAuthenticatorResponse (android.accounts.AccountAuthenticatorResponse)6 IAccountAuthenticatorResponse (android.accounts.IAccountAuthenticatorResponse)6 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 GeneralSecurityException (java.security.GeneralSecurityException)5 ResolveInfo (android.content.pm.ResolveInfo)2 AccountManager (android.accounts.AccountManager)1 AccountManagerFuture (android.accounts.AccountManagerFuture)1 ActivityInfo (android.content.pm.ActivityInfo)1 ApplicationInfo (android.content.pm.ApplicationInfo)1