Skip HostsideTetheringTests if tethering not supported

Bug: 379863419
Test: atest HostsideTetheringTests
Change-Id: I09e618508c9d6d8e8ca7c1c75ea0100665db7266
This commit is contained in:
Quang Anh Luong 2025-01-06 10:17:54 +09:00
commit abd12865e1

View file

@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull;
import android.content.Context;
import android.net.TetheringInterface;
import android.net.cts.util.CtsTetheringUtils;
import android.net.cts.util.CtsTetheringUtils.TestTetheringEventCallback;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiSsid;
@ -37,6 +38,7 @@ import java.nio.charset.StandardCharsets;
public class TetheringTest {
private CtsTetheringUtils mCtsTetheringUtils;
private TetheringHelperClient mTetheringHelperClient;
private TestTetheringEventCallback mTetheringEventCallback;
@Before
public void setUp() throws Exception {
@ -44,11 +46,14 @@ public class TetheringTest {
mCtsTetheringUtils = new CtsTetheringUtils(targetContext);
mTetheringHelperClient = new TetheringHelperClient(targetContext);
mTetheringHelperClient.bind();
mTetheringEventCallback = mCtsTetheringUtils.registerTetheringEventCallback();
}
@After
public void tearDown() throws Exception {
mTetheringHelperClient.unbind();
mCtsTetheringUtils.unregisterTetheringEventCallback(mTetheringEventCallback);
mCtsTetheringUtils.stopAllTethering();
}
/**
@ -57,24 +62,20 @@ public class TetheringTest {
*/
@Test
public void testSoftApConfigurationRedactedForOtherUids() throws Exception {
final CtsTetheringUtils.TestTetheringEventCallback tetherEventCallback =
mCtsTetheringUtils.registerTetheringEventCallback();
mTetheringEventCallback.assumeWifiTetheringSupported(
getInstrumentation().getTargetContext());
SoftApConfiguration softApConfig = new SoftApConfiguration.Builder()
.setWifiSsid(WifiSsid.fromBytes("This is an SSID!"
.getBytes(StandardCharsets.UTF_8))).build();
final TetheringInterface tetheringInterface =
mCtsTetheringUtils.startWifiTethering(tetherEventCallback, softApConfig);
mCtsTetheringUtils.startWifiTethering(mTetheringEventCallback, softApConfig);
assertNotNull(tetheringInterface);
assertEquals(softApConfig, tetheringInterface.getSoftApConfiguration());
try {
TetheringInterface tetheringInterfaceForApp2 =
mTetheringHelperClient.getTetheredWifiInterface();
assertNotNull(tetheringInterfaceForApp2);
assertNull(tetheringInterfaceForApp2.getSoftApConfiguration());
assertEquals(
tetheringInterface.getInterface(), tetheringInterfaceForApp2.getInterface());
} finally {
mCtsTetheringUtils.stopWifiTethering(tetherEventCallback);
}
TetheringInterface tetheringInterfaceForApp2 =
mTetheringHelperClient.getTetheredWifiInterface();
assertNotNull(tetheringInterfaceForApp2);
assertNull(tetheringInterfaceForApp2.getSoftApConfiguration());
assertEquals(
tetheringInterface.getInterface(), tetheringInterfaceForApp2.getInterface());
}
}