Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21b5ee3f authored by Sreeram Ramachandran's avatar Sreeram Ramachandran
Browse files

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
parent 08229e81
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -29,20 +29,23 @@ public class NetworkState implements Parcelable {
    public final NetworkInfo networkInfo;
    public final NetworkInfo networkInfo;
    public final LinkProperties linkProperties;
    public final LinkProperties linkProperties;
    public final NetworkCapabilities networkCapabilities;
    public final NetworkCapabilities networkCapabilities;
    public final Network network;
    /** Currently only used by testing. */
    /** Currently only used by testing. */
    public final String subscriberId;
    public final String subscriberId;
    public final String networkId;
    public final String networkId;


    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
            NetworkCapabilities networkCapabilities) {
            NetworkCapabilities networkCapabilities, Network network) {
        this(networkInfo, linkProperties, networkCapabilities, null, null);
        this(networkInfo, linkProperties, networkCapabilities, network, null, null);
    }
    }


    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
            NetworkCapabilities networkCapabilities, String subscriberId, String networkId) {
            NetworkCapabilities networkCapabilities, Network network, String subscriberId,
            String networkId) {
        this.networkInfo = networkInfo;
        this.networkInfo = networkInfo;
        this.linkProperties = linkProperties;
        this.linkProperties = linkProperties;
        this.networkCapabilities = networkCapabilities;
        this.networkCapabilities = networkCapabilities;
        this.network = network;
        this.subscriberId = subscriberId;
        this.subscriberId = subscriberId;
        this.networkId = networkId;
        this.networkId = networkId;
    }
    }
@@ -51,6 +54,7 @@ public class NetworkState implements Parcelable {
        networkInfo = in.readParcelable(null);
        networkInfo = in.readParcelable(null);
        linkProperties = in.readParcelable(null);
        linkProperties = in.readParcelable(null);
        networkCapabilities = in.readParcelable(null);
        networkCapabilities = in.readParcelable(null);
        network = in.readParcelable(null);
        subscriberId = in.readString();
        subscriberId = in.readString();
        networkId = in.readString();
        networkId = in.readString();
    }
    }
@@ -65,6 +69,7 @@ public class NetworkState implements Parcelable {
        out.writeParcelable(networkInfo, flags);
        out.writeParcelable(networkInfo, flags);
        out.writeParcelable(linkProperties, flags);
        out.writeParcelable(linkProperties, flags);
        out.writeParcelable(networkCapabilities, flags);
        out.writeParcelable(networkCapabilities, flags);
        out.writeParcelable(network, flags);
        out.writeString(subscriberId);
        out.writeString(subscriberId);
        out.writeString(networkId);
        out.writeString(networkId);
    }
    }
+122 −172

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Original line Diff line number Diff line
@@ -838,7 +838,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        final LinkProperties prop = new LinkProperties();
        final LinkProperties prop = new LinkProperties();
        prop.setInterfaceName(TEST_IFACE);
        prop.setInterfaceName(TEST_IFACE);
        return new NetworkState(info, prop, null, null, TEST_SSID);
        return new NetworkState(info, prop, null, null, null, TEST_SSID);
    }
    }


    private void expectCurrentTime() throws Exception {
    private void expectCurrentTime() throws Exception {
+3 −3
Original line number Original line Diff line number Diff line
@@ -1006,7 +1006,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        final LinkProperties prop = new LinkProperties();
        final LinkProperties prop = new LinkProperties();
        prop.setInterfaceName(TEST_IFACE);
        prop.setInterfaceName(TEST_IFACE);
        return new NetworkState(info, prop, null, null, TEST_SSID);
        return new NetworkState(info, prop, null, null, null, TEST_SSID);
    }
    }


    private static NetworkState buildMobile3gState(String subscriberId) {
    private static NetworkState buildMobile3gState(String subscriberId) {
@@ -1015,7 +1015,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        final LinkProperties prop = new LinkProperties();
        final LinkProperties prop = new LinkProperties();
        prop.setInterfaceName(TEST_IFACE);
        prop.setInterfaceName(TEST_IFACE);
        return new NetworkState(info, prop, null, subscriberId, null);
        return new NetworkState(info, prop, null, null, subscriberId, null);
    }
    }


    private static NetworkState buildMobile4gState(String iface) {
    private static NetworkState buildMobile4gState(String iface) {
@@ -1023,7 +1023,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        info.setDetailedState(DetailedState.CONNECTED, null, null);
        final LinkProperties prop = new LinkProperties();
        final LinkProperties prop = new LinkProperties();
        prop.setInterfaceName(iface);
        prop.setInterfaceName(iface);
        return new NetworkState(info, prop, null);
        return new NetworkState(info, prop, null, null);
    }
    }


    private NetworkStats buildEmptyStats() {
    private NetworkStats buildEmptyStats() {