From 4b584064d2537da87a4979fd39c18bc549aa3d65 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Sun, 28 Sep 2014 16:08:06 +0900 Subject: [PATCH] Update LegacyTypeTracker state before sending connect broadcasts. Currently, LegacyTypeTracker sends out connected broadcasts before updating its internal lists of networks. This creates a race condition where an app can query LegacyTypeTracker state (e.g., via getActiveNetworkInfo) as soon as it gets the broadcast, and get information that has not been updated. Bug: 17540101 Change-Id: Iefd6d5e9fd0b427c5872166208831f70fcef8b6f --- .../core/java/com/android/server/ConnectivityService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index a3c64d08e4..2a980f0fc1 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -516,11 +516,13 @@ public class ConnectivityService extends IConnectivityManager.Stub { return; } - if (list.isEmpty() || isDefaultNetwork(nai)) { + list.add(nai); + + // Send a broadcast if this is the first network of its type or if it's the default. + if (list.size() == 1 || isDefaultNetwork(nai)) { maybeLogBroadcast(nai, true, type); sendLegacyNetworkBroadcast(nai, true, type); } - list.add(nai); } /** Removes the given network from the specified legacy type list. */