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
Ignore-AOSP-First: Required APIs are not in downstream of AOSP yet
Change-Id: I89f391297e8c7108d3e790a3d2da7b373f7b4012
diff --git a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
index 5c8a97a..1fac108 100644
--- a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
@@ -59,6 +59,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;
@@ -813,9 +814,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);
+ }
}
}