diff options
| author | Chao Zhang <chaoz@codeaurora.org> | 2016-03-01 17:37:07 +0800 |
|---|---|---|
| committer | Steve Kondik <steve@cyngn.com> | 2016-09-26 04:54:48 -0700 |
| commit | 20df5ab44efdc152d9ad965224822057a7b305bc (patch) | |
| tree | 466545a64aa2c5bf4471129396f8482d99614484 | |
| parent | f73dfe7dc8652ba77c0cd3de35caf819251e8e63 (diff) | |
| download | android_packages_apps_Gallery2-20df5ab44efdc152d9ad965224822057a7b305bc.tar.gz android_packages_apps_Gallery2-20df5ab44efdc152d9ad965224822057a7b305bc.tar.bz2 android_packages_apps_Gallery2-20df5ab44efdc152d9ad965224822057a7b305bc.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
| -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 be2d776fb..869ace22a 100644 --- a/src/com/android/gallery3d/data/MediaSet.java +++ b/src/com/android/gallery3d/data/MediaSet.java @@ -42,6 +42,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 { /** @@ -161,17 +163,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(); + } } } |
