1page.title=Network Interface Statistics Overview 2@jd:body 3 4<!-- 5 Copyright 2013 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18--> 19<p>In Android 4.0, statistics reported by Linux network interfaces are 20recorded over time, and are used to enforce network quota limits, 21render user-visible charts, and more.</p> 22<p>Each network device driver (Wi-Fi included) must follow the standard 23kernel device lifecycle, and return correct statistics through 24<code>dev_get_stats()</code>. In particular, statistics returned must remain 25strictly monotonic while the interface is active. Drivers may reset 26statistics only after successfully completing an <code>unregister_netdev()</code> 27or the equivalent that generates a <code>NETDEV_UNREGISTER</code> event for 28callbacks registered with <code>register_netdevice_notifier()</code> / 29<code>register_inetaddr_notifier()</code> / <code>register_inet6addr_notifier()</code>.</p> 30<p>Mobile operators typically measure data usage at the Internet layer 31(IP). To match this approach in Android 4.0, we rely on the fact that 32for the kernel devices we care about the <code>rx_bytes</code> and <code>tx_bytes</code> 33values returned by <code>dev_get_stats()</code> return exactly the Internet layer 34(<code>IP</code>) bytes transferred. But we understand that for other devices it 35might not be the case. For now, the feature relies on this 36peculiarity. New drivers should have that property also, and the 37<code>dev_get_stats()</code> values must not include any encapsulation overhead 38of lower network layers (such as Ethernet headers), and should 39preferably not include other traffic (such as ARP) unless it is 40negligible.</p> 41<p>The Android framework only collects statistics from network interfaces 42associated with a <code>NetworkStateTracker</code> in <code>ConnectivityService</code>. This 43enables the framework to concretely identify each network interface, 44including its type (such as <code>TYPE_MOBILE</code> or <code>TYPE_WIFI</code>) and 45subscriber identity (such as IMSI). All network interfaces used to 46route data should be represented by a <code>NetworkStateTracker</code> so that 47statistics can be accounted correctly.</p> 48