Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ba87706 authored by Doris Ling's avatar Doris Ling
Browse files

Fix ConcurrentModificationException in DashboardCategory.

- When getting the copy of dashboard tiles, create a new list instead of
getting the unmodifiable list, as the underlying implementation of the
unmodifiable list actually access the original list directly.

This getTiles() method is meant to return a copy of the list of tiles
to avoid concurrent access to the original list, so, it needs a copy
instead of a direct reference to the original list.

- synchrnoized all updater methods in DashboardCategory

Change-Id: I696b669f39fea5019a3b12ca73da47a7c11b03fb
Fixes: 69677575
Test: make RunSettingsLibRoboTests
parent 839edb17
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -75,23 +75,27 @@ public class DashboardCategory implements Parcelable {
     * Note: the returned list serves as a read-only list. If tiles needs to be added or removed
     * from the actual tiles list, it should be done through {@link #addTile}, {@link #removeTile}.
     */
    public List<Tile> getTiles() {
        return Collections.unmodifiableList(mTiles);
    public synchronized List<Tile> getTiles() {
        final List<Tile> result = new ArrayList<>(mTiles.size());
        for (Tile tile : mTiles) {
            result.add(tile);
        }
        return result;
    }

    public void addTile(Tile tile) {
    public synchronized void addTile(Tile tile) {
        mTiles.add(tile);
    }

    public void addTile(int n, Tile tile) {
    public synchronized void addTile(int n, Tile tile) {
        mTiles.add(n, tile);
    }

    public void removeTile(Tile tile) {
    public synchronized void removeTile(Tile tile) {
        mTiles.remove(tile);
    }

    public void removeTile(int n) {
    public synchronized void removeTile(int n) {
        mTiles.remove(n);
    }

@@ -103,7 +107,7 @@ public class DashboardCategory implements Parcelable {
        return mTiles.get(n);
    }

    public boolean containsComponent(ComponentName component) {
    public synchronized boolean containsComponent(ComponentName component) {
        for (Tile tile : mTiles) {
            if (TextUtils.equals(tile.intent.getComponent().getClassName(),
                    component.getClassName())) {
@@ -129,7 +133,7 @@ public class DashboardCategory implements Parcelable {
    /**
     * Sort priority value and package name for tiles in this category.
     */
    public void sortTiles(String skipPackageName) {
    public synchronized void sortTiles(String skipPackageName) {
        // Sort mTiles based on [priority, package within priority]
        Collections.sort(mTiles, (tile1, tile2) -> {
            final String package1 = tile1.intent.getComponent().getPackageName();