自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
网络共享
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 13 中的更新
概览
网络共享模块可将 Android 设备的互联网连接与连接的其他客户端设备共享,这些设备可以通过 Wi-Fi、USB、蓝牙或以太网连接到网络共享设备。此模块包含网络共享组件(USB、Wi-Fi 接入点、蓝牙等)及其依赖项(与网络共享权限、IpServer
和 offloadController
的交互)。此模块是可更新的,这意味着它可在 Android 常规发布周期外的时间接收功能更新。
网络共享模块可让整个 Android 生态系统中的 OEM 使用单个标准参考实现,该实现具有以下优势。
拆分隧道技术
为了支持拆分隧道技术用例,我们在 Android 13 中新增了一个 API 来指定排除路由。
拆分隧道技术是指只让特定流量通过 VPN 的配置。一个常见示例是,组织希望常规的网上冲浪、带宽密集型应用(例如 YouTube、Netflix)或对延迟敏感的应用(例如 Office 365)绕过 VPN。在拆分隧道技术推出之前,VpnService.Builder
允许 VPN 客户端指明只能将部分子网路由到它(包含路由)。通过拆分隧道技术,您可以指定反面情况:将所有流量路由到 VPN,但特定子网除外(排除路由)。
新增的拆分隧道技术 API 的签名为:
public Builder excludeRoute(@NonNull IpPrefix prefix)
CrossDevice
Android 13 中引入的 CrossDevice 旨在使用标准协议提供跨设备通信技术。CrossDevice 为设备发现、经过身份验证的连接和其他跨设备体验提供了 API 和功能。
CrossDevice 动机
- 与 OEM 合作伙伴展开更紧密的协作。OEM 可以将自己的账号密钥系统与 CrossDevice 实现集成,而无需使用 Google 的解决方案。
- 协议实现更加开源透明。CrossDevice 模块是开源的,可让您更清晰地了解实现详情,并改善针对 CrossDevice 技术实现的隐私描述。
CrossDevice 模块边界
CrossDevice API |
在 packages/modules/CrossDevice/framework 中
NearbyManager
AccountProviderBase
|
CrossDevice 服务 |
在 packages/modules/CrossDevice/service 中
|
此模块的主要函数包含在 APEX 软件包中。这些资源打包成了 APK。
CrossDevice 依赖项
CrossDevice 依赖于以下几项技术:
- WiFi
- 蓝牙
- UWB
- module-utils-preconditions
- Proto 库
CrossDevice 自定义选项
我们计划允许 OEM 通过 RRO 自定义半页界面。我们不打算自定义该功能。
CrossDevice 测试策略
我们计划添加 Android 兼容性测试套件 (CTS) 测试来验证 CrossDevice 功能,并将跨设备测试加入到 MTS 中。
eBPF 网络共享分流
为了实现高速网络共享,而无需依赖硬件分流,Android 11 针对 IPv6 下载(流量流向已共享网络的设备)提供了一种称为 eBPF 网络共享分流的网络共享软件分流解决方案。
从 Android 12 开始,此功能(包括 eBPF 程序代码)完全由网络共享模块提供,该模块支持以下各项操作:
- IPv6 下载(流量流向已共享网络的设备)
- IPv6 上传(流量来自已共享网络的设备)
- IPv4 TCP/UDP 上传和下行(流量流向/来自已共享网络的设备)
- eBPF 分流
此功能默认处于启用状态,用户可通过 RRO 将 config_tether_enable_bpf_offload
配置覆盖为 false;如需了解详情,请参阅自定义。
IPv4 和 IPv6 支持
网络共享模块支持 IPv4 和 IPv6 双栈。
模块边界
对于 Android 12 及更高版本,packages/modules/Connectivity
下的所有文件/文件夹都处于网络共享模块的作用域内。
对于 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
代码已添加到网络共享 APEX。网络共享的范围已扩展至连接模块。
模块依赖项
网络共享模块具有以下依赖项:
- 系统服务器中的公共 API 和系统 API 方法
- 与系统服务器的稳定 AIDL IPC 接口
tetheroffload
HIDL(在 hardware/interfaces/tetheroffload/
中定义)
- DHCP 服务器(网络堆栈模块的一部分)
自定义
网络共享模块不支持自定义。
测试
Android 兼容性测试套件 (CTS) 可验证网络共享模块的功能。
本页面上的内容和代码示例受内容许可部分所述许可的限制。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,["# 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."]]