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

Commit 09c4bd85 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Android (Google) Code Review
Browse files

Merge "Input / display adjustments to computer control APIs" into main

parents cad6c745 d6a84572
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.companion.virtual.computercontrol;

import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -171,10 +170,9 @@ public final class ComputerControlSession implements AutoCloseable {
     * <p>The coordinates are in relative display space, e.g. (0.5, 0.5) is the center of the
     * display.</p>
     */
    public void tap(@FloatRange(from = 0.0, to = 1.0) float x,
            @FloatRange(from = 0.0, to = 1.0) float y) {
        if (x < 0 || x > 1 || y < 0 || y > 1) {
            throw new IllegalArgumentException("Tap coordinates must be in range [0, 1]");
    public void tap(@IntRange(from = 0) int x, @IntRange(from = 0) int y) {
        if (x < 0 || y < 0) {
            throw new IllegalArgumentException("Tap coordinates must be non-negative");
        }
        try {
            mSession.tap(x, y);
@@ -194,13 +192,10 @@ public final class ComputerControlSession implements AutoCloseable {
     * display.</p>
     */
    public void swipe(
            @FloatRange(from = 0.0, to = 1.0) float fromX,
            @FloatRange(from = 0.0, to = 1.0) float fromY,
            @FloatRange(from = 0.0, to = 1.0) float toX,
            @FloatRange(from = 0.0, to = 1.0) float toY) {
        if (fromX < 0 || fromX > 1 || fromY < 0 || fromY > 1
                || toX < 0 || toX > 1 || toY < 0 || toY > 1) {
            throw new IllegalArgumentException("Swipe coordinates must be in range [0, 1]");
            @IntRange(from = 0) int fromX, @IntRange(from = 0) int fromY,
            @IntRange(from = 0) int toX, @IntRange(from = 0) int toY) {
        if (fromX < 0 || fromY < 0 || toX < 0 || toY < 0) {
            throw new IllegalArgumentException("Swipe coordinates must be non-negative");
        }
        try {
            mSession.swipe(fromX, fromY, toX, toY);
+1 −11
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.view.Surface;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Parameters for creating a {@link ComputerControlSession}.
@@ -183,9 +182,6 @@ public final class ComputerControlSessionParams implements Parcelable {
         */
        @NonNull
        public Builder setDisplayWidthPx(@IntRange(from = 1) int displayWidthPx) {
            if (displayWidthPx <= 0) {
                throw new IllegalArgumentException("Display width must be positive");
            }
            mDisplayWidthPx = displayWidthPx;
            return this;
        }
@@ -198,9 +194,6 @@ public final class ComputerControlSessionParams implements Parcelable {
         */
        @NonNull
        public Builder setDisplayHeightPx(@IntRange(from = 1) int displayHeightPx) {
            if (displayHeightPx <= 0) {
                throw new IllegalArgumentException("Display height must be positive");
            }
            mDisplayHeightPx = displayHeightPx;
            return this;
        }
@@ -213,9 +206,6 @@ public final class ComputerControlSessionParams implements Parcelable {
         */
        @NonNull
        public Builder setDisplayDpi(@IntRange(from = 1) int displayDpi) {
            if (displayDpi <= 0) {
                throw new IllegalArgumentException("Display DPI must be positive");
            }
            mDisplayDpi = displayDpi;
            return this;
        }
@@ -228,7 +218,7 @@ public final class ComputerControlSessionParams implements Parcelable {
         */
        @NonNull
        public Builder setDisplaySurface(@NonNull Surface displaySurface) {
            mDisplaySurface = Objects.requireNonNull(displaySurface);
            mDisplaySurface = displaySurface;
            return this;
        }

+2 −2
Original line number Diff line number Diff line
@@ -32,10 +32,10 @@ interface IComputerControlSession {
    void launchApplication(in String packageName);

    /* Injects a tap event into the trusted virtual display. */
    void tap(float x, float y);
    void tap(int x, int y);

    /* Injects a swipe event into the trusted virtual display. */
    void swipe(float fromX, float fromY, float toX, float toY);
    void swipe(int fromX, int fromY, int toX, int toY);

    /** Returns the ID of the single trusted virtual display for this session. */
    int getVirtualDisplayId();
+10 −24
Original line number Diff line number Diff line
@@ -137,41 +137,27 @@ public class ComputerControlSessionTest {

    @Test
    public void tap_taps() throws RemoteException {
        mSession.tap(0.1f, 0.2f);
        verify(mMockSession).tap(eq(0.1f), eq(0.2f));
        mSession.tap(1, 2);
        verify(mMockSession).tap(eq(1), eq(2));
    }

    @Test
    public void tapNotInRange_throws() {
        assertThrows(IllegalArgumentException.class, () -> mSession.tap(-0.1f, 0.2f));
        assertThrows(IllegalArgumentException.class, () -> mSession.tap(1.1f, 0.2f));
        assertThrows(IllegalArgumentException.class, () -> mSession.tap(0.1f, -0.2f));
        assertThrows(IllegalArgumentException.class, () -> mSession.tap(0.1f, 1.2f));
        assertThrows(IllegalArgumentException.class, () -> mSession.tap(-1, 2));
        assertThrows(IllegalArgumentException.class, () -> mSession.tap(1, -2));
    }

    @Test
    public void swipe_swipes() throws RemoteException {
        mSession.swipe(0.1f, 0.2f, 0.3f, 0.4f);
        verify(mMockSession).swipe(eq(0.1f), eq(0.2f), eq(0.3f), eq(0.4f));
        mSession.swipe(1, 2, 3, 4);
        verify(mMockSession).swipe(eq(1), eq(2), eq(3), eq(4));
    }

    @Test
    public void swipeNotInRange_throws() {
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(-0.1f, 0.2f, 0.3f, 0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(1.1f, 0.2f, 0.3f, 0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(0.1f, -0.2f, 0.3f, 0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(0.1f, 1.2f, 0.3f, 0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(0.1f, 0.2f, -0.3f, 0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(0.1f, 0.2f, 1.3f, 0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(0.1f, 0.2f, 0.3f, -0.4f));
        assertThrows(IllegalArgumentException.class,
                () -> mSession.swipe(0.1f, 0.2f, 0.3f, 1.4f));
        assertThrows(IllegalArgumentException.class, () -> mSession.swipe(-1, 2, 3, 4));
        assertThrows(IllegalArgumentException.class, () -> mSession.swipe(1, -2, 3, 4));
        assertThrows(IllegalArgumentException.class, () -> mSession.swipe(1, 2, -3, 4));
        assertThrows(IllegalArgumentException.class, () -> mSession.swipe(1, 2, 3, -4));
    }
}
+7 −13
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.extensions.computercontrol;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.FloatRange;
import android.annotation.IntRange;
import android.app.ActivityOptions;
import android.companion.virtual.computercontrol.InteractiveMirrorDisplay;
import android.content.Context;
@@ -108,6 +108,7 @@ public final class ComputerControlSession implements AutoCloseable {
     */
    public void launchApplication(@NonNull String packageName) {
        mSession.launchApplication(Objects.requireNonNull(packageName));
        mAccessibilityProxy.resetStabilityState();
    }

    /**
@@ -127,13 +128,10 @@ public final class ComputerControlSession implements AutoCloseable {

    /**
     * Sends a tap event to the computer control session at the given location.
     *
     * <p>The coordinates are in relative display space, e.g. (0.5, 0.5) is the center of the
     * display.</p>
     */
    public void tap(@FloatRange(from = 0.0, to = 1.0) float x,
            @FloatRange(from = 0.0, to = 1.0) float y) {
    public void tap(@IntRange(from = 0) int x, @IntRange(from = 0) int y) {
        mSession.tap(x, y);
        mAccessibilityProxy.resetStabilityState();
    }

    /**
@@ -142,16 +140,12 @@ public final class ComputerControlSession implements AutoCloseable {
     * <p>To avoid misinterpreting the swipe as a fling, the individual touches are throttled, so
     * the entire action will take ~500ms. However, this is done in the background and this method
     * returns immediately. Any ongoing swipe will be canceled if a new swipe is requested.</p>
     *
     * <p>The coordinates are in relative display space, e.g. (0.5, 0.5) is the center of the
     * display.</p>
     */
    public void swipe(
            @FloatRange(from = 0.0, to = 1.0) float fromX,
            @FloatRange(from = 0.0, to = 1.0) float fromY,
            @FloatRange(from = 0.0, to = 1.0) float toX,
            @FloatRange(from = 0.0, to = 1.0) float toY) {
            @IntRange(from = 0) int fromX, @IntRange(from = 0) int fromY,
            @IntRange(from = 0) int toX, @IntRange(from = 0) int toY) {
        mSession.swipe(fromX, fromY, toX, toY);
        mAccessibilityProxy.resetStabilityState();
    }

    /**
Loading