Loading core/java/android/hardware/input/input_framework.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -236,3 +236,10 @@ flag { description: "Adds an accessibility setting to disable touchpads" bug: "372857036" } flag { name: "disable_settings_for_virtual_devices" namespace: "input" description: "Disable settings pages for virtual devices created using VDM or InputManager" bug: "402596982" } core/java/android/view/InputDevice.java +35 −5 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public final class InputDevice implements Parcelable { private final InputDeviceIdentifier mIdentifier; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) private final boolean mIsExternal; private final boolean mIsVirtualDevice; @Source private final int mSources; private final int mKeyboardType; Loading Loading @@ -498,11 +499,11 @@ public final class InputDevice implements Parcelable { * Called by native code */ private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId, int productId, int deviceBus, String descriptor, boolean isExternal, int sources, int keyboardType, KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, @Nullable String keyboardLayoutType, boolean hasVibrator, boolean hasMicrophone, boolean hasSensor, boolean hasBattery, int usiVersionMajor, int usiVersionMinor, int associatedDisplayId, boolean enabled) { int productId, int deviceBus, String descriptor, boolean isExternal, boolean isVirtualDevice, int sources, int keyboardType, KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, @Nullable String keyboardLayoutType, boolean hasVibrator, boolean hasMicrophone, boolean hasSensor, boolean hasBattery, int usiVersionMajor, int usiVersionMinor, int associatedDisplayId, boolean enabled) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; Loading @@ -512,6 +513,7 @@ public final class InputDevice implements Parcelable { mDeviceBus = deviceBus; mDescriptor = descriptor; mIsExternal = isExternal; mIsVirtualDevice = isVirtualDevice; mSources = sources; mKeyboardType = keyboardType; mKeyCharacterMap = keyCharacterMap; Loading Loading @@ -546,6 +548,7 @@ public final class InputDevice implements Parcelable { mDeviceBus = in.readInt(); mDescriptor = in.readString(); mIsExternal = in.readInt() != 0; mIsVirtualDevice = in.readInt() != 0; mSources = in.readInt(); mKeyboardType = in.readInt(); mKeyboardLanguageTag = in.readString8(); Loading Loading @@ -588,6 +591,7 @@ public final class InputDevice implements Parcelable { private int mDeviceBus = 0; private String mDescriptor = ""; private boolean mIsExternal = false; private boolean mIsVirtualDevice = false; private int mSources = 0; private int mKeyboardType = 0; private KeyCharacterMap mKeyCharacterMap = null; Loading Loading @@ -659,6 +663,12 @@ public final class InputDevice implements Parcelable { return this; } /** @see InputDevice#isPhysicalDevice() */ public Builder setIsVirtualDevice(boolean isVirtualDevice) { mIsVirtualDevice = isVirtualDevice; return this; } /** @see InputDevice#getSources() */ public Builder setSources(int sources) { mSources = sources; Loading Loading @@ -761,6 +771,7 @@ public final class InputDevice implements Parcelable { mDeviceBus, mDescriptor, mIsExternal, mIsVirtualDevice, mSources, mKeyboardType, mKeyCharacterMap, Loading Loading @@ -969,6 +980,23 @@ public final class InputDevice implements Parcelable { return mIsExternal; } /** * Returns {@code true} if it represents a real physical hardware that is connected to the * android device, returns {@code false} if it represents a virtual device that is created from * userspace like devices created using {@link android.companion.virtual.VirtualDeviceManager} * or {@link KeyCharacterMap#VIRTUAL_KEYBOARD} * * <p> * Use this method to identify if an InputDevice should be treated as a physically connected * peripheral for aspects like Settings, etc. * </p> * * @hide */ public boolean isPhysicalDevice() { return !mIsVirtualDevice && !isVirtual(); } /** * Returns true if the device is a full keyboard. * Loading Loading @@ -1592,6 +1620,7 @@ public final class InputDevice implements Parcelable { out.writeInt(mDeviceBus); out.writeString(mDescriptor); out.writeInt(mIsExternal ? 1 : 0); out.writeInt(mIsVirtualDevice ? 1 : 0); out.writeInt(mSources); out.writeInt(mKeyboardType); out.writeString8(mKeyboardLanguageTag); Loading Loading @@ -1634,6 +1663,7 @@ public final class InputDevice implements Parcelable { description.append(" Generation: ").append(mGeneration).append("\n"); description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append( "\n"); description.append(" Virtual: ").append(mIsVirtualDevice).append("\n"); description.append(" Enabled: ").append(isEnabled()).append("\n"); description.append(" Keyboard Type: "); Loading core/jni/android_view_InputDevice.cpp +8 −7 Original line number Diff line number Diff line Loading @@ -83,12 +83,13 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi static_cast<int32_t>(ident.vendor), static_cast<int32_t>(ident.product), static_cast<int32_t>(ident.bus), descriptorObj.get(), deviceInfo.isExternal(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), keyboardLanguageTagObj.get(), keyboardLayoutTypeObj.get(), deviceInfo.hasVibrator(), deviceInfo.hasMic(), deviceInfo.hasSensor(), deviceInfo.hasBattery(), usiVersion.majorVersion, usiVersion.minorVersion, deviceInfo.isExternal(), deviceInfo.isVirtualDevice(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), keyboardLanguageTagObj.get(), keyboardLayoutTypeObj.get(), deviceInfo.hasVibrator(), deviceInfo.hasMic(), deviceInfo.hasSensor(), deviceInfo.hasBattery(), usiVersion.majorVersion, usiVersion.minorVersion, deviceInfo.getAssociatedDisplayId(), deviceInfo.isEnabled())); // Note: We do not populate the Bluetooth address into the InputDevice object to avoid leaking Loading Loading @@ -125,7 +126,7 @@ int register_android_view_InputDevice(JNIEnv* env) gInputDeviceClassInfo.ctor = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "<init>", "(IIILjava/lang/String;IIILjava/lang/" "String;ZIILandroid/view/KeyCharacterMap;Ljava/" "String;ZZIILandroid/view/KeyCharacterMap;Ljava/" "lang/String;Ljava/lang/String;ZZZZIIIZ)V"); gInputDeviceClassInfo.addMotionRange = Loading services/core/java/com/android/server/input/InputManagerService.java +33 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.OptionalInt; import java.util.Set; import java.util.function.Consumer; /** The system implementation of {@link IInputManager} that manages input devices. */ Loading Loading @@ -314,6 +315,12 @@ public class InputManagerService extends IInputManager.Stub @GuardedBy("mAssociationsLock") private final Map<String, String> mKeyboardLayoutAssociations = new ArrayMap<>(); // The set of input ports (String) for all the devices that are marked as "virtual devices". // Typically all devices created from VDM or any other Uinput device created by system server // should be marked as virtual. @GuardedBy("mAssociationsLock") private final Set<String> mVirtualDevicePorts = new ArraySet<>(); // Stores input ports associated with device types. For example, adding an association // {"123", "touchNavigation"} here would mean that a touch device appearing at port "123" would // enumerate as a "touch navigation" device rather than the default "touchpad as a mouse Loading Loading @@ -1905,6 +1912,24 @@ public class InputManagerService extends IInputManager.Stub mNative.changeKeyboardLayoutAssociation(); } void addVirtualDevice(@NonNull String inputPort) { Objects.requireNonNull(inputPort); synchronized (mAssociationsLock) { mVirtualDevicePorts.add(inputPort); } mNative.changeVirtualDevices(); } void removeVirtualDevice(@NonNull String inputPort) { Objects.requireNonNull(inputPort); synchronized (mAssociationsLock) { mVirtualDevicePorts.remove(inputPort); } mNative.changeVirtualDevices(); } @Override // Binder call public InputSensorInfo[] getSensorList(int deviceId) { return mNative.getSensorList(deviceId); Loading Loading @@ -2984,6 +3009,14 @@ public class InputManagerService extends IInputManager.Stub return flatten(configs); } // Native callback. @SuppressWarnings("unused") private String[] getVirtualDevicePorts() { synchronized (mAssociationsLock) { return mVirtualDevicePorts.toArray(new String[0]); } } /** * Gets if an input device could dispatch to the given display". * @param deviceId The input device id. Loading services/core/java/com/android/server/input/NativeInputManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -231,6 +231,8 @@ interface NativeInputManagerService { void changeKeyboardLayoutAssociation(); void changeVirtualDevices(); void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled); void setMotionClassifierEnabled(boolean enabled); Loading Loading @@ -582,6 +584,9 @@ interface NativeInputManagerService { @Override public native void changeKeyboardLayoutAssociation(); @Override public native void changeVirtualDevices(); @Override public native void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled); Loading Loading
core/java/android/hardware/input/input_framework.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -236,3 +236,10 @@ flag { description: "Adds an accessibility setting to disable touchpads" bug: "372857036" } flag { name: "disable_settings_for_virtual_devices" namespace: "input" description: "Disable settings pages for virtual devices created using VDM or InputManager" bug: "402596982" }
core/java/android/view/InputDevice.java +35 −5 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public final class InputDevice implements Parcelable { private final InputDeviceIdentifier mIdentifier; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) private final boolean mIsExternal; private final boolean mIsVirtualDevice; @Source private final int mSources; private final int mKeyboardType; Loading Loading @@ -498,11 +499,11 @@ public final class InputDevice implements Parcelable { * Called by native code */ private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId, int productId, int deviceBus, String descriptor, boolean isExternal, int sources, int keyboardType, KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, @Nullable String keyboardLayoutType, boolean hasVibrator, boolean hasMicrophone, boolean hasSensor, boolean hasBattery, int usiVersionMajor, int usiVersionMinor, int associatedDisplayId, boolean enabled) { int productId, int deviceBus, String descriptor, boolean isExternal, boolean isVirtualDevice, int sources, int keyboardType, KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, @Nullable String keyboardLayoutType, boolean hasVibrator, boolean hasMicrophone, boolean hasSensor, boolean hasBattery, int usiVersionMajor, int usiVersionMinor, int associatedDisplayId, boolean enabled) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; Loading @@ -512,6 +513,7 @@ public final class InputDevice implements Parcelable { mDeviceBus = deviceBus; mDescriptor = descriptor; mIsExternal = isExternal; mIsVirtualDevice = isVirtualDevice; mSources = sources; mKeyboardType = keyboardType; mKeyCharacterMap = keyCharacterMap; Loading Loading @@ -546,6 +548,7 @@ public final class InputDevice implements Parcelable { mDeviceBus = in.readInt(); mDescriptor = in.readString(); mIsExternal = in.readInt() != 0; mIsVirtualDevice = in.readInt() != 0; mSources = in.readInt(); mKeyboardType = in.readInt(); mKeyboardLanguageTag = in.readString8(); Loading Loading @@ -588,6 +591,7 @@ public final class InputDevice implements Parcelable { private int mDeviceBus = 0; private String mDescriptor = ""; private boolean mIsExternal = false; private boolean mIsVirtualDevice = false; private int mSources = 0; private int mKeyboardType = 0; private KeyCharacterMap mKeyCharacterMap = null; Loading Loading @@ -659,6 +663,12 @@ public final class InputDevice implements Parcelable { return this; } /** @see InputDevice#isPhysicalDevice() */ public Builder setIsVirtualDevice(boolean isVirtualDevice) { mIsVirtualDevice = isVirtualDevice; return this; } /** @see InputDevice#getSources() */ public Builder setSources(int sources) { mSources = sources; Loading Loading @@ -761,6 +771,7 @@ public final class InputDevice implements Parcelable { mDeviceBus, mDescriptor, mIsExternal, mIsVirtualDevice, mSources, mKeyboardType, mKeyCharacterMap, Loading Loading @@ -969,6 +980,23 @@ public final class InputDevice implements Parcelable { return mIsExternal; } /** * Returns {@code true} if it represents a real physical hardware that is connected to the * android device, returns {@code false} if it represents a virtual device that is created from * userspace like devices created using {@link android.companion.virtual.VirtualDeviceManager} * or {@link KeyCharacterMap#VIRTUAL_KEYBOARD} * * <p> * Use this method to identify if an InputDevice should be treated as a physically connected * peripheral for aspects like Settings, etc. * </p> * * @hide */ public boolean isPhysicalDevice() { return !mIsVirtualDevice && !isVirtual(); } /** * Returns true if the device is a full keyboard. * Loading Loading @@ -1592,6 +1620,7 @@ public final class InputDevice implements Parcelable { out.writeInt(mDeviceBus); out.writeString(mDescriptor); out.writeInt(mIsExternal ? 1 : 0); out.writeInt(mIsVirtualDevice ? 1 : 0); out.writeInt(mSources); out.writeInt(mKeyboardType); out.writeString8(mKeyboardLanguageTag); Loading Loading @@ -1634,6 +1663,7 @@ public final class InputDevice implements Parcelable { description.append(" Generation: ").append(mGeneration).append("\n"); description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append( "\n"); description.append(" Virtual: ").append(mIsVirtualDevice).append("\n"); description.append(" Enabled: ").append(isEnabled()).append("\n"); description.append(" Keyboard Type: "); Loading
core/jni/android_view_InputDevice.cpp +8 −7 Original line number Diff line number Diff line Loading @@ -83,12 +83,13 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi static_cast<int32_t>(ident.vendor), static_cast<int32_t>(ident.product), static_cast<int32_t>(ident.bus), descriptorObj.get(), deviceInfo.isExternal(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), keyboardLanguageTagObj.get(), keyboardLayoutTypeObj.get(), deviceInfo.hasVibrator(), deviceInfo.hasMic(), deviceInfo.hasSensor(), deviceInfo.hasBattery(), usiVersion.majorVersion, usiVersion.minorVersion, deviceInfo.isExternal(), deviceInfo.isVirtualDevice(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), keyboardLanguageTagObj.get(), keyboardLayoutTypeObj.get(), deviceInfo.hasVibrator(), deviceInfo.hasMic(), deviceInfo.hasSensor(), deviceInfo.hasBattery(), usiVersion.majorVersion, usiVersion.minorVersion, deviceInfo.getAssociatedDisplayId(), deviceInfo.isEnabled())); // Note: We do not populate the Bluetooth address into the InputDevice object to avoid leaking Loading Loading @@ -125,7 +126,7 @@ int register_android_view_InputDevice(JNIEnv* env) gInputDeviceClassInfo.ctor = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "<init>", "(IIILjava/lang/String;IIILjava/lang/" "String;ZIILandroid/view/KeyCharacterMap;Ljava/" "String;ZZIILandroid/view/KeyCharacterMap;Ljava/" "lang/String;Ljava/lang/String;ZZZZIIIZ)V"); gInputDeviceClassInfo.addMotionRange = Loading
services/core/java/com/android/server/input/InputManagerService.java +33 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.OptionalInt; import java.util.Set; import java.util.function.Consumer; /** The system implementation of {@link IInputManager} that manages input devices. */ Loading Loading @@ -314,6 +315,12 @@ public class InputManagerService extends IInputManager.Stub @GuardedBy("mAssociationsLock") private final Map<String, String> mKeyboardLayoutAssociations = new ArrayMap<>(); // The set of input ports (String) for all the devices that are marked as "virtual devices". // Typically all devices created from VDM or any other Uinput device created by system server // should be marked as virtual. @GuardedBy("mAssociationsLock") private final Set<String> mVirtualDevicePorts = new ArraySet<>(); // Stores input ports associated with device types. For example, adding an association // {"123", "touchNavigation"} here would mean that a touch device appearing at port "123" would // enumerate as a "touch navigation" device rather than the default "touchpad as a mouse Loading Loading @@ -1905,6 +1912,24 @@ public class InputManagerService extends IInputManager.Stub mNative.changeKeyboardLayoutAssociation(); } void addVirtualDevice(@NonNull String inputPort) { Objects.requireNonNull(inputPort); synchronized (mAssociationsLock) { mVirtualDevicePorts.add(inputPort); } mNative.changeVirtualDevices(); } void removeVirtualDevice(@NonNull String inputPort) { Objects.requireNonNull(inputPort); synchronized (mAssociationsLock) { mVirtualDevicePorts.remove(inputPort); } mNative.changeVirtualDevices(); } @Override // Binder call public InputSensorInfo[] getSensorList(int deviceId) { return mNative.getSensorList(deviceId); Loading Loading @@ -2984,6 +3009,14 @@ public class InputManagerService extends IInputManager.Stub return flatten(configs); } // Native callback. @SuppressWarnings("unused") private String[] getVirtualDevicePorts() { synchronized (mAssociationsLock) { return mVirtualDevicePorts.toArray(new String[0]); } } /** * Gets if an input device could dispatch to the given display". * @param deviceId The input device id. Loading
services/core/java/com/android/server/input/NativeInputManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -231,6 +231,8 @@ interface NativeInputManagerService { void changeKeyboardLayoutAssociation(); void changeVirtualDevices(); void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled); void setMotionClassifierEnabled(boolean enabled); Loading Loading @@ -582,6 +584,9 @@ interface NativeInputManagerService { @Override public native void changeKeyboardLayoutAssociation(); @Override public native void changeVirtualDevices(); @Override public native void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled); Loading