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

Commit a894659b authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "CCS API: Add ability to simulate long press on CC display." into main

parents 7a7ca4f3 a57535b9
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -227,6 +227,23 @@ public final class ComputerControlSession implements AutoCloseable {
        }
    }

    /**
     * Sends a long press event to the computer control session for the given coordinates.
     *
     * <p>The coordinates are in relative display space, e.g. (0.5, 0.5) is the center of the
     * display.</p>
     */
    public void longPress(@IntRange(from = 0) int x, @IntRange(from = 0) int y) {
        if (x < 0 || y < 0) {
            throw new IllegalArgumentException("Long press coordinates must be non-negative");
        }
        try {
            mSession.longPress(x, y);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Returns the ID of the single trusted virtual display for this session. */
    public int getVirtualDisplayId() {
        try {
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ interface IComputerControlSession {
    /* Injects a swipe event into the trusted virtual display. */
    void swipe(int fromX, int fromY, int toX, int toY);

    /** Injects a long press event into the trusted virtual display. */
    void longPress(int x, int y);

    /** Returns the ID of the single trusted virtual display for this session. */
    int getVirtualDisplayId();

+12 −0
Original line number Diff line number Diff line
@@ -172,4 +172,16 @@ public class ComputerControlSessionTest {
        assertThrows(IllegalArgumentException.class, () -> mSession.swipe(1, 2, -3, 4));
        assertThrows(IllegalArgumentException.class, () -> mSession.swipe(1, 2, 3, -4));
    }

    @Test
    public void longPress_longPresses() throws RemoteException {
        mSession.longPress(1, 2);
        verify(mMockSession).longPress(eq(1), eq(2));
    }

    @Test
    public void longPressNotInRange_throws() {
        assertThrows(IllegalArgumentException.class, () -> mSession.longPress(-1, 2));
        assertThrows(IllegalArgumentException.class, () -> mSession.longPress(1, -2));
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -150,6 +150,14 @@ public final class ComputerControlSession implements AutoCloseable {
        mAccessibilityProxy.resetStabilityState();
    }

    /**
     * Sends a long press event to the computer control session for the given coordinates.
     */
    public void longPress(@IntRange(from = 0) int x, @IntRange(from = 0) int y) {
        mSession.longPress(x, y);
        mAccessibilityProxy.resetStabilityState();
    }

    /**
     * Injects a {@link TouchEvent} into the computer control session.
     */
+6 −0
Original line number Diff line number Diff line
@@ -148,6 +148,12 @@ public class ComputerControlSessionTest {
        verify(mIComputerControlSession).swipe(eq(1), eq(2), eq(3), eq(4));
    }

    @Test
    public void longPress_longPresses() throws Exception {
        mSession.longPress(1, 2);
        verify(mIComputerControlSession).longPress(eq(1), eq(2));
    }

    @Test
    public void sendKeyEvent_sendsKeyEvent() throws Exception {
        KeyEvent event = new KeyEvent.Builder()
Loading