Snap for 7852542 from 25f4b66ced1a021cd5a8ccbc0ed7d050c3c9a263 to sc-v2-release
Change-Id: Ibf1e071cc9fbeebce3fca91deb7e790fe81f2694
diff --git a/tests/unit/java/android/net/NetworkTemplateTest.kt b/tests/unit/java/android/net/NetworkTemplateTest.kt
index 49c7271..2db77f2 100644
--- a/tests/unit/java/android/net/NetworkTemplateTest.kt
+++ b/tests/unit/java/android/net/NetworkTemplateTest.kt
@@ -26,6 +26,8 @@
import android.net.NetworkIdentity.buildNetworkIdentity
import android.net.NetworkStats.DEFAULT_NETWORK_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.NetworkTemplate.MATCH_MOBILE
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
@@ -39,6 +41,8 @@
import android.net.NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_EXACT
import android.net.NetworkTemplate.WIFI_NETWORKID_ALL
import android.net.NetworkTemplate.buildTemplateCarrierMetered
+import android.net.NetworkTemplate.buildTemplateMobileAll
+import android.net.NetworkTemplate.buildTemplateMobileWildcard
import android.net.NetworkTemplate.buildTemplateMobileWithRatType
import android.net.NetworkTemplate.buildTemplateWifi
import android.net.NetworkTemplate.buildTemplateWifiWildcard
@@ -171,6 +175,57 @@
}
@Test
+ fun testMobileMatches() {
+ val templateMobileImsi1 = buildTemplateMobileAll(TEST_IMSI1)
+ val templateMobileImsi2WithRatType = buildTemplateMobileWithRatType(TEST_IMSI2,
+ TelephonyManager.NETWORK_TYPE_UMTS, METERED_YES)
+
+ val mobileImsi1 = buildNetworkState(TYPE_MOBILE, TEST_IMSI1, null /* ssid */,
+ OEM_NONE, true /* metered */)
+ val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
+ false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
+ val mobileImsi2 = buildMobileNetworkState(TEST_IMSI2)
+ val identMobile2Umts = buildNetworkIdentity(mockContext, mobileImsi2,
+ false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
+
+ val identWifiImsi1Ssid1 = buildNetworkIdentity(
+ mockContext, buildWifiNetworkState(TEST_IMSI1, TEST_SSID1), true, 0)
+
+ // Verify that the template matches type and the subscriberId.
+ templateMobileImsi1.assertMatches(identMobile1)
+ templateMobileImsi2WithRatType.assertMatches(identMobile2Umts)
+
+ // Verify that the template does not match the different subscriberId.
+ templateMobileImsi1.assertDoesNotMatch(identMobile2Umts)
+ templateMobileImsi2WithRatType.assertDoesNotMatch(identMobile1)
+
+ // Verify that the different type does not match.
+ templateMobileImsi1.assertDoesNotMatch(identWifiImsi1Ssid1)
+ }
+
+ @Test
+ fun testMobileWildcardMatches() {
+ val templateMobileWildcard = buildTemplateMobileWildcard()
+ val templateMobileNullImsiWithRatType = buildTemplateMobileWithRatType(null,
+ TelephonyManager.NETWORK_TYPE_UMTS, METERED_ALL)
+
+ val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
+ val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
+ false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
+
+ // Verify that the template matches any subscriberId.
+ templateMobileWildcard.assertMatches(identMobile1)
+ templateMobileNullImsiWithRatType.assertMatches(identMobile1)
+
+ val identWifiImsi1Ssid1 = buildNetworkIdentity(
+ mockContext, buildWifiNetworkState(TEST_IMSI1, TEST_SSID1), true, 0)
+
+ // Verify that the different type does not match.
+ templateMobileWildcard.assertDoesNotMatch(identWifiImsi1Ssid1)
+ templateMobileNullImsiWithRatType.assertDoesNotMatch(identWifiImsi1Ssid1)
+ }
+
+ @Test
fun testCarrierMeteredMatches() {
val templateCarrierImsi1Metered = buildTemplateCarrierMetered(TEST_IMSI1)
@@ -205,58 +260,131 @@
templateCarrierImsi1Metered.assertDoesNotMatch(identCarrierWifiImsi1NonMetered)
}
+ // TODO: Refactor this test to reduce the line of codes.
@Test
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
// 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.
- 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
// cannot be determined.
- val templateUnknown =
- buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN)
+ val templateUnknownMetered =
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
+ METERED_YES)
- val identUmts = buildNetworkIdentity(
- mockContext, stateMobile, false, TelephonyManager.NETWORK_TYPE_UMTS)
- val identHsdpa = buildNetworkIdentity(
- mockContext, stateMobile, false, TelephonyManager.NETWORK_TYPE_HSDPA)
- val identLte = buildNetworkIdentity(
- mockContext, stateMobile, false, TelephonyManager.NETWORK_TYPE_LTE)
- val identCombined = buildNetworkIdentity(
- mockContext, stateMobile, false, SUBTYPE_COMBINED)
- val identImsi2 = buildNetworkIdentity(mockContext, buildMobileNetworkState(TEST_IMSI2),
- false, TelephonyManager.NETWORK_TYPE_UMTS)
+ val templateUmtsNonMetered = buildTemplateMobileWithRatType(null,
+ TelephonyManager.NETWORK_TYPE_UMTS, METERED_NO)
+ val templateAllNonMetered = buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL,
+ METERED_NO)
+ val templateUnknownNonMetered =
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
+ METERED_NO)
+
+ val identUmtsMetered = buildNetworkIdentity(
+ 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(
mockContext, buildWifiNetworkState(null, TEST_SSID1), true, 0)
- // Assert that identity with the same RAT matches.
- templateUmts.assertMatches(identUmts)
- templateAll.assertMatches(identUmts)
- templateUnknown.assertDoesNotMatch(identUmts)
+ val identUmtsNonMetered = buildNetworkIdentity(
+ mockContext, stateMobileImsi1NonMetered, false, TelephonyManager.NETWORK_TYPE_UMTS)
+ val identHsdpaNonMetered = buildNetworkIdentity(
+ 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.
- templateUmts.assertMatches(identHsdpa)
- templateAll.assertMatches(identHsdpa)
- templateUnknown.assertDoesNotMatch(identHsdpa)
+ // Verify metered template.
+ templateUmtsMetered.assertMatches(identHsdpaMetered)
+ 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
// NETWORK_TYPE_ALL.
- templateUmts.assertDoesNotMatch(identLte)
- templateAll.assertMatches(identLte)
- templateUnknown.assertDoesNotMatch(identLte)
+ // Verify metered template.
+ templateUmtsMetered.assertDoesNotMatch(identLteMetered)
+ 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
// and NETWORK_TYPE_UNKNOWN.
- templateUmts.assertDoesNotMatch(identCombined)
- templateAll.assertMatches(identCombined)
- templateUnknown.assertMatches(identCombined)
+ // Verify metered template.
+ templateUmtsMetered.assertDoesNotMatch(identCombinedMetered)
+ 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.
- templateUmts.assertMatches(identImsi2)
- templateAll.assertMatches(identImsi2)
- templateUnknown.assertDoesNotMatch(identImsi2)
+ // Verify metered template.
+ templateUmtsMetered.assertMatches(identImsi2UmtsMetered)
+ 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.
- templateUmts.assertDoesNotMatch(identWifi)
- templateAll.assertDoesNotMatch(identWifi)
- templateUnknown.assertDoesNotMatch(identWifi)
+ templateUmtsMetered.assertDoesNotMatch(identWifi)
+ templateUnknownMetered.assertDoesNotMatch(identWifi)
+ templateUmtsNonMetered.assertDoesNotMatch(identWifi)
+ templateUnknownNonMetered.assertDoesNotMatch(identWifi)
}
@Test
diff --git a/tests/unit/java/com/android/server/net/NetworkStatsCollectionTest.java b/tests/unit/java/com/android/server/net/NetworkStatsCollectionTest.java
index e771558..6b4ead5 100644
--- a/tests/unit/java/com/android/server/net/NetworkStatsCollectionTest.java
+++ b/tests/unit/java/com/android/server/net/NetworkStatsCollectionTest.java
@@ -98,14 +98,11 @@
@Before
public void setUp() throws Exception {
sOriginalClock = RecurrenceRule.sClock;
- // ignore any device overlay while testing
- NetworkTemplate.forceAllNetworkTypes();
}
@After
public void tearDown() throws Exception {
RecurrenceRule.sClock = sOriginalClock;
- NetworkTemplate.resetForceAllNetworkTypes();
}
private void setClock(Instant instant) {
@@ -123,7 +120,7 @@
// verify that history read correctly
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
- 636016770L, 709306L, 88038768L, 518836L, NetworkStatsAccess.Level.DEVICE);
+ 636014522L, 709291L, 88037144L, 518820L, NetworkStatsAccess.Level.DEVICE);
// now export into a unified format
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -137,7 +134,7 @@
// and read back into structure, verifying that totals are same
collection.read(new ByteArrayInputStream(bos.toByteArray()));
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
- 636016770L, 709306L, 88038768L, 518836L, NetworkStatsAccess.Level.DEVICE);
+ 636014522L, 709291L, 88037144L, 518820L, NetworkStatsAccess.Level.DEVICE);
}
@Test
@@ -151,7 +148,7 @@
// verify that history read correctly
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
- 637076152L, 711413L, 88343717L, 521022L, NetworkStatsAccess.Level.DEVICE);
+ 637073904L, 711398L, 88342093L, 521006L, NetworkStatsAccess.Level.DEVICE);
// now export into a unified format
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -165,7 +162,7 @@
// and read back into structure, verifying that totals are same
collection.read(new ByteArrayInputStream(bos.toByteArray()));
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
- 637076152L, 711413L, 88343717L, 521022L, NetworkStatsAccess.Level.DEVICE);
+ 637073904L, 711398L, 88342093L, 521006L, NetworkStatsAccess.Level.DEVICE);
}
@Test
diff --git a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java
index ab76460..5f3d499 100644
--- a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java
+++ b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java
@@ -657,11 +657,14 @@
@Test
public void testMobileStatsByRatType() throws Exception {
final NetworkTemplate template3g =
- buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS);
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS,
+ METERED_YES);
final NetworkTemplate template4g =
- buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_LTE);
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_LTE,
+ METERED_YES);
final NetworkTemplate template5g =
- buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_NR);
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_NR,
+ METERED_YES);
final NetworkStateSnapshot[] states =
new NetworkStateSnapshot[]{buildMobile3gState(IMSI_1)};
@@ -1478,11 +1481,13 @@
// 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.
final NetworkTemplate template3g =
- buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS);
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UMTS,
+ METERED_YES);
final NetworkTemplate templateUnknown =
- buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN);
+ buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
+ METERED_YES);
final NetworkTemplate templateAll =
- buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL);
+ buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL, METERED_YES);
final NetworkStateSnapshot[] states =
new NetworkStateSnapshot[]{buildMobile3gState(IMSI_1)};
@@ -1580,7 +1585,7 @@
// Verify mobile summary is not changed by the operation count.
final NetworkTemplate templateMobile =
- buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL);
+ buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL, METERED_YES);
final NetworkStats statsMobile = mSession.getSummaryForAllUid(
templateMobile, Long.MIN_VALUE, Long.MAX_VALUE, true);
assertValues(statsMobile, IFACE_ALL, UID_RED, SET_ALL, TAG_NONE, METERED_ALL, ROAMING_ALL,