views:

40

answers:

2

I'm working on a Synergy port to the Android (see synergy-foss.org).

The only way I've found to inject keystrokes is to use the Cyanogen Mod and write keystrokes to /dev/uinput. However, my app does not have permissions to write to /dev/uinput. The only way around this that I've found is to chmod 777 /dev/uinput.

However... it seems after some time the permissions on /dev/uinput are reset -- by what? I don't know.

Is there a better way or is there a way to run your app as root in the Cyanogen mod?

Thanks

A: 

Hmm I guess it's as simple as

Process p = Runtime.getRuntime().exec("su");

Shaun
No, it's not that simple, at least if you intend to accomplish anything as root. su does not escalate the privilege of the current process, it creates a new (by default shell) process as a different (default root) user. You are going to have to tell that what you want it to do, either by launching it with command line arguments or by obtaining its stdin and injecting keystrokes into that.
Chris Stratton
Correct. I had to do the su and then chmod /dev/uniput from the output stream
Shaun
A: 

Look at IWindowManager.injectKeyEvent. It is in the layoutlib.jar in the platform SDK. I am not sure what permissions the application will need to call it (like root or not) but it is a start. I don't think you will need root to execute the method.

I was playing around with it for a little while and was able to inject keystrokes from my computer keyboard and have the device "repeat" the action.

Ryan Conrad
I believe IWindowManager only lets you inject keystrokes into your own app. I need to inject keystrokes (and hopefully mouse movements) into all apps
Shaun
my app runs on windows and sends data via a tcp connection to a running thread on the device. It injects the keyboard events in to any running application.
Ryan Conrad
Interesting. I was lead to believe -- from this post: http://mylifewithandroid.blogspot.com/2009/01/generating-keypresses-programmatically.html -- that it worked only on your application. Is the source available somewhere?
Shaun