android.accounts.AuthenticatorDescription Java Examples

The following examples show how to use android.accounts.AuthenticatorDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlModel.java    From opentasks with Apache License 2.0 6 votes vote down vote up
public XmlModel(Context context, AuthenticatorDescription authenticator) throws ModelInflaterException
{
    super(context, authenticator.type);
    mPackageName = authenticator.packageName;
    mPackageManager = context.getPackageManager();
    try
    {
        mModelContext = context.createPackageContext(authenticator.packageName, 0);
        AccountManager am = AccountManager.get(context);
        mAccountLabel = mModelContext.getString(authenticator.labelId);
    }
    catch (NameNotFoundException e)
    {
        throw new ModelInflaterException("No model definition found for package " + mPackageName);
    }

}
 
Example #2
Source File: AccountArrayAdapter.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.account_row, parent,
                false);
    }

    Account account = getItem(position);
    AuthenticatorDescription authenticator = mAuthenticatorMap.get(account.type);
    final ImageView iconImageView = convertView.findViewById(R.id.account_type_icon);
    final TextView accountNameTextView = convertView.findViewById(R.id.account_name);
    iconImageView.setImageDrawable(
            mPackageManager.getDrawable(authenticator.packageName, authenticator.iconId, null));
    accountNameTextView.setText(account.name);
    return convertView;
}
 
Example #3
Source File: ChooseTypeAndAccountActivity.java    From Android-AccountChooser with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: VAccountManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
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();
	}
}
 
Example #5
Source File: VAccountManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
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();
			}
		}
	}
}
 
Example #6
Source File: ContactAdderFragment.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #7
Source File: AccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
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();
    }
}
 
Example #8
Source File: Sources.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link AuthenticatorDescription} for the given account type.
 *
 * @param accountType
 *         The account type to find.
 *
 * @return The {@link AuthenticatorDescription} for the given account type or {@code null} if no such account exists.
 */
private AuthenticatorDescription getAuthenticator(AuthenticatorDescription[] authenticators, String accountType)
{
    for (AuthenticatorDescription auth : authenticators)
    {
        if (TextUtils.equals(accountType, auth.type))
        {
            return auth;
        }
    }
    // no authenticator for that account type found
    return null;
}
 
Example #9
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
private static void fillIcons(Context c){
    AccountManager am = AccountManager.get(c);
    AuthenticatorDescription[] auths = am.getAuthenticatorTypes();
    PackageManager pm = c.getPackageManager();
    for (AuthenticatorDescription auth : auths){
    	accountIcons.put(auth.type, pm.getDrawable(auth.packageName,  auth.iconId, null));
    /*	Log.i("Account:", auth.type);
    	Log.i("pkg:", auth.packageName);
    	Log.i("icon:", String.valueOf(auth.smallIconId));*/

    }
}
 
Example #10
Source File: AccountArrayAdapter.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
public AccountArrayAdapter(Context context, int resource, List<Account> accountList) {
    super(context, resource, accountList);
    mPackageManager = context.getPackageManager();
    mAuthenticatorMap = new HashMap<>();
    AccountManager accountManager = AccountManager.get(context);
    for (AuthenticatorDescription authenticator : accountManager.getAuthenticatorTypes()) {
        mAuthenticatorMap.put(authenticator.type, authenticator);
    }
}
 
Example #11
Source File: AccountManagerHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not there is an account authenticator for Google accounts.
 */
public boolean hasGoogleAccountAuthenticator() {
    AuthenticatorDescription[] descs = mDelegate.getAuthenticatorTypes();
    for (AuthenticatorDescription desc : descs) {
        if (GOOGLE_ACCOUNT_TYPE.equals(desc.type)) return true;
    }
    return false;
}
 
Example #12
Source File: ContactAdderFragment.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param name
 *            The name of the account. This is usually the user's email
 *            address or username.
 * @param description
 *            The description for this account. This will be dictated by
 *            the type of account returned, and can be obtained from the
 *            system AccountManager.
 */
public AccountData(String name, AuthenticatorDescription description) {
	mName = name;
	if (description != null) {
		mType = description.type;

		// The type string is stored in a resource, so we need to
		// convert it into something
		// human readable.
		final String packageName = description.packageName;
		final PackageManager pm = getActivity().getPackageManager();

		if (description.labelId != 0) {
			mTypeLabel = pm.getText(packageName, description.labelId,
					null);
			if (mTypeLabel == null) {
				throw new IllegalArgumentException(
						"LabelID provided, but label not found");
			}
		} else {
			mTypeLabel = "";
		}

		if (description.iconId != 0) {
			mIcon = pm.getDrawable(packageName, description.iconId,
					null);
			if (mIcon == null) {
				throw new IllegalArgumentException(
						"IconID provided, but drawable not " + "found");
			}
		} else {
			mIcon = getResources().getDrawable(
					android.R.drawable.sym_def_app_icon);
		}
	}
}
 
Example #13
Source File: ContactAdderFragment.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the AuthenticatorDescription for a given account type.
 * 
 * @param type
 *            The account type to locate.
 * @param dictionary
 *            An array of AuthenticatorDescriptions, as returned by
 *            AccountManager.
 * @return The description for the specified account type.
 */
private static AuthenticatorDescription getAuthenticatorDescription(
		String type, AuthenticatorDescription[] dictionary) {
	for (final AuthenticatorDescription element : dictionary) {
		if (element.type.equals(type)) {
			return element;
		}
	}
	// No match found
	throw new RuntimeException("Unable to find matching authenticator");
}
 
Example #14
Source File: VAccountManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthenticatorDescription[] getAuthenticatorTypes(int userId) {
	synchronized (cache) {
		AuthenticatorDescription[] descArray = new AuthenticatorDescription[cache.authenticators.size()];
		int i = 0;
		for (AuthenticatorInfo info : cache.authenticators.values()) {
			descArray[i] = info.desc;
			i++;
		}
		return descArray;
	}
}
 
Example #15
Source File: VAccountManager.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public AuthenticatorDescription[] getAuthenticatorTypes() {
	try {
		return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
	} catch (RemoteException e) {
		return VirtualRuntime.crash(e);
	}
}
 
Example #16
Source File: LogonManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private boolean hasLetvAuthenticator() {
    for (AuthenticatorDescription authenticatorType : this.accountManager.getAuthenticatorTypes()) {
        if (this.ACCOUNT_TYPE.equals(authenticatorType.type)) {
            return true;
        }
    }
    return false;
}
 
Example #17
Source File: AccountManagerHelper.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Whether or not there is an account authenticator for Google accounts.
 */
public boolean hasGoogleAccountAuthenticator() {
    AuthenticatorDescription[] descs = mAccountManager.getAuthenticatorTypes();
    for (AuthenticatorDescription desc : descs) {
        if (GOOGLE_ACCOUNT_TYPE.equals(desc.type)) return true;
    }
    return false;
}
 
Example #18
Source File: AccountManagerHelper.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Whether or not there is an account authenticator for Google accounts.
 */
public boolean hasGoogleAccountAuthenticator() {
    AuthenticatorDescription[] descs = mAccountManager.getAuthenticatorTypes();
    for (AuthenticatorDescription desc : descs) {
        if (GOOGLE_ACCOUNT_TYPE.equals(desc.type)) return true;
    }
    return false;
}
 
Example #19
Source File: ChooseAccountTypeActivity.java    From Android-AccountChooser with Apache License 2.0 4 votes vote down vote up
AuthInfo(AuthenticatorDescription desc, String name, Drawable drawable) {
    this.desc = desc;
    this.name = name;
    this.drawable = drawable;
}
 
Example #20
Source File: ChooseAccountActivity.java    From Android-AccountChooser with Apache License 2.0 4 votes vote down vote up
private void getAuthDescriptions() {
    for(AuthenticatorDescription desc : AccountManager.get(this).getAuthenticatorTypes()) {
        mTypeToAuthDescription.put(desc.type, desc);
    }
}
 
Example #21
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AuthenticatorDescription[] getAuthenticatorTypes() {
    return mAccountManager.getAuthenticatorTypes();
}
 
Example #22
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AuthenticatorDescription[] getAuthenticatorTypes() {
    return mAccountManager.getAuthenticatorTypes();
}
 
Example #23
Source File: AccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void writeAsXml(AuthenticatorDescription item, XmlSerializer out)
        throws IOException {
    out.attribute(null, "type", item.type);
}
 
Example #24
Source File: SystemAccountManagerDelegate.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public AuthenticatorDescription[] getAuthenticatorTypes() {
    return mAccountManager.getAuthenticatorTypes();
}
 
Example #25
Source File: VAccountManagerService.java    From container with GNU General Public License v3.0 4 votes vote down vote up
AuthenticatorInfo(AuthenticatorDescription desc, ServiceInfo info) {
	this.desc = desc;
	this.serviceInfo = info;
}
 
Example #26
Source File: AccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public AuthenticatorDescription createFromXml(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    return AuthenticatorDescription.newKey(parser.getAttributeValue(null, "type"));
}
 
Example #27
Source File: AccountManagerDelegate.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Get all the available authenticator types.
 */
@AnyThread
AuthenticatorDescription[] getAuthenticatorTypes();
 
Example #28
Source File: IAccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Sets a listener that will be notified whenever the authenticator set changes
 * @param listener the listener to notify, or null
 * @param handler the {@link Handler} on which the notification will be posted. If null
 * the notification will be posted on the main thread.
 */
void setListener(RegisteredServicesCacheListener<AuthenticatorDescription> listener,
        Handler handler);
 
Example #29
Source File: IAccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * @return A copy of a Collection of all the current Authenticators.
 */
Collection<RegisteredServicesCache.ServiceInfo<AuthenticatorDescription>> getAllServices(
        int userId);
 
Example #30
Source File: IAccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Accessor for the {@link android.content.pm.RegisteredServicesCache.ServiceInfo} that
 * matched the specified {@link android.accounts.AuthenticatorDescription} or null
 * if none match.
 * @param type the authenticator type to return
 * @return the {@link android.content.pm.RegisteredServicesCache.ServiceInfo} that
 * matches the account type or null if none is present
 */
RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> getServiceInfo(
        AuthenticatorDescription type, int userId);