Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.
Stay organized with collections
Save and categorize content based on your preferences.
Test Harness Mode is a feature added in Android 10 for
third-party app developers that wish
to automate a device or a fleet of devices. The feature provides a method to wipe all
user data on an Android device, retain ADB keys, and skip all first-time setup screens. This enables
the user to run a UI test immediately after startup without any manual interaction.
Customization
You can determine if a device is in Test Harness Mode by checking
ActivityManager.isRunningInUserTestHarness(). Keep customizations to a minimum;
limit to things like skipping setup screens (on the keyboard or setup wizard) that would break
UI tests or require manual interaction.
The default implementation of Test Harness Mode uses the same storage mechanism as
factory reset protection to store the adb keys temporarily in a persistent partition. If a
persistent partition with factory reset protection is already implemented on the test device,
little to no work is necessary to support the feature.
OEMs that don't have a persistent partition set up need to implement
PersistentDataBlockManagerInternal before running
TestHarnessModeService.
Check the status of Test Harness Mode
When Test Harness Mode is enabled,
ActivityManager.isRunningInUserTestHarness() returns true.
Run Test Harness Mode
Enabling Test Harness Mode wipes all data from the device and sets up the device for
testing. This means that all parts of the device that could interfere with testing (such as
auto-syncing accounts, package verification, and automatic updates) are all disabled by default
but the user can reenable them.
Run the adb command to enable Test Harness Mode:
adb shell cmd testharness enable
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-18 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```"]]