Create a new list when building suggestion data.

- using sublist of the original suggestions list may results in
ConcurrentModificationException if the originaly list is being modified.
Create a new list instead to avoid running into the issue.

Change-Id: Ia83a0432be542eeb428d177f6118d26fc2262e93
Fixes: 74194336
Test: run monkey
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index 99de73e..9d9058d 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -155,8 +155,8 @@
             // remain as the dashboard item. Need to refresh the dashboard list.
             setSuggestions(null);
         } else {
-            mSuggestionAdapter.removeSuggestion(suggestion);
-            notifyItemChanged(0, null);
+            list.remove(suggestion);
+            setSuggestions(list);
         }
     }
 
diff --git a/src/com/android/settings/dashboard/DashboardData.java b/src/com/android/settings/dashboard/DashboardData.java
index 45aab9a..113caba 100644
--- a/src/com/android/settings/dashboard/DashboardData.java
+++ b/src/com/android/settings/dashboard/DashboardData.java
@@ -246,7 +246,11 @@
         if (suggestions.size() <= MAX_SUGGESTION_COUNT) {
             return suggestions;
         }
-        return suggestions.subList(0, MAX_SUGGESTION_COUNT);
+        final List<Suggestion> suggestionsToShow = new ArrayList<>(MAX_SUGGESTION_COUNT);
+        for (int i = 0; i < MAX_SUGGESTION_COUNT; i++) {
+            suggestionsToShow.add(suggestions.get(i));
+        }
+        return suggestionsToShow;
     }
 
     /**
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index e28e89d..e45b02c 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -124,10 +124,9 @@
         final Suggestion suggestionToRemove = suggestions.get(1);
         adapter.onSuggestionClosed(suggestionToRemove);
 
-        assertThat(adapter.mDashboardData).isEqualTo(dashboardData);
         assertThat(suggestions.size()).isEqualTo(2);
         assertThat(suggestions.contains(suggestionToRemove)).isFalse();
-        verify(adapter, never()).notifyDashboardDataChanged(any());
+        verify(adapter).notifyDashboardDataChanged(any());
     }
 
     @Test