앱별 및 위임된 데이터 사용량 모니터링 및 추적 기능은 Android-3.0 Linux 커널 (kernel/net/netfilter/xt_qtaguid)의 xt_qtaguid 모듈에 의존합니다. 프레임워크 (system/core/libcutils/qtaguid.c)의 소켓 태그하기 기능은 xt_qtaguid 커널 모듈에서 내보낸 /proc/net/xt_qtaguid/ctrl 인터페이스의 존재에 주로 의존합니다.
quota2 넷필터 모듈(원래 xtables-addons 일부)은 명명된 할당량 한도를 설정하는 기능을 허용하고 특정 한도에 도달하면 사용자 공간에 알리는 지원으로 확장되었습니다. 할당량 한도에 도달하면 quota2 모듈은 모든 후속 네트워크 트래픽을 삭제합니다. 프레임워크는 추가 규칙을 지정하여 앱의 백그라운드 데이터 트래픽을 제한할 수도 있습니다 (com.android.server.NetworkManagementSocketTagger.setKernelCounterSet 및 android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND 참고).
기본 원리
qtaguid 넷필터 모듈은 소유 앱의 고유 UID를 사용하여 모든 앱의 소켓별로 네트워크 트래픽을 추적합니다. 시스템의 모든 소켓에는 두 개의 태그 구성요소가 연결되어 있습니다. 첫 번째 태그 구성요소는 데이터 전송을 담당하는 앱을 고유하게 식별하는 UID입니다. Linux에서는 각 네트워크 소켓의 소유권이 호출 앱의 UID에 있다고 지정할 수 있습니다. 두 번째 태그 구성요소는 앱 개발자가 지정한 카테고리로 트래픽의 특징을 추가로 지정하는 데 사용됩니다. 이러한 앱 수준 태그를 사용하면 앱이 트래픽을 여러 하위 카테고리로 프로파일링할 수 있습니다.
다운로드 관리자, 미디어 스트리밍 서비스 등 네트워크 데이터 전송을 서비스로 제공하는 앱의 경우 TrafficStats.setThreadStatsUid() 함수 호출을 사용하여 네트워크 데이터 전송의 소유권이 요청하는 앱의 UID에 있다고 지정할 수 있습니다. 호출자는 네트워크 트래픽의 소유권을 다시 할당하는 'android.permission.MODIFY_NETWORK_ACCOUNTING' 권한을 보유해야 합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-06-12(UTC)
[null,null,["최종 업데이트: 2025-06-12(UTC)"],[],[],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."]]