Search in sources :

Example 96 with AccountManager

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;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 97 with AccountManager

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;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 98 with AccountManager

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;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 99 with AccountManager

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());
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) HashSet(java.util.HashSet)

Example 100 with AccountManager

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;
}
Also used : PackageManager(android.content.pm.PackageManager) AccountManager(android.accounts.AccountManager) IntentSender(android.content.IntentSender)

Aggregations

AccountManager (android.accounts.AccountManager)104 Account (android.accounts.Account)75 Bundle (android.os.Bundle)14 IOException (java.io.IOException)11 Intent (android.content.Intent)10 OperationCanceledException (android.accounts.OperationCanceledException)7 AuthenticatorException (android.accounts.AuthenticatorException)5 View (android.view.View)5 TextView (android.widget.TextView)5 HashSet (java.util.HashSet)5 SharedPreferences (android.content.SharedPreferences)4 AccountManagerCallback (android.accounts.AccountManagerCallback)3 Paint (android.graphics.Paint)3 JSONException (org.json.JSONException)3 AccountsException (android.accounts.AccountsException)2 TargetApi (android.annotation.TargetApi)2 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 OperationApplicationException (android.content.OperationApplicationException)2