Search in sources :

Example 16 with AuthenticatorDescription

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

the class ManageAccountsSettings method isSafeIntent.

/**
     * Determines if the supplied Intent is safe. A safe intent is one that is
     * will launch a exported=true activity or owned by the same uid as the
     * authenticator supplying the intent.
     */
private boolean isSafeIntent(PackageManager pm, Intent intent) {
    AuthenticatorDescription authDesc = mAuthenticatorHelper.getAccountTypeDescription(mAccountType);
    ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
    if (resolveInfo == null) {
        return false;
    }
    ActivityInfo resolvedActivityInfo = resolveInfo.activityInfo;
    ApplicationInfo resolvedAppInfo = resolvedActivityInfo.applicationInfo;
    try {
        ApplicationInfo authenticatorAppInf = pm.getApplicationInfo(authDesc.packageName, 0);
        return resolvedActivityInfo.exported || resolvedAppInfo.uid == authenticatorAppInf.uid;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Intent considered unsafe due to exception.", e);
        return false;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AuthenticatorDescription(android.accounts.AuthenticatorDescription) ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 17 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project ETSMobile-Android2 by ApplETS.

the class ContactAdderFragment method onAccountsUpdated.

/**
	 * Updates account list spinner when the list of Accounts on the system
	 * changes. Satisfies OnAccountsUpdateListener implementation.
	 */
@Override
public void onAccountsUpdated(Account[] a) {
    Log.i(TAG, "Account list update detected");
    // Clear out any old data to prevent duplicates
    mAccounts.clear();
    // Get account data from system
    final AuthenticatorDescription[] accountTypes = AccountManager.get(getActivity()).getAuthenticatorTypes();
    // Populate tables
    for (final Account element : a) {
        // The user may have multiple accounts with the same name, so we
        // need to construct a
        // meaningful display name for each.
        final String systemAccountType = element.type;
        final AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType, accountTypes);
        final AccountData data = new AccountData(element.name, ad);
        mAccounts.add(data);
    }
    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}
Also used : AuthenticatorDescription(android.accounts.AuthenticatorDescription) Account(android.accounts.Account)

Example 18 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project VirtualApp by asLody.

the class VAccountManagerService method parseAuthenticatorDescription.

private static AuthenticatorDescription parseAuthenticatorDescription(Resources resources, String packageName, AttributeSet attributeSet) {
    TypedArray array = resources.obtainAttributes(attributeSet, R_Hide.styleable.AccountAuthenticator.get());
    try {
        String accountType = array.getString(R_Hide.styleable.AccountAuthenticator_accountType.get());
        int label = array.getResourceId(R_Hide.styleable.AccountAuthenticator_label.get(), 0);
        int icon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_icon.get(), 0);
        int smallIcon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_smallIcon.get(), 0);
        int accountPreferences = array.getResourceId(R_Hide.styleable.AccountAuthenticator_accountPreferences.get(), 0);
        boolean customTokens = array.getBoolean(R_Hide.styleable.AccountAuthenticator_customTokens.get(), false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, label, icon, smallIcon, accountPreferences, customTokens);
    } finally {
        array.recycle();
    }
}
Also used : AuthenticatorDescription(android.accounts.AuthenticatorDescription) TypedArray(android.content.res.TypedArray)

Example 19 with AuthenticatorDescription

use of android.accounts.AuthenticatorDescription in project VirtualApp by asLody.

the class VAccountManagerService method generateServicesMap.

private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map, IAccountParser accountParser) {
    for (ResolveInfo info : services) {
        XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo, AccountManager.AUTHENTICATOR_META_DATA_NAME);
        if (parser != null) {
            try {
                AttributeSet attributeSet = Xml.asAttributeSet(parser);
                int type;
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
                // Nothing to do
                }
                if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
                    AuthenticatorDescription desc = parseAuthenticatorDescription(accountParser.getResources(mContext, info.serviceInfo.applicationInfo), info.serviceInfo.packageName, attributeSet);
                    if (desc != null) {
                        map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AuthenticatorDescription(android.accounts.AuthenticatorDescription) XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 20 with AuthenticatorDescription

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

the class ChooseAccountTypeActivity method buildTypeToAuthDescriptionMap.

private void buildTypeToAuthDescriptionMap() {
    for (AuthenticatorDescription desc : AccountManager.get(this).getAuthenticatorTypes()) {
        String name = null;
        Drawable icon = null;
        try {
            Context authContext = createPackageContext(desc.packageName, 0);
            icon = authContext.getResources().getDrawable(desc.iconId);
            final CharSequence sequence = authContext.getResources().getText(desc.labelId);
            if (sequence != null) {
                name = sequence.toString();
            }
            name = sequence.toString();
        } catch (PackageManager.NameNotFoundException e) {
            // Nothing we can do much here, just log
            if (Log.isLoggable(TAG, Log.WARN)) {
                Log.w(TAG, "No icon name for account type " + desc.type);
            }
        } catch (Resources.NotFoundException e) {
            // Nothing we can do much here, just log
            if (Log.isLoggable(TAG, Log.WARN)) {
                Log.w(TAG, "No icon resource for account type " + desc.type);
            }
        }
        AuthInfo authInfo = new AuthInfo(desc, name, icon);
        mTypeToAuthenticatorInfo.put(desc.type, authInfo);
    }
}
Also used : Context(android.content.Context) AuthenticatorDescription(android.accounts.AuthenticatorDescription) PackageManager(android.content.pm.PackageManager) Drawable(android.graphics.drawable.Drawable) Resources(android.content.res.Resources)

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