自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
網路堆疊
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
網路堆疊是可更新的主線程模組,可確保 Android 能配合不斷演進的網路標準,並支援與新實作項目的互通性。舉例來說,網頁認證入口偵測和登入碼的更新可讓 Android 隨時掌握不斷變化的網頁認證入口模式,而 APF 的更新則可讓 Android 在新類型的封包變得普遍時,節省 Wi-Fi 的電力。
已納入的元件
網路堆疊模組包含下列元件。在使用此模組的裝置上,這些服務會移至其他程序,並透過穩定的 AIDL 介面存取。
IP 服務。IpClient
(舊稱 IpManager
) 是負責 IP 層部署和維護的元件。在 Android 9 中,藍牙等元件已跨程序使用此類型,而 Wi-Fi 等元件則在程序中使用。DhcpClient
會從 DHCP 伺服器取得 IP 位址,以便將這些位址指派給介面。
NetworkMonitor。NetworkMonitor
元件會在連線至新網路或網路發生錯誤時,以及偵測網頁認證入口和驗證網路時,測試網路可及性。
網頁認證入口登入應用程式:預先安裝的應用程式,負責管理網頁認證入口的登入作業。自 Android 5.0 起,這已是個獨立的應用程式,但會與 NetworkMonitor
互動,將部分使用者選擇轉送至系統。
受影響的路徑
以下列出經過重構後移至 Network Stack 模組的路徑。
已移動程式碼的新位置位於 packages/modules/NetworkStack
、packages/modules/CaptivePortalLogin
和其他一些共用位置。上述路徑是指檔案在移至 Mainline 之前的位置。packages/modules/NetworkStack
和 packages/modules/CaptivePortalLogin
中的檔案屬於 Mainline 模組,因此無法修改。
網路堆疊模組包含以下 APK 格式的元件:
- IP 服務
- 網頁認證入口登入 (
com.google.android.captiveportallogin
)
這個模組會搭配網路堆疊權限設定模組,這是預先安裝的 APK 檔案,可為網路堆疊元件定義必要權限。
依附元件
網路堆疊模組會依賴下列項目:
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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-07-27 (世界標準時間)。"],[],[],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."]]