Search in sources :

Example 21 with Account

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

Example 22 with Account

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

Example 23 with Account

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();
        }
    });
}
Also used : Account(android.accounts.Account) User(com.winsonchiu.reader.data.reddit.User) Bundle(android.os.Bundle) WebResourceRequest(android.webkit.WebResourceRequest) Request(okhttp3.Request) Intent(android.content.Intent)

Example 24 with Account

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);
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) AccountManagerFuture(android.accounts.AccountManagerFuture) FinalizingSubscriber(com.winsonchiu.reader.rx.FinalizingSubscriber)

Example 25 with Account

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

Aggregations

Account (android.accounts.Account)548 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)78 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)49 Intent (android.content.Intent)40 File (java.io.File)37 Cursor (android.database.Cursor)31 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)29 PersistableBundle (android.os.PersistableBundle)27 UserInfo (android.content.pm.UserInfo)22 MockContentResolver (android.test.mock.MockContentResolver)22 HashMap (java.util.HashMap)20 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 RemoteException (android.os.RemoteException)19 FileOutputStream (java.io.FileOutputStream)19 IOException (java.io.IOException)19 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 HashSet (java.util.HashSet)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16