Input System: Custom HID device on Android

I have a custom HID device I want to use with the Unity Input System. We have successfully been able to hook it up to Windows and macOS, but Android has given us some problems.

I found this thread , which kind of just went stale without any clear solution. That user seems to want to do something similar to what we are trying to.

On Windows and macOS, we’ve been able to use a state structure to interpret the HID reports from our device. Our device identifies as an HID gamepad, but is matched by our custom device class and streams IMU and motion data to our Unity project. All is well.

On Android, things go a bit differently. Our device is matched as an AndroidGameController, and if we try to intercept the HID reports / state updates (by implementing IInputStateCallbackReceiver on the custom device class), we don’t see the same report format as we do on Windows and macOS. From the previous thread, we understand that this is because we don’t actually get the raw HID report, but rather an AndroidGameControllerState object that has collected our report into a collection of axes. Is there any way to avoid this?

We have full control over the HID device descriptor, and are OK with presenting the device as something other than an HID Gamepad. But we haven’t been able to get Unity to recognize the device in other configurations.

We’ve been able to get a subset of our original input report by packing them up as different “axes” values. However, that is a pretty limited solution and feels way too hacky. Furthermore, it’s unclear which axes correspond to actual HID usages (especially the “generic” ones).

An alternative we’ve been looking at is implementing a “virtual” device, but before we put in the effort of writing specialized code to access the raw HID report on Android (if that’s at all possible), we’d like to exhaust all alternatives.

Has there been any development on the Android backend lately, or is there anything in the works?

@Rene-Damm , would be great to get your input on this :slight_smile:

At this point I’m mainly curious to know if what I want is at all possible? Am I wasting my time trying to get this to work without having the device recognized as an AndroidGamepad?

I think if standard android HID drivers are not capable of supporting your device (malformed HID descriptor, non-HID compliant device, not supported usage pages, etc) then unfortunately the only way is to make a plugin to talk to some HID api’s directly, like BluetoothHidDevice  |  Android Developers We’re currently not planning to support raw HID reports outside of desktop platforms

If the driver stack does manage to parse HID report correctly, and you get AndroidGameControllerState containing all the required data, I would try to find to which axes it mapped the data to and create a custom device alike how we do a dualshock here InputSystem/Packages/com.unity.inputsystem/InputSystem/Plugins/Android/AndroidGameController.cs at develop · Unity-Technologies/InputSystem · GitHub and here InputSystem/Packages/com.unity.inputsystem/InputSystem/Plugins/Android/AndroidSupport.cs at develop · Unity-Technologies/InputSystem · GitHub