diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java index e1c2db90e3..1ddeec4d41 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java @@ -89,6 +89,7 @@ import static com.android.testutils.TestPermissionUtil.runAsShell; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -2878,6 +2879,44 @@ public class TetheringTest { assertEquals(clientAddrParceled, params.singleClientAddr); } + @Test + @IgnoreAfter(Build.VERSION_CODES.VANILLA_ICE_CREAM) + public void testRequestStaticIpLegacyTetherFailure() throws Exception { + initTetheringOnTestThread(); + + // Call startTethering with static ip + final LinkAddress serverLinkAddr = new LinkAddress("192.168.0.123/24"); + final LinkAddress clientLinkAddr = new LinkAddress("192.168.0.42/24"); + final String serverAddr = "192.168.0.123"; + final int clientAddrParceled = 0xc0a8002a; + final ArgumentCaptor dhcpParamsCaptor = + ArgumentCaptor.forClass(DhcpServingParamsParcel.class); + when(mWifiManager.startTetheredHotspot(any())).thenReturn(true); + mTethering.startTethering(createTetheringRequest(TETHERING_WIFI, + serverLinkAddr, clientLinkAddr, false, CONNECTIVITY_SCOPE_GLOBAL, null), + TEST_CALLER_PKG, null); + mLooper.dispatchAll(); + verify(mWifiManager, times(1)).startTetheredHotspot(any()); + mTethering.interfaceStatusChanged(TEST_WLAN_IFNAME, true); + + // Call legacyTether on the interface before the link layer event comes back. + // This happens, for example, in pre-T bluetooth tethering: Settings calls startTethering, + // and then the bluetooth code calls the tether() API. + final ResultListener tetherResult = new ResultListener(TETHER_ERROR_NO_ERROR); + mTethering.legacyTether(TEST_WLAN_IFNAME, tetherResult); + mLooper.dispatchAll(); + tetherResult.assertHasResult(); + + // Verify that the static ip set in startTethering is not used + verify(mNetd).interfaceSetCfg(argThat(cfg -> !serverAddr.equals(cfg.ipv4Addr))); + verify(mIpServerDependencies, times(1)).makeDhcpServer(any(), dhcpParamsCaptor.capture(), + any()); + final DhcpServingParamsParcel params = dhcpParamsCaptor.getValue(); + assertNotEquals(serverAddr, intToInet4AddressHTH(params.serverAddr).getHostAddress()); + assertEquals(24, params.serverAddrPrefixLength); + assertNotEquals(clientAddrParceled, params.singleClientAddr); + } + @Test public void testUpstreamNetworkChanged() throws Exception { initTetheringOnTestThread();