Test tethered callback with TetheringInterface

The old callback only report interface list, new callback could provide
the mapping of interface and type. Replace old callback usage in cts
with new callback and check whether old callback could get the correct
interface list by comparing the result between old and new callback.

Bug: 162920185
Bug: 152203943
Test: atest CtsTetheringTest on S
      atest CtsTetheringTestLatestSdk on R
      atest MtsTetheringTestLatestSdk on S and R
Merged-In: I2a0b8c43fb340c3eaed7f0f90464199222a24280
Change-Id: I2a0b8c43fb340c3eaed7f0f90464199222a24280
This commit is contained in:
markchien
2021-05-18 20:22:17 +08:00
committed by Chiachang Wang
parent 35ad54b25e
commit 3a23d2e2a6
4 changed files with 149 additions and 61 deletions

View File

@@ -80,6 +80,7 @@ import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -349,7 +350,7 @@ public class EthernetTetheringTest {
private final CountDownLatch mLocalOnlyStartedLatch = new CountDownLatch(1);
private final CountDownLatch mLocalOnlyStoppedLatch = new CountDownLatch(1);
private final CountDownLatch mClientConnectedLatch = new CountDownLatch(1);
private final String mIface;
private final TetheringInterface mIface;
private volatile boolean mInterfaceWasTethered = false;
private volatile boolean mInterfaceWasLocalOnly = false;
@@ -358,20 +359,24 @@ public class EthernetTetheringTest {
MyTetheringEventCallback(TetheringManager tm, String iface) {
mTm = tm;
mIface = iface;
mIface = new TetheringInterface(TETHERING_ETHERNET, iface);
}
public void unregister() {
mTm.unregisterTetheringEventCallback(this);
mUnregistered = true;
}
@Override
public void onTetheredInterfacesChanged(List<String> interfaces) {
fail("Should only call callback that takes a Set<TetheringInterface>");
}
@Override
public void onTetheredInterfacesChanged(Set<TetheringInterface> interfaces) {
// Ignore stale callbacks registered by previous test cases.
if (mUnregistered) return;
if (!mInterfaceWasTethered && (mIface == null || interfaces.contains(mIface))) {
if (!mInterfaceWasTethered && interfaces.contains(mIface)) {
// This interface is being tethered for the first time.
Log.d(TAG, "Tethering started: " + interfaces);
mInterfaceWasTethered = true;
@@ -384,10 +389,15 @@ public class EthernetTetheringTest {
@Override
public void onLocalOnlyInterfacesChanged(List<String> interfaces) {
fail("Should only call callback that takes a Set<TetheringInterface>");
}
@Override
public void onLocalOnlyInterfacesChanged(Set<TetheringInterface> interfaces) {
// Ignore stale callbacks registered by previous test cases.
if (mUnregistered) return;
if (!mInterfaceWasLocalOnly && (mIface == null || interfaces.contains(mIface))) {
if (!mInterfaceWasLocalOnly && interfaces.contains(mIface)) {
// This interface is being put into local-only mode for the first time.
Log.d(TAG, "Local-only started: " + interfaces);
mInterfaceWasLocalOnly = true;