From 21b5ee3f0e39be4a79bcfb2b79b0529f75f5cb58 Mon Sep 17 00:00:00 2001 From: Sreeram Ramachandran Date: Wed, 12 Nov 2014 22:31:52 -0800 Subject: Eliminate race conditions in UID-based network filtering. The previous code retrieved information from the legacy tracker multiple times for each user query, leading to race conditions where the info could've changed between the calls. Refactors the handling of legacy data types in ConnectivityService and unifies call paths so that APIs that deal with legacy data types (NetworkInfo and int/networkType) and newer types (such as Network) go through common code paths, using NetworkState to hold all the necessary data pieces. This enables follow-on bug fixes to getActiveNetworkInfo(). The changes are limited to public "query" APIs (those that retrieve some network information or the other). More details about the specific changes and their rationale can be found in the code review thread. Bug: 17460017 Change-Id: I656ee7eddf2b8cace5627036452bb5748043406c --- core/java/android/net/NetworkState.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'core/java/android/net') diff --git a/core/java/android/net/NetworkState.java b/core/java/android/net/NetworkState.java index 2e0e9e4..d26c70d 100644 --- a/core/java/android/net/NetworkState.java +++ b/core/java/android/net/NetworkState.java @@ -29,20 +29,23 @@ public class NetworkState implements Parcelable { public final NetworkInfo networkInfo; public final LinkProperties linkProperties; public final NetworkCapabilities networkCapabilities; + public final Network network; /** Currently only used by testing. */ public final String subscriberId; public final String networkId; public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties, - NetworkCapabilities networkCapabilities) { - this(networkInfo, linkProperties, networkCapabilities, null, null); + NetworkCapabilities networkCapabilities, Network network) { + this(networkInfo, linkProperties, networkCapabilities, network, null, null); } public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties, - NetworkCapabilities networkCapabilities, String subscriberId, String networkId) { + NetworkCapabilities networkCapabilities, Network network, String subscriberId, + String networkId) { this.networkInfo = networkInfo; this.linkProperties = linkProperties; this.networkCapabilities = networkCapabilities; + this.network = network; this.subscriberId = subscriberId; this.networkId = networkId; } @@ -51,6 +54,7 @@ public class NetworkState implements Parcelable { networkInfo = in.readParcelable(null); linkProperties = in.readParcelable(null); networkCapabilities = in.readParcelable(null); + network = in.readParcelable(null); subscriberId = in.readString(); networkId = in.readString(); } @@ -65,6 +69,7 @@ public class NetworkState implements Parcelable { out.writeParcelable(networkInfo, flags); out.writeParcelable(linkProperties, flags); out.writeParcelable(networkCapabilities, flags); + out.writeParcelable(network, flags); out.writeString(subscriberId); out.writeString(networkId); } -- cgit v1.1