[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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```"]]