Kodi Community Forum
First longpress after input device standby/resume not working - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Android (https://forum.kodi.tv/forumdisplay.php?fid=164)
+---- Thread: First longpress after input device standby/resume not working (/showthread.php?tid=322224)



First longpress after input device standby/resume not working - CiNcH - 2017-10-09

Problem
The first longpress of a button on the Sony Android TV remote control  after not having used it for >30s always fails. The action of the shortpress is executed instead

Detailed Description
The Sony remote combines 2 functions:
- infrared for the buttons (keyboard from a Kodi point of view)
- Bluetooth for voice input (joystick from a Kodi point of view)

The Bluetooth part is detected as Joystick inside Kodi, which is suspended after a 30s idle time (see here) and is  woken up again when pressing any button, causing the Joystick to be re-detected by Kodi. If the button press which wakes the Bluetooth part is a longpress, the Joystick re-detection seems to reset the key early, effectively resulting in a shortpress. So the Joystick detection seems to have some influence on the keyboard input.

I created a log of the incident:

- play video
- longpress OK: pause
- longpress OK: play
- wait >30 seconds until remote device gets removed
- longpress OK: player controls (shortpress) instead of pause (longpress)

Code:
17:44:53.440 DEBUG: Keyboard: scancode: 0x17, sym: 0x000d, unicode: 0x0000, modifier: 0x0
17:44:53.937 DEBUG: Previous line repeats 1 times.
17:44:53.938 DEBUG: OnKey: long-return (0x100f00d) pressed, action is PlayPause
17:44:53.967 DEBUG: GOT ANNOUNCEMENT, type: 1, from xbmc, message OnPause
...
17:44:53.988 DEBUG: Keyboard: scancode: 0x17, sym: 0x000d, unicode: 0x0000, modifier: 0x0
17:44:56.791 DEBUG: Previous line repeats 17 times.
17:44:56.791 DEBUG: OnKey: long-return (0x100f00d) pressed, action is PlayPause
17:44:56.794 DEBUG: CAnnouncementManager - Announcement: OnPlay from xbmc
...
17:45:27.750  INFO: CPeripheralBusAndroid: input device "SONY TV RC MIC 001" with ID 21 removed
...
17:45:35.689   DEBUG: Keyboard: scancode: 0x17, sym: 0x000d, unicode: 0x0000, modifier: 0x0
17:45:35.733   DEBUG: CPeripheralBusAndroid: input device with ID 22 added
17:45:35.734   DEBUG: GetMappingForDevice - device (054C:0B91) mapped to  (type = joystick)
17:45:35.736 WARNING: Button mapping add-on not present for android/inputdevice/22 (SONY TV RC MIC 001), skipping
17:45:35.737   ERROR: CPeripheralJoystick: Invalid location (android/inputdevice/22)
17:45:35.737   DEBUG: CreatePeripheral - failed to initialise peripheral on 'android/inputdevice/22'
17:45:38.845   DEBUG: OnKey: return (0xf00d) pressed, action is OSD

[FULL LOG]


Workaround
Disabling Bluetooth on the Sony Android TV works around the issue, preventing the (re-)detection of the Joystick on a button press inside Kodi. But it obviously kills voice input, therefore rendering the workaround useless.


RE: Longpress not working under certain circumstances - CiNcH - 2017-10-22

I tried longpress on the Android TV HOME screen where it works properly after the mentioned 30s idle time and removal/re-detection of the input device. Also according to the LED on the Sony Android TV, longpress seems to work. But the re-detection of the input device inside Kodi after the 30s idle time seems to reset the key somehow.

The detected input device is actually not needed for key presses which are transmitted via infrared. Buttons on the remote are keyboard emulated. The input device represents the Bluetooth part of the remote which is responsible for voice input. Weird thing is that it is detected as Joystick (in the log), even after disabling the respective add-on.

Probably @garbear got some idea?


RE: Longpress not working under certain circumstances - garbear - 2017-10-24

(2017-10-22, 12:25)CiNcH Wrote: I tried longpress on the Android TV HOME screen where it works properly after the mentioned 30s idle time and removal/re-detection of the input device. Also according to the LED on the Sony Android TV, longpress seems to work. But the re-detection of the input device inside Kodi after the 30s idle time seems to reset the key somehow.

When the screen saver kicks in, Android changes the device from a keyboard to a joystick. I'm not sure why. I'll be able to look into this after DevCon next weekend. In the meantime, the best we can do is make the joystick device act like the keyboard device.

(2017-10-22, 12:25)CiNcH Wrote: Weird thing is that it is detected as Joystick (in the log), even after disabling the respective add-on.

The device type is determined by Android, not Kodi. Joystick detection is done by Kodi instead of the add-on. However, the add-on contains the button maps, so it must be enabled for joysticks to have any effect in Kodi.


RE: First longpress after input device standby/resume not working - CiNcH - 2017-10-24

Quote:When the screen saver kicks in

Just to clarify this... the problem mentioned here is not about device standby or screensaver, but about remote standby. The Bluetooth part in the remote is suspended after 30s idle time and woken up again when pressing a button even though button presses are transmitted via infrared and not Bluetooth. And this Bluetooth wake-up with subsequent Joystick re-detection in Kodi seems to interrupt the long button press.


RE: First longpress after input device standby/resume not working - CiNcH - 2017-10-24

Also keep in mind that only the first longpress after remote standby fails (which I assume is due to Kodi re-adding the input device on "remote resume"). After that, longpress works again... until the remote goes to sleep again due to 30s of inactivity. Then again first longpress won't work unless you have woken up the remote (e.g. with some short button press) before doing the longpress.


RE: First longpress after input device standby/resume not working - CiNcH - 2017-10-25

Quote:When the screen saver kicks in, Android changes the device from a keyboard to a joystick. I'm not sure why. I'll be able to look into this after DevCon next weekend. In the meantime, the best we can do is make the joystick device act like the keyboard device.
The remote is detected as joystick from the beginning. This joystick device however is actually not needed for anything. I think that it is the Bluetooth part of the remote which is responsible for capturing voice input. No clue why the remote says that it is a joystick at all. It might also have some other functionality via Bluetooth which I am not aware of. Button presses from this remote are however transmitted via infrared and detected as keyboard input. If the Bluetooth part goes to sleep after 30s of idle time, it is woken up again when pressing any button. If this button press is a long press, this long press seems to get interrupted by the input device detection (due to Bluetooth resume), effectively resulting in a short press. So the joystick detection seems to have some influence on keyboard input.

I will try to disable Bluetooth on my Sony TV. I assume it will solve the longpress issue. But it will obviously kill voice input, therefore rendering the workaround useless.


RE: First longpress after input device standby/resume not working - CiNcH - 2017-10-25

Quote: I will try to disable Bluetooth on my Sony TV. I assume it will solve the longpress issue. But it will obviously kill voice input, therefore rendering the workaround useless.

That's indeed the case. I updated the initial posting to summarize the problem and my findings in a hopefully understandable way.