Android 12 新增功能:IT 管理員可以停用公司裝置透過 USB 傳輸資料訊號的功能 (充電功能除外)。為支援這項功能,原始設備製造商必須更新 USB HAL,並利用新增的裝置政策管理員 API 支援功能。
裝置政策管理工具
如要支援透過 USB 停用信號傳輸,DevicePolicyManager 中包含下列三個公開 API:
setUsbDataSignalingEnabled(boolean enabled)是一個 API,可透過呼叫UsbManager中的enableUsbDataSignalAPI 啟用或停用 USB 資料信號。canUsbDataSignalingBeDisabled()API 會檢查裝置是否支援啟用或停用 USB 資料信號。isUsbDataSignalingEnabled()API 會檢查 USB 資料信號是否已啟用。- 這是檢查是否顯示政策透明度對話方塊視窗的必要條件。系統使用者可以呼叫這個特定 API 的隱藏變體,檢查特定使用者是否已啟用 USB 資料訊號。
- 輕觸 [設定]。
- 輕觸「已連結的裝置」。
- 輕觸「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 偏好設定,且偏好設定不會顯示在「已連線的裝置」視窗中。
如果 IT 管理員在公司裝置上停用 USB 資料訊號,使用者就無法修改 USB 偏好設定。而是會完全停用「設定」中的所有 USB 偏好設定,並建立政策透明度對話方塊視窗。
注意:如果停用 USB 資料信號,開發人員選項中的 USB 偵錯、預設 USB 設定和 USB 音訊路由偏好設定都會停用。