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

Commit d09ecf8e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "createVirtualKeyboard_api" into main

* changes:
  Remove display ID association requirement for VirtualInputDevices
  Add createVirtualKeyboard API
parents 091ab4a9 f649d795
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6094,6 +6094,10 @@ package android.hardware.hdmi {
package android.hardware.input {
  public final class InputManager {
    method @FlaggedApi("com.android.hardware.input.create_virtual_keyboard_api") @NonNull @RequiresPermission(anyOf={android.Manifest.permission.INJECT_KEY_EVENTS, android.Manifest.permission.INJECT_EVENTS}) public android.hardware.input.VirtualKeyboard createVirtualKeyboard(@NonNull android.hardware.input.VirtualKeyboardConfig);
  }
  public class VirtualDpad implements java.io.Closeable {
    method public void close();
    method @FlaggedApi("com.android.hardware.input.create_virtual_keyboard_api") public int getInputDeviceId();
+6 −0
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ import android.hardware.input.IKeyGestureEventListener;
import android.hardware.input.IKeyGestureHandler;
import android.hardware.input.IStickyModifierStateListener;
import android.hardware.input.ITabletModeChangedListener;
import android.hardware.input.IVirtualInputDevice;
import android.hardware.input.KeyboardLayoutSelectionResult;
import android.hardware.input.TouchCalibration;
import android.hardware.input.VirtualKeyboardConfig;
import android.os.CombinedVibration;
import android.hardware.input.IInputSensorEventListener;
import android.hardware.input.IKeyEventActivityListener;
@@ -84,6 +86,10 @@ interface IInputManager {
    @UnsupportedAppUsage
    boolean injectInputEvent(in InputEvent ev, int mode);

    @EnforcePermission(anyOf = {"INJECT_KEY_EVENTS", "INJECT_EVENTS"})
    IVirtualInputDevice createVirtualKeyboard(in IBinder token,
            in VirtualKeyboardConfig config);

    // Injects an input event into the system. The caller must have the INJECT_EVENTS permission.
    // The caller can target windows owned by a certain UID by providing a valid UID, or by
    // providing {@link android.os.Process#INVALID_UID} to target all windows.
+22 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserHandleAware;
@@ -998,6 +999,27 @@ public final class InputManager {
        return mGlobal.injectInputEvent(event, mode, targetUid);
    }

    /**
     * Returns a {@link VirtualKeyboard} to the caller.
     * See {@link android.hardware.input.VirtualKeyboardConfig} for additional configurations
     * available, e.g. display association, layout, and language.
     *
     * @param config the keyboard configuration
     * @return VirtualKeyboard a virtual keyboard device
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(anyOf = {
            Manifest.permission.INJECT_KEY_EVENTS,
            Manifest.permission.INJECT_EVENTS
    })
    @FlaggedApi(com.android.hardware.input.Flags.FLAG_CREATE_VIRTUAL_KEYBOARD_API)
    @NonNull
    public VirtualKeyboard createVirtualKeyboard(@NonNull VirtualKeyboardConfig config) {
        return mGlobal.createVirtualKeyboard(config);
    }

    /**
     * Injects an input event into the event system on behalf of an application.
     * The synchronization mode determines whether the method blocks while waiting for
+22 −0
Original line number Diff line number Diff line
@@ -1715,6 +1715,28 @@ public final class InputManagerGlobal {
        return injectInputEvent(event, mode, Process.INVALID_UID);
    }

    /**
     * @see InputManager#createVirtualKeyboard(VirtualKeyboardConfig)
     */
    @NonNull
    @RequiresPermission(anyOf = {
            Manifest.permission.INJECT_KEY_EVENTS,
            Manifest.permission.INJECT_EVENTS
    })
    public VirtualKeyboard createVirtualKeyboard(@NonNull VirtualKeyboardConfig config) {
        IVirtualInputDevice virtualInputDevice;
        try {
            // Pass a token to the server so that the server can be notified when the calling
            // process has died and therefore clean up the virtual device.
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualKeyboard:" + config.getInputDeviceName());
            virtualInputDevice = mIm.createVirtualKeyboard(token, config);
            return new VirtualKeyboard(config, virtualInputDevice);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#setPointerIcon(PointerIcon, int, int, int, IBinder)
     */
+45 −7
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@

package android.hardware.input;

import static com.android.hardware.input.Flags.createVirtualKeyboardApi;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.view.Display;
@@ -59,10 +62,13 @@ public abstract class VirtualInputDeviceConfig {
        mAssociatedDisplayId = builder.mAssociatedDisplayId;
        mInputDeviceName = Objects.requireNonNull(builder.mInputDeviceName, "Missing device name");

        // Check if no display association is allowed.
        if (!createVirtualKeyboardApi()) {
            if (mAssociatedDisplayId == Display.INVALID_DISPLAY) {
                throw new IllegalArgumentException(
                        "Display association is required for virtual input devices.");
            }
        }

        // Comparison is greater or equal because the device name must fit into a const char*
        // including the \0-terminator. Therefore the actual number of bytes that can be used
@@ -118,6 +124,21 @@ public abstract class VirtualInputDeviceConfig {
        return mInputDeviceName;
    }

    /**
     * Checks if a display ID is valid.
     * @throws IllegalArgumentException if an invalid display is associated with this device.
     *
     * @see Builder#setAssociatedDisplayId(int)
     *
     * @hide
     */
    public void checkForAssociatedDisplay() {
        if (getAssociatedDisplayId() == Display.INVALID_DISPLAY) {
            throw new IllegalArgumentException(
                    "Display association is required for virtual devices.");
        }
    }

    void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mVendorId);
        dest.writeInt(mProductId);
@@ -174,15 +195,32 @@ public abstract class VirtualInputDeviceConfig {
        }

        /**
         * Sets the associated display ID of the virtual input device. Required.
         * Sets the associated display ID of the virtual input device.
         *
         * <p>If an explicit display association is specified, the associated display must be owned
         * by the caller. The virtual input device is restricted to the display with the given ID
         * and may not send events to any other display.</p>
         * <p>The specified display must be trusted or mirror display.</p>
         *
         * <p>If there is no specific display ID to associate with, use
         * {@link Display.DEFAULT_DISPLAY} or {@link Display.INVALID_DISPLAY}.
         * Using {@link Display.INVALID_DISPLAY} requires the caller to be have either
         * {@link android.Manifest.permission#INJECT_KEY_EVENTS} or
         * {@link android.Manifest.permission#INJECT_EVENTS}
         * </p>
         *
         * <p>The input device is restricted to the display with the given ID and may not send
         * events to any other display.</p>
         * <p>The corresponding display must be trusted or mirror display.</p>
         * <p>Use {@link Display.DEFAULT_DISPLAY} if the virtual input device should only send
         * events to the primary default display. Events will not be sent to focused windows of the
         * non-primary display, e.g. extended monitor.</p>
         * <p>Use {@link Display.INVALID_DISPLAY} if there is no display association and
         * will only send events to the currently focused window of the currently focused display.
         * ONLY allowed for virtual input devices that exclusively sends key events, i.e. keyboard
         * and dpad, and if the caller has either of the aforementioned permissions.</p>
         *
         * @see android.hardware.display.DisplayManager#VIRTUAL_DISPLAY_FLAG_TRUSTED
         * @see android.hardware.display.DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
         */
        @SuppressLint("RequiresPermission")
        @NonNull
        public T setAssociatedDisplayId(int displayId) {
            mAssociatedDisplayId = displayId;
Loading