Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd8aed8c authored by Fred Quintana's avatar Fred Quintana
Browse files

change the account unlock enabling logic use async calls rather than

blocking calls

limit the account unlocks to google accounts

Change-Id: If412a7557716503f7d122ec3ff31375f47b624b9
http://b/issue?id=2544496
parent 00f4d986
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ public class AccountUnlockScreen extends RelativeLayout implements KeyguardScree
     * find a single best match.
     */
    private Account findIntendedAccount(String username) {
        Account[] accounts = AccountManager.get(mContext).getAccounts();
        Account[] accounts = AccountManager.get(mContext).getAccountsByType("com.google");

        // Try to figure out which account they meant if they
        // typed only the username (and not the domain), or got
+51 −35
Original line number Diff line number Diff line
@@ -331,46 +331,62 @@ public class LockPatternKeyguardView extends KeyguardViewBase {
        updateScreen(mMode);
    }

    private void maybeEnableFallback(Context context) {
        // Ask the account manager if we have an account that can be used as a
        // fallback in case the user forgets his pattern. The response comes
        // back in run() below; don't bother asking until you've called
        // createUnlockScreenFor(), else the information will go unused.
        Account[] accounts = AccountManager.get(context).getAccounts();
    private class AccountAnalyzer implements AccountManagerCallback<Bundle> {
        private final AccountManager mAccountManager;
        private final Account[] mAccounts;
        private int mAccountIndex;

        private AccountAnalyzer(AccountManager accountManager) {
            mAccountManager = accountManager;
            mAccounts = accountManager.getAccountsByType("com.google");
        }

        private void next() {
            // if we are ready to enable the fallback or if we depleted the list of accounts
            // then finish and get out
            if (mEnableFallback || mAccountIndex >= mAccounts.length) {
                if (mUnlockScreen == null) {
                    Log.w(TAG, "no unlock screen when trying to enable fallback");
                } else if (mUnlockScreen instanceof PatternUnlockScreen) {
                    ((PatternUnlockScreen)mUnlockScreen).setEnableFallback(mEnableFallback);
                }
                return;
            }

            // lookup the confirmCredentials intent for the current account
            mAccountManager.confirmCredentials(mAccounts[mAccountIndex], null, null, this, null);
        }

        public void start() {
            mEnableFallback = false;
            mAccountIndex = 0;
            next();
        }

        for (Account account : accounts) {
            // See whether this account can be used to unlock the screen.
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                // Passing null for action makes sure the confirmCredentials intent is not actually
                // executed - we're just checking whether it's supported.
                AccountManager.get(context)
                        .confirmCredentials(account, null, null, null, null)
                        .getResult();
                Bundle result = future.getResult();
                if (result.getParcelable(AccountManager.KEY_INTENT) != null) {
                    mEnableFallback = true;
                break;

                }
            } catch (OperationCanceledException e) {
                Log.w(TAG, "couldn't talk to AccountManager", e);

                // just skip the account if we are unable to query it
            } catch (IOException e) {
                // just skip the account if we are unable to query it
            } catch (AuthenticatorException e) {
                if (e.getCause() instanceof UnsupportedOperationException) {
                    // This is expected for accounts that don't support confirmCredentials
                    continue;
                } else {
                    Log.w(TAG, "couldn't talk to AccountManager", e);
                // just skip the account if we are unable to query it
            } finally {
                mAccountIndex++;
                next();
            }

            } catch (IOException e) {
                Log.w(TAG, "couldn't talk to AccountManager", e);
        }
    }

        if (mUnlockScreen == null) {
            Log.w(TAG, "no unlock screen when trying to enable fallback");
        } else if (mUnlockScreen instanceof PatternUnlockScreen) {
            ((PatternUnlockScreen)mUnlockScreen).setEnableFallback(mEnableFallback);
        }
    private void maybeEnableFallback(Context context) {
        // Ask the account manager if we have an account that can be used as a
        // fallback in case the user forgets his pattern.
        AccountAnalyzer accountAnalyzer = new AccountAnalyzer(AccountManager.get(context));
        accountAnalyzer.start();
    }