Android and Linux

Monday, April 11, 2011

Light posting

Well, that's not new, I'm not a very prolific blogger, but posting may (or may not) be light for the next month. I'm buying a new house- literally, it just got built- and will be going crazy trying to get everything done and get moved. I'm not sure when I will move, I told someone that I will probably follow the internet. Once the internet gets turned off here and on there, I'm moving that day!

On the plus side, I will finally have an excuse to go nuts with X10. The house has tray ceilings in the living room and master bedroom, so I'm planning to put in some lighting like this which just begs to be controlled with X10 and a dimmer.



Then there's the rest of the house, I'm just itching to go X10 crazy on it.

Anyway, if I don't post much for the next month, don't get alarmed and call Dog The Bounty Hunter to look for me. I'll be around.

Tuesday, April 5, 2011

Get current url from Android browser

I've been using an app called Wave Launcher, which allows you to swipe a certain area of the screen to pop up a launch bar. The launch bar contains 5 icons which you can set up to open an app or shortcut. With Folder Organizer, you can have it open a folder of apps, or, even cooler, a folder full of Tasker tasks.

I wanted to create a Tasker task to open my computer's browser to the same url that my phone's browser is on. I can do this by copying the url and running a task to share it, but that's too much work. After much digging, I found a way to extract the current url from the browser database.
sqlite3 /data/data/com.android.browser/databases/browser.db "SELECT * FROM bookmarks;" | tr '|' '\n' | grep http | tail -n1

If you go to cnn.com on the phone and run that command, the output is http://m.cnn.com/.

Using that, I can make a short script to make it open on my home computer via ssh:

#! /system/bin/sh
url=$(sqlite3 /data/data/com.android.browser/databases/browser.db "SELECT * FROM bookmarks;" | tr '|' '\n' | grep http | tail -n1)
ssh -i /PATH/TO/SSHKEY USER@IP "firefox $url"

If I'm browsing a page on the phone and want to read it on the computer instead, I can swipe Wave Launcher and select the task that runs this command. This will grab the last url visited, so it doesn't matter if the browser is open or closed.

Saturday, April 2, 2011

shell launcher for sl4a scripts

Scripting Layer for Android, or SL4A is an app which allows you to run scripts such as perl and python on your phone. The cool thing about them is that they have full access to Android API calls, unlike the Android command line. But sl4a scripts can be invoked from the command line and here's a script to do it.

Everything from "am" to the end needs to be on one line, but it's too long to post it that way here and I've always found the typical way of splitting lines on the web with a backslash confuses people, so just make sure "am...}" goes on a single line or copy it from the QR code below.

To run it, just execute the script with the name of an sl4a script as an argument. e.g., if you name the script slsh you run "slsh test.py"

#! /system/bin/sh
[ -z "$1" ] && exec echo "please specify the name of a script to run"
am start -a com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT
-n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher
-e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/${1}

This could give you the ability to do virtually anything on the phone through the command line by invoking sl4a scripts. sl4a would do the hard work, of course, but this gives you a lower level access to it. You could, for example, probably use it to easily ssh into the phone from the computer and send a text message or get the GPS location.

Copy "slsh" to your phone's clipboard with this QR code:

Friday, April 1, 2011

New Tasker Forum

Pent has created a new discussion group called Tasker Pro in response to this thread where people lamented the lack of a good place where people could put their heads together and come up with cool Tasker solutions.

Wednesday, March 30, 2011

wget Android port

I can't take credit for it, but someone ported the real GNU wget utility to Android. I found this many months ago and have kept it on my phone. The wget that came with busybox worked great for a while, but after my upgrade to Cyanogen 7 a couple of weeks ago, I noticed several of my Tasker tasks were failing. I finally figured out that it was due to the busybox wget located in /system/xbin/wget. I deleted it and dropped this into /system/bin and everything started working again.

I uploaded it here in case anyone wants it (and so I don't lose it myself.)

Thanks to whoever originally compiled it for Android!

Sunday, March 13, 2011

ssh hiccupped

I will never understand some things.

Last night, I sat down to watch a movie and dimmed the lights using ssh on my phone (using a Zoom widget to run the ssh command to my PC and trigger heyu controlling home automation, it's all here on the blog somewhere). After the movie, I went to brighten the lights and found that it didn't work. After much investigation, I found that ssh was failing to connect to my PC. No matter what I tried, ssh failed with this error:

no address associated with hostname

I recently installed an app which created network sockets in order to watch network traffic, so I thought maybe that screwed something up. I had no idea how to fix it, and it was time for an update anyway, so I wiped the phone and installed the latest Cyanogenmod today (7RC2). After getting everything installed and set up, I dropped to a terminal and tried to ssh in to the PC and got:

no address associated with hostname

What the..? Ping and everything else worked, so it didn't seem to be a DNS issue. Maybe Google shipped out an Android OTA update that changed the network stack somehow?

I finally found a fix by adding my PC's IP address to /etc/hosts and giving it a name:

xx.xxx.xx.xx home

Then ssh user@home worked! I keep the home IP address stored in a file so it was easy to change all of my ssh commands by changing the ip address in that file to "home", and it's worked all day with no problems.

Later tonight, I was trying to set up a new connection and accidentally typed ssh user@xx.xxx.xx.xx and, after changing absolutely nothing, it works again!

Well, the two lessons for today are that if ssh gives you that error, try hardcoding the ip address in /etc/hosts and connecting to it's hostname instead of the ip directly and when it comes to computing, just accept the fact that sometimes, things will make absolutely no sense whatsoever.

Thursday, March 10, 2011

RemoteDroid

RemoteDroid is a great little app that turns your Android phone into a mouse/keyboard to use with your computer. I mainly use it as a remote control for mplayer because mplayer uses keyboard shortcuts (which can be customized by editing ~/.mplayer/input.conf). I use the command line version, the GUI version is probably the same, but I've never used it so I can't say for sure.

The two work perfectly together. I can lay in bed and watch a movie on the computer at my desk and control it with my phone by tapping the keyboard in RemoteDroid. The only downside is that the server needed on the computer automatically opens a small screen. If you want to start the RemoteDroid server at boot, you have to live with that screen always being open. But there is a solution with KDE.

I'm sure something similar can be done with Gnome, but I've been using KDE for 10 years so I'm pretty much stuck with it and will probably still be using it when I'm an old ornery, cantankerous man (as opposed to the young ornery, cantankerous man I am today).

With KDE, When the RemoteDroid window comes up, right click on it and click "Configure Window Bahavior". This will bring up the KDE configuration utility.

Click Window Specific, then click "new" and click "Detect Window Properties". Your cursor will change to a crosshair. Click on the RemoteDroid window and it should automatically fill out the information for the RemoteDroid window.

Now go to the Geometry tab and click "minimized" then select the Preferences tab and select "Skip taskbar". Now when the window opens, it will be effectively invisible. It will be minimized so you won't see it on the screen, and it will not appear in the taskbar so there's no way for it to become unminimized.

Now, to run RemoteDroid when KDE starts, open a terminal and go to your kde autostart folder:

cd ~/.kde/Autostart

make a new script named startRemoteDroid.sh (or whatever you want to call it):

touch startRemoteDroid.sh

put this in the script, changing /PATH/TO to the path where RemoteDroid is on your system:

#! /bin/sh
java -jar /PATH/TO/RemoteDroidServer/RemoteDroidServer.jar &


make it executable:

chmod 755 startRemoteDroid.sh

and you're done. RemoteDroid will automatically start when KDE starts, and it will be invisible.

Followers