Update callers to use buildTemplateMobileWithRatType with metered
The method buildTemplateMobileWithRatType is updated to take metered as a parameter so the callers should be updated to the new version. Bug: 183776809 Test: atest FrameworksNetTest Change-Id: I859514b93705f9ee4f9ae4b0bcddcb61005a78ff Merged-In: I859514b93705f9ee4f9ae4b0bcddcb61005a78ff
This commit is contained in:
@@ -26,6 +26,8 @@ import android.net.NetworkIdentity.SUBTYPE_COMBINED
|
|||||||
import android.net.NetworkIdentity.buildNetworkIdentity
|
import android.net.NetworkIdentity.buildNetworkIdentity
|
||||||
import android.net.NetworkStats.DEFAULT_NETWORK_ALL
|
import android.net.NetworkStats.DEFAULT_NETWORK_ALL
|
||||||
import android.net.NetworkStats.METERED_ALL
|
import android.net.NetworkStats.METERED_ALL
|
||||||
|
import android.net.NetworkStats.METERED_NO
|
||||||
|
import android.net.NetworkStats.METERED_YES
|
||||||
import android.net.NetworkStats.ROAMING_ALL
|
import android.net.NetworkStats.ROAMING_ALL
|
||||||
import android.net.NetworkTemplate.MATCH_MOBILE
|
import android.net.NetworkTemplate.MATCH_MOBILE
|
||||||
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
|
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
|
||||||
@@ -176,7 +178,7 @@ class NetworkTemplateTest {
|
|||||||
fun testMobileMatches() {
|
fun testMobileMatches() {
|
||||||
val templateMobileImsi1 = buildTemplateMobileAll(TEST_IMSI1)
|
val templateMobileImsi1 = buildTemplateMobileAll(TEST_IMSI1)
|
||||||
val templateMobileImsi2WithRatType = buildTemplateMobileWithRatType(TEST_IMSI2,
|
val templateMobileImsi2WithRatType = buildTemplateMobileWithRatType(TEST_IMSI2,
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS)
|
TelephonyManager.NETWORK_TYPE_UMTS, METERED_YES)
|
||||||
|
|
||||||
val mobileImsi1 = buildNetworkState(TYPE_MOBILE, TEST_IMSI1, null /* ssid */,
|
val mobileImsi1 = buildNetworkState(TYPE_MOBILE, TEST_IMSI1, null /* ssid */,
|
||||||
OEM_NONE, true /* metered */)
|
OEM_NONE, true /* metered */)
|
||||||
@@ -205,7 +207,7 @@ class NetworkTemplateTest {
|
|||||||
fun testMobileWildcardMatches() {
|
fun testMobileWildcardMatches() {
|
||||||
val templateMobileWildcard = buildTemplateMobileWildcard()
|
val templateMobileWildcard = buildTemplateMobileWildcard()
|
||||||
val templateMobileNullImsiWithRatType = buildTemplateMobileWithRatType(null,
|
val templateMobileNullImsiWithRatType = buildTemplateMobileWithRatType(null,
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS)
|
TelephonyManager.NETWORK_TYPE_UMTS, METERED_ALL)
|
||||||
|
|
||||||
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
||||||
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
||||||
@@ -258,58 +260,131 @@ class NetworkTemplateTest {
|
|||||||
templateCarrierImsi1Metered.assertDoesNotMatch(identCarrierWifiImsi1NonMetered)
|
templateCarrierImsi1Metered.assertDoesNotMatch(identCarrierWifiImsi1NonMetered)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor this test to reduce the line of codes.
|
||||||
@Test
|
@Test
|
||||||
fun testRatTypeGroupMatches() {
|
fun testRatTypeGroupMatches() {
|
||||||
val stateMobile = buildMobileNetworkState(TEST_IMSI1)
|
val stateMobileImsi1Metered = buildMobileNetworkState(TEST_IMSI1)
|
||||||
|
val stateMobileImsi1NonMetered = buildNetworkState(TYPE_MOBILE, TEST_IMSI1,
|
||||||
|
null /* ssid */, OEM_NONE, false /* metered */)
|
||||||
|
val stateMobileImsi2NonMetered = buildNetworkState(TYPE_MOBILE, TEST_IMSI2,
|
||||||
|
null /* ssid */, OEM_NONE, false /* metered */)
|
||||||
|
|
||||||
// Build UMTS template that matches mobile identities with RAT in the same
|
// Build UMTS template that matches mobile identities with RAT in the same
|
||||||
// group with any IMSI. See {@link NetworkTemplate#getCollapsedRatType}.
|
// group with any IMSI. See {@link NetworkTemplate#getCollapsedRatType}.
|
||||||
val templateUmts = buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS)
|
val templateUmtsMetered = buildTemplateMobileWithRatType(null,
|
||||||
|
TelephonyManager.NETWORK_TYPE_UMTS, METERED_YES)
|
||||||
// Build normal template that matches mobile identities with any RAT and IMSI.
|
// Build normal template that matches mobile identities with any RAT and IMSI.
|
||||||
val templateAll = buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL)
|
val templateAllMetered = buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL,
|
||||||
|
METERED_YES)
|
||||||
// Build template with UNKNOWN RAT that matches mobile identities with RAT that
|
// Build template with UNKNOWN RAT that matches mobile identities with RAT that
|
||||||
// cannot be determined.
|
// cannot be determined.
|
||||||
val templateUnknown =
|
val templateUnknownMetered =
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN)
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||||
|
METERED_YES)
|
||||||
|
|
||||||
val identUmts = buildNetworkIdentity(
|
val templateUmtsNonMetered = buildTemplateMobileWithRatType(null,
|
||||||
mockContext, stateMobile, false, TelephonyManager.NETWORK_TYPE_UMTS)
|
TelephonyManager.NETWORK_TYPE_UMTS, METERED_NO)
|
||||||
val identHsdpa = buildNetworkIdentity(
|
val templateAllNonMetered = buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL,
|
||||||
mockContext, stateMobile, false, TelephonyManager.NETWORK_TYPE_HSDPA)
|
METERED_NO)
|
||||||
val identLte = buildNetworkIdentity(
|
val templateUnknownNonMetered =
|
||||||
mockContext, stateMobile, false, TelephonyManager.NETWORK_TYPE_LTE)
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||||
val identCombined = buildNetworkIdentity(
|
METERED_NO)
|
||||||
mockContext, stateMobile, false, SUBTYPE_COMBINED)
|
|
||||||
val identImsi2 = buildNetworkIdentity(mockContext, buildMobileNetworkState(TEST_IMSI2),
|
val identUmtsMetered = buildNetworkIdentity(
|
||||||
false, TelephonyManager.NETWORK_TYPE_UMTS)
|
mockContext, stateMobileImsi1Metered, false, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
|
val identHsdpaMetered = buildNetworkIdentity(
|
||||||
|
mockContext, stateMobileImsi1Metered, false, TelephonyManager.NETWORK_TYPE_HSDPA)
|
||||||
|
val identLteMetered = buildNetworkIdentity(
|
||||||
|
mockContext, stateMobileImsi1Metered, false, TelephonyManager.NETWORK_TYPE_LTE)
|
||||||
|
val identCombinedMetered = buildNetworkIdentity(
|
||||||
|
mockContext, stateMobileImsi1Metered, false, SUBTYPE_COMBINED)
|
||||||
|
val identImsi2UmtsMetered = buildNetworkIdentity(mockContext,
|
||||||
|
buildMobileNetworkState(TEST_IMSI2), false, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
val identWifi = buildNetworkIdentity(
|
val identWifi = buildNetworkIdentity(
|
||||||
mockContext, buildWifiNetworkState(null, TEST_SSID1), true, 0)
|
mockContext, buildWifiNetworkState(null, TEST_SSID1), true, 0)
|
||||||
|
|
||||||
// Assert that identity with the same RAT matches.
|
val identUmtsNonMetered = buildNetworkIdentity(
|
||||||
templateUmts.assertMatches(identUmts)
|
mockContext, stateMobileImsi1NonMetered, false, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
templateAll.assertMatches(identUmts)
|
val identHsdpaNonMetered = buildNetworkIdentity(
|
||||||
templateUnknown.assertDoesNotMatch(identUmts)
|
mockContext, stateMobileImsi1NonMetered, false,
|
||||||
|
TelephonyManager.NETWORK_TYPE_HSDPA)
|
||||||
|
val identLteNonMetered = buildNetworkIdentity(
|
||||||
|
mockContext, stateMobileImsi1NonMetered, false, TelephonyManager.NETWORK_TYPE_LTE)
|
||||||
|
val identCombinedNonMetered = buildNetworkIdentity(
|
||||||
|
mockContext, stateMobileImsi1NonMetered, false, SUBTYPE_COMBINED)
|
||||||
|
val identImsi2UmtsNonMetered = buildNetworkIdentity(mockContext,
|
||||||
|
stateMobileImsi2NonMetered, false, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
|
|
||||||
|
// Assert that identity with the same RAT and meteredness matches.
|
||||||
|
// Verify metered template.
|
||||||
|
templateUmtsMetered.assertMatches(identUmtsMetered)
|
||||||
|
templateAllMetered.assertMatches(identUmtsMetered)
|
||||||
|
templateUnknownMetered.assertDoesNotMatch(identUmtsMetered)
|
||||||
|
// Verify non-metered template.
|
||||||
|
templateUmtsNonMetered.assertMatches(identUmtsNonMetered)
|
||||||
|
templateAllNonMetered.assertMatches(identUmtsNonMetered)
|
||||||
|
templateUnknownNonMetered.assertDoesNotMatch(identUmtsNonMetered)
|
||||||
|
|
||||||
|
// Assert that identity with the same RAT but meteredness is different.
|
||||||
|
// Thus, it does not match.
|
||||||
|
templateUmtsNonMetered.assertDoesNotMatch(identUmtsMetered)
|
||||||
|
templateAllNonMetered.assertDoesNotMatch(identUmtsMetered)
|
||||||
|
|
||||||
// Assert that identity with the RAT within the same group matches.
|
// Assert that identity with the RAT within the same group matches.
|
||||||
templateUmts.assertMatches(identHsdpa)
|
// Verify metered template.
|
||||||
templateAll.assertMatches(identHsdpa)
|
templateUmtsMetered.assertMatches(identHsdpaMetered)
|
||||||
templateUnknown.assertDoesNotMatch(identHsdpa)
|
templateAllMetered.assertMatches(identHsdpaMetered)
|
||||||
|
templateUnknownMetered.assertDoesNotMatch(identHsdpaMetered)
|
||||||
|
// Verify non-metered template.
|
||||||
|
templateUmtsNonMetered.assertMatches(identHsdpaNonMetered)
|
||||||
|
templateAllNonMetered.assertMatches(identHsdpaNonMetered)
|
||||||
|
templateUnknownNonMetered.assertDoesNotMatch(identHsdpaNonMetered)
|
||||||
|
|
||||||
// Assert that identity with the RAT out of the same group only matches template with
|
// Assert that identity with the RAT out of the same group only matches template with
|
||||||
// NETWORK_TYPE_ALL.
|
// NETWORK_TYPE_ALL.
|
||||||
templateUmts.assertDoesNotMatch(identLte)
|
// Verify metered template.
|
||||||
templateAll.assertMatches(identLte)
|
templateUmtsMetered.assertDoesNotMatch(identLteMetered)
|
||||||
templateUnknown.assertDoesNotMatch(identLte)
|
templateAllMetered.assertMatches(identLteMetered)
|
||||||
|
templateUnknownMetered.assertDoesNotMatch(identLteMetered)
|
||||||
|
// Verify non-metered template.
|
||||||
|
templateUmtsNonMetered.assertDoesNotMatch(identLteNonMetered)
|
||||||
|
templateAllNonMetered.assertMatches(identLteNonMetered)
|
||||||
|
templateUnknownNonMetered.assertDoesNotMatch(identLteNonMetered)
|
||||||
|
// Verify non-metered template does not match identity with metered.
|
||||||
|
templateAllNonMetered.assertDoesNotMatch(identLteMetered)
|
||||||
|
|
||||||
// Assert that identity with combined RAT only matches with template with NETWORK_TYPE_ALL
|
// Assert that identity with combined RAT only matches with template with NETWORK_TYPE_ALL
|
||||||
// and NETWORK_TYPE_UNKNOWN.
|
// and NETWORK_TYPE_UNKNOWN.
|
||||||
templateUmts.assertDoesNotMatch(identCombined)
|
// Verify metered template.
|
||||||
templateAll.assertMatches(identCombined)
|
templateUmtsMetered.assertDoesNotMatch(identCombinedMetered)
|
||||||
templateUnknown.assertMatches(identCombined)
|
templateAllMetered.assertMatches(identCombinedMetered)
|
||||||
|
templateUnknownMetered.assertMatches(identCombinedMetered)
|
||||||
|
// Verify non-metered template.
|
||||||
|
templateUmtsNonMetered.assertDoesNotMatch(identCombinedNonMetered)
|
||||||
|
templateAllNonMetered.assertMatches(identCombinedNonMetered)
|
||||||
|
templateUnknownNonMetered.assertMatches(identCombinedNonMetered)
|
||||||
|
// Verify that identity with metered does not match non-metered template.
|
||||||
|
templateAllNonMetered.assertDoesNotMatch(identCombinedMetered)
|
||||||
|
templateUnknownNonMetered.assertDoesNotMatch(identCombinedMetered)
|
||||||
|
|
||||||
// Assert that identity with different IMSI matches.
|
// Assert that identity with different IMSI matches.
|
||||||
templateUmts.assertMatches(identImsi2)
|
// Verify metered template.
|
||||||
templateAll.assertMatches(identImsi2)
|
templateUmtsMetered.assertMatches(identImsi2UmtsMetered)
|
||||||
templateUnknown.assertDoesNotMatch(identImsi2)
|
templateAllMetered.assertMatches(identImsi2UmtsMetered)
|
||||||
|
templateUnknownMetered.assertDoesNotMatch(identImsi2UmtsMetered)
|
||||||
|
// Verify non-metered template.
|
||||||
|
templateUmtsNonMetered.assertMatches(identImsi2UmtsNonMetered)
|
||||||
|
templateAllNonMetered.assertMatches(identImsi2UmtsNonMetered)
|
||||||
|
templateUnknownNonMetered.assertDoesNotMatch(identImsi2UmtsNonMetered)
|
||||||
|
// Verify that the same RAT but different meteredness should not match.
|
||||||
|
templateUmtsNonMetered.assertDoesNotMatch(identImsi2UmtsMetered)
|
||||||
|
templateAllNonMetered.assertDoesNotMatch(identImsi2UmtsMetered)
|
||||||
|
|
||||||
// Assert that wifi identity does not match.
|
// Assert that wifi identity does not match.
|
||||||
templateUmts.assertDoesNotMatch(identWifi)
|
templateUmtsMetered.assertDoesNotMatch(identWifi)
|
||||||
templateAll.assertDoesNotMatch(identWifi)
|
templateUnknownMetered.assertDoesNotMatch(identWifi)
|
||||||
templateUnknown.assertDoesNotMatch(identWifi)
|
templateUmtsNonMetered.assertDoesNotMatch(identWifi)
|
||||||
|
templateUnknownNonMetered.assertDoesNotMatch(identWifi)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -657,11 +657,14 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testMobileStatsByRatType() throws Exception {
|
public void testMobileStatsByRatType() throws Exception {
|
||||||
final NetworkTemplate template3g =
|
final NetworkTemplate template3g =
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS);
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS,
|
||||||
|
METERED_YES);
|
||||||
final NetworkTemplate template4g =
|
final NetworkTemplate template4g =
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_LTE);
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_LTE,
|
||||||
|
METERED_YES);
|
||||||
final NetworkTemplate template5g =
|
final NetworkTemplate template5g =
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_NR);
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_NR,
|
||||||
|
METERED_YES);
|
||||||
final NetworkStateSnapshot[] states =
|
final NetworkStateSnapshot[] states =
|
||||||
new NetworkStateSnapshot[]{buildMobile3gState(IMSI_1)};
|
new NetworkStateSnapshot[]{buildMobile3gState(IMSI_1)};
|
||||||
|
|
||||||
@@ -1478,11 +1481,13 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
// Build 3G template, type unknown template to get stats while network type is unknown
|
// Build 3G template, type unknown template to get stats while network type is unknown
|
||||||
// and type all template to get the sum of all network type stats.
|
// and type all template to get the sum of all network type stats.
|
||||||
final NetworkTemplate template3g =
|
final NetworkTemplate template3g =
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS);
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS,
|
||||||
|
METERED_YES);
|
||||||
final NetworkTemplate templateUnknown =
|
final NetworkTemplate templateUnknown =
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN);
|
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||||
|
METERED_YES);
|
||||||
final NetworkTemplate templateAll =
|
final NetworkTemplate templateAll =
|
||||||
buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL);
|
buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL, METERED_YES);
|
||||||
final NetworkStateSnapshot[] states =
|
final NetworkStateSnapshot[] states =
|
||||||
new NetworkStateSnapshot[]{buildMobile3gState(IMSI_1)};
|
new NetworkStateSnapshot[]{buildMobile3gState(IMSI_1)};
|
||||||
|
|
||||||
@@ -1580,7 +1585,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
|
|
||||||
// Verify mobile summary is not changed by the operation count.
|
// Verify mobile summary is not changed by the operation count.
|
||||||
final NetworkTemplate templateMobile =
|
final NetworkTemplate templateMobile =
|
||||||
buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL);
|
buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL, METERED_YES);
|
||||||
final NetworkStats statsMobile = mSession.getSummaryForAllUid(
|
final NetworkStats statsMobile = mSession.getSummaryForAllUid(
|
||||||
templateMobile, Long.MIN_VALUE, Long.MAX_VALUE, true);
|
templateMobile, Long.MIN_VALUE, Long.MAX_VALUE, true);
|
||||||
assertValues(statsMobile, IFACE_ALL, UID_RED, SET_ALL, TAG_NONE, METERED_ALL, ROAMING_ALL,
|
assertValues(statsMobile, IFACE_ALL, UID_RED, SET_ALL, TAG_NONE, METERED_ALL, ROAMING_ALL,
|
||||||
|
|||||||
Reference in New Issue
Block a user