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 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'java/com/android/dialer/searchfragment/list/NewSearchFragment.java') 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) { -- cgit v1.2.3