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

Commit 8124f47d authored by Benedict Wong's avatar Benedict Wong
Browse files

Remove subIds from Telephony NetworkRequests.

Since NetworkProviders do not at present support requests with subIds
(they always provide an empty list, therefore never have an overlap),
the TelephonyBringupRequests must never present subIds as part of the
requested capabilities.

Bug: 183174340
Test: atest FrameworksVcnTests
Change-Id: I2e52ff67748c0ca226a648682b37dfe0996cb850
parent bd1085ef
Loading
Loading
Loading
Loading
+38 −9
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class UnderlyingNetworkTracker {
        if (!mIsQuitting) {
            mRouteSelectionCallback = new RouteSelectionCallback();
            mConnectivityManager.requestBackgroundNetwork(
                    getBaseNetworkRequestBuilder().build(), mHandler, mRouteSelectionCallback);
                    getRouteSelectionRequest(), mHandler, mRouteSelectionCallback);

            mWifiBringupCallback = new NetworkBringupCallback();
            mConnectivityManager.requestBackgroundNetwork(
@@ -149,12 +149,48 @@ public class UnderlyingNetworkTracker {
        }
    }

    /**
     * Builds the Route selection request
     *
     * <p>This request is guaranteed to select carrier-owned, non-VCN underlying networks by virtue
     * of a populated set of subIds as expressed in NetworkCapabilities#getSubIds(). Only carrier
     * owned networks may be selected, as the request specifies only subIds in the VCN's
     * subscription group, while the VCN networks are excluded by virtue of not having subIds set on
     * the VCN-exposed networks.
     */
    private NetworkRequest getRouteSelectionRequest() {
        return getBaseNetworkRequestBuilder()
                .setSubIds(mLastSnapshot.getAllSubIdsInGroup(mSubscriptionGroup))
                .build();
    }

    /**
     * Builds the WiFi bringup request
     *
     * <p>This request is built specifically to match only carrier-owned WiFi networks, but is also
     * built to ONLY keep Carrier WiFi Networks alive (but never bring them up). This is a result of
     * the WifiNetworkFactory not advertising a list of subIds, and therefore not accepting this
     * request. As such, it will bind to a Carrier WiFi Network that has already been brought up,
     * but will NEVER bring up a Carrier WiFi network itself.
     */
    private NetworkRequest getWifiNetworkRequest() {
        return getBaseNetworkRequestBuilder()
                .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
                .setSubIds(mLastSnapshot.getAllSubIdsInGroup(mSubscriptionGroup))
                .build();
    }

    /**
     * Builds a Cellular bringup request for a given subId
     *
     * <p>This request is filed in order to ensure that the Telephony stack always has a
     * NetworkRequest to bring up a VCN underlying cellular network. It is required in order to
     * ensure that even when a VCN (appears as Cellular) satisfies the default request, Telephony
     * will bring up additional underlying Cellular networks.
     *
     * <p>Since this request MUST make it to the TelephonyNetworkFactory, subIds are not specified
     * in the NetworkCapabilities, but rather in the TelephonyNetworkSpecifier.
     */
    private NetworkRequest getCellNetworkRequestForSubId(int subId) {
        return getBaseNetworkRequestBuilder()
                .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
@@ -164,20 +200,13 @@ public class UnderlyingNetworkTracker {

    /**
     * Builds and returns a NetworkRequest builder common to all Underlying Network requests
     *
     * <p>This request is guaranteed to select carrier-owned, non-VCN underlying networks by virtue
     * of a populated set of subIds as expressed in NetworkCapabilities#getSubIds(). Only carrier
     * owned networks may be selected, as the request specifies only subIds in the VCN's
     * subscription group, while the VCN networks are excluded by virtue of not having subIds set on
     * the VCN-exposed networks.
     */
    private NetworkRequest.Builder getBaseNetworkRequestBuilder() {
        return new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED)
                .setSubIds(mLastSnapshot.getAllSubIdsInGroup(mSubscriptionGroup));
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);
    }

    /**
+8 −8
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public class UnderlyingNetworkTrackerTest {
        for (final int subId : expectedSubIds) {
            verify(mConnectivityManager)
                    .requestBackgroundNetwork(
                            eq(getCellRequestForSubId(subId, expectedSubIds)),
                            eq(getCellRequestForSubId(subId)),
                            any(),
                            any(NetworkBringupCallback.class));
        }
@@ -189,30 +189,30 @@ public class UnderlyingNetworkTrackerTest {
    }

    private NetworkRequest getWifiRequest(Set<Integer> netCapsSubIds) {
        return getExpectedRequestBase(netCapsSubIds)
        return getExpectedRequestBase()
                .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
                .setSubIds(netCapsSubIds)
                .build();
    }

    private NetworkRequest getCellRequestForSubId(int subId, Set<Integer> netCapsSubIds) {
        return getExpectedRequestBase(netCapsSubIds)
    private NetworkRequest getCellRequestForSubId(int subId) {
        return getExpectedRequestBase()
                .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
                .setNetworkSpecifier(new TelephonyNetworkSpecifier(subId))
                .build();
    }

    private NetworkRequest getRouteSelectionRequest(Set<Integer> netCapsSubIds) {
        return getExpectedRequestBase(netCapsSubIds).build();
        return getExpectedRequestBase().setSubIds(netCapsSubIds).build();
    }

    private NetworkRequest.Builder getExpectedRequestBase(Set<Integer> subIds) {
    private NetworkRequest.Builder getExpectedRequestBase() {
        final NetworkRequest.Builder builder =
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                        .removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
                        .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                        .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED)
                        .setSubIds(subIds);
                        .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);

        return builder;
    }