From d1def087b15801002d0dad243841bda08886547d Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Sun, 29 Sep 2019 10:02:14 -0700 Subject: Add synchroniztaion to prevent concurrent modification exception Fix unsynchronized concurrent use. Bug: 141503388 Test: atest com.android.server.wifi.HalDeviceManagerTest Change-Id: Ibe3ffccfca4d175e3f6eb57b202ae0d76d5f33ef (cherry picked from commit 175e0b8a9bbaf173d02bde574de5c22f82617f51) --- service/java/com/android/server/wifi/HalDeviceManager.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/HalDeviceManager.java b/service/java/com/android/server/wifi/HalDeviceManager.java index d2ad47f48..e10234f68 100644 --- a/service/java/com/android/server/wifi/HalDeviceManager.java +++ b/service/java/com/android/server/wifi/HalDeviceManager.java @@ -1723,9 +1723,11 @@ public class HalDeviceManager { int requestedIfaceType, WifiIfaceInfo[][] currentIfaces, int numNecessaryInterfaces) { // rule 0: check for any low priority interfaces int numAvailableLowPriorityInterfaces = 0; - for (InterfaceCacheEntry entry : mInterfaceInfoCache.values()) { - if (entry.type == existingIfaceType && entry.isLowPriority) { - numAvailableLowPriorityInterfaces++; + synchronized (mLock) { + for (InterfaceCacheEntry entry : mInterfaceInfoCache.values()) { + if (entry.type == existingIfaceType && entry.isLowPriority) { + numAvailableLowPriorityInterfaces++; + } } } if (numAvailableLowPriorityInterfaces >= numNecessaryInterfaces) { @@ -1780,8 +1782,10 @@ public class HalDeviceManager { LongSparseArray orderedListLowPriority = new LongSparseArray<>(); LongSparseArray orderedList = new LongSparseArray<>(); for (WifiIfaceInfo info : interfaces) { - InterfaceCacheEntry cacheEntry = mInterfaceInfoCache.get( - Pair.create(info.name, getType(info.iface))); + InterfaceCacheEntry cacheEntry; + synchronized (mLock) { + cacheEntry = mInterfaceInfoCache.get(Pair.create(info.name, getType(info.iface))); + } if (cacheEntry == null) { Log.e(TAG, "selectInterfacesToDelete: can't find cache entry with name=" + info.name); -- cgit v1.2.3