summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChulwoo Lee <chulwoo@google.com>2014-08-17 15:24:44 -0700
committerChulwoo Lee <chulwoo@google.com>2014-08-17 23:44:49 +0000
commit404bef8a1de30045d36a7579a00c510dc7f2518d (patch)
tree6e66a9a0dba3ab5607906050fa9bc16a3cf4eb9b
parent804322564b1b4e4ccff0b1c8cd312bac75ec5bb0 (diff)
downloadframeworks_base-404bef8a1de30045d36a7579a00c510dc7f2518d.zip
frameworks_base-404bef8a1de30045d36a7579a00c510dc7f2518d.tar.gz
frameworks_base-404bef8a1de30045d36a7579a00c510dc7f2518d.tar.bz2
Fix ConcurrentModificationException in PersistentDataStore
BUG: 17092853 Change-Id: I613c90b5b78ce317996edb2fda1703aaa318fb1e
-rw-r--r--services/core/java/com/android/server/tv/PersistentDataStore.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/tv/PersistentDataStore.java b/services/core/java/com/android/server/tv/PersistentDataStore.java
index 05a2bde..fcfaaea 100644
--- a/services/core/java/com/android/server/tv/PersistentDataStore.java
+++ b/services/core/java/com/android/server/tv/PersistentDataStore.java
@@ -45,6 +45,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -69,7 +70,8 @@ final class PersistentDataStore {
// The atomic file used to safely read or write the file.
private final AtomicFile mAtomicFile;
- private final List<TvContentRating> mBlockedRatings = new ArrayList<TvContentRating>();
+ private final List<TvContentRating> mBlockedRatings =
+ Collections.synchronizedList(new ArrayList<TvContentRating>());
private boolean mBlockedRatingsChanged;
@@ -107,9 +109,11 @@ final class PersistentDataStore {
public boolean isRatingBlocked(TvContentRating rating) {
loadIfNeeded();
- for (TvContentRating blcokedRating : mBlockedRatings) {
- if (rating.contains(blcokedRating)) {
- return true;
+ synchronized (mBlockedRatings) {
+ for (TvContentRating blcokedRating : mBlockedRatings) {
+ if (rating.contains(blcokedRating)) {
+ return true;
+ }
}
}
return false;
@@ -271,10 +275,12 @@ final class PersistentDataStore {
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_TV_INPUT_MANAGER_STATE);
serializer.startTag(null, TAG_BLOCKED_RATINGS);
- for (TvContentRating rating : mBlockedRatings) {
- serializer.startTag(null, TAG_RATING);
- serializer.attribute(null, ATTR_STRING, rating.flattenToString());
- serializer.endTag(null, TAG_RATING);
+ synchronized (mBlockedRatings) {
+ for (TvContentRating rating : mBlockedRatings) {
+ serializer.startTag(null, TAG_RATING);
+ serializer.attribute(null, ATTR_STRING, rating.flattenToString());
+ serializer.endTag(null, TAG_RATING);
+ }
}
serializer.endTag(null, TAG_BLOCKED_RATINGS);
serializer.startTag(null, TAG_PARENTAL_CONTROLS);