自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
網路共用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 13 更新
總覽
網路共用模組可將 Android 裝置的網際網路連線與其他已連線的用戶端裝置共用,這些裝置可透過 Wi-Fi、USB、藍牙或乙太網路連線至網路共用裝置。這個模組包含共用網路元件 (USB、Wi-Fi 存取點、藍牙等) 及其依附元件 (與共用網路授權、IpServer
和 offloadController
的互動)。這個模組可更新,也就是說,它可以接收功能的更新,而非在一般 Android 發布週期之外。
連線模組可讓 Android 生態系統中的原始設備製造商 (OEM) 使用單一標準參考實作項目,帶來下列優點。
分割通道
為支援分割隧道用途,Android 13 新增了 API,可用於指定排除路徑。
分割通道是指某些流量會透過 VPN,而其他流量則不會透過 VPN 的設定。常見的例子是,機構希望一般網頁瀏覽、頻寬需求高的應用程式 (例如 YouTube、Netflix) 或對延遲敏感的應用程式 (例如 Office 365) 能繞過 VPN。在分割式通道可用之前,VpnService.Builder
允許 VPN 用戶端指出只應將部分子網路轉送至該用戶端 (include 路徑)。透過分割通道,您可以指定相反的情況:將所有流量轉送至 VPN,除了特定子網路 (排除路徑) 以外。
新的分割隧道 API 簽章如下:
public Builder excludeRoute(@NonNull IpPrefix prefix)
CrossDevice
在 Android 13 中推出的 CrossDevice,旨在提供使用標準通訊協定的跨裝置通訊技術。提供裝置探索、驗證連線和其他跨裝置體驗的 API 和功能。
跨裝置動機
- 與原始設備製造商 (OEM) 合作夥伴更緊密地合作。原始設備製造商 (OEM) 可以將自己的帳戶金鑰系統與 CrossDevice 實作整合,而不需要使用 Google 的解決方案。
- 更明顯的通訊協定實作方式。CrossDevice 模組是開放原始碼,可讓您更清楚瞭解實作細節,並改善 CrossDevice 技術實作的隱私權說明。
CrossDevice 模組邊界
CrossDevice API |
在 packages/modules/CrossDevice/framework
NearbyManager
AccountProviderBase
|
跨裝置服務 |
在 packages/modules/CrossDevice/service
|
這個模組的主函式已納入 APEX 套件。資源會封裝在 APK 中。
CrossDevice 依附元件
CrossDevice 取決於下列因素:
- Wi-Fi
- 藍牙
- UWB
- modules-utils-preconditions
- Proto 程式庫
CrossDevice 自訂選項
我們預計允許 OEM 透過 RRO 自訂半頁的 UI。我們沒有計劃自訂這項功能。
跨裝置測試策略
我們預計會新增 Android Compatibility Test Suite (CTS) 測試,以驗證 CrossDevice 功能,並將跨裝置測試納入 MTS。
eBPF 網路共用卸載
為了在不依賴硬體卸載的情況下提供高速網路共用功能,Android 11 提供名為 eBPF 網路共用卸載的軟體卸載解決方案,可用於 IPv6 下載 (流量流向網路共用裝置)。
自 Android 12 起,這項功能 (包括 eBPF 程式碼) 完全由 Tethering 模組提供,後者支援下列項目:
- IPv6 下載 (流量流向已綁定裝置)
- IPv6 上傳 (來自已綁定裝置的流量)
- IPv4 TCP/UDP 上傳和下載 (流量流向/來自 Tethered 裝置)
- eBPF 卸載
這項功能預設為啟用,使用者可以透過 RRO 將 config_tether_enable_bpf_offload
設定覆寫為 false。詳情請參閱「自訂」一節。
支援 IPv4 和 IPv6
共用網路模組支援 IPv4 和 IPv6 雙重堆疊。
模組邊界
在 Android 12 以上版本中,packages/modules/Connectivity
底下的所有檔案/資料夾都屬於 Tethering 模組範圍。
針對 Android 11 以下版本,網路共用模組在 packages/modules/Tethering
中包含下列 Android 10 檔案。
frameworks/base/services/core/java/com/android/server/connectivity/Tethering.java
frameworks/base/services/core/java/com/android/server/connectivity/tethering/
frameworks/base/services/core/java/com/android/server/NetworkManagementService.java
frameworks/base/services/net/java/android/net/ip/{InterfaceController,IpServer,RouterAdvertisementDaemon}.java
frameworks/base/services/net/java/android/net/{netlink,dhcp}/*
frameworks/base/services/net/java/android/net/util/{InterfaceSet,InterfaceParams,NetdService,PrefixUtils,SharedLog,VersionedBroadcastListener}.java
frameworks/base/core/java/android/net/{ITetheringEventCallback,ITetheringStatsProvider}.aidl
frameworks/base/core/java/android/net/{NetworkUtils,util/IpUtils}.java
frameworks/base/core/java/com/android/internal/util/{BitUtils,IndentingPrintWriter,State,StateMachine}.java
frameworks/base/core/java/com/android/server/connectivity/MockableSystemProperties.java
frameworks/base/core/java/android/os/INetworkManagementService.aidl
frameworks/base/core/java/android/bluetooth/BluetoothPan.java
frameworks/base/services/core/jni/com_android_server_connectivity_tethering_OffloadHardwareInterface.cpp
packages/apps/Settings/src/com/android/settings/wifi/tether/TetherService.java
packages/apps/Settings/src/com/android/settings/network/TetherProvisioningActivity.java
共用網路模組 (com.android.tethering
) 採用 APEX 格式,適用於搭載 Android 11 以上版本的裝置。
加入 ConnectivityService
自 Android 12 起,實作 L3+ 連線的核心元件的 ConnectivityService
程式碼已新增至 Tethering APEX。網路共用功能的範圍擴大至連線模組。
模組依附元件
共用網路模組有下列依附元件:
- 系統伺服器中的公開和系統 API 方法
- 穩定的 AIDL IPC 與系統伺服器介面
tetheroffload
HIDL (在 hardware/interfaces/tetheroffload/
中定義)
- DHCP 伺服器 (網路堆疊模組的一部分)
自訂
共用網路模組不支援自訂設定。
測試
Android Compatibility Test Suite (CTS) 可驗證 Tethering 模組的功能。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Tethering\n\nUpdates in Android 13\n---------------------\n\n| Update | More information |\n|-----------------------------|-------------------------------------|\n| Introduced CrossDevice | [CrossDevice](#crossdevice) |\n| Introduced split tunnelling | [Split tunneling](#split-tunneling) |\n\nOverview\n--------\n\nThe Tethering module shares an Android device's internet connection with other\nconnected client devices, which can connect to tethering devices over Wi-Fi,\nUSB, Bluetooth, or Ethernet. This module includes the tethering component (USB,\nWi-Fi access point, Bluetooth, etc.) and its dependencies (interaction with\ntethering entitlement, `IpServer`, and `offloadController`). This module is\nupdatable, meaning it can receive updates to functionality outside of the normal\nAndroid release cycle.\n\nThe Tethering module enables OEMs throughout the Android ecosystem to use a\nsingle, standard reference implementation that brings the following benefits.\n\n- End users get a consistent experience across Android devices and fixes to\n interoperability issues through module updates.\n\n- OEMs can fulfill carrier requirements while also reducing costs for\n individual customizations (as they don't need different implementations of the\n same requirements in different ways).\n\nSplit tunneling\n---------------\n\nTo support split tunneling use cases, a new API is added to Android\n13 to specify exclude routes.\n\nSplit tunneling refers to the configuration where certain traffic goes through\nthe VPN while other traffic does not. A common example is where an organization\nwants general web surfing, bandwidth-heavy (for example, YouTube, Netflix) or\nlatency-sensitive applications (for example, [Office 365](https://docs.microsoft.com/en-us/microsoft-365/enterprise/microsoft-365-vpn-split-tunnel?view=o365-worldwide)) to bypass the VPN. Before split tunneling was available,\n[`VpnService.Builder`](https://developer.android.com/reference/android/net/VpnService.Builder)\nallowed the VPN client to indicate that only some subnets should be routed to it\n(**include** routes). With split tunneling, you have the ability to specify the\ninverse: to route all traffic to the VPN, except for specific subnets\n(**exclude** routes).\n\nThe signature of the new split tunneling API is:\n\n`public Builder excludeRoute(@NonNull IpPrefix prefix)`\n\nCrossDevice\n-----------\n\nCrossDevice, introduced in Android 13, aims\nto provide cross-device communication technologies using standard protocols. It\nprovides APIs and features for device discovery, authenticated\nconnection, and other cross-device experiences.\n\n### CrossDevice motivation\n\n- Tighter collaboration with OEM partners. OEMs can integrate their own account key system with CrossDevice implementation instead of needing to use Google's solution.\n- More visible implementation of the protocol. The CrossDevice module is open source, providing more visibility into the implementation details and better privacy story for CrossDevice technologies implementation.\n\n### CrossDevice module boundary\n\n|--------------------------|---------------------------------------------------------------------------------------|\n| **CrossDevice APIs** | In `packages/modules/CrossDevice/framework` - `NearbyManager` - `AccountProviderBase` |\n| **CrossDevice Services** | In `packages/modules/CrossDevice/service` - `NearbyService` - scanning API |\n\n### CrossDevice package format\n\nThe main function of this module is included in an APEX package. The resources\nare packaged in an APK.\n\n### CrossDevice dependencies\n\nCrossDevice depends on the following:\n\n- WiFi\n- Bluetooth\n- UWB\n- modules-utils-preconditions\n- Proto libraries\n\n### CrossDevice customization options\n\nWe plan to allow OEMS to customize the UI for half sheet through RRO. There is\nno plan to customize the functionality.\n\n### CrossDevice testing strategy\n\nWe plan to add Android Compatibility Test Suite (CTS) tests to verify\nCrossDevice functionality, and cross device testing into MTS.\n\neBPF tethering offload\n----------------------\n\nTo provide high-speed tethering without relying on hardware offloads,\nAndroid 11 provides a tethering software offload solution called eBPF\ntethering offload for IPv6 download (traffic flowing to tethered device).\n\nFrom Android 12, this functionality (including the\neBPF program code) is entirely provided by the Tethering module, which\nsupports the following:\n\n- IPv6 download (traffic flowing to tethered device)\n- IPv6 upload (traffic flowing from tethered device)\n- IPv4 TCP/UDP upload and downstream (traffic flowing to/from tethered device)\n- eBPF offload\n\nThis feature is enabled by default, users\ncan override `config_tether_enable_bpf_offload` configuration to false by RRO.\nSee [Customization](#customization) for more information.\n\nIPv4 and IPv6 support\n---------------------\n\nThe Tethering module supports IPv4 and IPv6 dual stack.\n\n- For IPv4 networks, the module sets up network address translation (NAT) and\n adopts dynamic host configuration protocol (DHCP) for IP address assignment.\n\n- For IPv6 networks, the module adopts IPv6 stateless address autoconfiguration\n (SLAAC) for IP address assignment.\n\nModule boundary\n---------------\n\nFor Android 12 and higher, all the files/folders\nunder `packages/modules/Connectivity` are in the Tethering module scope.\n\nFor Android 11 and lower, the Tethering module has\nthe following Android 10 files in `packages/modules/Tethering`.\n\n- `frameworks/base/services/core/java/com/android/server/connectivity/Tethering.java`\n- `frameworks/base/services/core/java/com/android/server/connectivity/tethering/`\n- `frameworks/base/services/core/java/com/android/server/NetworkManagementService.java`\n- `frameworks/base/services/net/java/android/net/ip/{InterfaceController,IpServer,RouterAdvertisementDaemon}.java`\n- `frameworks/base/services/net/java/android/net/{netlink,dhcp}/*`\n- `frameworks/base/services/net/java/android/net/util/{InterfaceSet,InterfaceParams,NetdService,PrefixUtils,SharedLog,VersionedBroadcastListener}.java`\n- `frameworks/base/core/java/android/net/{ITetheringEventCallback,ITetheringStatsProvider}.aidl`\n- `frameworks/base/core/java/android/net/{NetworkUtils,util/IpUtils}.java`\n- `frameworks/base/core/java/com/android/internal/util/{BitUtils,IndentingPrintWriter,State,StateMachine}.java`\n- `frameworks/base/core/java/com/android/server/connectivity/MockableSystemProperties.java`\n- `frameworks/base/core/java/android/os/INetworkManagementService.aidl`\n- `frameworks/base/core/java/android/bluetooth/BluetoothPan.java`\n- `frameworks/base/services/core/jni/com_android_server_connectivity_tethering_OffloadHardwareInterface.cpp`\n- `packages/apps/Settings/src/com/android/settings/wifi/tether/TetherService.java`\n- `packages/apps/Settings/src/com/android/settings/network/TetherProvisioningActivity.java`\n\nModule format\n-------------\n\nThe Tethering module (`com.android.tethering`) is in APEX format and is\navailable for devices running Android 11 or higher.\n\nInclude ConnectivityService\n---------------------------\n\nFrom Android 12, the `ConnectivityService` code that\nimplements the central component of L3+ connectivity is added to the Tethering\nAPEX. The scope of Tethering expands into a Connectivity module.\n\nModule dependencies\n-------------------\n\nThe Tethering module has the following dependencies:\n\n- Public and system API methods in the system server\n- Stable AIDL IPCs interface with the system server\n- `tetheroffload` HIDL (defined in `hardware/interfaces/tetheroffload/`)\n- DHCP server (part of the Network Stack module)\n\nCustomization\n-------------\n\nThe Tethering module doesn't support customization.\n\nTesting\n-------\n\nThe Android Compatibility Test Suite (CTS) verifies functionality of the\nTethering module."]]