Java security, launching applications from a kindlet
Hello.
I am working on a morse code decoder for Kindle. I developed a similar application for Pocket PC already. I was pondering whether to write the application as Kindlet or as a native application. The problem with Kindlet was how to access the microphone. I was thinking to either write a JNI interface for sound, or to write a TCP server.
I found out the simplest method is to execute the shell command "arecord" (the alsa recording application) from Java. One just need to elevate Java security.
Here is an example to allow listing of processes from the kindlet:
1) SSH to your kindle.
2) mount root as rw - execute "mntroot rw"
3) edit /opt/amazon/ebook/security/external.policy
4) add following line to allow executing the system ps command (list running processes)
permission java.io.FilePermission "/bin/ps", "execute";
5) mount root as ro - execute "mntroot ro"
6) Restart your kindle. I suppose there is a faster way to do it than to restart the whole Linux box, but it is not known to me.
Now you could list running processes by running following piece of Java code:
String[] cmdarray = new String[2];
cmdarray[0] = "/bin/ps";
cmdarray[1] = "-lA";
Process process = Runtime.getRuntime().exec(cmdarray);
And access the input / output streams
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
By running the arecord tool with particular commands and output format "raw", one can record raw audio data. By executing "aplay" command one can replay the sound.
One may write a simple kindlet to access the shell. Just execute the shell directly without connecting to ssh or telnet server. I am considering to write such terminal with a UI to configure and execute shortcuts.
Have fun,
Vojtech
|