OSDN Git Service

Fix a ConcurrentModificationException crash.
authorChalard Jean <jchalard@google.com>
Wed, 23 May 2018 00:07:51 +0000 (09:07 +0900)
committerChalard Jean <jchalard@google.com>
Wed, 6 Jun 2018 08:25:19 +0000 (08:25 +0000)
This is a pinpoint fix against the bug listed below. While a client
is synchronously reading the LinkProperties of a network, the
ConnectivityServiceThread is updating its properties. Make sure
that update is done atomically.

This is a stopgap countermeasure against a problem that is
pervasive with usage of LinkProperties, but fixing the problem
itself will happen later.

Clean cherry-pick of ag/4174798

Bug: 80077223
Test: runtest frameworks-net
Change-Id: I61b262d824c98b4ced36395a597b73de9193a199
Merged-In: I25007ac26349e451bb47f966af70d590d699c347
Merged-In: I03526187645b6955eb89ca4d2e4a930ebac236b8

services/core/java/com/android/server/ConnectivityService.java

index fe0f6d2..789092d 100644 (file)
@@ -4630,7 +4630,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
     }
 
     private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties oldLp) {
-        LinkProperties newLp = networkAgent.linkProperties;
+        LinkProperties newLp = new LinkProperties(networkAgent.linkProperties);
         int netId = networkAgent.network.netId;
 
         // The NetworkAgentInfo does not know whether clatd is running on its network or not. Before
@@ -4664,6 +4664,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
         }
         // TODO - move this check to cover the whole function
         if (!Objects.equals(newLp, oldLp)) {
+            synchronized (networkAgent) {
+                networkAgent.linkProperties = newLp;
+            }
             notifyIfacesChangedForNetworkStats();
             notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED);
         }