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.

Posted in Development, Tips | 1 Comment

ADWLauncher Settings

I’ve mentioned the preview setting in ADW Launcher previously. Recently I installed the Cyanogenmod 7.1 release on my Nexus S and started using that as my daily phone for a bit. There are a few additional settings in there I’m really liking. I like the dockbar a lot more than the main dock. What I really like to tune for is density of the screen. I wish there was an effective way to swap to the dockbar all the time. Instead what I’ve ended up doing is:

  • Enable the dockbar
  • Bind swipe up to show the dockbar
  • Bind swipe down to app the app drawer
  • Disable hiding the dockbar on app launch

And what I end up with is a dockbar I can drag shortcuts into/out of, and I just use the swipe action to open the app drawer. My homescreen ends up looking something like this:
Screenshot of ADW Launcher
You have to use the swipe up to bring up the dockbar instead of the main dock, but once you do it sticks around.

Posted in Tips | Tagged , , | Leave a comment

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.

Posted in Applications | Leave a comment

Using Your Android Phone as a Remote Control

What I initially set out to do was find a program for my G2 that would allow me to use it as a Bluetooth trackpad and keyboard with the Mac mini I have hooked up to my television. I use it as a media PC, but it’s also a general purpose system. Every now and again it’s convenient to be able to control it using a full keyboard and mouse.

I haven’t yet run across the right tool to get my phone to work as a Bluetooth HID device for my computer. But there are some decent VNC clients that do interesting things. I’ve started using AndroidVNC as my default. I wish I could turn off the screen on the device completely. As is I turn the color depth all the way down. Because I’m sitting in front of the computer I can watch the pointer onscreen, transferring the video data over my G2 just cases it to lag.

The essential part to making it work well is to go into the settings and swap the pointer mode to trackpad. That way you can use the touchscreen on the device as a trackpad instead of having to pan around and touch directly (or use the tiny directional trackpad). You still need a VNC server on your PC, but I’m running one anyway so it’s not much of an issue for me. Still, would be nice to be able to use the Bluetooth HID version for other cases. Surprised at the lack of Bluetooth based Android hackery.

Posted in Applications, Tips | Tagged , , , , , , , | 2 Comments

Installing Firefox Mobile on a Samsung Captivate

Mozilla just released a mobile version of Firefox for Android devices. Unfortunately they haven’t directly published the link to the apk. If you follow the download link from a desktop system it takes you to the desktop installer. From a device it takes you to the apk, but I’m on a Samsung Captivate I haven’t rooted yet, so I can’t install from the browser. Instead I downloaded through the browser, sucked the file out using ADB, and the installed that way:

  • ./adb pull /sdcard/download/fennec.apk ~/fennec.apk
  • ./adb install ~/fennec.apk

Dear Mozilla, great idea directing folks to the right download automatically, but please take this case into consideration. Lots of folks on AT&T devices who can’t install directly. Or, alternatively, AT&T could stop being idiots. Slim chance of that though.

Posted in Applications, Tips | Tagged , , , , , , , , , | 2 Comments

Essential Android Apps for Geeks

A few essential apps for those more technically minded Android users out there. If you know of others that should be in here let me know in the comments.

Terminal

This one is almost a no-brainer. Everyone who knows Android is Linux underneath (and who knows Linux) normally heads for a command line to check things out right off the bat. You can get access via ADB, but having direct access right on the device is killer. This app gives you access to the command shell built into the device.

Market link: Android Terminal Emulator

ConnectBot

ConnectBot is an SSH client application for your phone. It’s a fantastic application for quick access to remote systems. If you’re on a device without a physical keyboard it’s not quite as slick to use (I wouldn’t recommend trying to use vi on a remote system from a Samsung Galaxy for instance), but for quick tasks it can be fantastically convenient.

Market link: ConnectBot

Advanced Task Killer

This seems to be a pretty consistent tool in most advanced user’s toolboxes. Android apps can keep running in the background. Most of the ones that do give you good ways to control when they run, and the OS itself does a generally good job of managing them. But if you tend to poke around with lots of apps and try out all the different tools you hear about you’re bound to run across one or two that misbehave every once in a while. When you do, Advanced Task Killer can help you figure out what’s going on and set things right again.

Market link: Advanced Task Killer

Astro File Manager

This is the free version of a file manager application. There’s a paid version that includes a ton of additional features, but so far I’ve stuck with the free version. Nice interface for browsing around and seeing what files are on your device. Includes built in viewers that generally handle text and image files well.

Market link: Astro File Manager

Dropbox

Dropbox is a free service that lets you store files online and sync them between systems. If you don’t already have an account and want to try it out please sign up using this affiliate link (I get credit for the signup and get some free space on Dropbox if you do). They have an Android application that allows viewing, downloading, or uploading. Together with an application like Astro you can upload arbitrary files from your phone to Dropbox as well. From within Dropbox use upload from the menu, and then select any file and use Astro to complete the action.

Market link: Dropbox

Scripting Layer for Android

An app that allows for accessing native Android functions from multiple scripting languages. Once you install SL4A you can use it to pull down interpreters. A bunch are available, like Unix shell, Python, Perl, Ruby, and others. Then you can run scripts in those languages that tie into Android specific functions. SL4A is not available in the Marketplace however, so use the info on the Google Project page to download the apk directly. If you’re on an AT&T device like the Samsung Captivate and haven’t hacked it to allow direct third party installs you’ll have to load the apk files using ADB. As of right now, it seems you need to download the core SL4A app and then separate downloader shims for the different interpreters. The base sl4a seems to only have shell installed by default. But once you install something like python_for_android_r1.apk and click install within that app you’ll get Python support in sl4a.

Posted in Applications | Tagged , , , , , , | 2 Comments

Samsung Captivate Tethering for OS X

When I plugged my Samsung Captivate into my OS X machine I was surprised to see a network connection dialog pop up on my laptop and what looked like a tethering app pop up on the device. Given that AT&T tries to kill off tethering in every way possible with the iPhone, I figured it wouldn’t be on with my Captivate either. Or at least not easy to get working. No problem though. I just needed to figure out which set of settings to put in the network connection dialogs in OS X.

In the main network settings screen under System Preferences:

  • leave telephone number blank
  • use ‘WAP@CINGULARGPRS.COM’ for Account Name
  • use ‘CINGULAR1′ for Password

Then click the advanced button and setup:

  • Vendor generic
  • Model GPRS (GSM/3G)
  • APN is ‘wap.cingular’
  • CID set to 1

After that starting up a network session with my Captivate attached over USB yielded a pretty quick network connection! Now if only they could fix these GPS issues….

Posted in Tips | Tagged , , , , , , , | 5 Comments

On Device Packet Capture

When I need to capture network traffic from my device I normally capture traffic at a router to see what’s going on. I had seen some mentions of running tcpdump on device and pulling off the pcap file to a desktop to inspect, but Androshark was what people mentioned the most. And it didn’t seem to be actively developed any more. I ran across Shark for Root and Sharkreader recently however. It’s an app for packet capture and a simple packet capture viewer directly on the device. Works out pretty well. Requires root access, and it seems to be working quite well on my Nexus One with CM6. Screenshots below.

Start/stop capture, writes to the sdcard by default:

image

View packet dump stream:

image

View contents of an individual packet:

image

Posted in Tips | Tagged , , , , , , , | 1 Comment

Assember/Disassembler for Dalvik

I ran across a mention of an assember/disassember pair for Dalvik in an XDA Forum posting. Just had a chance to give at least the assembler a try and make sure I could get things working before I posted. Yep, working on the emulator at least. There are a few examples you can start with, instructions for assembling and running are in the comments. And some pages in the wiki that look like they’ll provide some great starting points.

Posted in Development | Tagged , , , , | Leave a comment

Text to Speech Using Scripting

I’ve been fooling around with Scripting Layer for Android to generate some speech notifications. Two issues I ran into, figured I would share if anyone else does. The first was that the examples still use the droid.speak() call, and it should be droid.ttsSpeak() instead. Quick fix. The second however I only saw on my CM6 device, which was that no speech was coming out ever after I updated the ttsSpeak() call. logcat turned up the issue quickly enough though. I just needed to go into settings from the home screen and download the data necessary to generate speech. Once you’re in the “Voice Input and Output” area the process is obvious. It’s just knowing that you need to go into settings to get speech working that’s a bit tricky.

Posted in Development | Tagged , , , , , , | Leave a comment