Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 1 | page.title=Overview |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- |
Clay Murphy | 768b82a | 2013-11-12 11:32:41 -0800 | [diff] [blame] | 5 | Copyright 2013 The Android Open Source Project |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 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 |
| 20 | functionality relies on the xt_qtaguid module in the android-3.0 Linux |
| 21 | kernel (<code>kernel/net/netfilter/xt_qtaguid</code>). The socket tagging |
| 22 | functionality in the framework (<code>system/core/libcutils/qtaguid.c</code>) |
| 23 | relies mainly on the existence of <code>/proc/net/xt_qtaguid/ctrl</code> |
| 24 | interface 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>) |
| 26 | allows the functionality to set named quota limits and was extended to |
| 27 | support notifying userspace when certain limits are reached. Once the |
| 28 | quota limit is reached, the <code>quota2</code> module discards all subsequent |
| 29 | network traffic. The framework can also specify additional rules to |
| 30 | restrict background data traffic for an application (refer to |
| 31 | <code>com.android.server.NetworkManagementSocketTagger.setKernelCounterSet</code> |
| 32 | and |
| 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 |
| 36 | per-socket basis for every application using the unique UID of the |
| 37 | owning application. There are two tag components associated with any |
| 38 | socket in the system. The first is the UID which uniquely identifies |
| 39 | the application which is responsible for the data transfer (Linux |
| 40 | allows the ability to ascribe the ownership of each network socket to |
| 41 | the UID of the calling application). The second tag component is used |
| 42 | to support additional characterization of the traffic into application |
| 43 | developer specified categories. Using these application level tags, an |
| 44 | application can profile the traffic into several sub-categories.</p> |
| 45 | <p>In the case of applications that provide network data transfer as a |
| 46 | service, such as the download manager, media streaming service, etc, |
| 47 | it is possible to attribute the ownership of the network data transfer |
| 48 | to the UID of the requesting application using the |
| 49 | <code>TrafficStats.setThreadStatsUid()</code> function call. The caller must hold |
| 50 | the “<code>android.permission.MODIFY_NETWORK_ACCOUNTING</code>” permission to |
| 51 | re-assign the ownership of the network traffic.</p> |