Android 4 controller problems

The OUYA was known for providing a custom input handling system, because the standard Android 4.1 one was not sufficient.

I never knew the exact cause, but yesterday I stumbled upon the archived PlayJam Games Network Controller Guidelines - it lists the bugs in detail:

1. D-pad event misidentification

Due to an overly simplistic implementation of the dpad translation code in Android, (up to and including Android 4.4), using onKeyDown() and onKeyUp() events with multiple controllers is not recommended. While onKey*() events work acceptably for single controllers, when multiple controllers are used it is possible for events from one controller to be misidentified as coming from another.

2. Controller identification

Android provides several different methods for identifying controllers, however they are not all equal in terms of functionality:

InputDevice.getId()
  • Guaranteed unique for the current power cycle
  • Not stable – They are simple incrementing integers that are assigned to each device as it connects – even if it is a device that has already been connected – as such it is guaranteed that a different value will be returned for a controller before and after a power cycle of that controller, (i.e. if it disconnects, its getId() will change).
InputDevice.getDescriptor()
  • Stable – The value for any controllers will stay the same through power cycles of the controller and/or the platform – the value itself is derived from physical properties of the device.
  • Not guaranteed unique – As the value is derived from a set of physical parameters of the device, it is possible for devices which share the same set of parameters to return the same value. This is generally not a problem for Bluetooth devices, as the MAC address of the Bluetooth client is part of the input to the id generator.
InputDevice.getName()
  • PlayJam provides managed naming of controllers – in that the controller with a specific player lit up will remain the same name – so the controller with light one on, (Player 1), will always return the device name of “GameStick Controller 1”. Note that the order of light assignment is currently related to the power up order of controllers – so turning off controllers and repowering in a different order will result in name changes – however the controller itself will still show the correct light for its name, (making the assignment clean to the user).

I guess that the OUYA developers implemented something like the GameStick people, which meant that all games that wanted to support multiple controllers had to use the OUYA SDK, or do all the work themselves.

Written by Christian Weiske.

Comments? Please send an e-mail.