Skip to content

Commit

Permalink
am ed18828: Don\'t access mRecentLoaderResults in background
Browse files Browse the repository at this point in the history
* commit 'ed1882813d7c6b87543d8006a9d02aa55fef8b0d':
  Don't access mRecentLoaderResults in background
  • Loading branch information
AttwellBrian authored and Android Git Automerger committed Feb 12, 2015
2 parents 2ea58b6 + ed18828 commit 6d83095
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/com/android/contacts/quickcontact/QuickContactActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,9 @@ private int colorFromBitmap(Bitmap bitmap) {
private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) {
final List<Entry> entries = new ArrayList<>();
for (ContactInteraction interaction : interactions) {
if (interaction == null) {
continue;
}
entries.add(new Entry(/* id = */ -1,
interaction.getIcon(this),
interaction.getViewHeader(this),
Expand Down Expand Up @@ -2030,20 +2033,37 @@ private void bindRecentData() {
final List<ContactInteraction> allInteractions = new ArrayList<>();
final List<List<Entry>> interactionsWrapper = new ArrayList<>();

// Serialize mRecentLoaderResults into a single list. This should be done on the main
// thread to avoid races against mRecentLoaderResults edits.
for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) {
allInteractions.addAll(loaderInteractions);
}

mRecentDataTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Trace.beginSection("sort recent loader results");

for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) {
allInteractions.addAll(loaderInteractions);
}

// Sort the interactions by most recent
Collections.sort(allInteractions, new Comparator<ContactInteraction>() {
@Override
public int compare(ContactInteraction a, ContactInteraction b) {
return a.getInteractionDate() >= b.getInteractionDate() ? -1 : 1;
if (a == null && b == null) {
return 0;
}
if (a == null) {
return 1;
}
if (b == null) {
return -1;
}
if (a.getInteractionDate() > b.getInteractionDate()) {
return -1;
}
if (a.getInteractionDate() == b.getInteractionDate()) {
return 0;
}
return 1;
}
});

Expand Down

0 comments on commit 6d83095

Please sign in to comment.