Add isUsageSupportedForUpstreamType() helper method
This new helper method provides a convenient way to validate and determine whether tethering metrics' data usage can be collected for a given upstream type. Bug: 282861165 Test: atest TetheringMetricsTest Change-Id: I7527ce56815e1f7e9382be1a54b84c91552e1129
This commit is contained in:
parent
99d585c2e8
commit
9651e04bf0
2 changed files with 36 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue