Merge "Verifying equality of LinkProperties with callbacks"

This commit is contained in:
Junyu Lai 2022-11-14 05:55:58 +00:00 • committed by Gerrit Code Review
commit b99524e467

View file

@ -559,6 +559,11 @@ public class ConnectivityManagerTest {
// got from other APIs.
final Network[] networks = mCm.getAllNetworks();
assertGreaterOrEqual(networks.length, 1);
final TestableNetworkCallback allNetworkLinkPropertiesListener =
new TestableNetworkCallback();
mCm.registerNetworkCallback(new NetworkRequest.Builder().clearCapabilities().build(),
allNetworkLinkPropertiesListener);
final List<NetworkStateSnapshot> snapshots = runWithShellPermissionIdentity(
() -> mCm.getAllNetworkStateSnapshots(), NETWORK_SETTINGS);
assertEquals(networks.length, snapshots.size());
@ -584,7 +589,18 @@ public class ConnectivityManagerTest {
assertEquals("", caps.describeImmutableDifferences(
snapshot.getNetworkCapabilities()
.setNetworkSpecifier(redactedSnapshotCapSpecifier)));
assertEquals(mCm.getLinkProperties(network), snapshot.getLinkProperties());
// Don't check that the mutable fields are the same with synchronous calls, as
// the device may add or remove content of these fields in the middle of the test.
// Instead, search the target LinkProperties from received LinkPropertiesChanged
// callbacks. This is guaranteed to succeed because the callback is registered
// before getAllNetworkStateSnapshots is called.
final LinkProperties lpFromSnapshot = snapshot.getLinkProperties();
allNetworkLinkPropertiesListener.eventuallyExpect(CallbackEntry.LINK_PROPERTIES_CHANGED,
NETWORK_CALLBACK_TIMEOUT_MS, 0 /* mark */, entry ->
entry.getNetwork().equals(network)
&& entry.getLp().equals(lpFromSnapshot));
assertEquals(mCm.getNetworkInfo(network).getType(), snapshot.getLegacyType());
if (network.equals(cellNetwork)) {