停用透過 USB 發送數據訊號

Android 12 增加了 IT 管理員在企業擁有的裝置上停用透過 USB 發送資料訊號的功能(充電功能除外)。為了支援此功能,OEM 必須更新其 USB HAL 並利用對裝置策略管理器 API 的新增支援。

裝置策略管理器

為了支援停用 USB 訊號傳輸, DevicePolicyManager中包含以下三個公共 API:

  • setUsbDataSignalingEnabled(boolean enabled)是一個透過呼叫UsbManager中的enableUsbDataSignal API 來啟用或停用 USB 資料訊號的 API。
  • 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 首選項和網路共用設定。若要存取 USB 首選項螢幕,請執行以下操作:

    1. 點擊設定。
    2. 點選已連接的裝置。
    3. 點擊USB。

    注意:如果未連接 USB,則無法修改 USB 首選項,並且不會顯示在「已連接裝置」視窗中。

    如果 IT 管理員在公司擁有的裝置上停用 USB 資料訊號傳輸,則使用者無法修改其 USB 首選項。相反, “設定”中的所有 USB 首選項均已完全停用,這將建立一個策略透明對話方塊視窗。

    注意:如果停用 USB 資料訊號,則開發者選項中的 USB 偵錯、預設 USB 配置和 USB 音訊路由首選項都將停用。