Update tethered/local only interfaces when no all networks request

If there is no request for all networks, the tethered/local only
interface changes will be ignored. However, these available
interfaces are not used for mDNS when a user requests a socket
with a null network because the interfaces are lost due to the
previous ignore. Therefore, the interface changes should be
retained and will be used for socket creations afterwards.

Bug: 284939720
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: If830eb53af26f21f497314477b131ce28468a971
This commit is contained in:
Paul Hu
2023-05-30 19:18:48 +08:00
parent fbba5e8307
commit bb69412f5b
2 changed files with 20 additions and 1 deletions

View File

@@ -449,11 +449,13 @@ public class MdnsSocketProvider {
if (!hasAllNetworksRequest()) { if (!hasAllNetworksRequest()) {
// Currently, the network for tethering can not be requested, so the sockets for // Currently, the network for tethering can not be requested, so the sockets for
// tethering are only created if there is a request for all networks (interfaces). // tethering are only created if there is a request for all networks (interfaces).
// Therefore, this change can skip if there is no such request. // Therefore, only update the interface list and skip this change if no such request.
if (DBG) { if (DBG) {
Log.d(TAG, "Ignore tether interfaces change. There is no request for all" Log.d(TAG, "Ignore tether interfaces change. There is no request for all"
+ " networks."); + " networks.");
} }
current.clear();
current.addAll(updated);
return; return;
} }

View File

@@ -745,4 +745,21 @@ public class MdnsSocketProviderTest {
List.of(WIFI_P2P_IFACE_NAME))); List.of(WIFI_P2P_IFACE_NAME)));
testCallback.expectedNoCallback(); testCallback.expectedNoCallback();
} }
@Test
public void testTetherInterfacesChangedBeforeGetAllNetworksRequest() {
startMonitoringSockets();
// Receive an interface added change for the wifi p2p interface. Expect a socket creation
// callback.
runOnHandler(() -> mTetheringEventCallback.onLocalOnlyInterfacesChanged(
List.of(TETHERED_IFACE_NAME)));
verify(mTetheredIfaceWrapper, never()).getNetworkInterface();
// Request a socket with null network.
final TestSocketCallback testCallback = new TestSocketCallback();
runOnHandler(() -> mSocketProvider.requestSocket(null /* network */, testCallback));
verify(mTetheredIfaceWrapper).getNetworkInterface();
testCallback.expectedSocketCreatedForNetwork(null /* network */, List.of());
}
} }