Pass EthernetPort to EthernetNetworkFactory#updateInterfaceLinkState

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I7e78be87824e29eab90074b1a2263e0cbd779021
This commit is contained in:
Patrick Rohr 2025-06-05 14:55:48 -07:00
commit db32c1bbdc
4 changed files with 10 additions and 11 deletions

View file

@ -233,8 +233,8 @@ public class EthernetNetworkFactory {
}
/** Returns true if state has been modified */
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
protected boolean updateInterfaceLinkState(@NonNull final String ifaceName, final boolean up) {
public boolean updateInterfaceLinkState(EthernetPort port, boolean up) {
final String ifaceName = port.getInterfaceName();
if (!hasInterface(ifaceName)) {
return false;
}

View file

@ -713,7 +713,7 @@ public class EthernetTracker {
// no need to send an interface state change as this is not a true "state change". The
// callers (maybeTrackInterface() and setTetheringInterfaceMode()) already broadcast the
// state change.
mFactory.updateInterfaceLinkState(iface, true);
mFactory.updateInterfaceLinkState(port, true);
}
}
@ -745,7 +745,7 @@ public class EthernetTracker {
}
// If updateInterfaceLinkState returns false, the interface is already in the correct state.
if (mFactory.updateInterfaceLinkState(iface, up)) {
if (mFactory.updateInterfaceLinkState(port, up)) {
broadcastInterfaceStateChange(iface);
}
}

View file

@ -234,7 +234,7 @@ public class EthernetNetworkFactoryTest {
final IpConfiguration ipConfig = createDefaultIpConfig();
mNetFactory.addInterface(port, ipConfig,
createInterfaceCapsBuilder(transportType).build());
assertTrue(mNetFactory.updateInterfaceLinkState(port.getInterfaceName(), true));
assertTrue(mNetFactory.updateInterfaceLinkState(port, true));
ArgumentCaptor<NetworkOfferCallback> captor = ArgumentCaptor.forClass(
NetworkOfferCallback.class);
@ -287,8 +287,7 @@ public class EthernetNetworkFactoryTest {
createInterfaceUndergoingProvisioning(TEST_IFACE);
// verify that the IpClient gets shut down when interface state changes to down.
final boolean ret =
mNetFactory.updateInterfaceLinkState(TEST_IFACE.getInterfaceName(), false /* up */);
final boolean ret = mNetFactory.updateInterfaceLinkState(TEST_IFACE, false /* up */);
assertTrue(ret);
verify(mIpClient).shutdown();
@ -299,8 +298,7 @@ public class EthernetNetworkFactoryTest {
initEthernetNetworkFactory();
// if interface was never added, link state cannot be updated.
final boolean ret =
mNetFactory.updateInterfaceLinkState(TEST_IFACE.getInterfaceName(), true /* up */);
final boolean ret = mNetFactory.updateInterfaceLinkState(TEST_IFACE, true /* up */);
assertFalse(ret);
verifyNoStopOrStart();
@ -543,7 +541,7 @@ public class EthernetNetworkFactoryTest {
public void testOnNetworkNeededOnStaleNetworkOffer() throws Exception {
initEthernetNetworkFactory();
createAndVerifyProvisionedInterface(TEST_IFACE);
mNetFactory.updateInterfaceLinkState(TEST_IFACE.getInterfaceName(), false);
mNetFactory.updateInterfaceLinkState(TEST_IFACE, false);
verify(mNetworkProvider).unregisterNetworkOffer(mNetworkOfferCallback);
// It is possible that even after a network offer is unregistered, CS still sends it
// onNetworkNeeded() callbacks.

View file

@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@ -77,7 +78,7 @@ public class EthernetTrackerTest {
public void setUp() throws RemoteException {
MockitoAnnotations.initMocks(this);
initMockResources();
doReturn(false).when(mFactory).updateInterfaceLinkState(anyString(), anyBoolean());
doReturn(false).when(mFactory).updateInterfaceLinkState(any(), anyBoolean());
doReturn(new String[0]).when(mNetd).interfaceGetList();
doReturn(new String[0]).when(mFactory).getInterfacesSorted(anyBoolean());
mHandlerThread = new HandlerThread(THREAD_NAME);