自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
网络栈
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
网络堆栈是一个可更新的 Mainline 模块,可以确保 Android 能够适应不断完善的网络标准,并支持与新实现进行互操作。例如,通过对强制门户检测和登录代码的更新,Android 能够及时了解不断变化的强制门户模型;通过对 APF 的更新,Android 能够在新型数据包变得常见的同时节省 Wi-Fi 耗电量。
包含的组件
网络堆栈模块包含以下组件。在使用该模块的设备上,以下服务已移至其他进程,现在通过稳定的 AIDL 接口进行访问。
IP 服务。IpClient
(以前称为 IpManager
)是一个负责 IP 层配置和维护的组件。在 Android 9 中,它已被蓝牙等组件用于进程间处理,被 Wi-Fi 等组件用于进程内处理。DhcpClient
会从 DHCP 服务器获取 IP 地址,以便将它们分配给接口。
NetworkMonitor。NetworkMonitor
组件会在连接到新网络或出现网络故障时、检测强制门户时以及验证网络时测试互联网可达性。
强制门户登录应用。一款预安装应用,负责管理强制门户的登录操作。从 Android 5.0 开始,此应用一直是一款独立应用,但它会与 NetworkMonitor
交互,以将一些用户选择项转发给系统。
受影响的路径
下面列出了因重构而移至网络堆栈模块的路径。
移动的代码的新位置是在 packages/modules/NetworkStack
、packages/modules/CaptivePortalLogin
以及其他一些共享位置。上述路径是指在为 Mainline 将文件移至这些新位置之前的文件位置。packages/modules/NetworkStack
和 packages/modules/CaptivePortalLogin
中的文件是 Mainline 模块的一部分,不能修改。
网络堆栈模块包含以下 APK 格式的组件:
- IP 服务
- 强制门户登录 (
com.google.android.captiveportallogin
)
此模块附带网络堆栈权限配置模块,后者是一个为网络堆栈组件定义必要权限的预安装 APK 文件。
依赖项
网络堆栈模块依赖于以下各项:
系统服务器中的特权 @hide 方法(例如,IConnectivityManager.aidl
中的此类方法)。这些 API 已成为 @SystemApi
并受到适当保护,这样一来,它们可由 Mainline 模块访问,但不能由其他特权应用访问(例如,使用新的签名权限)。
INetd.aidl
中定义的指向 netd
的 Binder IPC。此接口已转换为稳定的 AIDL,并且需要进行符合性测试。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Network Stack is an updatable Mainline module that ensures that Android can\nadapt to evolving network standards and allows for interoperability with new\nimplementations. For example, updates to captive portal detection and login code\nallow Android to stay up to date with changing captive portal models, and\nupdates to APF allow Android to save power on Wi-Fi as new types of packets\nbecome common.\n\nIncluded components\n-------------------\n\nThe Network Stack module contains the following components. On devices using the\nmodule, these services were moved to a different process and are accessed\nthrough a stable AIDL interface.\n\n- **IP services.** `IpClient` (formerly `IpManager`) is a component in charge of\n IP layer provisioning and maintenance. In Android 9, it was already used\n cross-process by components such as Bluetooth, and in-process by components\n such as Wi-Fi. `DhcpClient` obtains IP addresses from DHCP servers so they can\n be assigned to interfaces.\n\n- **NetworkMonitor.** The `NetworkMonitor` component tests for internet\n reachability when connecting to a new network or upon network failures, when\n detecting captive portals, and when validating networks.\n\n- **Captive portal login app.** A preinstalled app in charge of managing login\n on captive portals. This has been a separate app since Android 5.0, but it\n interacts with `NetworkMonitor` to forward some user choices to the system.\n\nAffected paths\n--------------\n\nThe paths moved to the Network Stack module by the refactor are listed below.\n\n- **IP services.** In `frameworks/base/services/net/java/android/net/`:\n\n - `apf`\n - `dhcp`\n - `ip`\n - `netlink`\n - `util` (partly)\n- **Captive portal detection and login.** In `frameworks/base/`:\n\n - `core/java/android/net/captiveportal/`\n - `services/core/java/com/android/server/connectivity/NetworkMonitor.java`\n - `packages/CaptivePortalLogin/*`\n\nThe new location of the moved code is in `packages/modules/NetworkStack`,\n`packages/modules/CaptivePortalLogin` and some other shared locations. The above\npaths refer to the location of files before being moved there for Mainline.\nFiles in `packages/modules/NetworkStack` and\n`packages/modules/CaptivePortalLogin` are part of the Mainline module and cannot\nbe modified.\n\nPackage format\n--------------\n\nThe Network Stack module contains the following components in APK format:\n\n- IP services\n- Captive portal login (`com.google.android.captiveportallogin`)\n\nThis module is accompanied by the Network Stack Permission Config module,\nwhich is a pre-installed APK file that defines the necessary permissions for the\nNetwork Stack components.\n\nDependencies\n------------\n\nThe Network Stack module depends on the following:\n\n- Privileged @hide methods in the system server (e.g., in\n `IConnectivityManager.aidl`). These APIs have been made `@SystemApi` and\n appropriately protected so that they are accessible to the Mainline module but\n not other privileged apps (e.g., using a new signature permission).\n\n- Binder IPCs to `netd` defined in\n [`INetd.aidl`](https://android.googlesource.com/platform/system/netd/+/android16-release/server/binder/android/net/INetd.aidl).\n This interface has been converted to stable AIDL and is subject to conformance\n tests."]]