diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 2c8fb895dc..c0ecc1a2b0 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -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; } diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java index 419a09bfaf..b772d6f8ec 100644 --- a/service-t/src/com/android/server/ethernet/EthernetTracker.java +++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java @@ -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); } } diff --git a/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java index 292803183c..74b02367c0 100644 --- a/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java +++ b/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java @@ -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 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. diff --git a/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java index 5013d78c31..7b6985e522 100644 --- a/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java +++ b/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java @@ -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);