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();
}
}
}
}
java类android.accounts.AuthenticatorDescription的实例源码
VAccountManagerService.java 文件源码
项目:VirtualHook
阅读 38
收藏 0
点赞 0
评论 0
VAccountManagerService.java 文件源码
项目:container
阅读 36
收藏 0
点赞 0
评论 0
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();
}
}
}
}
ContactAdder.java 文件源码
项目:buildAPKsSamples
阅读 23
收藏 0
点赞 0
评论 0
/**
* Updates account list spinner when the list of Accounts on the system changes. Satisfies
* OnAccountsUpdateListener implementation.
*/
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
AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();
// Populate tables
for (int i = 0; i < a.length; i++) {
// The user may have multiple accounts with the same name, so we need to construct a
// meaningful display name for each.
String systemAccountType = a[i].type;
AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType,
accountTypes);
AccountData data = new AccountData(a[i].name, ad);
mAccounts.add(data);
}
// Update the account spinner
mAccountAdapter.notifyDataSetChanged();
}
VAccountManagerService.java 文件源码
项目:VirtualHook
阅读 37
收藏 0
点赞 0
评论 0
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();
}
}
ChooseTypeAndAccountActivity.java 文件源码
项目:TPlayer
阅读 25
收藏 0
点赞 0
评论 0
/**
* Return a set of account types specified 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;
final String[] allowedAccountTypes =
intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
AuthenticatorDescription[] descs = VAccountManager.get().getAuthenticatorTypes();
Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
for (AuthenticatorDescription desc : descs) {
supportedAccountTypes.add(desc.type);
}
if (allowedAccountTypes != null) {
setOfRelevantAccountTypes = new HashSet<>();
Collections.addAll(setOfRelevantAccountTypes, allowedAccountTypes);
setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
} else {
setOfRelevantAccountTypes = supportedAccountTypes;
}
return setOfRelevantAccountTypes;
}
ChooseAccountTypeActivity.java 文件源码
项目:TPlayer
阅读 20
收藏 0
点赞 0
评论 0
private void buildTypeToAuthDescriptionMap() {
for(AuthenticatorDescription desc : VAccountManager.get().getAuthenticatorTypes()) {
String name = null;
Drawable icon = null;
try {
Resources res = VirtualCore.get().getResources(desc.packageName);
icon = res.getDrawable(desc.iconId);
final CharSequence sequence = res.getText(desc.labelId);
name = sequence.toString();
name = sequence.toString();
} catch (Resources.NotFoundException e) {
// Nothing we can do much here, just log
VLog.w(TAG, "No icon resource for account type " + desc.type);
}
AuthInfo authInfo = new AuthInfo(desc, name, icon);
mTypeToAuthenticatorInfo.put(desc.type, authInfo);
}
}
VAccountManagerService.java 文件源码
项目:TPlayer
阅读 45
收藏 0
点赞 0
评论 0
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();
}
}
VAccountManagerService.java 文件源码
项目:container
阅读 39
收藏 0
点赞 0
评论 0
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();
}
}
Util.java 文件源码
项目:SyncSettings
阅读 23
收藏 0
点赞 0
评论 0
public static String accountToReadableString(Context context, Account account, boolean detailed) {
PackageManager pm = context.getPackageManager();
String result = null;
for (AuthenticatorDescription d: AccountManager.get(context).getAuthenticatorTypes()) {
if (account.type.equals(d.type)) {
try {
result = pm.getResourcesForApplication(d.packageName).getString(d.labelId);
} catch (Exception e) {
if (DEBUG) {
Log.i(LOG_TAG, "accountToReadableString() got exception: "
+ e.getMessage());
}
}
break;
}
}
if (TextUtils.isEmpty(result)) {
result = account.type;
} else if (detailed) {
result = context.getString(R.string.sync_account_detailed, result, account.type);
}
return context.getString(R.string.sync_account, account.name, result);
}
ContactAdderFragment.java 文件源码
项目:asstudydemo
阅读 27
收藏 0
点赞 0
评论 0
/**
* Updates account list spinner when the list of Accounts on the system changes. Satisfies OnAccountsUpdateListener implementation.
*
* @param accounts
*/
@Override
public void onAccountsUpdated(Account[] accounts) {
LogUtils.i("Account list update detected");
// Clear out any old data to prevent duplicates.
mAccounts.clear();
// Get account data from system
AuthenticatorDescription[] accountTypes = AccountManager.get(getContext()).getAuthenticatorTypes();
// Populate tables
for (int i = 0; i < accounts.length; i++) {
// The user may have multiple accounts with the same name, so we need to construct a meaningful display name for each.
String systemAccountType = accounts[i].type;
AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType, accountTypes);
AccountData data = new AccountData(accounts[i].name, ad);
mAccounts.add(data);
}
// Update the account spinner
mAccountAdapter.notifyDataSetChanged();
}
ContactAdderFragment.java 文件源码
项目:asstudydemo
阅读 24
收藏 0
点赞 0
评论 0
public AccountData(String name, AuthenticatorDescription description) {
mName = name;
if (null != description) {
mType = description.type;
// The type string is stored in a resource, so we need to convert it into something human readable.
String packageName = description.packageName;
PackageManager pm = getActivity().getPackageManager();
if (description.labelId != 0) {
mTypeLabel = pm.getText(packageName, description.labelId, null);
if (null == mTypeLabel) {
throw new IllegalArgumentException("LabelID provided, but label not fount");
}
} else {
mTypeLabel = "";
}
if (description.iconId != 0) {
mIcon = pm.getDrawable(packageName, description.iconId, null);
if (null == mIcon) {
throw new IllegalArgumentException("IconID provided, but drawable not found");
}
} else {
mIcon = getResources().getDrawable(android.R.drawable.sym_def_app_icon);
}
}
}
ContactAdder.java 文件源码
项目:AndroidSampleCode
阅读 25
收藏 0
点赞 0
评论 0
/**
* Updates account list spinner when the list of Accounts on the system changes. Satisfies
* OnAccountsUpdateListener implementation.
*/
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
AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();
// Populate tables
for (int i = 0; i < a.length; i++) {
// The user may have multiple accounts with the same name, so we need to construct a
// meaningful display name for each.
String systemAccountType = a[i].type;
AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType,
accountTypes);
AccountData data = new AccountData(a[i].name, ad);
mAccounts.add(data);
}
// Update the account spinner
mAccountAdapter.notifyDataSetChanged();
}
ContactAdderActivity.java 文件源码
项目:kidsdialer
阅读 25
收藏 0
点赞 0
评论 0
/**
* Updates account list spinner when the list of Accounts on the system
* changes. Satisfies OnAccountsUpdateListener implementation.
*/
public void onAccountsUpdated(Account[] a) {
Log.i("Account list update detected");
// Clear out any old data to prevent duplicates
mAccounts.clear();
// Get account data from system
AuthenticatorDescription[] accountTypes = AccountManager.get(this)
.getAuthenticatorTypes();
// Populate tables
for (int i = 0; i < a.length; i++) {
// The user may have multiple accounts with the same name, so we
// need to construct a
// meaningful display name for each.
String systemAccountType = a[i].type;
AuthenticatorDescription ad = getAuthenticatorDescription(
systemAccountType, accountTypes);
AccountData data = new AccountData(a[i].name, ad);
mAccounts.add(data);
}
// Update the account spinner
mAccountAdapter.notifyDataSetChanged();
}
XmlModel.java 文件源码
项目:opentasks
阅读 27
收藏 0
点赞 0
评论 0
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);
}
}
ChooseTypeAndAccountActivity.java 文件源码
项目:Android-AccountChooser
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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;
}
LogonManager.java 文件源码
项目:letv
阅读 23
收藏 0
点赞 0
评论 0
private boolean hasLetvAuthenticator() {
for (AuthenticatorDescription authenticatorType : this.accountManager.getAuthenticatorTypes()) {
if (this.ACCOUNT_TYPE.equals(authenticatorType.type)) {
return true;
}
}
return false;
}
ContactAdder.java 文件源码
项目:buildAPKsSamples
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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 (int i = 0; i < dictionary.length; i++) {
if (dictionary[i].type.equals(type)) {
return dictionary[i];
}
}
// No match found
throw new RuntimeException("Unable to find matching authenticator");
}
ContactAdder.java 文件源码
项目:buildAPKsSamples
阅读 24
收藏 0
点赞 0
评论 0
/**
* @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.
String packageName = description.packageName;
PackageManager pm = 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);
}
}
}
VAccountManager.java 文件源码
项目:VirtualHook
阅读 24
收藏 0
点赞 0
评论 0
public AuthenticatorDescription[] getAuthenticatorTypes() {
try {
return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
} catch (RemoteException e) {
return VirtualRuntime.crash(e);
}
}
VAccountManagerService.java 文件源码
项目:VirtualHook
阅读 38
收藏 0
点赞 0
评论 0
@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;
}
}
VAccountManager.java 文件源码
项目:TPlayer
阅读 24
收藏 0
点赞 0
评论 0
public AuthenticatorDescription[] getAuthenticatorTypes() {
try {
return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
} catch (RemoteException e) {
return VirtualRuntime.crash(e);
}
}
VAccountManagerService.java 文件源码
项目:TPlayer
阅读 37
收藏 0
点赞 0
评论 0
@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;
}
}
VAccountManager.java 文件源码
项目:container
阅读 25
收藏 0
点赞 0
评论 0
public AuthenticatorDescription[] getAuthenticatorTypes() {
try {
return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
} catch (RemoteException e) {
return VirtualRuntime.crash(e);
}
}
VAccountManagerService.java 文件源码
项目:container
阅读 37
收藏 0
点赞 0
评论 0
@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;
}
}
ContactAdderFragment.java 文件源码
项目:asstudydemo
阅读 21
收藏 0
点赞 0
评论 0
private AuthenticatorDescription getAuthenticatorDescription(String type, AuthenticatorDescription[] dictionary) {
for (int i = 0; i < dictionary.length; i++) {
if (dictionary[i].type.equals(type)) {
return dictionary[i];
}
}
// No match found
throw new RuntimeException("Unable to find matching authenticator");
}
AccountManagerHelper.java 文件源码
项目:365browser
阅读 29
收藏 0
点赞 0
评论 0
/**
* @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;
}
AccountManagerTest.java 文件源码
项目:FullRobolectricTestSample
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void testAddAuthenticator() {
Robolectric.shadowOf(am).addAuthenticator("type");
AuthenticatorDescription[] result = am.getAuthenticatorTypes();
assertThat(result.length).isEqualTo(1);
assertThat(result[0].type).isEqualTo("type");
}
SaveActivity.java 文件源码
项目:SafeSlinger-Android
阅读 32
收藏 0
点赞 0
评论 0
private AuthenticatorDescription getAuthenticatorDescription(String type,
AuthenticatorDescription[] dictionary) {
for (int i = 0; i < dictionary.length; i++) {
if (dictionary[i].type.equals(type)) {
return dictionary[i];
}
}
// No match found
return null;
}
SettingsActivity.java 文件源码
项目:SafeSlinger-Android
阅读 30
收藏 0
点赞 0
评论 0
private static AuthenticatorDescription getAuthenticatorDescription(String type,
AuthenticatorDescription[] dictionary) {
for (int i = 0; i < dictionary.length; i++) {
if (dictionary[i].type.equals(type)) {
return dictionary[i];
}
}
// No match found
return null;
}
AccountData.java 文件源码
项目:SafeSlinger-Android
阅读 27
收藏 0
点赞 0
评论 0
public AccountData(Context ctx, 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.
String packageName = description.packageName;
PackageManager pm = ctx.getPackageManager();
if (description.labelId != 0) {
mTypeLabel = pm.getText(packageName, description.labelId, null);
if (mTypeLabel == null) {
mTypeLabel = ctx.getString(R.string.label_undefinedTypeLabel);
}
} else {
mTypeLabel = "";
}
if (description.iconId != 0) {
mIcon = pm.getDrawable(packageName, description.iconId, null);
} else {
mIcon = ctx.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
}
}
}