Search in sources :

Example 26 with AuthenticatorDescription

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

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 27 with AuthenticatorDescription

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

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)

Example 28 with AuthenticatorDescription

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

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 29 with AuthenticatorDescription

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

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 30 with AuthenticatorDescription

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

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)

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