Android phone as computer mouse - android

I created an Android app that serves the touch screen sensor data to a java client that is listening on Debian Lenny machine.
The client maps this data to locations on the screen just like a wacom pad does. I would like to out put the x_loc and y_loc to a file and have the file recognized as a device.(I foggily believe this is how it is supposed to work)
I have experience with Linux but have not had to create a device before. How do I tell Linux that this file is a mouse. Do I have to create a driver?

There's many ways to do this, ranging from writing an actual device driver, over writing X clients to generate X events (using the XTest extension for example), to using kernel interfaces to inject input subsystem events.
I'd go with the last one and use the uinput subsystem. That's part of pretty much all recent kernels and provides /dev/uinput, which you can open regularly and do various ioctls on to create input devices from regular userspace.
Please also note that some mechanisms for this already exist. Bluetooth Human Interface Devices, which work just fine on Linux, are one example. rinputd, a daemon to listen to rinput clients and generating uinput events based on the data they send. is another. You might want to consider just making your Android app akt as an rinput client.

You can either write a linux device driver to interpret your data as a genuine mouse, or you can convince the X server (or whatever else) to accept input from something else, such as a named pipe.
Actual device files are not files with any content - they are merely references to a major and minor number used to talk to a driver in the kernel which can perform vaguely file-like options on some device. You create device files with mknod, but they won't work until backed by a kernel driver with matching numbers. Believe there are now some stub mechanisms so the bulk of the actual driver can run in userspace.

Related

How input received by SPI may be interpreted by Android

This is my first question on stackoverflow even though I'm a continuous reader of this problem-solving source.
Anyway, this is the issue I'm facing :
I'm trying to connect with a bus SPI two evalboards :
The first one (source of data) simulates a touchscreen and is a Linux distro (for now : Raspbian).
The second one is an Android embedded.
I would like to connect those two by SPI and send from the Linux one to Android the touch sequence (according to the multi-touch protocol (https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt)).
spidev is enabled, but I have no idea about how to "perform" the touches I will receive.
From what I see : I can't use Android input Devices (https://source.android.com/devices/input/input-device-configuration-files.html) because it can't rely on SPI communication.
Must I create a driver in the linux kernel then ? What is the "best practice" in this particular situation ?
Thanks in advance, you might be saving my internship :)
If your Android Linux kernel is set up to expose /dev/spidev (or you can set that up in the kernel), you do not have to create a Linux kernel module. You can access /dev/spidev from Android by writing an NDK wrapper in c/c++.
I have done that and it works. I would suggest that you start with writing a small c-program that configures and opens a /dev/spidev spi channel, and sends/receives some test data. When that works, rewrite the c-program into an NDK wrapper library you can access from an Android program.
This assumes that the Android app is one you write yourself. If you want to make the touch-events available to Android in general, I think you need to write a touch-driver as a kernel module.

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

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:
Simulate a mouse input on android - This guy seems to do it in his own app, although his questions wasn't answered ;)
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.
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.
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.
Yes, it's quite easy using the AOA2 protocol check this & this links for details ( you'll need to switch your device to the Accessory mode )
This may be possible (or at least be easier) using the Robolectric library, which simulates a full Android device locally. Although it is intended primarily for testing, the fact that it simulates a whole device locally - including Bluetooth and USB - means adding to it may be an easier approach.
In other words, you may be able to modify the classes it uses to simulate these abilities locally (i.e. in the IDE itself without an emulator or device) in order to simulate them on the device itself. After all, it does provide full simulations of these functions. You could simply change these Bluetooth and USB simulating classes to load onto the device itself rather than onto the local Robolectric test "device."
This is just an idea though - I can't confirm this will work - it just might be a good place for you to start.

Hayes AT command support on Android

A current product I work on supports standard modem AT commands over the serial link. Commands such as ATD, ATH, ATV, ATQ ATE etc to either get information from the device or seti info on the device.
The device also supports dial-up PPP connection which is typically preceded by some AT commands when initiated from the PC - ATD for e.g.
We are looking at creating a similar device using Android and I searched whether Android or Linux support Hayes modem AT commands over the serial interface such as RS232 or USB and am unable to find such a layer or component.
On Android RIL page I see it says that, "Android provides a reference Vendor RIL, using the Hayes AT command set, that you can use as a quick start for telephony testing and a guide for commercial vendor RILs". But I believe this may be for interfacing with the Baseband or Telephony layer. Is this also typically used with the serial interface where a DTE can issue AT commands and talk to the Android device ?
I also researched Linux and it does have a basic set of AT commands but they are not modem related and serve a different purpose - e.g. atq lists the user's pending jobs, atrm deletes jobs, identified by their job number.
So I am looking to undestand, whether Android or the Linux kernel has a default AT command parser which supports the Hayes AT Command set, which can be accessed by a DTE connected to the Android device over a serial link.
I think this is a typical case for phones and other may have come across the same question or issue, but I have not found an answer searching on the Android forums.
adding more info to clarify my question as it seems from the answers, it wasnt very clear what I was asking
To clarify my question, I am not trying to issue AT commands from the Android phone. Rather I am looking to issue AT commands from a PC to an Android phone over a serial link such as RS232/USB/Bluetooth.
I am trying to understand if Android inherently supports AT commands and has an AT parser ?
For e.g. to establish a PPP link (dial-up connection) from Windows to a device that supports PPP, windows will first send some AT commands and finally the ATD (dial) command. The device responds with a CONNECT response, afterwhich it switches to online mode and a PPP link is established and IP data cab be sent between the PC and the device. Thus typically such devices (modems) by default are in AT mode. ATD is just one such command. There are several other AT commands supported by the device.
Now to develop a similar device using Android, I'd like to do that without significantly altering the Linux kernel or Andorid architecture and am looking to understand if a AT command parser which recognizes the standard set of AT commands is inhenrently supported by android.
To make my question clearer, consider the case where a PC for e.g. connects to a device (phone) using the BT DUNS (dialup networking) profile. The DUNS profile requires the phone to support i.e. parse and recognize certain AT commands such as AT&C, &D, &F, +GCAP, +GMI, +GMM, +GMR, ATA, D, E, H, L, M etc.
How does Android address this ? Does it have native support for reconizing and responding to such AT commands ?
thanks in advance!
If I understood you correctly you like to send AT-commands via a serial communication from an Android device to your hardware - and get the responses back.
Basically one would implement a serial communication either via Bluetooth - or starting with level 12 using USB communication.
I have done quite extensive serial communication in both ways it it works quite well. The main problem so far has been that while Bluetooth serial-Adapters are quite expensive - the new USB-serial communication has flaws on certain devices.
The last time I tested Samsung Galaxy Tab, the USB driver's were not functional. On some other Android device there were no USB-drivers at all installed.
But once you have a working Android device serial communication (with or without using AT-commands) works fine
For more info you might like to check http://developer.android.com/guide/topics/usb/host.html
On linux, there's the chat command, which was typically used by the pppd demon. Then there's the classical TCL expect, which allows scripting. It has been ported to many languages, eg expect for Java, Python expect. I haven't used the latter two, but it looks as if you can use them as a library and don't have to call them as external programs.
It's a curious thing that the most advanced mobile phones still use the archaic Hayes AT command set instead of a proper API..

how to control pc mouse from android device without client server

I need to create an application that control PC mouse(pointer) through android device without downloading a server on pc, it should be able to communicate directly with my pc I already checked out the remote droid application but the user would need to download a client server to communicate with the phone
so is there way to remote control pc mouse through phone without downloading a client server on pc?
note: I am working on android 2.3.3 thus i cant use wifi direct and usb accessor
Why not just simulate regular bluetooth mouse, a standard bluetooth mouse which has its drivers as part of most os's.
no one can control your pc remotely without bluetooth pairing.
in theory i think it should be possible, but it requires knowledge in hardware and low level software (so its not a task suitable for most developers).
It doesn't matter what the client is, the fundamental question is "Can you move the mouse cursor on your PC from anywhere without installing software"
The short answer is no - which is a good thing! Otherwise, anyone on your network could just take control of your PC...
That said, you could, in theory, create an RDP (Remote Desktop) connection and use that to control the PC as a whole - but that is very complex, has been done already and would still require the user to allow remote desktop connections to the computer (Control Panel->System->Advanced->Remote)
Edit - Bare minimum app:
There are a number of ways to approach this but the absolute simplest app I can envision involves having an application on the PC listen for connections on a TCP/IP port. You'd then send messages to this port from Android using the Sockets classes.
The app would receive these messages, parse them and perform the appropriate mouse actions.
Make sure that you include an authentication/authorisation mechanism - you don't want random strangers to be able to control your PC just because they broke your wifi.
You may find it easier to build the desktop app to accept messages using the HTTP protocol (RFC) - This is a standard, widely used and very flexible mechanism for client-server communication. Why reinvent the wheel? This would also make your Android-side code far simpler as you could use HttpURLConnection and other similar classes which abstract the complexity of managing sockets.
You may also want to consider if the app should provide any feedback to the client - eg the new mouse position or a success/failure.
NB: Running the app as a windows service or website might seem preferable to a desktop app (doesn't need to be started by the user, nothing in taskbar/system tray) but there are considerable drawbacks to both - Windows services can't interract with the desktop easily (what happens if nobody is logged in?) and websites run as a different user so in addition to not having the same desktop, they have limited permissions.
It might be a case that i misunderstood the point. I think however that you can play with the BT protocols. If you find a way to recognize the phone form the pc like a BT mouse you can control the pointer. I think some of the low end SonyEriksson phones had that option build in.(SE880i).
Though I am not sure how the driver problem will be solved.
Regards
TT
If it is possible to plug into PC's USB Then
Arduino mouse using a cheap Arduino board
https://www.arduino.cc/reference/en/language/functions/usb/mouse/
Arduino wifi or bluetooth using same or another board (or connect by Serial, UART, SPI, I2C cable).
software on cell phone (Android) to connect to wifi/bluetooth
Some hacking at the C level.
Notes
- no driver on the PC
- Could do the same with PIC32 (even with
PIC8/16 but might take longer).
This is a typical real world IoT type project.
As a project it is between 40 and 160 hours to demo prototype for an experienced consultant. Parts cost estimate under $400 besides cell phone cost.
120 to 500 hours for 20 production prototypes + layout and assembly cost about $4000.
Production target unit cost under $25.
In other words a neat Kickstarter project.
Experienced soft/hardware & lucky hacker could do it 24 to 36 hours.
In Micromax q2+ Iam able to access the bluetooth - remote control and after pairing be able to move the mouse to my pc. One thing is am unable to do any action events.

Android USB isochronous data transfer

I am currently trying to find a way to handle USB data transfer on an isochronous endpoint on my Android 3.2 tablet (Host Mode supported). After writing some prototype code, I noticed that in the constants file for USB_ENDPOINT_XFER_ISOC states that "Isochronous endpoint type (currently not supported)".
Is this possible without rooting the device? If so how would I go about doing this?
Ideally I was hoping to stay within the java API, but if this is possible only via the NDK I would have to pursue that instead. I also understand that there might be some USB bandwidth issues based on the following post: User mode USB isochronous transfer from device-to-host
I have written a Java class for USB isochronous data transfer under Android (or Linux): UsbIso
It uses JNA to access the USBFS API via IOCTL calls.
You "can" do it without root, I believe.
You'll need to do it all using some native C code interfacing with the USB device using USBFS. The big issue comes from the lack of documentation of linux's usbfs. Basically everything has to be done through ioctls. That said you do open a device as you would normally from Java. Then you pass the file descriptor from the USBDeviceConnection
Add to that you will need to parse all the USB descriptors yourself. You can get at them, again from the USBDeviceConnection. Jumping from descriptor to descriptor is simple finding the documentation for what each descriptor means is a MASSIVE headache but you can find most of the documentation on www.usb.org.
I've written most of the code that is required to do the parsing for audio devices and I got all the way up to trying to submit an isochronous transfer and then started getting errors.
After switching to libusb I discovered that the problem, in my case, was because the audio device also had HID controllers and the default driver was atatching to those and stealing all the bandwidth away from the isochronous transfer. Had I known this earlier I might have persevered with the non-root non-libusb method. As it was I did get isochronous transfers working through lib usb but it required a rooted device :(
At some point I'll go back to it.
In summary, I'm pretty sure its possible but its not gonna be easy!!
you can find a runnable Solution of the UsbIso 64 bit on my git hub repo:
https://github.com/Peter-St/Android-UVC-Camera/tree/master/app/src/main/java/humer/uvc_camera/UsbIso64
You need all 5 files of the UsbIso64 folder and can use the USBIso like following:
USBIso usbIso64 = new USBIso(camDeviceConnection.getFileDescriptor(), packetsPerRequest, maxPacketSize, (byte) camStreamingEndpoint.getAddress());
usbIso64.preallocateRequests(activeUrbs);
usbdevice_fs_util.setInterface(camDeviceConnection.getFileDescriptor(), camStreamingInterface.getId(), altSetting);
usbIso64.submitUrbs();
// While loop //
USBIso.Request req = usbIso64.reapRequest(true);
req.initialize();
req.submit();
You can use this version of UsbIso with 32 and 64 bit devices.
So far,
Peter

Categories

Resources