From e87bf658c4f31633a418144d6c29c2d176c55d3c Mon Sep 17 00:00:00 2001 From: Quang Anh Luong Date: Tue, 18 Feb 2025 13:44:52 +0900 Subject: [PATCH] Use pending request when legacy tethering Legacy tethering was changed to use it's own tethering requests with REQUEST_TYPE_LEGACY in aosp/3465235 instead of using the pending request as it was thought that pending requests (from startTethering) and legacy tethering would always be mutually exclusive. However, pre-T Bluetooth tethering actually relies on startTethering(request) to add the pending request, and then BT service directly calls legacyTether(iface) to start tethering. Thus we should continue to use pending requests even for legacyTether. Bug: 216524590 Test: atest TetheringTest Change-Id: I0aa7b5cc6d6d54f516a07b0e89259c61e1d05f69 --- .../com/android/networkstack/tethering/Tethering.java | 5 ++++- .../android/networkstack/tethering/TetheringTest.java | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index b50831d56a..56185e6c47 100644 --- a/Tethering/src/com/android/networkstack/tethering/Tethering.java +++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java @@ -1152,7 +1152,10 @@ public class Tethering { } catch (RemoteException e) { } } - final TetheringRequest request = createLegacyGlobalScopeTetheringRequest(type); + TetheringRequest request = getPendingTetheringRequest(type); + if (request == null) { + request = createLegacyGlobalScopeTetheringRequest(type); + } int result = tetherInternal(request, iface); switch (type) { case TETHERING_WIFI: 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 1ddeec4d41..50ecfe1bfe 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java @@ -89,7 +89,6 @@ 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; @@ -2881,7 +2880,7 @@ public class TetheringTest { @Test @IgnoreAfter(Build.VERSION_CODES.VANILLA_ICE_CREAM) - public void testRequestStaticIpLegacyTetherFailure() throws Exception { + public void testRequestStaticIpLegacyTether() throws Exception { initTetheringOnTestThread(); // Call startTethering with static ip @@ -2907,14 +2906,14 @@ public class TetheringTest { 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 that the static ip set in startTethering is 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(serverAddr, intToInet4AddressHTH(params.serverAddr).getHostAddress()); assertEquals(24, params.serverAddrPrefixLength); - assertNotEquals(clientAddrParceled, params.singleClientAddr); + assertEquals(clientAddrParceled, params.singleClientAddr); } @Test