Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
5d412489
Commit
5d412489
authored
4 years ago
by
Junyu Lai
Committed by
Gerrit Code Review
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Add test for increment operation count on non-default network"
parents
a9b2fddb
decbf9f6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
+51
-6
51 additions, 6 deletions
.../java/com/android/server/net/NetworkStatsServiceTest.java
with
51 additions
and
6 deletions
tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
+
51
−
6
View file @
5d412489
...
...
@@ -23,6 +23,7 @@ import static android.net.ConnectivityManager.TYPE_VPN;
import
static
android
.
net
.
ConnectivityManager
.
TYPE_WIFI
;
import
static
android
.
net
.
ConnectivityManager
.
TYPE_WIMAX
;
import
static
android
.
net
.
NetworkStats
.
DEFAULT_NETWORK_ALL
;
import
static
android
.
net
.
NetworkStats
.
DEFAULT_NETWORK_NO
;
import
static
android
.
net
.
NetworkStats
.
DEFAULT_NETWORK_YES
;
import
static
android
.
net
.
NetworkStats
.
IFACE_ALL
;
import
static
android
.
net
.
NetworkStats
.
INTERFACES_ALL
;
...
...
@@ -917,7 +918,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
public
void
testMetered
()
throws
Exception
{
// pretend that network comes online
expectDefaultSettings
();
NetworkState
[]
states
=
new
NetworkState
[]
{
buildWifiState
(
true
/* isMetered */
)};
NetworkState
[]
states
=
new
NetworkState
[]
{
buildWifiState
(
true
/* isMetered */
,
TEST_IFACE
)};
expectNetworkStatsSummary
(
buildEmptyStats
());
expectNetworkStatsUidDetail
(
buildEmptyStats
());
...
...
@@ -1146,7 +1148,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
public
void
testStatsProviderUpdateStats
()
throws
Exception
{
// Pretend that network comes online.
expectDefaultSettings
();
final
NetworkState
[]
states
=
new
NetworkState
[]{
buildWifiState
(
true
/* isMetered */
)};
final
NetworkState
[]
states
=
new
NetworkState
[]{
buildWifiState
(
true
/* isMetered */
,
TEST_IFACE
)};
expectNetworkStatsSummary
(
buildEmptyStats
());
expectNetworkStatsUidDetail
(
buildEmptyStats
());
...
...
@@ -1206,7 +1209,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
public
void
testStatsProviderSetAlert
()
throws
Exception
{
// Pretend that network comes online.
expectDefaultSettings
();
NetworkState
[]
states
=
new
NetworkState
[]{
buildWifiState
(
true
/* isMetered */
)};
NetworkState
[]
states
=
new
NetworkState
[]{
buildWifiState
(
true
/* isMetered */
,
TEST_IFACE
)};
mService
.
forceUpdateIfaces
(
NETWORKS_WIFI
,
states
,
getActiveIface
(
states
),
new
VpnInfo
[
0
]);
// Register custom provider and retrieve callback.
...
...
@@ -1319,6 +1323,47 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
assertUidTotal
(
templateAll
,
UID_RED
,
22L
+
35L
,
26L
+
29L
,
19L
+
7L
,
5L
+
11L
,
1
);
}
@Test
public
void
testOperationCount_nonDefault_traffic
()
throws
Exception
{
// Pretend mobile network comes online, but wifi is the default network.
expectDefaultSettings
();
NetworkState
[]
states
=
new
NetworkState
[]{
buildWifiState
(
true
/*isMetered*/
,
TEST_IFACE2
),
buildMobile3gState
(
IMSI_1
)};
expectNetworkStatsUidDetail
(
buildEmptyStats
());
mService
.
forceUpdateIfaces
(
NETWORKS_WIFI
,
states
,
getActiveIface
(
states
),
new
VpnInfo
[
0
]);
// Create some traffic on mobile network.
incrementCurrentTime
(
HOUR_IN_MILLIS
);
expectNetworkStatsUidDetail
(
new
NetworkStats
(
getElapsedRealtime
(),
4
)
.
insertEntry
(
TEST_IFACE
,
UID_RED
,
SET_DEFAULT
,
TAG_NONE
,
METERED_NO
,
ROAMING_NO
,
DEFAULT_NETWORK_NO
,
2L
,
1L
,
3L
,
4L
,
0L
)
.
insertEntry
(
TEST_IFACE
,
UID_RED
,
SET_DEFAULT
,
TAG_NONE
,
METERED_NO
,
ROAMING_NO
,
DEFAULT_NETWORK_YES
,
1L
,
3L
,
2L
,
1L
,
0L
)
.
insertEntry
(
TEST_IFACE
,
UID_RED
,
SET_DEFAULT
,
0xF00D
,
5L
,
4L
,
1L
,
4L
,
0L
));
// Increment operation count, which must have a specific tag.
mService
.
incrementOperationCount
(
UID_RED
,
0xF00D
,
2
);
forcePollAndWaitForIdle
();
// Verify mobile summary is not changed by the operation count.
final
NetworkTemplate
templateMobile
=
buildTemplateMobileWithRatType
(
null
,
NETWORK_TYPE_ALL
);
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
,
DEFAULT_NETWORK_ALL
,
3L
,
4L
,
5L
,
5L
,
0
);
assertValues
(
statsMobile
,
IFACE_ALL
,
UID_RED
,
SET_ALL
,
0xF00D
,
METERED_ALL
,
ROAMING_ALL
,
DEFAULT_NETWORK_ALL
,
5L
,
4L
,
1L
,
4L
,
0
);
// Verify the operation count is blamed onto the default network.
// TODO: Blame onto the default network is not very reasonable. Consider blame onto the
// network that generates the traffic.
final
NetworkTemplate
templateWifi
=
buildTemplateWifiWildcard
();
final
NetworkStats
statsWifi
=
mSession
.
getSummaryForAllUid
(
templateWifi
,
Long
.
MIN_VALUE
,
Long
.
MAX_VALUE
,
true
);
assertValues
(
statsWifi
,
IFACE_ALL
,
UID_RED
,
SET_ALL
,
0xF00D
,
METERED_ALL
,
ROAMING_ALL
,
DEFAULT_NETWORK_ALL
,
0L
,
0L
,
0L
,
0L
,
2
);
}
private
static
File
getBaseDir
(
File
statsDir
)
{
File
baseDir
=
new
File
(
statsDir
,
"netstats"
);
baseDir
.
mkdirs
();
...
...
@@ -1446,14 +1491,14 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
}
private
static
NetworkState
buildWifiState
()
{
return
buildWifiState
(
false
);
return
buildWifiState
(
false
,
TEST_IFACE
);
}
private
static
NetworkState
buildWifiState
(
boolean
isMetered
)
{
private
static
NetworkState
buildWifiState
(
boolean
isMetered
,
@NonNull
String
iface
)
{
final
NetworkInfo
info
=
new
NetworkInfo
(
TYPE_WIFI
,
0
,
null
,
null
);
info
.
setDetailedState
(
DetailedState
.
CONNECTED
,
null
,
null
);
final
LinkProperties
prop
=
new
LinkProperties
();
prop
.
setInterfaceName
(
TEST_IFACE
);
prop
.
setInterfaceName
(
iface
);
final
NetworkCapabilities
capabilities
=
new
NetworkCapabilities
();
capabilities
.
setCapability
(
NetworkCapabilities
.
NET_CAPABILITY_NOT_METERED
,
!
isMetered
);
capabilities
.
setCapability
(
NetworkCapabilities
.
NET_CAPABILITY_NOT_ROAMING
,
true
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment