diff --git a/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java b/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java index 4a116ec5f4..136dfb1da7 100644 --- a/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java +++ b/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java @@ -401,4 +401,22 @@ public class TetheringMetrics { return UpstreamType.UT_UNKNOWN; } + + /** + * Check whether tethering metrics' data usage can be collected for a given upstream type. + * + * @param type the upstream type + */ + public static boolean isUsageSupportedForUpstreamType(@NonNull UpstreamType type) { + switch(type) { + case UT_CELLULAR: + case UT_WIFI: + case UT_BLUETOOTH: + case UT_ETHERNET: + return true; + default: + break; + } + return false; + } } diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java index 0046ce1df7..7cef9cbf0c 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java @@ -46,6 +46,7 @@ import static android.net.TetheringManager.TETHER_ERROR_UNKNOWN_TYPE; import static android.net.TetheringManager.TETHER_ERROR_UNSUPPORTED; import static android.net.TetheringManager.TETHER_ERROR_UNTETHER_IFACE_ERROR; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; @@ -374,4 +375,21 @@ public final class TetheringMetricsTest { UserType.USER_SETTINGS, upstreamEvents, currentTimeMillis() - wifiTetheringStartTime); } + + private void runUsageSupportedForUpstreamTypeTest(final UpstreamType upstreamType, + final boolean isSupported) { + final boolean result = TetheringMetrics.isUsageSupportedForUpstreamType(upstreamType); + assertEquals(isSupported, result); + } + + @Test + public void testUsageSupportedForUpstreamTypeTest() { + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_CELLULAR, true /* isSupported */); + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_WIFI, true /* isSupported */); + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_BLUETOOTH, true /* isSupported */); + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_ETHERNET, true /* isSupported */); + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_WIFI_AWARE, false /* isSupported */); + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_LOWPAN, false /* isSupported */); + runUsageSupportedForUpstreamTypeTest(UpstreamType.UT_UNKNOWN, false /* isSupported */); + } }