Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate USB/Bluetooth HID device locally in order to inject events?

Tags:

Is it possible to simulate a USB or Bluetooth device connected to Android?

I would like to make an app which is able to simulate an HID device locally. What I mean by this is: the app should make Android believe that an USB/Bluetooth HID device is connected. This would allow my app to inject touch events globally, I hope. Is there anyway to simulate a (virtual) device? Note that I don't really care about the device, I just want to use the built-in support for HID input.

I know a lot of people already asked about touch event injections but this approach seems to be a little bit different. I do not want to use this for testing purpose, so InstrumentationTestCase and the like won't help.

Rooting the device might be an option, although I can also imagine to ask my endusers to install a specifically signed app manually (according to https://stackoverflow.com/a/16737083/2923406 and https://stackoverflow.com/a/22902808/2923406 this works, but it would be device specific).

I am aware of:

  1. Simulate a mouse input on android - This guy seems to do it in his own app, although his questions wasn't answered ;)

  2. http://www.pocketmagic.net/2013/01/programmatically-injecting-events-on-android-part-2/#.U58SqfldVHV - Needs Root. Did anyone succeeded in using this? Also, the solution seems very device-specific again.

  3. Bluetooth + simulating mouse - That's not what I want. The phone itself should not be an HID device, but use the (virtually created) one itself. Same for this: https://stackoverflow.com/a/8174973/2923406

Note that I do not want to turn my phone into an HID device of any kind.

like image 496
Rolf Avatar asked Jun 16 '14 16:06

Rolf


1 Answers

Simulating is a broad term. When I created my Bluetooth app I "simulated" a Bluetooth connection in two ways.

Way 1: Use a serial port UART converter and hook it up to a Bluetooth module transmitter.

Then you can use a terminal program like CoolTerm, to send your data.

Like so. In this case I coded in a string to send on successful connection with the device however you can make a infinite loop for testing purposes effectively not requiring your phone to be turned into a HID device.

Way 2 (not easy): Use your computers bluetooth in a server/client relashionship model.

This is harder to do. What you can do is convert your pc/mac into a server and the Android phone into a client or vice-versa. For this you will need to write external code which will need to be compiled separately on a jvm(java virtual machine). The procedure to do this can be found here. If you are using a Linux machine you have to separately download the Bluez module. I have not tried this on any other operating sytem other than Ubuntu, and it was a pain to get functional.

Hopefully that helped.

like image 174
SeahawksRdaBest Avatar answered Sep 17 '22 20:09

SeahawksRdaBest