summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/contacts/model/AccountTypeManager.java42
-rw-r--r--src/com/android/contacts/util/AccountSelectionUtil.java12
-rw-r--r--src/com/android/contacts/vcard/ImportVCardActivity.java2
-rw-r--r--src/com/android/contacts/vcard/NfcImportVCardActivity.java2
-rw-r--r--src/com/android/contacts/vcard/SelectAccountActivity.java2
-rw-r--r--tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java2
6 files changed, 28 insertions, 34 deletions
diff --git a/src/com/android/contacts/model/AccountTypeManager.java b/src/com/android/contacts/model/AccountTypeManager.java
index b3f05c5a9..cb0fe2460 100644
--- a/src/com/android/contacts/model/AccountTypeManager.java
+++ b/src/com/android/contacts/model/AccountTypeManager.java
@@ -139,11 +139,6 @@ public abstract class AccountTypeManager {
private static final AccountTypeManager EMPTY = new AccountTypeManager() {
@Override
- public List<AccountWithDataSet> getAccounts(boolean contactWritableOnly) {
- return Collections.emptyList();
- }
-
- @Override
public ListenableFuture<List<AccountInfo>> getAccountsAsync() {
return Futures.immediateFuture(Collections.<AccountInfo>emptyList());
}
@@ -178,9 +173,29 @@ public abstract class AccountTypeManager {
/**
* Returns the list of all accounts (if contactWritableOnly is false) or just the list of
* contact writable accounts (if contactWritableOnly is true).
+ *
+ * <p>TODO(mhagerott) delete this method. It's left in place to prevent build breakages when
+ * this change is automerged. Usages of this method in downstream branches should be
+ * replaced with an asynchronous account loading pattern</p>
+ */
+ public List<AccountWithDataSet> getAccounts(boolean contactWritableOnly) {
+ return contactWritableOnly
+ ? blockForWritableAccounts()
+ : AccountInfo.extractAccounts(Futures.getUnchecked(getAccountsAsync()));
+ }
+
+ /**
+ * Returns all contact writable accounts
+ *
+ * <p>In general this method should be avoided. It exists to support some legacy usages of
+ * accounts in infrequently used features where refactoring to asynchronous loading is
+ * not justified. The chance that this will actually block is pretty low if the app has been
+ * launched previously</p>
*/
- // TODO: Consider splitting this into getContactWritableAccounts() and getAllAccounts()
- public abstract List<AccountWithDataSet> getAccounts(boolean contactWritableOnly);
+ public List<AccountWithDataSet> blockForWritableAccounts() {
+ return AccountInfo.extractAccounts(
+ Futures.getUnchecked(filterAccountsAsync(AccountFilter.CONTACTS_WRITABLE)));
+ }
/**
* Loads accounts in background and returns future that will complete with list of all accounts
@@ -520,19 +535,6 @@ class AccountTypeManagerImpl extends AccountTypeManager
mMainThreadExecutor);
}
- /**
- * Return list of all known or contact writable {@link AccountWithDataSet}'s.
- * {@param contactWritableOnly} whether to restrict to contact writable accounts only
- */
- @Override
- public List<AccountWithDataSet> getAccounts(boolean contactWritableOnly) {
- final Predicate<AccountInfo> filter = contactWritableOnly ?
- writableFilter() : Predicates.<AccountInfo>alwaysTrue();
- // TODO: Shouldn't have a synchronous version for getting all accounts
- return Lists.transform(Futures.getUnchecked(filterAccountsAsync(filter)),
- AccountInfo.ACCOUNT_EXTRACTOR);
- }
-
@Override
public ListenableFuture<List<AccountInfo>> getAccountsAsync() {
return getAllAccountsAsyncInternal();
diff --git a/src/com/android/contacts/util/AccountSelectionUtil.java b/src/com/android/contacts/util/AccountSelectionUtil.java
index a29af9ac3..bfe8a08b3 100644
--- a/src/com/android/contacts/util/AccountSelectionUtil.java
+++ b/src/com/android/contacts/util/AccountSelectionUtil.java
@@ -84,15 +84,6 @@ public class AccountSelectionUtil {
}
}
- public static Dialog getSelectAccountDialog(Activity activity, int resId) {
- return getSelectAccountDialog(activity, resId, null, null);
- }
-
- public static Dialog getSelectAccountDialog(Activity activity, int resId,
- DialogInterface.OnClickListener onClickListener) {
- return getSelectAccountDialog(activity, resId, onClickListener, null);
- }
-
/**
* When OnClickListener or OnCancelListener is null, uses a default listener.
* The default OnCancelListener just closes itself with {@link Dialog#dismiss()}.
@@ -101,7 +92,8 @@ public class AccountSelectionUtil {
DialogInterface.OnClickListener onClickListener,
DialogInterface.OnCancelListener onCancelListener) {
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(activity);
- final List<AccountWithDataSet> writableAccountList = accountTypes.getAccounts(true);
+ final List<AccountWithDataSet> writableAccountList =
+ accountTypes.blockForWritableAccounts();
Log.i(LOG_TAG, "The number of available accounts: " + writableAccountList.size());
diff --git a/src/com/android/contacts/vcard/ImportVCardActivity.java b/src/com/android/contacts/vcard/ImportVCardActivity.java
index 6d486e3ee..2c69cdfd6 100644
--- a/src/com/android/contacts/vcard/ImportVCardActivity.java
+++ b/src/com/android/contacts/vcard/ImportVCardActivity.java
@@ -597,7 +597,7 @@ public class ImportVCardActivity extends Activity implements ImportVCardDialogFr
mAccount = new AccountWithDataSet(accountName, accountType, dataSet);
} else {
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this);
- final List<AccountWithDataSet> accountList = accountTypes.getAccounts(true);
+ final List<AccountWithDataSet> accountList = accountTypes.blockForWritableAccounts();
if (accountList.size() == 0) {
mAccount = null;
} else if (accountList.size() == 1) {
diff --git a/src/com/android/contacts/vcard/NfcImportVCardActivity.java b/src/com/android/contacts/vcard/NfcImportVCardActivity.java
index 4793d4742..4eb9b577b 100644
--- a/src/com/android/contacts/vcard/NfcImportVCardActivity.java
+++ b/src/com/android/contacts/vcard/NfcImportVCardActivity.java
@@ -194,7 +194,7 @@ public class NfcImportVCardActivity extends Activity implements ServiceConnectio
mRecord = msg.getRecords()[0];
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this);
- final List<AccountWithDataSet> accountList = accountTypes.getAccounts(true);
+ final List<AccountWithDataSet> accountList = accountTypes.blockForWritableAccounts();
if (accountList.size() == 0) {
mAccount = null;
} else if (accountList.size() == 1) {
diff --git a/src/com/android/contacts/vcard/SelectAccountActivity.java b/src/com/android/contacts/vcard/SelectAccountActivity.java
index 8809fac89..ac5b3eb71 100644
--- a/src/com/android/contacts/vcard/SelectAccountActivity.java
+++ b/src/com/android/contacts/vcard/SelectAccountActivity.java
@@ -58,7 +58,7 @@ public class SelectAccountActivity extends Activity {
// - no account -> use phone-local storage without asking the user
final int resId = R.string.import_from_vcf_file;
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this);
- final List<AccountWithDataSet> accountList = accountTypes.getAccounts(true);
+ final List<AccountWithDataSet> accountList = accountTypes.blockForWritableAccounts();
if (accountList.size() == 0) {
Log.w(LOG_TAG, "Account does not exist");
finish();
diff --git a/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java b/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java
index 956f775b4..b5ccb1eef 100644
--- a/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java
+++ b/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java
@@ -66,7 +66,7 @@ public class MockAccountTypeManager extends AccountTypeManager {
}
@Override
- public List<AccountWithDataSet> getAccounts(boolean writableOnly) {
+ public List<AccountWithDataSet> blockForWritableAccounts() {
return Arrays.asList(mAccounts);
}