Skip to content

Commit

Permalink
Use device id 0 for touch/mouse events
Browse files Browse the repository at this point in the history
Virtual device is only for keyboard sources, not mouse or touchscreen
sources. Here is the value of InputDevice.getDevice(-1).toString():

    Input Device -1: Virtual
      Descriptor: ...
      Generation: 2
      Location: built-in
      Keyboard Type: alphabetic
      Has Vibrator: false
      Has mic: false
      Sources: 0x301 ( keyboard dpad )

InputDevice.getDeviceId() documentation says:

> An id of zero indicates that the event didn't come from a physical
> device and maps to the default keymap.

<https://developer.android.com/reference/android/view/InputEvent#getDeviceId()>

However, injecting events with a device id of 0 causes event.getDevice()
to be null on the client-side.

Commit 26529d3 used -1 as a workaround
to avoid a NPE on a specific Android TV device. But this is a bug in the
device system, which wrongly assumes that input device may not be null.

A similar issue was present in Flutter, but it is now fixed:
 - <flutter/flutter#30665>
 - <flutter/engine#7986>

On the other hand, using an id of -1 for touchscreen events (which is
invalid) causes issues for some apps:
<#2125 (comment)>

Therefore, use a device id of 0.

An alternative could be to find an existing device matching the source,
like "adb shell input" does. See getInputDeviceId():
<https://android.googlesource.com/platform/frameworks/base.git/+/master/cmds/input/src/com/android/commands/input/Input.java>

But it seems better to indicate that the event didn't come from a
physical device, and it would not solve #962 anyway, because an Android
TV has no touchscreen.

Refs #962 <#962>
Fixes #2125 <#2125>
  • Loading branch information
rom1v committed Mar 14, 2021
1 parent 429fdef commit d9786c6
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit d9786c6

Please sign in to comment.