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

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

Merge "Add CC API to performAction globally like back navigation" into main

parents 6530b7c1 e6454ba8
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -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();
@@ -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,
@@ -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));
+3 −0
Original line number Diff line number Diff line
@@ -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();
}
+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 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);
+13 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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())
@@ -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}.
     */
+11 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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