TrafficStats API are being used for querying realtime network
statistics for years. However, on certain devices, some network
traffic are produced by hardware components and not be
able to seen by kernel counters.
Thus, include statistics for those missing network traffic is
necessary. Note that the included statistics might be stale
since polling newest stats from hardware might impact system
health and not suitable for TrafficStats API use cases.
Test: atest FrameworksNetTests TetheringTests
Bug: 16229221
Change-Id: I6741c41cb5145ca8748f9b083b9c15e7e2735681
It is safe because these mandatory algorithms are already required
before new algorithms are added
It is also a quick fix to unblock b/171279612, whose root cause is
the device first sdk is wrong
Bug: 171279612
Test: atest CtsNetTestCases:IpSecManagerTest
Change-Id: I5b9d85b2bc8f13f54467c97160d138a4628265f7
This CL adds new mandatory IPsec algorithms and allows
OEM to enable them on old devices using resource overlay
Bug: 161716062
Test: FrameworksNetTests:IpSecAlgorithmTest
Change-Id: Ib827b05ea27dbe61b14ad236e858f825293ed994
Currently, getAllCollapsedRatTypes is used to retrieve
all RAT types which will be recorded into NetworkStatsService.
However, there is a missing part that 5G NSA virtual RAT type
is not added into this list. This makes callers such as statsd
do not aware of 5G NSA RAT type and missed to collect data
usage of it.
Test: atest NetworkStatsSubscriptionsMonitorTest#test5g
Test: adb shell cmd stats pull-source 10082
Test: ./out/host/linux-x86/bin/statsd_testdrive 10082
Test: atest UidAtomTests#testMobileBytesTransfer \
UidAtomTests#testMobileBytesTransferByFgBg \
UidAtomTests#testDataUsageBytesTransfer
Bug: 163021464
Change-Id: I0faeda20f0506a48ac1131b234c5fc40d95dfbe0
Merged-In: I0faeda20f0506a48ac1131b234c5fc40d95dfbe0
(cherry-picked from ag/12355984)
This is a partial cherry-pick of ag/10293594
Test: TH
Bug: 129082217
Merged-In: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
Change-Id: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
Avoid recording negative data by doing integer-based
math as much as possible, but switch to double-based
math if we detect that we'd end up causing an overflow.
Test :
- Builds, Boots
- High data throughput scenarios
- NetworkStatsHistoryTest, NetworkStatsCollectionTest,
NetworkStatsTest
Bug: 119527458
Change-Id: I55d4aa649bea3ae201ad513074ff2b71cb918dad
This is sent from the system server, and the system server doesn't like
being blocked by apps.
Change-Id: I603be3038831974baf1dc392ff0d062e9db91b63
Test: atest CtsTetheringTest
Bug: 160389275
In Android 10 additional restrictions were required to access the
subscriberId. The NetworkStatsManager has several methods that accept
a subscriberId of the mobile network for which usage should be queried.
This commit updates the docs for these methods to reference the new
access restrictions and offer null as an option to obtain the usage
for all mobile networks.
Fixes: 157871064
Test: m docs
Change-Id: I95c730c9418fced6312eb3ba4e0d69e6299f3ded
This should no longer be needed after all the cleanups.
Test: atest NetworkStatsTest NetworkStatsFactoryTest
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I289d935f84b616ed857ef4c5a7427d57c282d00c
Merged-In: I289d935f84b616ed857ef4c5a7427d57c282d00c
This is due to the previous addition of the ip6tables raw PREROUTING
drop rules for incoming ipv6 clat traffic pre-translation to ipv4.
Since we no longer double account, we no longer need these fixups.
Test: atest bpf_module_test clatd_test libbpf_android_test libnetdbpf_test
netd_integration_test netd_unit_test netdutils_test
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia171b7797cdc99367064d0649bf1293c71579941
Merged-In: Ia171b7797cdc99367064d0649bf1293c71579941
This should no longer be needed after all the cleanups.
Test: atest NetworkStatsTest NetworkStatsFactoryTest
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I289d935f84b616ed857ef4c5a7427d57c282d00c
This is due to the previous addition of the ip6tables raw PREROUTING
drop rules for incoming ipv6 clat traffic pre-translation to ipv4.
Since we no longer double account, we no longer need these fixups.
Test: atest bpf_module_test clatd_test libbpf_android_test libnetdbpf_test
netd_integration_test netd_unit_test netdutils_test
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia171b7797cdc99367064d0649bf1293c71579941
The NetworkStatsService.getUidStats() currently doesn't have any
permission check to make sure unpriviledged apps cannot read the stats
of a different uid. It will protentially have security problem since
apps with ACCESS_NETWORK_STATS permission can directly calling into
NetworkStatsService and bypass the check in TrafficStats. Move the uid
check from TrafficStats to NetworkStatsService to fix the problem.
Bug: 129151407
Test: atest AppSecurityTests#testAppFailAccessPrivateData_full
Test: atest AppSecurityTests#testAppFailAccessPrivateData_instant
Test: atest android.app.usage.cts.NetworkUsageStatsTest
Test: atest NetworkStatsBinderTest
Change-Id: Iae85676cfe5f114da69ec278afc2c904bc907234
In current design, entries with zeros are preserved after
addition/subtraction. These entries are not very useful
and lead to difficulty of verifying the result of
addition/subtraction.
However, change the behavior in the original NetworkStats
is considered risky in current stage.
Thus, this change provide a function that could remove these
empty entries in tests.
Test: atest FrameworksNetTests
Bug: 152827872
Bug: 150644692
Change-Id: I40a76935d55712b8083ee1e17e137a8a4ef5e029
Merged-In: I40a76935d55712b8083ee1e17e137a8a4ef5e029
(cherry picked from commit 6c7bef3064dbe949b7b213036b8e70c125ddd343)
In current design, entries with zeros are preserved after
addition/subtraction. These entries are not very useful
and lead to difficulty of verifying the result of
addition/subtraction.
However, change the behavior in the original NetworkStats
is considered risky in current stage.
Thus, this change provide a function that could remove these
empty entries in tests.
Test: atest FrameworksNetTests
Bug: 152827872
Bug: 150644692
Change-Id: I40a76935d55712b8083ee1e17e137a8a4ef5e029
This CL adds a setIncludeTestInterfaces method to EthernetManager
that, when called, causes the Ethernet service to recognize and
manage test interfaces created by TestNetworkManager.
Bug: 150644681
Test: Tested by EthernetTetheringTest in same topic
Change-Id: I86eef7a93267f800dbfc8eafd307effa76a344ca
Merged-In: I86eef7a93267f800dbfc8eafd307effa76a344ca
(cherry picked from commit 3410fb0aa92bbd4f9d7dc031e89f6f528ff34245)
Note that enabling/disabling would not take effect until device
reboot. This will be addressed in follow-up patch.
Test: 1. atest NetworkStatsServieTest SettingsBackupTest
2. adb shell settings put global netstats_combine_subtype_enabled 1|0
Bug: 146415925
Change-Id: Ic94da540afa479ed18f1b6fbda4ae3216c37476b
Merged-In: Ic94da540afa479ed18f1b6fbda4ae3216c37476b
(cherry picked from commit 1227f32c58 and
fix merge conflict in SettingsBackupTest)
Switch on the recording in device side. Metrics will be
collected in follow-up patches which can be independently
enabled/disabled.
This change also fix the fail in NetworkStatsCollectionTest
which caused by enabling this feature, where the rounding
problem happened when records are distributed into smaller
buckets and categorized into more NetworkIdentity.
Test: atest FrameworksNetTests
Bug: 129082217
Change-Id: If330e85330a4ff713dd420c98d42fa741eabd90a
Merged-In: If330e85330a4ff713dd420c98d42fa741eabd90a
(cherry picked from commit 8413d3c1af)
Add a NetworkTemplate build function that allows user to specify
subType. NetworkStats corresponding to the same group would
be retrieved.
Test: atest FrameworksNetTests
Bug: 129082217
Change-Id: Ie2d229be0b6bd239f799989c070475c73a096d71
Merged-In: Ie2d229be0b6bd239f799989c070475c73a096d71
(cherry picked from commit 82d9f7cbb0)
Previously network stats could be recorded by different rat type.
However, the feature was disabled by ag/173504 since rat type
frequently flapping between HSPA+ and UMTS.
Given that this feature might be useful for collecting metrics,
re-implement it based on current architecture and reduce the
overhead introduced by frequently flapping by:
1. only react when rat type changes between 2G/3G/4G/5G.
2. reduce the number of records by only recording a subset
of rat type that represented for a given network class.
3. enforce 1 second rate limit if flapping too much.
Note that the feature is still disabled but will be enabled
in follow-up patches.
Test: manual test
Bug: 129082217
Change-Id: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
Merged-In: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
(cherry picked from commit 96105f0d21)
Note that enabling/disabling would not take effect until device
reboot. This will be addressed in follow-up patch.
Test: 1. atest NetworkStatsServieTest SettingsBackupTest
2. adb shell settings put global netstats_combine_subtype_enabled 1|0
Bug: 146415925
Change-Id: Ic94da540afa479ed18f1b6fbda4ae3216c37476b
Merged-In: Ic94da540afa479ed18f1b6fbda4ae3216c37476b
(cherry picked from commit c4f77ac90bf2e48a655ad19b162fe74a23bf3fb0)
This CL adds a setIncludeTestInterfaces method to EthernetManager
that, when called, causes the Ethernet service to recognize and
manage test interfaces created by TestNetworkManager.
Bug: 150644681
Test: Tested by EthernetTetheringTest in same topic
Change-Id: I86eef7a93267f800dbfc8eafd307effa76a344ca
Switch on the recording in device side. Metrics will be
collected in follow-up patches which can be independently
enabled/disabled.
This change also fix the fail in NetworkStatsCollectionTest
which caused by enabling this feature, where the rounding
problem happened when records are distributed into smaller
buckets and categorized into more NetworkIdentity.
Test: atest FrameworksNetTests
Bug: 129082217
Change-Id: If330e85330a4ff713dd420c98d42fa741eabd90a
Merged-In: If330e85330a4ff713dd420c98d42fa741eabd90a
(cherry picked from commit 2d4fa2c0fae8c2d79a25093d9f732a33c2f91dd4)
Add a NetworkTemplate build function that allows user to specify
subType. NetworkStats corresponding to the same group would
be retrieved.
Test: atest FrameworksNetTests
Bug: 129082217
Change-Id: Ie2d229be0b6bd239f799989c070475c73a096d71
Merged-In: Ie2d229be0b6bd239f799989c070475c73a096d71
(cherry picked from commit e19045cc4ab1f2cd133ce5dc0c3a38e3275417ad)
Previously network stats could be recorded by different rat type.
However, the feature was disabled by ag/173504 since rat type
frequently flapping between HSPA+ and UMTS.
Given that this feature might be useful for collecting metrics,
re-implement it based on current architecture and reduce the
overhead introduced by frequently flapping by:
1. only react when rat type changes between 2G/3G/4G/5G.
2. reduce the number of records by only recording a subset
of rat type that represented for a given network class.
3. enforce 1 second rate limit if flapping too much.
Note that the feature is still disabled but will be enabled
in follow-up patches.
Test: manual test
Bug: 129082217
Change-Id: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
Merged-In: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
(cherry picked from commit 15ab452e7e3f00289fbedbdb86c512ad560dda7e)
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.
Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record conditionally,
name them addEntry.
addValues -> addEntry
Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Fix: 148895143
Change-Id: I9495a198cf247e6c79100f7ac1edcea370b071de
Merged-In: I9495a198cf247e6c79100f7ac1edcea370b071de
(cherry picked from ag/10700816)
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.
Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record conditionally,
name them addEntry.
addValues -> addEntry
Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Fix: 148895143
Change-Id: I9495a198cf247e6c79100f7ac1edcea370b071de
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.
Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record unconditionally,
name them insertEntry.
setIfaceValues -> insertEntry
addEntry -> insertEntry
Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: I801ddc49e283a254b9586700c9b597c0adb0d459
Merged-In: I801ddc49e283a254b9586700c9b597c0adb0d459
(cherry picked from aosp/1256352)
This change add several javadoc for NetworkStats and its Entry
class. Also remove IFACE_ALL constant accordlingly.
Test: atest FrameworkNetTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: Id1b8f41be79f847ad73197ff0e18258b6ee8a730
Merged-In: Id1b8f41be79f847ad73197ff0e18258b6ee8a730
(cherry picked from aosp/1256351)
Currently, registerNetworkStatsProvider requires the
UPDATE_DEVICE_STATS permission. This is a privileged permission
so it can be granted to preinstalled apps. Thus, apps like
GmsCore, or preinstalled apps will be able to update network stats.
This change checks for a new permission that would only allow
signature apps to declare that. Also check
MAINLINE_NETWORK_STACK permission to allow NetworkStack process
to use it.
Test: adb shell dumpsys netstats
Test: atest FrameworksNetTests
Bug: 149652079
Change-Id: Iaecbf10a7610461bd52e315659006c7332c416e6
Merged-In: Iaecbf10a7610461bd52e315659006c7332c416e6
Merged-In: Idfebd0a1988c3dcfd812d87e30f6a2034d6fbf6b
(cherry picked from commit e9e8d8f9ff096c1723eba1d74b17bb7cade7f23b)
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.
Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record unconditionally,
name them insertEntry.
setIfaceValues -> insertEntry
addEntry -> insertEntry
Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: I801ddc49e283a254b9586700c9b597c0adb0d459
This change add several javadoc for NetworkStats and its Entry
class. Also remove IFACE_ALL constant accordlingly.
Test: atest FrameworkNetTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: Id1b8f41be79f847ad73197ff0e18258b6ee8a730
The method requires NETWORK_STACK or MAINLINE_NETWORK_STACK permissions,
but the annotation was missing.
Test: m
Fixes: 150877670
Merged-In: I2af74cbcfa642f05f5e7bf85b2a8e8c38595f6ca
(cherry picked from commit e45d3ff849695977cb063cc59550c505b220bd6c)
Change-Id: Ia215b74df99ae60be2e380917be68a272d658ef4
The method requires NETWORK_STACK or MAINLINE_NETWORK_STACK permissions,
but the annotation was missing.
Test: m
Fixes: 150877670
Change-Id: I2af74cbcfa642f05f5e7bf85b2a8e8c38595f6ca
This change fix two things:
1. Handle ethernet callback in internal thread to avoid crash. IpServer
should be created from tethering thread, otherwise mIpNeighborMonitor of
IpServer would throw
IllegalStateException("start() called from off-thread")
2. Ethernet tethering request may be duplicated if multiple
startTethering is called but no stopTethering
Bug: 130840861
Bug: 148824036
Test: ON/OFF ethernet tehtering manually
atest TetheringTests
Change-Id: Ibd3ea6bc6751bd65647ff381f9b0124bc3395c09
Merged-In: I7c5127e96d80d077735010d2e62c7227805ccb10
Merged-In: Ibd3ea6bc6751bd65647ff381f9b0124bc3395c09
(cherry picked from commit 72702b979654234c18045f04270040056a74cf90)