Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Tắt tính năng truyền tín hiệu dữ liệu qua USB
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Android 12 đã bổ sung tính năng cho phép quản trị viên CNTT tắt tính năng báo hiệu dữ liệu qua USB trên các thiết bị thuộc sở hữu của công ty (ngoại trừ chức năng sạc). Để hỗ trợ chức năng này, OEM phải cập nhật HAL USB và sử dụng tính năng hỗ trợ bổ sung cho API Trình quản lý chính sách thiết bị.
Trình quản lý chính sách thiết bị
Để hỗ trợ việc tắt tính năng báo hiệu qua USB, DevicePolicyManager
bao gồm 3 API công khai sau:
setUsbDataSignalingEnabled(boolean enabled)
là một API bật hoặc tắt tính năng báo hiệu dữ liệu USB bằng cách gọi API enableUsbDataSignal
trong UsbManager
.
canUsbDataSignalingBeDisabled()
là một API kiểm tra xem việc bật hoặc tắt tính năng báo hiệu dữ liệu qua USB có được hỗ trợ trên thiết bị hay không.
isUsbDataSignalingEnabled()
là một API kiểm tra xem bạn đã bật tính năng báo hiệu dữ liệu qua USB hay chưa.
- Bạn cần thực hiện việc này để kiểm tra xem cửa sổ hộp thoại về tính minh bạch của chính sách có hiển thị hay không. Người dùng hệ thống có thể gọi một biến thể ẩn cho API cụ thể này mà người dùng hệ thống có thể gọi để kiểm tra xem tính năng báo hiệu dữ liệu qua USB đã được bật cho một người dùng cụ thể hay chưa.
Ví dụ về cách triển khai Trình quản lý chính sách thiết bị
Sau đây là ví dụ về cách triển khai Trình quản lý chính sách thiết bị.
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();
Cài đặt
Người dùng có thể sửa đổi chế độ cài đặt ưu tiên USB và chế độ chia sẻ Internet ngay khi kết nối USB. Để truy cập vào màn hình lựa chọn ưu tiên về USB, hãy làm như sau:
- Nhấn vào Cài đặt.
- Nhấn vào Thiết bị đã kết nối.
- Nhấn vào USB.
Lưu ý: Nếu USB không được kết nối, bạn sẽ không thể chỉnh sửa các tuỳ chọn USB và các tuỳ chọn này sẽ không xuất hiện trong cửa sổ Thiết bị đã kết nối.
Nếu quản trị viên CNTT tắt tính năng báo hiệu dữ liệu USB trên thiết bị thuộc sở hữu của công ty, thì người dùng không thể sửa đổi lựa chọn ưu tiên về USB. Thay vào đó, tất cả các lựa chọn ưu tiên về USB trong phần Cài đặt sẽ bị tắt hoàn toàn, tạo ra một cửa sổ hộp thoại minh bạch về chính sách.
Lưu ý: Nếu bạn tắt tính năng báo hiệu dữ liệu qua USB, thì tính năng gỡ lỗi qua USB, cấu hình USB mặc định và lựa chọn ưu tiên định tuyến âm thanh qua USB đều sẽ bị tắt trong tuỳ chọn cho nhà phát triển.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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."]]