[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-12 (世界標準時間)。"],[],[],null,["# Kernel overview\n\nThe per-app and delegated data usage monitoring and tracking\nfunctionality relies on the xt_qtaguid module in the android-3.0 Linux\nkernel (`kernel/net/netfilter/xt_qtaguid`). The socket tagging\nfunctionality in the framework (`system/core/libcutils/qtaguid.c`)\nrelies mainly on the existence of `/proc/net/xt_qtaguid/ctrl`\ninterface exported by the `xt_qtaguid` kernel module.\n| **Note:** Support for `xt_qtaguid` will be phased out starting in the Android 9 release. See [eBPF Traffic\n| Monitoring](/docs/core/data/ebpf-traffic-monitor) for more information.\n\nThe `quota2` netfilter module (originally part of `xtables-addons`)\nallows the functionality to set named quota limits and was extended to\nsupport notifying userspace when certain limits are reached. Once the\nquota limit is reached, the `quota2` module discards all subsequent\nnetwork traffic. The framework can also specify additional rules to\nrestrict background data traffic for an app (refer to\n`com.android.server.NetworkManagementSocketTagger.setKernelCounterSet`\nand\n`android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND`).\n\nHow does it work?\n-----------------\n\nThe `qtaguid` netfilter module tracks the network traffic on a\nper-socket basis for every app using the unique UID of the\nowning app. There are two tag components associated with any\nsocket in the system. The first is the UID which uniquely identifies\nthe app which is responsible for the data transfer (Linux\nallows the ability to ascribe the ownership of each network socket to\nthe UID of the calling app). The second tag component is used\nto support additional characterization of the traffic into app\ndeveloper specified categories. Using these app level tags, an\napp can profile the traffic into several sub-categories.\n\nIn the case of apps that provide network data transfer as a\nservice, such as the download manager, media streaming service, etc,\nit is possible to attribute the ownership of the network data transfer\nto the UID of the requesting app using the\n`TrafficStats.setThreadStatsUid()` function call. The caller must hold\nthe \"`android.permission.MODIFY_NETWORK_ACCOUNTING`\" permission to\nre-assign the ownership of the network traffic."]]