Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 03-06-2011, 09:16 AM   #1
bubnikv
Member
bubnikv began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Mar 2011
Device: Kindle 3
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
bubnikv is offline   Reply With Quote
Old 03-06-2011, 02:52 PM   #2
hawhill
Wizard
hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.
 
hawhill's Avatar
 
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
Yep, good findings.

Using JNI instead has given me headaches, though. I have not been able to proper unload a library (loading JNI libs works fine otherwise, given you add the relevant permissions) - and it does not unload automatically for me. That's relevant because at the _second_ start of a kindlet, it will refuse to load the JNI lib again because it is already loaded. It will not, however, allow access to the methods defined in this lib anymore. So I dropped my approaches towards JNI for now.

The "faster way" after editing permissions is "/etc/init.d/framework restart".

You can do a lot of things by "just running" applications the way you found. However, the main difference compared to the telnet/ssh approaches is that the latter will provide apps with a full fledged (pseudo) tty. Some (mainly UI-based) apps simply don't work well without a TTY. Running apps that just do simple input/output will work fine.
hawhill is offline   Reply With Quote
Advert
Old 03-06-2011, 04:48 PM   #3
bubnikv
Member
bubnikv began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Mar 2011
Device: Kindle 3
> You can do a lot of things by "just running" applications the way you found.
> However, the main difference compared to the telnet/ssh approaches is that
> the latter will provide apps with a full fledged (pseudo) tty. Some (mainly
> UI-based) apps simply don't work well without a TTY. Running apps that just
> do simple input/output will work fine.[/QUOTE]

Thanks for the hint on the JNI and TTYs. It looks like starting the telnetd is not such a bad idea after all. It has been a long time since I was working with Linux. Actually I even worked part time for SuSE in Prag some 11 years ago.

I am looking into your Kindlet terminal source code. I would like to see two things:

1) A hint table shown on the screen when the alt key is active. Ideally this table would change with the alt mode. I can imagine having more than one table, for example for accented characters.

2) Macros, ideally accessible through the menu button and editable in the applet.

Thanks, Vojtech
bubnikv is offline   Reply With Quote
Old 03-07-2011, 03:05 AM   #4
dsmid
Linux devotee
dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.dsmid ought to be getting tired of karma fortunes by now.
 
dsmid's Avatar
 
Posts: 598
Karma: 2069047
Join Date: Feb 2011
Device: Kindle 3, Kindle 4B, Kindle PW2
There already is a terminal application for Kindle, it's written in C though.
It's called kiterm, made by Luigi Rizzo.
dsmid is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sudoku Kindlet (GPL3) hawhill Kindle Developer's Corner 28 12-28-2012 11:59 AM
Snake game kindlet anmipo Kindle Developer's Corner 6 04-26-2011 01:09 AM
Kindlet Entwicklungstutorial sala Amazon Kindle 0 01-20-2011 04:33 AM
iLiad Java applications on iLiad M@rcel iRex Developer's Corner 6 12-04-2008 12:18 PM
[Apple]Java Embedding Plugin 0.9.2: Force java to run in browsers other than Safari Zire Lounge 4 05-24-2005 09:12 PM


All times are GMT -4. The time now is 08:16 PM.


MobileRead.com is a privately owned, operated and funded community.