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

Commit 87df8d63 authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-merger
Browse files

Backporting shortcut manager test utils to mr1 am: a49bafad

am: d76622fb

Change-Id: I70a85bdb9548a79ebf534867938ba5f740eecd7c
parents f77a2fcc d76622fb
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,6 @@ LOCAL_MODULE_TAGS := optional


LOCAL_MODULE := ShortcutManagerTestUtils
LOCAL_MODULE := ShortcutManagerTestUtils


LOCAL_SDK_VERSION := current
LOCAL_SDK_VERSION := test_current


include $(BUILD_STATIC_JAVA_LIBRARY)
include $(BUILD_STATIC_JAVA_LIBRARY)
+11 −6
Original line number Original line Diff line number Diff line
@@ -156,10 +156,10 @@ public class ShortcutManagerTestUtils {
        return result;
        return result;
    }
    }


    private static List<String> runCommand(Instrumentation instrumentation, String command) {
    public static List<String> runCommand(Instrumentation instrumentation, String command) {
        return runCommand(instrumentation, command, null);
        return runCommand(instrumentation, command, null);
    }
    }
    private static List<String> runCommand(Instrumentation instrumentation, String command,
    public static List<String> runCommand(Instrumentation instrumentation, String command,
            Predicate<List<String>> resultAsserter) {
            Predicate<List<String>> resultAsserter) {
        Log.d(TAG, "Running command: " + command);
        Log.d(TAG, "Running command: " + command);
        final List<String> result;
        final List<String> result;
@@ -175,11 +175,11 @@ public class ShortcutManagerTestUtils {
        return result;
        return result;
    }
    }


    private static void runCommandForNoOutput(Instrumentation instrumentation, String command) {
    public static void runCommandForNoOutput(Instrumentation instrumentation, String command) {
        runCommand(instrumentation, command, result -> result.size() == 0);
        runCommand(instrumentation, command, result -> result.size() == 0);
    }
    }


    private static List<String> runShortcutCommand(Instrumentation instrumentation, String command,
    public static List<String> runShortcutCommand(Instrumentation instrumentation, String command,
            Predicate<List<String>> resultAsserter) {
            Predicate<List<String>> resultAsserter) {
        return runCommand(instrumentation, "cmd shortcut " + command, resultAsserter);
        return runCommand(instrumentation, "cmd shortcut " + command, resultAsserter);
    }
    }
@@ -204,7 +204,8 @@ public class ShortcutManagerTestUtils {
    }
    }


    public static void setDefaultLauncher(Instrumentation instrumentation, String component) {
    public static void setDefaultLauncher(Instrumentation instrumentation, String component) {
        runCommand(instrumentation, "cmd package set-home-activity " + component,
        runCommand(instrumentation, "cmd package set-home-activity --user "
                + instrumentation.getContext().getUserId() + " " + component,
                result -> result.contains("Success"));
                result -> result.contains("Success"));
    }
    }


@@ -1053,7 +1054,11 @@ public class ShortcutManagerTestUtils {
    }
    }


    public static void retryUntil(BooleanSupplier checker, String message) {
    public static void retryUntil(BooleanSupplier checker, String message) {
        final long timeOut = System.currentTimeMillis() + 30 * 1000; // wait for 30 seconds.
        retryUntil(checker, message, 30);
    }

    public static void retryUntil(BooleanSupplier checker, String message, long timeoutSeconds) {
        final long timeOut = System.currentTimeMillis() + timeoutSeconds * 1000;
        while (!checker.getAsBoolean()) {
        while (!checker.getAsBoolean()) {
            if (System.currentTimeMillis() > timeOut) {
            if (System.currentTimeMillis() > timeOut) {
                break;
                break;