From 7f1975092f146bc53a00d20c93556ca2f755d338 Mon Sep 17 00:00:00 2001 From: paulhu Date: Fri, 10 Apr 2020 15:34:04 +0800 Subject: [PATCH] Add TetheringEventCallback CTS test Test APIs below: onOffloadStatusChanged(int) Bug: 153619369 Test: atests CtsTetheringTest Change-Id: Ia7edd0d3d8184e30373ac8b657299107ff9b4c1e --- .../tethering/cts/TetheringManagerTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java b/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java index b132982e1a..718b4f8892 100644 --- a/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java +++ b/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java @@ -15,6 +15,9 @@ */ package android.tethering.test; +import static android.net.TetheringManager.TETHER_HARDWARE_OFFLOAD_FAILED; +import static android.net.TetheringManager.TETHER_HARDWARE_OFFLOAD_STARTED; +import static android.net.TetheringManager.TETHER_HARDWARE_OFFLOAD_STOPPED; import static android.net.TetheringManager.TETHERING_USB; import static android.net.TetheringManager.TETHERING_WIFI; @@ -273,6 +276,7 @@ public class TetheringManagerTest { ON_TETHERED_IFACES, ON_ERROR, ON_CLIENTS, + ON_OFFLOAD_STATUS, }; public static class CallbackValue { @@ -330,6 +334,11 @@ public class TetheringManagerTest { mCallbacks.add(new CallbackValue(CallbackType.ON_CLIENTS, clients, 0)); } + @Override + public void onOffloadStatusChanged(int status) { + mCallbacks.add(new CallbackValue(CallbackType.ON_OFFLOAD_STATUS, status, 0)); + } + public CallbackValue pollCallback() { try { return mCallbacks.poll(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS); @@ -382,6 +391,17 @@ public class TetheringManagerTest { } } + public void expectOneOfOffloadStatusChanged(int... offloadStatuses) { + while (true) { + final CallbackValue cv = pollCallback(); + if (cv == null) fail("No expected offload status change callback"); + if (cv.callbackType != CallbackType.ON_OFFLOAD_STATUS) continue; + + final int status = (int) cv.callbackParam; + for (int offloadStatus : offloadStatuses) if (offloadStatus == status) return; + } + } + public TetheringInterfaceRegexps getTetheringInterfaceRegexps() { return mTetherableRegex; } @@ -403,6 +423,7 @@ public class TetheringManagerTest { mTM.registerTetheringEventCallback(c -> c.run(), tetherEventCallback); tetherEventCallback.expectCallbackStarted(); + tetherEventCallback.expectOneOfOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED); final TetheringInterfaceRegexps tetherableRegexs = tetherEventCallback.getTetheringInterfaceRegexps(); @@ -422,10 +443,14 @@ public class TetheringManagerTest { } tetherEventCallback.expectTetheredInterfacesChanged(wifiRegexs); + tetherEventCallback.expectOneOfOffloadStatusChanged( + TETHER_HARDWARE_OFFLOAD_STARTED, + TETHER_HARDWARE_OFFLOAD_FAILED); mTM.stopTethering(TETHERING_WIFI); tetherEventCallback.expectTetheredInterfacesChanged(null); + tetherEventCallback.expectOneOfOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED); mTM.unregisterTetheringEventCallback(tetherEventCallback); } }