Fix testCallback fail caused by lacking of looper
For T- devices, the registerUsageCallback invocation without
a handler needs a looper from the thread that calls into
the API, which is not available in the test.
Thus, skip related checks if the sdk level is below T.
Test: atest CtsNetTestCasesLatestSdk:android.net.cts.NetworkStatsManagerTest#testCallback
on R device
Bug: 218845894
(cherry-picked from ag/16835803)
Change-Id: I89f391297e8c7108d3e790a3d2da7b373f7b4012
Merged-In: I89f391297e8c7108d3e790a3d2da7b373f7b4012
diff --git a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
index 3626210..de4f41b 100644
--- a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
@@ -62,6 +62,7 @@
import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.compatibility.common.util.SystemUtil;
+import com.android.modules.utils.build.SdkLevel;
import com.android.testutils.DevSdkIgnoreRule;
import java.io.IOException;
@@ -840,9 +841,13 @@
mNsm.unregisterUsageCallback(usageCallback);
- mNsm.registerUsageCallback(mNetworkInterfacesToTest[i].getNetworkType(),
- getSubscriberId(i), THRESHOLD_BYTES, usageCallback);
- mNsm.unregisterUsageCallback(usageCallback);
+ // For T- devices, the registerUsageCallback invocation below will need a looper
+ // from the thread that calls into the API, which is not available in the test.
+ if (SdkLevel.isAtLeastT()) {
+ mNsm.registerUsageCallback(mNetworkInterfacesToTest[i].getNetworkType(),
+ getSubscriberId(i), THRESHOLD_BYTES, usageCallback);
+ mNsm.unregisterUsageCallback(usageCallback);
+ }
}
}