1page.title=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>The per-application/delegated data usage monitoring and tracking 20functionality relies on the xt_qtaguid module in the android-3.0 Linux 21kernel (<code>kernel/net/netfilter/xt_qtaguid</code>). The socket tagging 22functionality in the framework (<code>system/core/libcutils/qtaguid.c</code>) 23relies mainly on the existence of <code>/proc/net/xt_qtaguid/ctrl</code> 24interface exported by the <code>xt_qtaguid</code> kernel module.</p> 25<p>The <code>quota2</code> netfilter module (originally part of <code>xtables-addons</code>) 26allows the functionality to set named quota limits and was extended to 27support notifying userspace when certain limits are reached. Once the 28quota limit is reached, the <code>quota2</code> module discards all subsequent 29network traffic. The framework can also specify additional rules to 30restrict background data traffic for an application (refer to 31<code>com.android.server.NetworkManagementSocketTagger.setKernelCounterSet</code> 32and 33<code>android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND</code>).</p> 34<h1 id="how-does-it-work">How does it work?</h1> 35<p>The <code>qtaguid</code> netfilter module tracks the network traffic on a 36per-socket basis for every application using the unique UID of the 37owning application. There are two tag components associated with any 38socket in the system. The first is the UID which uniquely identifies 39the application which is responsible for the data transfer (Linux 40allows the ability to ascribe the ownership of each network socket to 41the UID of the calling application). The second tag component is used 42to support additional characterization of the traffic into application 43developer specified categories. Using these application level tags, an 44application can profile the traffic into several sub-categories.</p> 45<p>In the case of applications that provide network data transfer as a 46service, such as the download manager, media streaming service, etc, 47it is possible to attribute the ownership of the network data transfer 48to the UID of the requesting application using the 49<code>TrafficStats.setThreadStatsUid()</code> function call. The caller must hold 50the “<code>android.permission.MODIFY_NETWORK_ACCOUNTING</code>” permission to 51re-assign the ownership of the network traffic.</p> 52