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

Commit 71355cd5 authored by Philip Junker's avatar Philip Junker
Browse files

Add API to get KeyCode produced by physical key location.

The physical key location is provided as a location keyCode pointing to a location on a US keyboard layout.

Bug: 179812917
Test: atest KeyboardLayoutChangeTest
Test: atest android.hardware.input.cts.tests -m
Change-Id: Ie1b424a0e0bfea2bc15b0b3a644f2f718f16094e
parent 7ade3e1c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -48358,6 +48358,7 @@ package android.view {
    method public static int[] getDeviceIds();
    method public int getId();
    method public android.view.KeyCharacterMap getKeyCharacterMap();
    method public int getKeyCodeForKeyLocation(int);
    method public int getKeyboardType();
    method @NonNull public android.hardware.lights.LightsManager getLightsManager();
    method public android.view.InputDevice.MotionRange getMotionRange(int);
+4 −0
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ interface IInputManager {
    // Reports whether the hardware supports the given keys; returns true if successful
    boolean hasKeys(int deviceId, int sourceMask, in int[] keyCodes, out boolean[] keyExists);

    // Returns the keyCode produced when pressing the key at the specified location, given the
    // active keyboard layout.
    int getKeyCodeForKeyLocation(int deviceId, in int locationKeyCode);

    // Temporarily changes the pointer speed.
    void tryPointerSpeed(int speed);

+22 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.util.SparseArray;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputMonitor;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.VerifiedInputEvent;
@@ -1044,6 +1045,27 @@ public final class InputManager {
        return ret;
    }

    /**
     * Gets the key code produced by the specified location on a US keyboard layout.
     * Key code as defined in {@link android.view.KeyEvent}.
     * This API is only functional for devices with {@link InputDevice#SOURCE_KEYBOARD} available
     * which can alter their key mapping using country specific keyboard layouts.
     *
     * @param deviceId The input device id.
     * @param locationKeyCode The location of a key on a US keyboard layout.
     * @return The key code produced when pressing the key at the specified location, given the
     *         active keyboard layout. Returns {@link KeyEvent#KEYCODE_UNKNOWN} if the requested
     *         mapping could not be determined, or if an error occurred.
     * @hide
     */
    public int getKeyCodeForKeyLocation(int deviceId, int locationKeyCode) {
        try {
            return mIm.getKeyCodeForKeyLocation(deviceId, locationKeyCode);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }


    /**
     * Injects an input event into the event system on behalf of an application.
+15 −0
Original line number Diff line number Diff line
@@ -734,6 +734,21 @@ public final class InputDevice implements Parcelable {
        return InputManager.getInstance().deviceHasKeys(mId, keys);
    }

    /**
     * Gets the key code produced by the specified location on a US keyboard layout.
     * Key code as defined in {@link android.view.KeyEvent}.
     * This API is only functional for devices with {@link InputDevice#SOURCE_KEYBOARD} available
     * which can alter their key mapping using country specific keyboard layouts.
     *
     * @param locationKeyCode The location of a key on a US keyboard layout.
     * @return The key code produced when pressing the key at the specified location, given the
     *         active keyboard layout. Returns {@link KeyEvent#KEYCODE_UNKNOWN} if the requested
     *         mapping could not be determined, or if an error occurred.
     */
    public int getKeyCodeForKeyLocation(int locationKeyCode) {
        return InputManager.getInstance().getKeyCodeForKeyLocation(mId, locationKeyCode);
    }

    /**
     * Gets information about the range of values for a particular {@link MotionEvent} axis.
     * If the device supports multiple sources, the same axis may have different meanings
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.input;

import static android.view.KeyEvent.KEYCODE_UNKNOWN;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Notification;
@@ -284,6 +286,8 @@ public class InputManagerService extends IInputManager.Stub
            int deviceId, int sourceMask, int sw);
    private static native boolean nativeHasKeys(long ptr,
            int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
    private static native int nativeGetKeyCodeForKeyLocation(long ptr, int deviceId,
            int locationKeyCode);
    private static native InputChannel nativeCreateInputChannel(long ptr, String name);
    private static native InputChannel nativeCreateInputMonitor(long ptr, int displayId,
            boolean isGestureMonitor, String name, int pid);
@@ -657,6 +661,22 @@ public class InputManagerService extends IInputManager.Stub
        return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists);
    }

    /**
     * Returns the keyCode generated by the specified location on a US keyboard layout.
     * This takes into consideration the currently active keyboard layout.
     *
     * @param deviceId The input device id.
     * @param locationKeyCode The location of a key on a US keyboard layout.
     * @return The KeyCode this physical key location produces.
     */
    @Override // Binder call
    public int getKeyCodeForKeyLocation(int deviceId, int locationKeyCode) {
        if (locationKeyCode <= KEYCODE_UNKNOWN || locationKeyCode > KeyEvent.getMaxKeyCode()) {
            return KEYCODE_UNKNOWN;
        }
        return nativeGetKeyCodeForKeyLocation(mPtr, deviceId, locationKeyCode);
    }

    /**
     * Transfer the current touch gesture to the provided window.
     *
Loading