自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
停用透過 USB 傳輸資料的信號
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 12 新增了 IT 管理員可在公司裝置上停用 USB 資料訊號的功能 (充電功能除外)。為了支援這項功能,原始設備製造商 (OEM) 必須更新 USB HAL,並利用新增的 Device Policy Manager API 支援。
裝置政策管理工具
為支援停用透過 USB 傳送的信號,DevicePolicyManager
中包含以下三個公開 API:
setUsbDataSignalingEnabled(boolean enabled)
是一種 API,可透過呼叫 UsbManager
中的 enableUsbDataSignal
API 啟用或停用 USB 資料訊號。
canUsbDataSignalingBeDisabled()
是 API,可檢查裝置是否支援啟用或停用 USB 資料訊號。
isUsbDataSignalingEnabled()
是用來檢查是否已啟用 USB 資料信號的 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 偏好設定和 Tethering 設定。如要存取 USB 偏好設定畫面,請按照下列步驟操作:
- 輕觸 [設定]。
- 輕觸「已連結的裝置」。
- 輕觸「USB」。
注意:如果未連接 USB,就無法修改 USB 偏好設定,且不會顯示在「已連結的裝置」視窗中。
如果 IT 管理員在公司裝置上停用 USB 資料訊號,使用者就無法修改 USB 偏好設定。相反地,設定中的所有 USB 偏好設定都會完全停用,這會建立政策資訊對話方塊視窗。
注意:如果停用 USB 資料信號,開發人員選項中的 USB 偵錯、預設 USB 設定和 USB 音訊路由偏好設定都會停用。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# 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."]]