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

Commit 28e6b26c authored by Chalard Jean's avatar Chalard Jean
Browse files

[NS A18] Reverse listens and request-availables

This is a long standing bug that happens to now be trivial
to fix, and also be beneficial for refactoring

Test: FrameworksNetTests NetworkStackTests
Change-Id: I38110f3a4a75936ea755788e7f9fee67863e14be
parent 82001cf9
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -6453,6 +6453,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
                   newNetwork.name(), score, newNetwork.getCurrentScore()));
        }

        // Notify requested networks are available after the default net is switched, but
        // before LegacyTypeTracker sends legacy broadcasts
        for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri);

        // Second pass: process all listens.
        if (wasBackgroundNetwork != newNetwork.isBackgroundNetwork()) {
            // If the network went from background to foreground or vice versa, we need to update
@@ -6463,10 +6467,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
        } else {
            processListenRequests(newNetwork, false);
        }

        // do this after the default net is switched, but
        // before LegacyTypeTracker sends legacy broadcasts
        for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri);
    }

    /**
+1 −4
Original line number Diff line number Diff line
@@ -3134,14 +3134,11 @@ public class ConnectivityServiceTest {
                .addTransportType(TRANSPORT_CELLULAR).build();
        final TestNetworkCallback cellCallback = new TestNetworkCallback();
        mCm.requestNetwork(cellRequest, cellCallback);
        // NOTE: This request causes the network's capabilities to change. This
        // is currently delivered before the onAvailable() callbacks.
        // TODO: Fix this.
        cellCallback.expectCapabilitiesWith(NET_CAPABILITY_FOREGROUND, mCellNetworkAgent);
        cellCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
        fgCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
        // Expect a network capabilities update with FOREGROUND, because the most recent
        // request causes its state to change.
        cellCallback.expectCapabilitiesWith(NET_CAPABILITY_FOREGROUND, mCellNetworkAgent);
        callback.expectCapabilitiesWith(NET_CAPABILITY_FOREGROUND, mCellNetworkAgent);
        assertTrue(isForegroundNetwork(mCellNetworkAgent));
        assertTrue(isForegroundNetwork(mWiFiNetworkAgent));