Fix the exception of accessing an ArrayMap

- ArrayMap is not thread-safe.
- When accessing the map across threads at the same time, the map may
throw a ConcurrentModificationException.
- Convert the map to a synchronizedMap to avoid the exception.

Fixes: 159813482
Test: robotest
Change-Id: I3b8bdd435c7c546acf736fa8aafd2ceaed94d081
This commit is contained in:
Jason Chiu
2020-07-01 17:18:29 +08:00
parent f002dd72ac
commit ea689abbcd

View File

@@ -33,6 +33,7 @@ import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -190,7 +191,8 @@ public abstract class SliceBackgroundWorker<E> implements Closeable {
private static NotifySliceChangeHandler sHandler; private static NotifySliceChangeHandler sHandler;
private final Map<Uri, Long> mLastUpdateTimeLookup = new ArrayMap<>(); private final Map<Uri, Long> mLastUpdateTimeLookup = Collections.synchronizedMap(
new ArrayMap<>());
private static NotifySliceChangeHandler getInstance() { private static NotifySliceChangeHandler getInstance() {
if (sHandler == null) { if (sHandler == null) {