[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
This commit is contained in:
Chalard Jean
2019-11-19 21:30:44 +09:00
parent adb58138bd
commit 9127f03a5c
2 changed files with 5 additions and 8 deletions

View File

@@ -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);
}
/**

View File

@@ -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));