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

Commit 3a567f17 authored by chaviw's avatar chaviw
Browse files

Added shell command for some general input events

Added shell command for events DOWN, UP, and MOVE. This can be invoked
by calling 'adb shell input event <DOWN|UP|MOVE> <x> <y>'

This was needed to test transferTouchFocus, but can be useful for other
testing as well.

Test: 'adb shell input event <DOWN|UP|MOVE> <x> <y>'
Change-Id: If3e77b04c7172505e7fe8998b5b3c496044870bb
parent fa432cf4
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ public class Input extends BaseCommand {
    private static final String INVALID_DISPLAY_ARGUMENTS =
            "Error: Invalid arguments for display ID.";

    private static final float DEFAULT_PRESSURE = 1.0f;
    private static final float NO_PRESSURE = 0.0f;

    private static final Map<String, Integer> SOURCES = new HashMap<String, Integer>() {{
        put("keyboard", InputDevice.SOURCE_KEYBOARD);
        put("dpad", InputDevice.SOURCE_DPAD);
@@ -76,6 +79,7 @@ public class Input extends BaseCommand {
        COMMANDS.put("draganddrop", new InputDragAndDrop());
        COMMANDS.put("press", new InputPress());
        COMMANDS.put("roll", new InputRoll());
        COMMANDS.put("motionevent", new InputMotionEvent());
    }

    @Override
@@ -304,6 +308,41 @@ public class Input extends BaseCommand {
        }
    }

    class InputMotionEvent implements InputCmd {
        @Override
        public void run(int inputSource, int displayId) {
            inputSource = getSource(inputSource, InputDevice.SOURCE_TOUCHSCREEN);
            sendMotionEvent(inputSource, nextArgRequired(), Float.parseFloat(nextArgRequired()),
                    Float.parseFloat(nextArgRequired()), displayId);
        }

        private void sendMotionEvent(int inputSource, String motionEventType, float x, float y,
                int displayId) {
            final int action;
            final float pressure;

            switch (motionEventType.toUpperCase()) {
                case "DOWN":
                    action = MotionEvent.ACTION_DOWN;
                    pressure = DEFAULT_PRESSURE;
                    break;
                case "UP":
                    action = MotionEvent.ACTION_UP;
                    pressure = NO_PRESSURE;
                    break;
                case "MOVE":
                    action = MotionEvent.ACTION_MOVE;
                    pressure = DEFAULT_PRESSURE;
                    break;
                default:
                    throw new IllegalArgumentException("Unknown motionevent " + motionEventType);
            }

            final long now = SystemClock.uptimeMillis();
            injectMotionEvent(inputSource, action, now, now, x, y, pressure, displayId);
        }
    }

    /**
     * Abstract class for command
     * use nextArgRequired or nextArg to check next argument if necessary.
@@ -391,5 +430,6 @@ public class Input extends BaseCommand {
                + " (Default: touchscreen)");
        out.println("      press (Default: trackball)");
        out.println("      roll <dx> <dy> (Default: trackball)");
        out.println("      event <DOWN|UP|MOVE> <x> <y> (Default: touchscreen)");
    }
}