diff options
| author | Chao Zhang <chaoz@codeaurora.org> | 2016-03-01 17:37:07 +0800 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-03-07 18:12:57 -0800 |
| commit | 3d27906176c2d4381bc038245313ddac2440fdee (patch) | |
| tree | 6897c6c4b3e7d3913df6ea45f145da100ef5e6df /src | |
| parent | ee586846cc5e3916398dc25fe59ed9f2601a4790 (diff) | |
| download | android_packages_apps_Gallery2-3d27906176c2d4381bc038245313ddac2440fdee.tar.gz android_packages_apps_Gallery2-3d27906176c2d4381bc038245313ddac2440fdee.tar.bz2 android_packages_apps_Gallery2-3d27906176c2d4381bc038245313ddac2440fdee.zip | |
Gallery2: fix ConcurrentModificationException in MediaSet.java.
ConcurrentModificationException occured in mListeners' traversal operator
if another thread remove mListeners' item.
Add synchronized block to avoide ConcurrentModificationException.
Change-Id: I8816707a8340ffddf1900209b503029aa6683738
CRs-Fixed: 982803
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/android/gallery3d/data/MediaSet.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/com/android/gallery3d/data/MediaSet.java b/src/com/android/gallery3d/data/MediaSet.java index b43874070..d0f0ec3c4 100644 --- a/src/com/android/gallery3d/data/MediaSet.java +++ b/src/com/android/gallery3d/data/MediaSet.java @@ -43,6 +43,8 @@ public abstract class MediaSet extends MediaObject { public static final int SYNC_RESULT_CANCELLED = 1; public static final int SYNC_RESULT_ERROR = 2; + private final Object mLock = new Object(); + /** Listener to be used with requestSync(SyncListener). */ public static interface SyncListener { /** @@ -180,17 +182,23 @@ public abstract class MediaSet extends MediaObject { // listener is automatically removed when there is no other reference to // the listener. public void addContentListener(ContentListener listener) { - mListeners.put(listener, null); + synchronized (mLock) { + mListeners.put(listener, null); + } } public void removeContentListener(ContentListener listener) { - mListeners.remove(listener); + synchronized (mLock) { + mListeners.remove(listener); + } } // This should be called by subclasses when the content is changed. public void notifyContentChanged() { - for (ContentListener listener : mListeners.keySet()) { - listener.onContentDirty(); + synchronized (mLock) { + for (ContentListener listener : mListeners.keySet()) { + listener.onContentDirty(); + } } } |
