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;
}
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;
}
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);
}
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;
}
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");
}
}
Aggregations