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.
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
Checking the status of Test Harness Mode
When Test Harness Mode is enabled,
Running 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 may be re-enabled by the user.
adb command to enable Test Harness Mode:
adb shell cmd testharness enable