use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.
the class AccountManagerServiceTest method testPasswords.
public void testPasswords() throws Exception {
Account a11 = new Account("account1", "type1");
Account a12 = new Account("account1", "type2");
mAms.addAccountExplicitly(a11, "p11", null);
mAms.addAccountExplicitly(a12, "p12", null);
assertEquals("p11", mAms.getPassword(a11));
assertEquals("p12", mAms.getPassword(a12));
mAms.setPassword(a11, "p11b");
assertEquals("p11b", mAms.getPassword(a11));
assertEquals("p12", mAms.getPassword(a12));
}
use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.
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.Account in project Reader by TheKeeperOfPie.
the class ActivityLogin method loadAccountInfo.
private void loadAccountInfo(final String tokenAuth, final String tokenRefresh, final long timeExpire) {
Request request = new Request.Builder().url(Reddit.OAUTH_URL + "/api/v1/me").header(Reddit.USER_AGENT, Reddit.CUSTOM_USER_AGENT).header(Reddit.AUTHORIZATION, Reddit.BEARER + tokenAuth).header(Reddit.CONTENT_TYPE, Reddit.CONTENT_TYPE_APP_JSON).get().build();
reddit.load(request).flatMap(UtilsRx.flatMapWrapError(response -> User.fromJson(ComponentStatic.getObjectMapper().readValue(response, JsonNode.class)))).subscribe(new FinalizingSubscriber<User>() {
@Override
public void next(User user) {
Account account = new Account(user.getName(), Reddit.ACCOUNT_TYPE);
Intent result = new Intent();
result.putExtra(AccountManager.KEY_ACCOUNT_NAME, user.getName());
result.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Reddit.ACCOUNT_TYPE);
result.putExtra(AccountManager.KEY_AUTHTOKEN, tokenAuth);
if (getIntent().getBooleanExtra(KEY_IS_NEW_ACCOUNT, false)) {
Bundle extras = new Bundle();
extras.putString(KEY_TIME_EXPIRATION, String.valueOf(timeExpire));
accountManager.addAccountExplicitly(account, tokenRefresh, extras);
accountManager.setAuthToken(account, Reddit.AUTH_TOKEN_FULL_ACCESS, tokenAuth);
}
destroyWebView();
setAccountAuthenticatorResult(result.getExtras());
setResult(RESULT_OK, result);
ActivityLogin.this.finish();
}
});
}
use of android.accounts.Account in project Reader by TheKeeperOfPie.
the class ActivityMain method addNewAccount.
public void addNewAccount() {
accountManager.addAccount(Reddit.ACCOUNT_TYPE, Reddit.AUTH_TOKEN_FULL_ACCESS, null, null, this, new AccountManagerCallback<Bundle>() {
@Override
public void run(final AccountManagerFuture<Bundle> future) {
Observable.just(future).subscribeOn(Schedulers.computation()).observeOn(Schedulers.computation()).flatMap(UtilsRx.flatMapWrapError(AccountManagerFuture::getResult)).observeOn(AndroidSchedulers.mainThread()).subscribe(new FinalizingSubscriber<Bundle>() {
@Override
public void next(Bundle next) {
super.next(next);
String name = next.getString(AccountManager.KEY_ACCOUNT_NAME);
Account[] accounts = accountManager.getAccountsByType(Reddit.ACCOUNT_TYPE);
for (Account account : accounts) {
if (account.name.equals(name)) {
setAccount(account);
break;
}
}
}
@Override
public void error(Throwable e) {
super.error(e);
Toast.makeText(ActivityMain.this, R.string.error_account, Toast.LENGTH_LONG).show();
}
@Override
public void finish() {
super.finish();
resetAccountList();
}
});
}
}, null);
}
use of android.accounts.Account in project Reader by TheKeeperOfPie.
the class ActivityMain method loadAccount.
public void loadAccount() {
String name;
if (getIntent().hasExtra(ACCOUNT)) {
name = getIntent().getStringExtra(ACCOUNT);
} else {
name = sharedPreferences.getString(AppSettings.ACCOUNT_NAME, "");
}
Account[] accounts = accountManager.getAccountsByType(Reddit.ACCOUNT_TYPE);
Account accountUser = null;
for (Account account : accounts) {
if (account.name.equals(name)) {
accountUser = account;
break;
}
}
if (accountUser == null) {
clearAccount();
} else {
setAccount(accountUser);
}
}
Aggregations