Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Network interface statistics overview
Stay organized with collections
Save and categorize content based on your preferences.
In Android 4.0, statistics reported by Linux network interfaces are
recorded over time, and are used to enforce network quota limits,
render user-visible charts, and more.
Each network device driver (Wi-Fi included) must follow the standard
kernel device lifecycle, and return correct statistics through
dev_get_stats()
. In particular, statistics returned must remain
strictly monotonic while the interface is active. Drivers may reset
statistics only after successfully completing an unregister_netdev()
or the equivalent that generates a NETDEV_UNREGISTER
event for
callbacks registered with register_netdevice_notifier()
/
register_inetaddr_notifier()
/ register_inet6addr_notifier()
.
Mobile operators typically measure data usage at the Internet layer
(IP). To match this approach in Android 4.0, we rely on the fact that
for the kernel devices we care about the rx_bytes
and tx_bytes
values returned by dev_get_stats()
return exactly the Internet layer
(IP
) bytes transferred. But we understand that for other devices it
might not be the case. For now, the feature relies on this
peculiarity. New drivers should have that property also, and the
dev_get_stats()
values must not include any encapsulation overhead
of lower network layers (such as Ethernet headers), and should
preferably not include other traffic (such as ARP) unless it is
negligible.
The Android framework only collects statistics from network interfaces
associated with a NetworkStateTracker
in ConnectivityService
. This
enables the framework to concretely identify each network interface,
including its type (such as TYPE_MOBILE
or TYPE_WIFI
) and
subscriber identity (such as IMSI). All network interfaces used to
route data should be represented by a NetworkStateTracker
so that
statistics can be accounted correctly.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-08-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-26 UTC."],[],[],null,["# Network interface statistics overview\n\nIn Android 4.0, statistics reported by Linux network interfaces are\nrecorded over time, and are used to enforce network quota limits,\nrender user-visible charts, and more.\n\nEach network device driver (Wi-Fi included) must follow the standard\nkernel device lifecycle, and return correct statistics through\n`dev_get_stats()`. In particular, statistics returned must remain\nstrictly monotonic while the interface is active. Drivers may reset\nstatistics only after successfully completing an `unregister_netdev()`\nor the equivalent that generates a `NETDEV_UNREGISTER` event for\ncallbacks registered with `register_netdevice_notifier()` /\n`register_inetaddr_notifier()` / `register_inet6addr_notifier()`.\n\nMobile operators typically measure data usage at the Internet layer\n(IP). To match this approach in Android 4.0, we rely on the fact that\nfor the kernel devices we care about the `rx_bytes` and `tx_bytes`\nvalues returned by `dev_get_stats()` return exactly the Internet layer\n(`IP`) bytes transferred. But we understand that for other devices it\nmight not be the case. For now, the feature relies on this\npeculiarity. New drivers should have that property also, and the\n`dev_get_stats()` values must not include any encapsulation overhead\nof lower network layers (such as Ethernet headers), and should\npreferably not include other traffic (such as ARP) unless it is\nnegligible.\n\nThe Android framework only collects statistics from network interfaces\nassociated with a `NetworkStateTracker` in `ConnectivityService`. This\nenables the framework to concretely identify each network interface,\nincluding its type (such as `TYPE_MOBILE` or `TYPE_WIFI`) and\nsubscriber identity (such as IMSI). All network interfaces used to\nroute data should be represented by a `NetworkStateTracker` so that\nstatistics can be accounted correctly."]]