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

Commit aefdaa5c authored by Simranjit Singh Kohli's avatar Simranjit Singh Kohli Committed by Android (Google) Code Review
Browse files

Merge "[ChooseAccount/AccountManager.newChooseAccountIntent Bug Fixes]" into mnc-dev

parents 8f51279d 734f8fb6
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -2326,7 +2326,8 @@ public class AccountManager {
     * shown. If not specified then this field will not limit the displayed accounts.
     * shown. If not specified then this field will not limit the displayed accounts.
     * @param allowableAccountTypes an optional string array of account types. These are used
     * @param allowableAccountTypes an optional string array of account types. These are used
     * both to filter the shown accounts and to filter the list of account types that are shown
     * both to filter the shown accounts and to filter the list of account types that are shown
     * when adding an account.
     * when adding an account. If not specified then this field will not limit the displayed
     * account types when adding an account.
     * @param alwaysPromptForAccount if set the account chooser screen is always shown, otherwise
     * @param alwaysPromptForAccount if set the account chooser screen is always shown, otherwise
     * it is only shown when there is more than one account from which to choose
     * it is only shown when there is more than one account from which to choose
     * @param descriptionOverrideText if non-null this string is used as the description in the
     * @param descriptionOverrideText if non-null this string is used as the description in the
+30 −25
Original line number Original line Diff line number Diff line
@@ -132,7 +132,6 @@ public class ChooseTypeAndAccountActivity extends Activity


    @Override
    @Override
    public void onCreate(Bundle savedInstanceState) {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "ChooseTypeAndAccountActivity.onCreate(savedInstanceState="
            Log.v(TAG, "ChooseTypeAndAccountActivity.onCreate(savedInstanceState="
                    + savedInstanceState + ")");
                    + savedInstanceState + ")");
@@ -192,7 +191,6 @@ public class ChooseTypeAndAccountActivity extends Activity
        mAlwaysPromptForAccount = intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false);
        mAlwaysPromptForAccount = intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false);
        mDescriptionOverride = intent.getStringExtra(EXTRA_DESCRIPTION_TEXT_OVERRIDE);
        mDescriptionOverride = intent.getStringExtra(EXTRA_DESCRIPTION_TEXT_OVERRIDE);


        // Need to do this once here to request the window feature. Can't do it in onResume
        mAccounts = getAcceptableAccountChoices(AccountManager.get(this));
        mAccounts = getAcceptableAccountChoices(AccountManager.get(this));
        if (mAccounts.isEmpty()
        if (mAccounts.isEmpty()
                && mDisallowAddAccounts) {
                && mDisallowAddAccounts) {
@@ -200,17 +198,11 @@ public class ChooseTypeAndAccountActivity extends Activity
            setContentView(R.layout.app_not_authorized);
            setContentView(R.layout.app_not_authorized);
            mDontShowPicker = true;
            mDontShowPicker = true;
        }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (mDontShowPicker) return;

        final AccountManager accountManager = AccountManager.get(this);


        mAccounts = getAcceptableAccountChoices(accountManager);
        if (mDontShowPicker) {
            super.onCreate(savedInstanceState);
            return;
        }


        // In cases where the activity does not need to show an account picker, cut the chase
        // In cases where the activity does not need to show an account picker, cut the chase
        // and return the result directly. Eg:
        // and return the result directly. Eg:
@@ -220,6 +212,7 @@ public class ChooseTypeAndAccountActivity extends Activity
            // If there are no relevant accounts and only one relevant account type go directly to
            // If there are no relevant accounts and only one relevant account type go directly to
            // add account. Otherwise let the user choose.
            // add account. Otherwise let the user choose.
            if (mAccounts.isEmpty()) {
            if (mAccounts.isEmpty()) {
                setNonLabelThemeAndCallSuperCreate(savedInstanceState);
                if (mSetOfRelevantAccountTypes.size() == 1) {
                if (mSetOfRelevantAccountTypes.size() == 1) {
                    runAddAccountForAuthenticator(mSetOfRelevantAccountTypes.iterator().next());
                    runAddAccountForAuthenticator(mSetOfRelevantAccountTypes.iterator().next());
                } else {
                } else {
@@ -231,6 +224,7 @@ public class ChooseTypeAndAccountActivity extends Activity
            // if there is only one allowable account return it
            // if there is only one allowable account return it
            if (!mAlwaysPromptForAccount && mAccounts.size() == 1) {
            if (!mAlwaysPromptForAccount && mAccounts.size() == 1) {
                Account account = mAccounts.get(0);
                Account account = mAccounts.get(0);
                super.onCreate(savedInstanceState);
                setResultAndFinish(account.name, account.type);
                setResultAndFinish(account.name, account.type);
                return;
                return;
            }
            }
@@ -240,8 +234,7 @@ public class ChooseTypeAndAccountActivity extends Activity
        mSelectedItemIndex = getItemIndexToSelect(
        mSelectedItemIndex = getItemIndexToSelect(
            mAccounts, mSelectedAccountName, mSelectedAddNewAccount);
            mAccounts, mSelectedAccountName, mSelectedAddNewAccount);


        // Cannot set content view until we know that mPendingRequest is not null, otherwise
        super.onCreate(savedInstanceState);
        // would cause screen flicker.
        setContentView(R.layout.choose_type_and_account);
        setContentView(R.layout.choose_type_and_account);
        overrideDescriptionIfSupplied(mDescriptionOverride);
        overrideDescriptionIfSupplied(mDescriptionOverride);
        populateUIAccountList(listItems);
        populateUIAccountList(listItems);
@@ -409,6 +402,17 @@ public class ChooseTypeAndAccountActivity extends Activity
        finish();
        finish();
    }
    }


    /**
     * The default activity theme shows label at the top. Set a theme which does
     * not show label, which effectively makes the activity invisible. Note that
     * no content is being set. If something gets set, using this theme may be
     * useless.
     */
    private void setNonLabelThemeAndCallSuperCreate(Bundle savedInstanceState) {
        setTheme(R.style.Theme_Material_Light_Dialog_NoActionBar);
        super.onCreate(savedInstanceState);
    }

    private void onAccountSelected(Account account) {
    private void onAccountSelected(Account account) {
      Log.d(TAG, "selected account " + account);
      Log.d(TAG, "selected account " + account);
      setResultAndFinish(account.name, account.type);
      setResultAndFinish(account.name, account.type);
@@ -489,8 +493,7 @@ public class ChooseTypeAndAccountActivity extends Activity
              mCallingUid);
              mCallingUid);
      ArrayList<Account> accountsToPopulate = new ArrayList<Account>(accounts.length);
      ArrayList<Account> accountsToPopulate = new ArrayList<Account>(accounts.length);
      for (Account account : accounts) {
      for (Account account : accounts) {
          if (mSetOfAllowableAccounts != null
          if (mSetOfAllowableAccounts != null && !mSetOfAllowableAccounts.contains(account)) {
                  && !mSetOfAllowableAccounts.contains(account)) {
              continue;
              continue;
          }
          }
          if (mSetOfRelevantAccountTypes != null
          if (mSetOfRelevantAccountTypes != null
@@ -503,7 +506,7 @@ public class ChooseTypeAndAccountActivity extends Activity
    }
    }


    /**
    /**
     * Return a set of account types speficied by the intent as well as supported by the
     * Return a set of account types specified by the intent as well as supported by the
     * AccountManager.
     * AccountManager.
     */
     */
    private Set<String> getReleventAccountTypes(final Intent intent) {
    private Set<String> getReleventAccountTypes(final Intent intent) {
@@ -512,14 +515,16 @@ public class ChooseTypeAndAccountActivity extends Activity
      Set<String> setOfRelevantAccountTypes = null;
      Set<String> setOfRelevantAccountTypes = null;
      final String[] allowedAccountTypes =
      final String[] allowedAccountTypes =
              intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
              intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
      if (allowedAccountTypes != null) {
          setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes);
        AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
        AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
        Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
        Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
        for (AuthenticatorDescription desc : descs) {
        for (AuthenticatorDescription desc : descs) {
            supportedAccountTypes.add(desc.type);
            supportedAccountTypes.add(desc.type);
        }
        }
        if (allowedAccountTypes != null) {
            setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes);
            setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
            setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
        } else {
            setOfRelevantAccountTypes = supportedAccountTypes;
      }
      }
      return setOfRelevantAccountTypes;
      return setOfRelevantAccountTypes;
    }
    }