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

Commit cbabf19c authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Launch account addition activity from Settings instead of from AccountManager

This enables us to watch for failure cases from certain authenticators that
misbehave.

Bug: 7318390
Change-Id: I43398e7622214cabd1d1bf171502c6a988af00a3
parent 553074f0
Loading
Loading
Loading
Loading
+30 −7
Original line number Diff line number Diff line
@@ -67,18 +67,31 @@ public class AddAccountSettings extends Activity {
    static final String EXTRA_HAS_MULTIPLE_USERS = "hasMultipleUsers";

    private static final int CHOOSE_ACCOUNT_REQUEST = 1;
    private static final int ADD_ACCOUNT_REQUEST = 2;

    private PendingIntent mPendingIntent;

    private AccountManagerCallback<Bundle> mCallback = new AccountManagerCallback<Bundle>() {
        public void run(AccountManagerFuture<Bundle> future) {
            boolean done = true;
            try {
                Bundle bundle = future.getResult();
                bundle.keySet();
                //bundle.keySet();
                Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
                if (intent != null) {
                    done = false;
                    Bundle addAccountOptions = new Bundle();
                    addAccountOptions.putParcelable(KEY_CALLER_IDENTITY, mPendingIntent);
                    addAccountOptions.putBoolean(EXTRA_HAS_MULTIPLE_USERS,
                            Utils.hasMultipleUsers(AddAccountSettings.this));
                    intent.putExtras(addAccountOptions);
                    startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
                } else {
                    setResult(RESULT_OK);

                    if (mPendingIntent != null) {
                        mPendingIntent.cancel();
                        mPendingIntent = null;
                    }
                }

                if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "account added: " + bundle);
@@ -89,9 +102,11 @@ public class AddAccountSettings extends Activity {
            } catch (AuthenticatorException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "addAccount failed: " + e);
            } finally {
                if (done) {
                    finish();
                }
            }
        }
    };

    private boolean mAddAccountCalled = false;
@@ -136,6 +151,14 @@ public class AddAccountSettings extends Activity {
            // Go to account setup screen. finish() is called inside mCallback.
            addAccount(data.getStringExtra(EXTRA_SELECTED_ACCOUNT));
            break;
        case ADD_ACCOUNT_REQUEST:
            setResult(resultCode);
            if (mPendingIntent != null) {
                mPendingIntent.cancel();
                mPendingIntent = null;
            }
            finish();
            break;
        }
    }

@@ -155,7 +178,7 @@ public class AddAccountSettings extends Activity {
                null, /* authTokenType */
                null, /* requiredFeatures */
                addAccountOptions,
                this,
                null,
                mCallback,
                null /* handler */);
        mAddAccountCalled  = true;