From d4dbf3c2d76767a7c4567a441fad27a5c1b22035 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Wed, 4 Oct 2017 14:26:41 -0700 Subject: Copy directory list into new list to prevent modifications. Since lists are passed by reference, if the directory list passed into RemoteContactsCursorLoader was modified before #lodInBackground was called, the directory list would change and crash when compared to the list of cursors. Since directory lists are small, there shouldn't be any memory issues with copying the list. Additionally, this CL adds some logging to the new Search Fragment. Bug: 66902071,66902062 Test: RemoteContactsCursorLoaderTest PiperOrigin-RevId: 171063035 Change-Id: Id2faa542805da4167fc7045e6fbe71d02c644ab6 --- .../dialer/searchfragment/list/NewSearchFragment.java | 12 ++++++++++-- .../dialer/searchfragment/remote/RemoteContactsCursor.java | 5 ++++- .../searchfragment/remote/RemoteContactsCursorLoader.java | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'java/com/android/dialer/searchfragment') diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java index 47a4ee608..b06f9c3ad 100644 --- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java +++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java @@ -165,6 +165,7 @@ public final class NewSearchFragment extends Fragment @Override public Loader onCreateLoader(int id, Bundle bundle) { + LogUtil.i("NewSearchFragment.onCreateLoader", "loading cursor: " + id); if (id == CONTACTS_LOADER_ID) { return new SearchContactsCursorLoader(getContext(), query); } else if (id == NEARBY_PLACES_LOADER_ID) { @@ -187,6 +188,7 @@ public final class NewSearchFragment extends Fragment @Override public void onLoadFinished(Loader loader, Cursor cursor) { + LogUtil.i("NewSearchFragment.onLoadFinished", "Loader finished: " + loader); if (cursor != null && !(loader instanceof RemoteDirectoriesCursorLoader) && !(cursor instanceof SearchCursor)) { @@ -218,8 +220,14 @@ public final class NewSearchFragment extends Fragment @Override public void onLoaderReset(Loader loader) { - adapter.clear(); - recyclerView.setAdapter(null); + LogUtil.i("NewSearchFragment.onLoaderReset", "Loader reset: " + loader); + if (loader instanceof SearchContactsCursorLoader) { + adapter.setContactsCursor(null); + } else if (loader instanceof NearbyPlacesCursorLoader) { + adapter.setNearbyPlacesCursor(null); + } else if (loader instanceof RemoteContactsCursorLoader) { + adapter.setRemoteContactsCursor(null); + } } public void setQuery(String query, CallInitiationType.Type callInitiationType) { diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java index 5d80a452c..e9e83c19b 100644 --- a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java +++ b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java @@ -60,7 +60,10 @@ public final class RemoteContactsCursor extends MergeCursor implements SearchCur public static RemoteContactsCursor newInstance( Context context, Cursor[] cursors, List directories) { Assert.checkArgument( - cursors.length == directories.size(), "Directories and cursors must be the same size."); + cursors.length == directories.size(), + "Directories (%d) and cursors (%d) must be the same size.", + directories.size(), + cursors.length); Cursor[] cursorsWithHeaders = insertHeaders(context, cursors, directories); if (cursorsWithHeaders.length > 0) { return new RemoteContactsCursor(cursorsWithHeaders); diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java index 771b7f183..37695be50 100644 --- a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java +++ b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java @@ -28,6 +28,7 @@ import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import com.android.dialer.searchfragment.common.Projections; import com.android.dialer.searchfragment.remote.RemoteDirectoriesCursorLoader.Directory; +import java.util.ArrayList; import java.util.List; /** @@ -58,7 +59,7 @@ public final class RemoteContactsCursorLoader extends CursorLoader { null, Phone.SORT_KEY_PRIMARY); this.query = query; - this.directories = directories; + this.directories = new ArrayList<>(directories); cursors = new Cursor[directories.size()]; } -- cgit v1.2.3