停用透過 USB 傳輸資料的信號

Android 12 新增一項功能,可讓 IT 管理員停用數據訊號 。為了支援這項功能,原始設備製造商必須更新 USB HAL,並利用新增的 Device Policy Manager API 支援。

裝置政策管理工具

為支援停用 USB 訊號功能,系統偵測到下列三個公用 API DevicePolicyManager:

  • 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 偏好設定和網路共用設定 已連線。如要存取 USB 偏好設定畫面,請按照下列步驟操作:

    1. 輕觸 [設定]
    2. 輕觸「已連結的裝置」
    3. 輕觸「USB」

    注意:如果未連接 USB,就無法修改 USB 偏好設定,且不會顯示在「已連結的裝置」視窗中。

    如果 IT 管理員在公司裝置上停用 USB 資料訊號,使用者就無法修改 USB 偏好設定。相反地, 設定完全停用,會建立政策 透明度對話方塊視窗。

    注意:如果停用 USB 資料訊號,開發人員選項中的 USB 偵錯、預設 USB 設定和 USB 音訊路由偏好設定都會停用。