Lead Hacker

This user hasn't shared any biographical information


Posts by Lead Hacker

sl4a-linux

Communicating Linux Chroot to Android

The technique of installing a full Linux distro on your Android phone has been around for a long time. I’ve used it in the past, but for a while didn’t have a phone with a physical keyboard, which made it less useful. Now that I have CM7.1 on my G2 I’ve installed it again. I’m actually using an updated prepackaged version of Ubuntu, which has been fantastic.

However, generally speaking you can run the command line stuff and have it manipulate stuff on the filesystem, but the stuff you run “in Linux” don’t interact with Android. Poking around the other day I noticed that SL4A, the Android scripting system has a “server mode”. Normally the scripts run by SL4A communicate with a generic RPC service which hooks the interpreters back into the Android system. There’s also a mode to just startup the RPC service and bind it to the loopback port or a public interface. And it talks JSON!

So, theoretically, I should be able to startup a SL4A server, run scripts in the Linux environment, and they can send messages to the outside Android system. I needed to test it out of course. If you have SL4A installed you select View from the top level menu, then Interpreters, and then “Start Server” from the menu there, and select “Private” from the context menu that pops up. There should now be a SL4A entry in the dropdown notification area, if you tap on that you can see the running server and it’ll tell you the port. Or, you could just get it from the command line, since thats where we’re going next.

Login via ADB or terminal, or however you prefer. Swap over to Linux, or mount up the unionfs stuff if you’re doing it Saurik’s way. And then you can use anything that can connect to a TCP socket and emit some JSON to send messages. I used netcat for the simplest example:

echo ‘{“id”:1,”method”:”makeToast”,”params”:["The Great HooDoo ..."]}’ | nc 127.0.0.1 38804

And tada! The message shows up on my device:

Really hacky thing to do right now, but it’s interesting in that it would potentially let that stuff running as Linux commands to interact with the rest of the system. Even just being able to deliver local notifications so that you know to check back on something running in terminal to see updates is pretty cool.

Nook Sideload Launching

One of the most annoying aspects of working with a stock Nook for development is trying to load up your application after you install it. The arcane series of buttons you need to press, and tapping on the speaker icon. Just stupid. And the fact that you need to reboot the device in order to get it to recognize a newly installed app – it’s like they don’t want you to create apps for the platform.

There are a few different workarounds, like launching using an adb command (ie. adb shell am start -a android.intent.action.MAIN -n com.example.myapp/com.example.myactivity). But my favorite so far is simply installing a new launcher application. I grabbed the Home sample from the Android resources, compiled that, sideloaded and launched it with the adb command.

Now when I hit the ‘n’ button on my device I have the option of launching into the Nook default home or the Home Sample application. From the Home Sample I can just pick the app I want directly, and I don’t need to reboot the device to see anything new I put on there. Great for when I’m poking around with a bunch of new stuff.

Bonus tip: On OS X you can use /etc/fstab to keep your development machine from mounting up the device every time you plug it in, resulting in an annoying error if you unplug without ejecting. Just add a line like this to keep it from mounting by default:


LABEL=MyNOOKcolor none msdos rw,noauto

When you do want to mount it, you can either do it from the command line or fire up Disk Utility.