Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a96d3d3f authored by William Hester's avatar William Hester
Browse files

Implement test harness mode

Test Harness Mode is a feature for device farms that want to wipe
their devices after each test run. It stores the ADB keys in the
persistent partition (used for Factory Reset Protection) then performs
a factory reset by broadcasting the MASTER_CLEAR intent.

Upon rebooting, the Setup Wizard is skipped, and a few settings are set:
  * Package Verifier is disabled
  * Stay Awake While Charging is enabled
  * OTA Updates are disabled
  * Auto-Sync for accounts is disabled

Other apps may configure themselves differently in Test Harness Mode by
checking ActivityManager.isRunningInUserTestHarness()

Bug: 80137798
Test: make && fastboot flashall -w
Test: adb shell cmd testharness enable
Change-Id: I91285c056666e36ad0caf778bffc140a0656fcfa
parent 4e9df81c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3941,7 +3941,8 @@ package android.app {
    method public boolean isBackgroundRestricted();
    method @Deprecated public boolean isInLockTaskMode();
    method public boolean isLowRamDevice();
    method public static boolean isRunningInTestHarness();
    method @Deprecated public static boolean isRunningInTestHarness();
    method public static boolean isRunningInUserTestHarness();
    method public static boolean isUserAMonkey();
    method @RequiresPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES) public void killBackgroundProcesses(String);
    method @RequiresPermission(android.Manifest.permission.REORDER_TASKS) public void moveTaskToFront(int, int);
+20 −0
Original line number Diff line number Diff line
@@ -3529,11 +3529,31 @@ public class ActivityManager {

    /**
     * Returns "true" if device is running in a test harness.
     *
     * @deprecated this method is false for all user builds. Users looking to check if their device
     * is running in a device farm should see {@link #isRunningInUserTestHarness()}.
     */
    @Deprecated
    public static boolean isRunningInTestHarness() {
        return SystemProperties.getBoolean("ro.test_harness", false);
    }

    /**
     * Returns "true" if the device is running in Test Harness Mode.
     *
     * <p>Test Harness Mode is a feature that allows devices to run without human interaction in a
     * device farm/testing harness (such as Firebase Test Lab). You should check this method if you
     * want your app to behave differently when running in a test harness to skip setup screens that
     * would impede UI testing. e.g. a keyboard application that has a full screen setup page for
     * the first time it is launched.
     *
     * <p>Note that you should <em>not</em> use this to determine whether or not your app is running
     * an instrumentation test, as it is not set for a standard device running a test.
     */
    public static boolean isRunningInUserTestHarness() {
        return SystemProperties.getBoolean("persist.sys.test_harness", false);
    }

    /**
     * Unsupported compiled sdk warning should always be shown for the intput activity
     * even in cases where the system would normally not show the warning. E.g. when running in a
+4 −0
Original line number Diff line number Diff line
@@ -1748,6 +1748,10 @@
    <permission android:name="android.permission.MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED"
        android:protectionLevel="signature" />

    <!-- @hide Allows the device to be reset, clearing all data and enables Test Harness Mode. -->
    <permission android:name="android.permission.ENABLE_TEST_HARNESS_MODE"
        android:protectionLevel="signature" />

    <!-- ================================== -->
    <!-- Permissions for accessing accounts -->
    <!-- ================================== -->
+2 −0
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@
    <uses-permission android:name="android.permission.CONTROL_KEYGUARD" />
    <uses-permission android:name="android.permission.SUSPEND_APPS" />
    <uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND" />
    <!-- Permission needed to wipe the device for Test Harness Mode -->
    <uses-permission android:name="android.permission.ENABLE_TEST_HARNESS_MODE" />

    <uses-permission android:name="android.permission.MANAGE_APPOPS" />

+13 −0
Original line number Diff line number Diff line
@@ -31,6 +31,19 @@ public interface PersistentDataBlockManagerInternal {
     */
    byte[] getFrpCredentialHandle();

    /** Stores the data used to enable the Test Harness Mode after factory-resetting. */
    void setTestHarnessModeData(byte[] data);

    /**
     * Retrieves the data used to place the device into Test Harness Mode.
     *
     * @throws IllegalStateException if the underlying storage is corrupt or inaccessible.
     */
    byte[] getTestHarnessModeData();

    /** Clear out the Test Harness Mode data. */
    void clearTestHarnessModeData();

    /** Update the OEM unlock enabled bit, bypassing user restriction checks. */
    void forceOemUnlockEnabled(boolean enabled);
}
Loading