Fix EthernetTetheringTest failure if tethering is not supported
Do not run ethernet tethering tests if tethering is not supported
because Tethering APIs would fail. Also skip the test if
EthernetManager is not avaliable. EthernetManager would be null if
there are no FEATURE_ETHERNET and FEATURE_USB_HOST.
Bug: 159869957
Test: atest CtsTetheringTest
Change-Id: I2b9be6799c6edeefc8cd74897a8704dbe80dd061
diff --git a/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java b/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
index 74df113..c93a86b 100644
--- a/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
+++ b/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
@@ -101,17 +101,21 @@
private UiAutomation mUiAutomation =
InstrumentationRegistry.getInstrumentation().getUiAutomation();
+ private boolean mRunTests;
@Before
public void setUp() throws Exception {
- mHandlerThread = new HandlerThread(getClass().getSimpleName());
- mHandlerThread.start();
- mHandler = new Handler(mHandlerThread.getLooper());
- mTetheredInterfaceRequester = new TetheredInterfaceRequester(mHandler, mEm);
// Needed to create a TestNetworkInterface, to call requestTetheredInterface, and to receive
// tethered client callbacks.
mUiAutomation.adoptShellPermissionIdentity(
MANAGE_TEST_NETWORKS, NETWORK_SETTINGS, TETHER_PRIVILEGED);
+ mRunTests = mTm.isTetheringSupported() && mEm != null;
+ assumeTrue(mRunTests);
+
+ mHandlerThread = new HandlerThread(getClass().getSimpleName());
+ mHandlerThread.start();
+ mHandler = new Handler(mHandlerThread.getLooper());
+ mTetheredInterfaceRequester = new TetheredInterfaceRequester(mHandler, mEm);
}
private void cleanUp() throws Exception {
@@ -135,7 +139,7 @@
@After
public void tearDown() throws Exception {
try {
- cleanUp();
+ if (mRunTests) cleanUp();
} finally {
mUiAutomation.dropShellPermissionIdentity();
}