Search in sources :

Example 91 with AccountManager

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

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

use of android.accounts.AccountManager in project PocketHub by pockethub.

the class AccountUtils method getPasswordAccessibleAccount.

/**
     * Get default account where password can be retrieved
     *
     * @param context
     * @return password accessible account or null if none
     */
public static Account getPasswordAccessibleAccount(final Context context) {
    AccountManager manager = AccountManager.get(context);
    Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE);
    if (accounts == null || accounts.length == 0) {
        return null;
    }
    try {
        accounts = getPasswordAccessibleAccounts(manager, accounts);
    } catch (AuthenticatorConflictException e) {
        return null;
    }
    return accounts != null && accounts.length > 0 ? accounts[0] : null;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 93 with AccountManager

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

the class ShadowAccountManagerTest method testGet.

@Test
public void testGet() {
    assertThat(am).isNotNull();
    assertThat(am).isSameAs(AccountManager.get(RuntimeEnvironment.application));
    AccountManager activityAM = AccountManager.get(RuntimeEnvironment.application);
    assertThat(activityAM).isNotNull();
    assertThat(activityAM).isSameAs(am);
}
Also used : AccountManager(android.accounts.AccountManager) Test(org.junit.Test)

Example 94 with AccountManager

use of android.accounts.AccountManager in project httpclient by pixmob.

the class GoogleAppEngineAuthenticator method fetchAuthCookie.

private String fetchAuthCookie(String authToken, boolean invalidateToken) throws HttpClientException {
    final AccountManager am = (AccountManager) getContext().getSystemService(Context.ACCOUNT_SERVICE);
    if (invalidateToken) {
        // Invalidate authentication token, and generate a new one.
        am.invalidateAuthToken(GOOGLE_ACCOUNT_TYPE, authToken);
        authToken = generateAuthToken();
    }
    final String loginUrl = "https://" + gaeHost + "/_ah/login?continue=http://localhost/&auth=" + urlEncode(authToken);
    final HttpClient hc = new HttpClient(getContext());
    final HttpResponse resp;
    try {
        resp = hc.get(loginUrl).expect(HttpURLConnection.HTTP_MOVED_TEMP).execute();
    } catch (HttpClientException e) {
        throw new HttpClientException("Authentication failed", e);
    }
    // The authentication was successful.
    // Now we need to get the authentication cookie from the response.
    final Map<String, String> cookies = resp.getCookies();
    String authCookie = cookies.get("SACSID");
    if (authCookie == null) {
        if (!invalidateToken) {
            // Try again with a new authentication token.
            return fetchAuthCookie(authToken, true);
        }
    }
    if (authCookie == null) {
        throw new HttpClientException("Authentication failed");
    }
    return authCookie;
}
Also used : AccountManager(android.accounts.AccountManager)

Example 95 with AccountManager

use of android.accounts.AccountManager in project PocketHub by pockethub.

the class MainActivity method onNavigationItemSelected.

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    int itemId = menuItem.getItemId();
    if (itemId == R.id.navigation_home) {
        switchFragment(new HomePagerFragment(), org);
        getSupportActionBar().setTitle(getString(R.string.app_name));
        return true;
    } else if (itemId == R.id.navigation_gists) {
        switchFragment(new GistsPagerFragment(), null);
        getSupportActionBar().setTitle(menuItem.getTitle());
        return true;
    } else if (itemId == R.id.navigation_issue_dashboard) {
        switchFragment(new IssueDashboardPagerFragment(), null);
        getSupportActionBar().setTitle(menuItem.getTitle());
        return true;
    } else if (itemId == R.id.navigation_bookmarks) {
        switchFragment(new FilterListFragment(), null);
        getSupportActionBar().setTitle(menuItem.getTitle());
        return true;
    } else if (itemId == R.id.navigation_log_out) {
        AccountManager accountManager = getAccountManager();
        Account[] allGitHubAccounts = accountManager.getAccountsByType(getString(R.string.account_type));
        for (Account account : allGitHubAccounts) {
            accountManager.removeAccount(account, null, null);
        }
        Intent in = new Intent(this, LoginActivity.class);
        in.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(in);
        finish();
        return false;
    } else if (menuItemOrganizationMap.containsKey(menuItem)) {
        switchFragment(new HomePagerFragment(), menuItemOrganizationMap.get(menuItem));
        navigationView.getMenu().findItem(R.id.navigation_home).setChecked(true);
        return false;
    } else {
        throw new IllegalStateException("MenuItem " + menuItem + " not known");
    }
}
Also used : FilterListFragment(com.github.pockethub.android.ui.issue.FilterListFragment) Account(android.accounts.Account) IssueDashboardPagerFragment(com.github.pockethub.android.ui.issue.IssueDashboardPagerFragment) AccountManager(android.accounts.AccountManager) Intent(android.content.Intent) HomePagerFragment(com.github.pockethub.android.ui.user.HomePagerFragment) GistsPagerFragment(com.github.pockethub.android.ui.gist.GistsPagerFragment)

Aggregations

AccountManager (android.accounts.AccountManager)105 Account (android.accounts.Account)76 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