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

Commit ada1aef3 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Add API to insert text into computer control display EditText

DD: go/computer-control-typing

Bug: 422134565
Test: atest ComputerControlSessionTest
Flag: android.companion.virtualdevice.flags.computer_control_typing
Change-Id: I12a00d0521bb6c7964c08cc379c28ba317008aed
parent b504a04e
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.RemoteException;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;
import android.view.inputmethod.InputConnection;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -222,6 +223,26 @@ public final class ComputerControlSession implements AutoCloseable {
        }
    }

    /**
     * Inserts provided text into the currently active text field on the display associated with
     * the {@link ComputerControlSession}.
     *
     * <p> This method expects a text field to be in focus with an active {@link InputConnection}.
     * It inserts text at the current cursor position in the text field and moves the cursor to
     * the end of inserted text. </p>
     *
     * @param text to be inserted
     * @param replaceExisting whether the current text in the text field needs to be overwritten
     * @param commit whether the text should be submitted after insertion
     */
    public void insertText(@NonNull String text, boolean replaceExisting, boolean commit) {
        try {
            mSession.insertText(text, replaceExisting, commit);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Injects a touch event into the trusted virtual display. */
    public void sendTouchEvent(@NonNull VirtualTouchEvent event) {
        try {
+10 −0
Original line number Diff line number Diff line
@@ -50,6 +50,16 @@ interface IComputerControlSession {
    IInteractiveMirrorDisplay createInteractiveMirrorDisplay(
            int width, int height, in Surface surface);

    /**
     * Inserts text into the current active input connection (if available).
     *
     * @param text to be inserted
     * @param replaceExisting whether the existing text in the input field should be replaced. If
     *                        {@code false}, we will insert the text the current cursor position.
     * @param commit whether the text should be submitted after insertion
     */
    void insertText(in String text, boolean replaceExisting, boolean commit);

    /** Closes this session. */
    void close();
}
+10 −0
Original line number Diff line number Diff line
@@ -266,3 +266,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "computer_control_typing"
    namespace: "virtual_devices"
    description: "Support input connection based CC text manipulation APIs"
    bug: "422134565"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -101,6 +101,12 @@ public class ComputerControlSessionTest {
        verify(mMockSession).sendKeyEvent(eq(keyEvent));
    }

    @Test
    public void insertText_insertsText() throws RemoteException {
        mSession.insertText("text", true, true);
        verify(mMockSession).insertText(eq("text"), eq(true), eq(true));
    }

    @Test
    public void sendTouchEvent_sendsEvent() throws RemoteException {
        VirtualTouchEvent touchEvent = new VirtualTouchEvent.Builder()
+18 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.view.accessibility.AccessibilityDisplayProxy;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityWindowInfo;
import android.view.inputmethod.InputConnection;

import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
@@ -186,6 +187,23 @@ public final class ComputerControlSession implements AutoCloseable {
        mAccessibilityProxy.resetStabilityState();
    }

    /**
     * Inserts provided text into the currently active text field on the display associated with
     * the {@link ComputerControlSession}.
     *
     * <p> This method expects a text field to be in focus with an active {@link InputConnection}.
     * It inserts text at the current cursor position in the text field and moves the cursor to
     * the end of inserted text. </p>
     *
     * @param text to be inserted
     * @param replaceExisting whether the current text in the text field needs to be overwritten
     * @param commit whether the text should be submitted after insertion
     */
    public void insertText(@NonNull String text, boolean replaceExisting, boolean commit) {
        mSession.insertText(text, replaceExisting, commit);
        mAccessibilityProxy.resetStabilityState();
    }

    /**
     * Returns all windows on the display associated with the {@link ComputerControlSession}.
     */
Loading