use of android.accounts.AccountManager in project android_frameworks_base by DirtyUnicorns.
the class SuggestionParser method satisfiesRequiredAccount.
public boolean satisfiesRequiredAccount(Tile suggestion) {
String requiredAccountType = suggestion.metaData.getString(META_DATA_REQUIRE_ACCOUNT);
if (requiredAccountType == null) {
return true;
}
AccountManager accountManager = AccountManager.get(mContext);
Account[] accounts = accountManager.getAccountsByType(requiredAccountType);
return accounts.length > 0;
}
use of android.accounts.AccountManager in project android_frameworks_base by ResurrectionRemix.
the class SuggestionParser method satisfiesRequiredAccount.
public boolean satisfiesRequiredAccount(Tile suggestion) {
String requiredAccountType = suggestion.metaData.getString(META_DATA_REQUIRE_ACCOUNT);
if (requiredAccountType == null) {
return true;
}
AccountManager accountManager = AccountManager.get(mContext);
Account[] accounts = accountManager.getAccountsByType(requiredAccountType);
return accounts.length > 0;
}
use of android.accounts.AccountManager in project android_frameworks_base by ResurrectionRemix.
the class BugreportProgressService method findSendToAccount.
/**
* Find the best matching {@link Account} based on build properties.
*/
private static Account findSendToAccount(Context context) {
final AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
if (!preferredDomain.startsWith("@")) {
preferredDomain = "@" + preferredDomain;
}
final Account[] accounts;
try {
accounts = am.getAccounts();
} catch (RuntimeException e) {
Log.e(TAG, "Could not get accounts for preferred domain " + preferredDomain, e);
return null;
}
if (DEBUG)
Log.d(TAG, "Number of accounts: " + accounts.length);
Account foundAccount = null;
for (Account account : accounts) {
if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
if (!preferredDomain.isEmpty()) {
// looking
if (account.name.endsWith(preferredDomain)) {
return account;
} else {
foundAccount = account;
}
// if we don't have a preferred domain, just return since it looks like
// an email address
} else {
return account;
}
}
}
return foundAccount;
}
use of android.accounts.AccountManager in project android_frameworks_base by ResurrectionRemix.
the class AppLaunch method checkAccountSignIn.
private void checkAccountSignIn() {
// for Gmail
if (mRequiredAccounts == null || mRequiredAccounts.isEmpty()) {
return;
}
final AccountManager am = (AccountManager) getInstrumentation().getTargetContext().getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = am.getAccounts();
// use set here in case device has multiple accounts of the same type
Set<String> foundAccounts = new HashSet<String>();
for (Account account : accounts) {
if (mRequiredAccounts.contains(account.type)) {
foundAccounts.add(account.type);
}
}
// are missing
if (mRequiredAccounts.size() != foundAccounts.size()) {
mRequiredAccounts.removeAll(foundAccounts);
StringBuilder sb = new StringBuilder("Device missing these accounts:");
for (String account : mRequiredAccounts) {
sb.append(' ');
sb.append(account);
}
fail(sb.toString());
}
}
use of android.accounts.AccountManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccountSyncSettings method requestAccountAccessIfNeeded.
private boolean requestAccountAccessIfNeeded(String packageName) {
if (packageName == null) {
return false;
}
final int uid;
try {
uid = getContext().getPackageManager().getPackageUidAsUser(packageName, mUserHandle.getIdentifier());
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Invalid sync ", e);
return false;
}
AccountManager accountManager = getContext().getSystemService(AccountManager.class);
if (!accountManager.hasAccountAccess(mAccount, packageName, mUserHandle)) {
IntentSender intent = accountManager.createRequestAccountAccessIntentSenderAsUser(mAccount, packageName, mUserHandle);
if (intent != null) {
try {
startIntentSenderForResult(intent, uid, null, 0, 0, 0, null);
return true;
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Error requesting account access", e);
}
}
}
return false;
}
Aggregations