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.
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.
Chế độ Bộ kiểm thử là một tính năng được thêm vào Android 10 dành cho các nhà phát triển ứng dụng bên thứ ba muốn tự động hoá một thiết bị hoặc một nhóm thiết bị. Tính năng này cung cấp một phương thức để xoá tất cả dữ liệu người dùng trên thiết bị Android, giữ lại các khoá ADB và bỏ qua tất cả màn hình thiết lập lần đầu. Điều này cho phép người dùng chạy kiểm thử giao diện người dùng ngay sau khi khởi động mà không cần tương tác thủ công.
Tuỳ chỉnh
Bạn có thể xác định xem một thiết bị có đang ở Chế độ khai thác kiểm thử hay không bằng cách kiểm tra ActivityManager.isRunningInUserTestHarness(). Giảm thiểu việc tuỳ chỉnh; chỉ giới hạn ở những việc như bỏ qua màn hình thiết lập (trên bàn phím hoặc trình hướng dẫn thiết lập) có thể làm hỏng các bài kiểm thử giao diện người dùng hoặc yêu cầu tương tác thủ công.
Cách triển khai mặc định của Chế độ bộ kiểm thử sử dụng cùng một cơ chế lưu trữ với tính năng bảo vệ đặt lại về trạng thái ban đầu để tạm thời lưu trữ các khoá adb trong một phân vùng ổn định. Nếu một phân vùng ổn định có tính năng bảo vệ khi đặt lại về trạng thái ban đầu đã được triển khai trên thiết bị thử nghiệm, thì bạn gần như không cần làm gì để hỗ trợ tính năng này.
Các OEM không thiết lập phân vùng cố định cần triển khai PersistentDataBlockManagerInternal trước khi chạy TestHarnessModeService.
Kiểm tra trạng thái của Chế độ khai thác kiểm thử
Khi bạn bật Chế độ khai thác kiểm thử, ActivityManager.isRunningInUserTestHarness() sẽ trả về true.
Chạy Chế độ khai thác kiểm thử
Việc bật Chế độ khai thác kiểm thử sẽ xoá sạch tất cả dữ liệu khỏi thiết bị và thiết lập thiết bị để kiểm thử. Điều này có nghĩa là tất cả các phần của thiết bị có thể gây cản trở hoạt động kiểm thử (chẳng hạn như tài khoản tự động đồng bộ hoá, xác minh gói và cập nhật tự động) đều bị tắt theo mặc định, nhưng người dùng có thể bật lại các phần đó.
Chạy lệnh adb để bật Chế độ khai thác kiểm thử:
adb shell cmd testharness enable
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,["# Implement Test Harness Mode\n\nTest Harness Mode is a feature added in Android 10 for\nthird-party app developers that wish\nto automate a device or a fleet of devices. The feature provides a method to wipe *all*\nuser data on an Android device, retain ADB keys, and skip all first-time setup screens. This enables\nthe user to run a UI test immediately after startup without any manual interaction.\n| **Note:** Test Harness Mode is different from TradeFed Test Harness. Don't use it when running CTS test.\n\nCustomization\n-------------\n\nYou can determine if a device is in Test Harness Mode by checking\n`ActivityManager.isRunningInUserTestHarness()`. Keep customizations to a minimum;\nlimit to things like skipping setup screens (on the keyboard or setup wizard) that would break\nUI tests or require manual interaction.\n\nImplementation\n--------------\n\nThe default implementation of [`PersistentDataBlockManagerInternal`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/services/core/java/com/android/server/pdb/PersistentDataBlockManagerInternal.java)\nis in [`PersistentDataBlockService`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/services/core/java/com/android/server/pdb/PersistentDataBlockService.java).\nTest Harness Mode is implemented in [`TestHarnessModeService`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/services/core/java/com/android/server/testharness/TestHarnessModeService.java).\n\nThe default implementation of Test Harness Mode uses the same storage mechanism as\nfactory reset protection to store the adb keys temporarily in a persistent partition. If a\npersistent partition with factory reset protection is already implemented on the test device,\nlittle to no work is necessary to support the feature.\n\nOEMs that don't have a persistent partition set up need to implement\n`PersistentDataBlockManagerInternal` before running\n`TestHarnessModeService`.\n\nCheck the status of Test Harness Mode\n-------------------------------------\n\nWhen Test Harness Mode is enabled,\n`ActivityManager.isRunningInUserTestHarness()` returns `true`.\n\nRun Test Harness Mode\n---------------------\n\nEnabling Test Harness Mode wipes all data from the device and sets up the device for\ntesting. This means that all parts of the device that could interfere with testing (such as\nauto-syncing accounts, package verification, and automatic updates) are all disabled by default\nbut the user can reenable them.\n\nRun the `adb` command to enable Test Harness Mode: \n\n```\nadb shell cmd testharness enable\n```"]]