自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
停用 USB 数据信号传输
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 12 添加了一项功能,可供 IT 管理员停用公司自有设备上的 USB 数据信号传输(充电功能除外)。为了支持此功能,OEM 必须更新其 USB HAL,并利用新增的设备政策管理器 API 支持。
设备政策管理器
为了支持停用 USB 信号传输,DevicePolicyManager
中包含以下三个公共 API:
setUsbDataSignalingEnabled(boolean enabled)
是通过调用 UsbManager
中的 enableUsbDataSignal
API 来启用或停用 USB 数据信号传输的 API。
canUsbDataSignalingBeDisabled()
是用于检查设备是否支持启用或停用 USB 数据信号传输的 API。
isUsbDataSignalingEnabled()
是用于检查是否已启用 USB 数据信号传输的 API。
- 这是检查系统是否显示政策透明度对话框窗口所必需的 API。系统用户可以调用此特定 API 的一个隐藏变体。通过调用该变体,系统用户可以检查是否已为特定用户启用 USB 数据信号传输。
设备政策管理器实现示例
以下示例展示了如何实现设备政策管理器。
class android.app.admin.DevicePolicyManager {
/**
* Called by device owner or profile owner of an organization-owned managed profile to
* enable or disable USB data signaling for the device. When disabled, USB data connections
* (except from charging functions) are prohibited.
*
* <p> This API is not supported on all devices, the caller should call
* {@link #canUsbDataSignalingBeDisabled()} to check whether enabling or disabling USB data
* signaling is supported on the device.
*
* @param enabled whether USB data signaling should be enabled or not.
* @throws SecurityException if the caller is not a device owner or a profile owner on
* an organization-owned managed profile.
* @throws IllegalStateException if disabling USB data signaling is not supported or
* if USB data signaling fails to be enabled/disabled.
*/
public void setUsbDataSignalingEnabled(boolean enabled);
/**
* Called by device owner or profile owner of an organization-owned managed profile to return
* whether USB data signaling is currently enabled by the admin.
*
* @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
*/
public boolean isUsbDataSignalingEnabled();
/**
* Called by the system to check whether USB data signaling is currently enabled for this user.
*
* @param userId which user to check for.
* @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
* @hide
*/
public boolean isUsbDataSignalingEnabledForUser(@UserIdInt int userId);
/**
* Returns whether enabling or disabling USB data signaling is supported on the device.
*
* @return {@code true} if the device supports enabling and disabling USB data signaling.
*/
public boolean canUsbDataSignalingBeDisabled();
设置
连接 USB 后,用户可以立即修改 USB 偏好设置和网络共享设置。如需访问 USB 偏好设置屏幕,请执行以下操作:
- 点按设置。
- 点按已连接的设备。
- 点按 USB。
注意:如果未连接 USB,就无法修改 USB 偏好设置,而且 USB 偏好设置也不会显示在“已连接的设备”窗口中。
如果 IT 管理员在公司自有设备上停用了 USB 数据信号传输,用户便无法修改其 USB 偏好设置。相反,设置中的所有 USB 偏好设置都会完全停用,这种情况会导致创建一个政策透明度对话框窗口。
注意:如果停用 USB 数据信号传输,开发者选项中的 USB 调试、默认 USB 配置和 USB 音频路由偏好设置都会停用。
本页面上的内容和代码示例受内容许可部分所述许可的限制。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,["# Disable data signaling over USB\n\nAndroid 12 has added the ability for IT admins to disable data signaling\nover USB on corporate-owned devices (except for the charging function). In order to support this\nfunctionality, OEMs must update their USB HAL and utilize the added support for Device Policy\nManager APIs.\n\nDevice Policy Manager\n---------------------\n\nTo support disabling signaling over USB, the following three public APIs are included in\n`DevicePolicyManager`:\n\n- `setUsbDataSignalingEnabled(boolean enabled)` is an API that enables or disables USB data signaling by calling the `enableUsbDataSignal` API in `UsbManager`.\n- `canUsbDataSignalingBeDisabled()` is an API that checks whether enabling or disabling USB data signaling is supported on the device.\n- `isUsbDataSignalingEnabled()` is an API that checks whether USB data signaling has been enabled.\n - This is required to check whether or not a policy transparency dialog window is shown. System users can call a hidden variant for this particular API that can be called by the system user to check if USB data signaling has been enabled for a particular user.\n\n### Device Policy Manager implementation example\n\nThe following is an example of how to implement the Device Policy Manager. \n\n```\nclass android.app.admin.DevicePolicyManager {\n /**\n * Called by device owner or profile owner of an organization-owned managed profile to\n * enable or disable USB data signaling for the device. When disabled, USB data connections\n * (except from charging functions) are prohibited.\n *\n * \u003cp\u003e This API is not supported on all devices, the caller should call\n * {@link #canUsbDataSignalingBeDisabled()} to check whether enabling or disabling USB data\n * signaling is supported on the device.\n *\n * @param enabled whether USB data signaling should be enabled or not.\n * @throws SecurityException if the caller is not a device owner or a profile owner on\n * an organization-owned managed profile.\n * @throws IllegalStateException if disabling USB data signaling is not supported or\n * if USB data signaling fails to be enabled/disabled.\n */\n public void setUsbDataSignalingEnabled(boolean enabled);\n\n\n /**\n * Called by device owner or profile owner of an organization-owned managed profile to return\n * whether USB data signaling is currently enabled by the admin.\n *\n * @return {@code true} if USB data signaling is enabled, {@code false} otherwise.\n */\n public boolean isUsbDataSignalingEnabled();\n\n\n /**\n * Called by the system to check whether USB data signaling is currently enabled for this user.\n *\n * @param userId which user to check for.\n * @return {@code true} if USB data signaling is enabled, {@code false} otherwise.\n * @hide\n */\n public boolean isUsbDataSignalingEnabledForUser(@UserIdInt int userId);\n\n\n /**\n * Returns whether enabling or disabling USB data signaling is supported on the device.\n *\n * @return {@code true} if the device supports enabling and disabling USB data signaling.\n */\n public boolean canUsbDataSignalingBeDisabled();\n```\n\nSettings\n--------\n\n- Users can modify USB preference and tethering settings as soon as USB is connected. To access the USB preferences screen, do the following:\n 1. Tap **Settings.**\n 2. Tap **Connected devices.**\n 3. Tap **USB.**\n- **Note:** If USB is not connected, USB preferences can't be modified and will not appear in the Connected devices window.\n- If an IT admin disables USB data signaling on a corporate-owned device, the user can't modify their USB preferences. Instead, all USB preferences in **Settings** are totally disabled, which will create a policy transparency dialog window.\n- **Note:** If USB data signaling is disabled, USB debugging, default USB configurations, and USB audio routing preferences will all be disabled in developer options."]]