OSDN Git Service

Fix Array Index out of bounds error.
authorSundeep Ghuman <sghuman@google.com>
Tue, 2 May 2017 22:58:39 +0000 (15:58 -0700)
committerSundeep Ghuman <sghuman@google.com>
Tue, 2 May 2017 23:35:23 +0000 (16:35 -0700)
This error was caused by concurrent modification of the
mPendingNotifications SparseIntArray which fell outside the
synchronization block in copyAndNotifyListeners. Now the entire
copyAndNotifyListeners is synchronized on mLock.

Bug: b/37775443
Test: runtest --path
frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java

Change-Id: I19e8a4ecea5cd45122f4ca89f8ed959e500c951a

packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java

index 646b6ba..be15e65 100644 (file)
@@ -124,7 +124,8 @@ public class WifiTracker {
     */
     private final Object mLock = new Object();
 
-    //visible to both worker and main thread. Guarded by #mInternalAccessPoints
+    //visible to both worker and main thread.
+    @GuardedBy("mLock")
     private final AccessPointListenerAdapter mAccessPointListenerAdapter
             = new AccessPointListenerAdapter();
 
@@ -1005,12 +1006,13 @@ public class WifiTracker {
         if (DBG) {
             Log.d(TAG, "Starting to copy AP items on the MainHandler");
         }
-        if (notifyListeners) {
-            notificationMap = mAccessPointListenerAdapter.mPendingNotifications.clone();
-        }
-
-        mAccessPointListenerAdapter.mPendingNotifications.clear();
         synchronized (mLock) {
+            if (notifyListeners) {
+                notificationMap = mAccessPointListenerAdapter.mPendingNotifications.clone();
+            }
+
+            mAccessPointListenerAdapter.mPendingNotifications.clear();
+
             for (AccessPoint internalAccessPoint : mInternalAccessPoints) {
                 AccessPoint accessPoint = oldAccessPoints.get(internalAccessPoint.mId);
                 if (accessPoint == null) {