diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index 59fef3c66fd..2bf1c01f144 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -211,8 +211,7 @@ public class DashboardAdapter extends RecyclerView.Adapter return null; } + public void removeSuggestion(Tile suggestion) { + mSuggestions.remove(suggestion); + notifyDataSetChanged(); + } } diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java index a86c3c95305..8a8a13d02be 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java @@ -351,6 +351,30 @@ public class DashboardAdapterTest { verify(adapter, never()).notifyDashboardDataChanged(any()); } + @Test + public void testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash() { + final RecyclerView data = new RecyclerView(RuntimeEnvironment.application); + final View itemView = mock(View.class); + when(itemView.findViewById(R.id.data)).thenReturn(data); + final DashboardAdapter.SuggestionAndConditionContainerHolder holder = + new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView); + final List suggestions = + makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4"); + final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null /*savedInstance */, + null /* conditions */, null /* suggestionParser */, null /* callback */)); + adapter.setCategoriesAndSuggestions(null /* category */, suggestions); + adapter.onBindConditionAndSuggestion( + holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION); + // default mode, only displaying 2 suggestions + + adapter.onSuggestionDismissed(suggestions.get(1)); + + // verify operations that access the lists will not cause ConcurrentModificationException + assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1); + adapter.setCategoriesAndSuggestions(null /* category */, suggestions); + // should not crash + } + @Test public void testSuggestionDismissed_onlySuggestion_updateDashboardData() { DashboardAdapter adapter =