Loading core/java/android/companion/virtual/computercontrol/ComputerControlSession.java +21 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading core/java/android/companion/virtual/computercontrol/IComputerControlSession.aidl +10 −0 Original line number Diff line number Diff line Loading @@ -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(); } core/java/android/companion/virtual/flags/flags.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -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 } } core/tests/coretests/src/android/companion/virtual/computercontrol/ComputerControlSessionTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -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() Loading libs/computercontrol/src/com/android/extensions/computercontrol/ComputerControlSession.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
core/java/android/companion/virtual/computercontrol/ComputerControlSession.java +21 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading
core/java/android/companion/virtual/computercontrol/IComputerControlSession.aidl +10 −0 Original line number Diff line number Diff line Loading @@ -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(); }
core/java/android/companion/virtual/flags/flags.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -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 } }
core/tests/coretests/src/android/companion/virtual/computercontrol/ComputerControlSessionTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -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() Loading
libs/computercontrol/src/com/android/extensions/computercontrol/ComputerControlSession.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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