Sources.get() can be safely called from the UI thread. Updated source.
Change-Id: I5157f581fe078c7cd73044a1595b7295a202d96e
diff --git a/src/com/android/contacts/model/Sources.java b/src/com/android/contacts/model/Sources.java
index be3f17d..44631e8 100644
--- a/src/com/android/contacts/model/Sources.java
+++ b/src/com/android/contacts/model/Sources.java
@@ -42,7 +42,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Locale;
/**
* Singleton holder for all parsed {@link ContactsSource} available on the
@@ -64,8 +63,7 @@
/**
* Requests the singleton instance of {@link Sources} with data bound from
- * the available authenticators. This method blocks until its interaction
- * with {@link AccountManager} is finished, so don't call from a UI thread.
+ * the available authenticators. This method can safely be called from the UI thread.
*/
public static synchronized Sources getInstance(Context context) {
Sources sources = sInstance == null ? null : sInstance.get();
@@ -179,8 +177,7 @@
}
/**
- * Blocking call to load all {@link AuthenticatorDescription} known by the
- * {@link AccountManager} on the system.
+ * Loads all {@link AuthenticatorDescription} known by the {@link AccountManager} on the system.
*/
protected synchronized void queryAccounts() {
mSources.clear();
diff --git a/src/com/android/contacts/views/detail/ContactDetailFragment.java b/src/com/android/contacts/views/detail/ContactDetailFragment.java
index 953943a..e5fa013 100644
--- a/src/com/android/contacts/views/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/views/detail/ContactDetailFragment.java
@@ -261,7 +261,6 @@
mWritableRawContactIds.clear();
- // TODO: This should be done in the background thread
final Sources sources = Sources.getInstance(mContext);
// Build up method entries
diff --git a/src/com/android/contacts/views/editor/ContactEditorFragment.java b/src/com/android/contacts/views/editor/ContactEditorFragment.java
index c58a4e6..f75cfd1 100644
--- a/src/com/android/contacts/views/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/views/editor/ContactEditorFragment.java
@@ -59,7 +59,6 @@
import android.graphics.Bitmap;
import android.media.MediaScannerConnection;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.RemoteException;
@@ -370,18 +369,8 @@
private boolean doAddAction() {
// Load Accounts async so that we can present them
- AsyncTask<Void, Void, ArrayList<Account>> loadAccountsTask =
- new AsyncTask<Void, Void, ArrayList<Account>>() {
- @Override
- protected ArrayList<Account> doInBackground(Void... params) {
- return Sources.getInstance(mContext).getAccounts(true);
- }
- @Override
- protected void onPostExecute(ArrayList<Account> result) {
- selectAccountAndCreateContact(result, true);
- }
- };
- loadAccountsTask.execute();
+ final ArrayList<Account> accounts = Sources.getInstance(mContext).getAccounts(true);
+ selectAccountAndCreateContact(accounts, true);
return true;
}
@@ -395,7 +384,6 @@
return false;
int readOnlySourcesCnt = 0;
int writableSourcesCnt = 0;
- // TODO: This shouldn't be called from the UI thread
final Sources sources = Sources.getInstance(mContext);
for (EntityDelta delta : mState) {
final String accountType = delta.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
@@ -1122,7 +1110,6 @@
private class DeleteClickListener implements DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int which) {
- // TODO: Don't do this from the UI thread
final Sources sources = Sources.getInstance(mContext);
// Mark all raw contacts for deletion
for (EntityDelta delta : mState) {