blob: d21e0a3b2bc66967ab71d3f746cc76e48c83fd79 [file] [log] [blame] [view]
Ashish Sharmae0cec462012-02-28 17:43:58 -08001<!--
2 Copyright 2012 The Android Open Source Project
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
16
17# Overview #
18
19The per-application/delegated data usage monitoring and tracking
20functionality relies on the xt_qtaguid module in the android-3.0 Linux
21kernel (`kernel/net/netfilter/xt_qtaguid`). The socket tagging
22functionality in the framework (`system/core/libcutils/qtaguid.c`)
23relies mainly on the existence of `/proc/net/xt_qtaguid/ctrl`
24interface exported by the `xt_qtaguid` kernel module.
25
26The `quota2` netfilter module (originally part of `xtables-addons`)
27allows the functionality to set named quota limits and was extended to
28support notifying userspace when certain limits are reached. Once the
29quota limit is reached, the `quota2` module discards all subsequent
30network traffic. The framework can also specify additional rules to
31restrict background data traffic for an application (refer to
32`com.android.server.NetworkManagementSocketTagger.setKernelCounterSet`
33and
34`android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND`).
35
36# How does it work? #
37
38The `qtaguid` netfilter module tracks the network traffic on a
39per-socket basis for every application using the unique UID of the
40owning application.  There are two tag components associated with any
41socket in the system. The first is the UID which uniquely identifies
42the application which is responsible for the data transfer (Linux
43allows the ability to ascribe the ownership of each network socket to
44the UID of the calling application). The second tag component is used
45to support additional characterization of the traffic into application
46developer specified categories. Using these application level tags, an
47application can profile the traffic into several sub-categories.
48
49In the case of applications that provide network data transfer as a
50service, such as the download manager, media streaming service, etc,
51it is possible to attribute the ownership of the network data transfer
52to the UID of the requesting application using the
53`TrafficStats.setThreadStatsUid()` function call. The caller must hold
54the “`android.permission.MODIFY_NETWORK_ACCOUNTING`” permission to
55re-assign the ownership of the network traffic.