Loading core/java/android/companion/virtual/computercontrol/ComputerControlSession.java +29 −1 Original line number Diff line number Diff line Loading @@ -96,6 +96,20 @@ public final class ComputerControlSession implements AutoCloseable { public @interface SessionCreationError { } /** * Computer control action that performs back navigation. */ public static final int ACTION_GO_BACK = 1; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = "ACTION_", value = { ACTION_GO_BACK, }) @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) public @interface Action { } @NonNull private final IComputerControlSession mSession; private final Object mLock = new Object(); Loading @@ -103,6 +117,14 @@ public final class ComputerControlSession implements AutoCloseable { @Nullable private ImageReader mImageReader; /** Perform provided action on the trusted virtual display. */ public void performAction(@Action int actionCode) { try { mSession.performAction(actionCode); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** @hide */ public ComputerControlSession(int displayId, @NonNull IVirtualDisplayCallback displayToken, Loading Loading @@ -214,7 +236,13 @@ public final class ComputerControlSession implements AutoCloseable { } } /** Injects a key event into the trusted virtual display. */ /** * Injects a key event into the trusted virtual display. * * @deprecated use {@link #insertText(String, boolean, boolean)} for injecting text into the * text field and use {@link #performAction(int)} to perform actions like "back navigation". */ @Deprecated public void sendKeyEvent(@NonNull VirtualKeyEvent event) { try { mSession.sendKeyEvent(Objects.requireNonNull(event)); Loading core/java/android/companion/virtual/computercontrol/IComputerControlSession.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,9 @@ interface IComputerControlSession { */ void insertText(in String text, boolean replaceExisting, boolean commit); /** Performs computer control action on the computer control display. */ void performAction(int actionCode); /** Closes this session. */ void close(); } 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 performAction_performsAction() throws RemoteException { mSession.performAction(ComputerControlSession.ACTION_GO_BACK); verify(mMockSession).performAction(eq(ComputerControlSession.ACTION_GO_BACK)); } @Test public void insertText_insertsText() throws RemoteException { mSession.insertText("text", true, true); Loading libs/computercontrol/src/com/android/extensions/computercontrol/ComputerControlSession.java +13 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.extensions.computercontrol; import android.accessibilityservice.AccessibilityServiceInfo; import android.annotation.IntRange; import android.app.ActivityOptions; import android.companion.virtual.computercontrol.ComputerControlSession.Action; import android.companion.virtual.computercontrol.InteractiveMirrorDisplay; import android.content.Context; import android.content.Intent; Loading Loading @@ -175,7 +176,11 @@ public final class ComputerControlSession implements AutoCloseable { /** * Injects a {@link KeyEvent} into the computer control session. * * @deprecated use {@link #insertText(String, boolean, boolean)} for injecting text into the * text field and use {@link #performAction(int)} to perform actions like "back navigation". */ @Deprecated public void sendKeyEvent(KeyEvent keyEvent) { VirtualKeyEvent virtualKeyEvent = new VirtualKeyEvent.Builder() .setKeyCode(keyEvent.getKeyCode()) Loading Loading @@ -204,6 +209,14 @@ public final class ComputerControlSession implements AutoCloseable { mAccessibilityProxy.resetStabilityState(); } /** * Perform provided action on the display associated with the {@link ComputerControlSession}. */ public void performAction(@Action int actionCode) { mSession.performAction(actionCode); mAccessibilityProxy.resetStabilityState(); } /** * Returns all windows on the display associated with the {@link ComputerControlSession}. */ Loading libs/computercontrol/tests/src/com/android/extensions/computercontrol/ComputerControlSessionTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.extensions.computercontrol; import static android.companion.virtual.computercontrol.ComputerControlSession.ACTION_GO_BACK; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -217,4 +219,13 @@ public class ComputerControlSessionTest { verify(mStabilityHintCallback, timeout(TIMEOUT_MS)).onStabilityHint(false); } @Test public void performAction_performsAction() throws Exception { mSession.performAction(ACTION_GO_BACK); verify(mIComputerControlSession).performAction(eq(ACTION_GO_BACK)); verify(mStabilityHintCallback, timeout(TIMEOUT_MS)).onStabilityHint(false); } } Loading
core/java/android/companion/virtual/computercontrol/ComputerControlSession.java +29 −1 Original line number Diff line number Diff line Loading @@ -96,6 +96,20 @@ public final class ComputerControlSession implements AutoCloseable { public @interface SessionCreationError { } /** * Computer control action that performs back navigation. */ public static final int ACTION_GO_BACK = 1; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = "ACTION_", value = { ACTION_GO_BACK, }) @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) public @interface Action { } @NonNull private final IComputerControlSession mSession; private final Object mLock = new Object(); Loading @@ -103,6 +117,14 @@ public final class ComputerControlSession implements AutoCloseable { @Nullable private ImageReader mImageReader; /** Perform provided action on the trusted virtual display. */ public void performAction(@Action int actionCode) { try { mSession.performAction(actionCode); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** @hide */ public ComputerControlSession(int displayId, @NonNull IVirtualDisplayCallback displayToken, Loading Loading @@ -214,7 +236,13 @@ public final class ComputerControlSession implements AutoCloseable { } } /** Injects a key event into the trusted virtual display. */ /** * Injects a key event into the trusted virtual display. * * @deprecated use {@link #insertText(String, boolean, boolean)} for injecting text into the * text field and use {@link #performAction(int)} to perform actions like "back navigation". */ @Deprecated public void sendKeyEvent(@NonNull VirtualKeyEvent event) { try { mSession.sendKeyEvent(Objects.requireNonNull(event)); Loading
core/java/android/companion/virtual/computercontrol/IComputerControlSession.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,9 @@ interface IComputerControlSession { */ void insertText(in String text, boolean replaceExisting, boolean commit); /** Performs computer control action on the computer control display. */ void performAction(int actionCode); /** Closes this session. */ void close(); }
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 performAction_performsAction() throws RemoteException { mSession.performAction(ComputerControlSession.ACTION_GO_BACK); verify(mMockSession).performAction(eq(ComputerControlSession.ACTION_GO_BACK)); } @Test public void insertText_insertsText() throws RemoteException { mSession.insertText("text", true, true); Loading
libs/computercontrol/src/com/android/extensions/computercontrol/ComputerControlSession.java +13 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.extensions.computercontrol; import android.accessibilityservice.AccessibilityServiceInfo; import android.annotation.IntRange; import android.app.ActivityOptions; import android.companion.virtual.computercontrol.ComputerControlSession.Action; import android.companion.virtual.computercontrol.InteractiveMirrorDisplay; import android.content.Context; import android.content.Intent; Loading Loading @@ -175,7 +176,11 @@ public final class ComputerControlSession implements AutoCloseable { /** * Injects a {@link KeyEvent} into the computer control session. * * @deprecated use {@link #insertText(String, boolean, boolean)} for injecting text into the * text field and use {@link #performAction(int)} to perform actions like "back navigation". */ @Deprecated public void sendKeyEvent(KeyEvent keyEvent) { VirtualKeyEvent virtualKeyEvent = new VirtualKeyEvent.Builder() .setKeyCode(keyEvent.getKeyCode()) Loading Loading @@ -204,6 +209,14 @@ public final class ComputerControlSession implements AutoCloseable { mAccessibilityProxy.resetStabilityState(); } /** * Perform provided action on the display associated with the {@link ComputerControlSession}. */ public void performAction(@Action int actionCode) { mSession.performAction(actionCode); mAccessibilityProxy.resetStabilityState(); } /** * Returns all windows on the display associated with the {@link ComputerControlSession}. */ Loading
libs/computercontrol/tests/src/com/android/extensions/computercontrol/ComputerControlSessionTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.extensions.computercontrol; import static android.companion.virtual.computercontrol.ComputerControlSession.ACTION_GO_BACK; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -217,4 +219,13 @@ public class ComputerControlSessionTest { verify(mStabilityHintCallback, timeout(TIMEOUT_MS)).onStabilityHint(false); } @Test public void performAction_performsAction() throws Exception { mSession.performAction(ACTION_GO_BACK); verify(mIComputerControlSession).performAction(eq(ACTION_GO_BACK)); verify(mStabilityHintCallback, timeout(TIMEOUT_MS)).onStabilityHint(false); } }