Search in sources :

Example 11 with AccountManager

use of android.accounts.AccountManager in project android-bootstrap by AndroidBootstrap.

the class TestUserAccountUtil method ensureValidAccountAvailable.

/**
     * Checks the device has a valid Bootstrap (on parse.com via the example API),
     * account, if not, adds one using the test credentials found in system
     * property 'bootstrap.test.api.key'.
     *
     * The credentials can be passed on the command line like this: mvn
     * -bootstrap.test.api.key=0123456789abcdef0123456789abcdef install
     *
     * @param instrumentation
     *            taken from the test context
     * @return true if valid account credentials are available
     */
public static boolean ensureValidAccountAvailable(Instrumentation instrumentation) {
    Context c = instrumentation.getContext();
    AccountManager accountManager = AccountManager.get(instrumentation.getTargetContext());
    for (Account account : accountManager.getAccountsByType(BOOTSTRAP_ACCOUNT_TYPE)) {
        if (accountManager.peekAuthToken(account, AUTHTOKEN_TYPE) != null) {
            Ln.i("Using existing account : " + account.name);
            // we have a valid account that has successfully authenticated
            return true;
        }
    }
    String testApiKey = c.getString(R.string.test_account_api_key);
    String truncatedApiKey = testApiKey.substring(0, 4) + "…";
    if (!testApiKey.matches("\\p{XDigit}{32}")) {
        Ln.w("No valid test account credentials in bootstrap.test.api.key : " + truncatedApiKey);
        return false;
    }
    Ln.i("Adding test account using supplied api key credential : " + truncatedApiKey);
    Account account = new Account("test@example.com", BOOTSTRAP_ACCOUNT_TYPE);
    // this test account will not have a valid password
    accountManager.addAccountExplicitly(account, null, null);
    accountManager.setAuthToken(account, AUTHTOKEN_TYPE, testApiKey);
    return true;
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 12 with AccountManager

use of android.accounts.AccountManager in project android_frameworks_base by AOSPA.

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 13 with AccountManager

use of android.accounts.AccountManager in project platform_frameworks_base by android.

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 14 with AccountManager

use of android.accounts.AccountManager in project platform_frameworks_base by android.

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 15 with AccountManager

use of android.accounts.AccountManager in project platform_frameworks_base by android.

the class DevicePolicyManagerService method hasIncompatibleAccountsLocked.

/**
     * Return true if a given user has any accounts that'll prevent installing a device or profile
     * owner {@code owner}.
     * - If the user has no accounts, then return false.
     * - Otherwise, if the owner is unknown (== null), or is not test-only, then return true.
     * - Otherwise, if there's any account that does not have ..._ALLOWED, or does have
     *   ..._DISALLOWED, return true.
     * - Otherwise return false.
     */
private boolean hasIncompatibleAccountsLocked(int userId, @Nullable ComponentName owner) {
    final long token = mInjector.binderClearCallingIdentity();
    try {
        final AccountManager am = AccountManager.get(mContext);
        final Account[] accounts = am.getAccountsAsUser(userId);
        if (accounts.length == 0) {
            return false;
        }
        final String[] feature_allow = { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED };
        final String[] feature_disallow = { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED };
        // Even if we find incompatible accounts along the way, we still check all accounts
        // for logging.
        boolean compatible = true;
        for (Account account : accounts) {
            if (hasAccountFeatures(am, account, feature_disallow)) {
                Log.e(LOG_TAG, account + " has " + feature_disallow[0]);
                compatible = false;
            }
            if (!hasAccountFeatures(am, account, feature_allow)) {
                Log.e(LOG_TAG, account + " doesn't have " + feature_allow[0]);
                compatible = false;
            }
        }
        if (compatible) {
            Log.w(LOG_TAG, "All accounts are compatible");
        } else {
            Log.e(LOG_TAG, "Found incompatible accounts");
        }
        // Then check if the owner is test-only.
        String log;
        if (owner == null) {
            // Owner is unknown.  Suppose it's not test-only
            compatible = false;
            log = "Only test-only device/profile owner can be installed with accounts";
        } else if (isAdminTestOnlyLocked(owner, userId)) {
            if (compatible) {
                log = "Installing test-only owner " + owner;
            } else {
                log = "Can't install test-only owner " + owner + " with incompatible accounts";
            }
        } else {
            compatible = false;
            log = "Can't install non test-only owner " + owner + " with accounts";
        }
        if (compatible) {
            Log.w(LOG_TAG, log);
        } else {
            Log.e(LOG_TAG, log);
        }
        return !compatible;
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) ParcelableString(com.android.internal.util.ParcelableString)

Aggregations

AccountManager (android.accounts.AccountManager)180 Account (android.accounts.Account)121 Bundle (android.os.Bundle)28 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)16 View (android.view.View)16 TextView (android.widget.TextView)16 Context (android.content.Context)15 IOException (java.io.IOException)14 UserAccountManager (com.nextcloud.client.account.UserAccountManager)13 OperationCanceledException (android.accounts.OperationCanceledException)11 ImageView (android.widget.ImageView)9 AuthenticatorDescription (android.accounts.AuthenticatorDescription)8 UserHandle (android.os.UserHandle)8 LayoutInflater (android.view.LayoutInflater)8 AuthenticatorException (android.accounts.AuthenticatorException)7 UserInfo (android.content.pm.UserInfo)7 Resources (android.content.res.Resources)7 Drawable (android.graphics.drawable.Drawable)7 LinearLayout (android.widget.LinearLayout)7