Fix ConcurrentModificationException in SummaryLoader.

When the dashboard summary is being initialized, it will rebuild the UI
while the summary loader tries to to go through the tiles to update the
summary. Both is being done on a separate backgroud thread, and it will
run into concurrent modification issue if the thread is being swapped
while one is looping through the list.

Instead of letting clients access the list of tiles directly, add a
getter method in DashboardCategory to get a copy of the list of tiles
for all read-only operations.

Change-Id: I479669abd8d1d0a8ee9a4113d8ad2244da56f4d8
Fixes: 69677575
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-11-22 17:29:21 -08:00
parent c2d84d8d2f
commit bcb76351b3
11 changed files with 33 additions and 39 deletions

View File

@@ -216,7 +216,7 @@ public class SummaryLoader {
if (category == null) {
return;
}
for (Tile tile : category.tiles) {
for (Tile tile : category.getTiles()) {
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
if (mSummaryTextMap.containsKey(key)) {
tile.summary = mSummaryTextMap.get(key);
@@ -250,12 +250,13 @@ public class SummaryLoader {
}
private Tile getTileFromCategory(DashboardCategory category, ComponentName component) {
if (category == null || category.tiles == null) {
if (category == null || category.getTilesCount() == 0) {
return null;
}
final int tileCount = category.tiles.size();
final List<Tile> tiles = category.getTiles();
final int tileCount = tiles.size();
for (int j = 0; j < tileCount; j++) {
final Tile tile = category.tiles.get(j);
final Tile tile = tiles.get(j);
if (component.equals(tile.intent.getComponent())) {
return tile;
}
@@ -291,10 +292,10 @@ public class SummaryLoader {
case MSG_GET_CATEGORY_TILES_AND_SET_LISTENING:
final DashboardCategory category =
mDashboardFeatureProvider.getTilesForCategory(mCategoryKey);
if (category == null || category.tiles == null) {
if (category == null || category.getTilesCount() == 0) {
return;
}
final List<Tile> tiles = category.tiles;
final List<Tile> tiles = category.getTiles();
for (Tile tile : tiles) {
makeProviderW(tile);
}