Android and Linux

Wednesday, December 21, 2011

Woe is me...

Since getting the Galaxy Nexus, I've had a little trouble and have been flashing ROMs like crazy and spending enough time in recovery that I could have put Betty Ford's kids through college. Wait... I'm not sure that made sense.

Anyway, I assumed the problems were from hacks being rushed to the public with little testing, but I think I actually got a lemon and am going to swap it for a new one.

To begin with, I kept losing root after an hour or two for some unknown reason. I noticed that the file manager I was using was registering battery usage almost as high as the display after one such unrooting, so I stopped using it. That helped me get through a day or two with root intact, but I'm not entirely sure that was the problem because I was working in the terminal last night and lost root again.

I've also had random shutdowns and really bad slowdowns, and I've spend a couple of days trying, and failing, to get ssh to work. Oddly, I can ssh from the phone to my computer from anywhere on the cell network, but it simply will not work when connected to my router.

On the router, I had assigned the phone a certain IP address but it seemed to connect at a different one for the past few days. I kept setting it, thinking maybe I had kept forgetting to hit "apply" or something, until I finally realized tonight that I had set it yesterday for a different MAC address.

A little investigation revealed that my phone's MAC address changes on every boot. Oops, MAC addresses aren't supposed to do that! It's a pretty neat trick but not only troublesome for IP reservation, but could be causing a lot of other problems as well.

I found someone else on XDA who had the same problem and Samsung said it was a hardware problem and swapped it for him. Verizon's phone number is right there on the charger and I didn't know Samsung's so I called the big V and they were a little puzzled. They called Samsung and they were puzzled too, but the Verizon guy told me to swap it.

I'm going to swap it at the store tomorrow so I don't have to wait for one to be shipped.

It nearly brought a tear to my eye, but I just typed "fastboot oem lock" in a terminal and brought my phone back to stock. But hopefully I'll be ready to start playing with the GNex for real after tomorrow.

Sunday, December 18, 2011

Galaxy Nexus

I finally got a Galaxy Nexus. I went Thursday at 11:15, walked in and told them I wanted a Galaxy Nexus and they said "We don't have them yet. They're coming in via UPS today. We're getting 8 of them and can save one for you if you want."

Yes, I live in a small town.

I didn't get around to buying one until yesterday afternoon. Since I enjoy voiding warranties within an hour of purchase, I promptly rooted it but didn't have time to do much else. Last night, I was a little upset because I kept losing root. I still don't know what the problem was, I'd flash the recovery and su binary and I would be doing something as root in a terminal when suddenly it would tell me "only root can do that" and I could no longer su. The root checker app said I had root, and the superuser app showed that certain apps were allowed and logged them as allowed when I opened them, but they still reported that they couldn't gain root.

It kept losing root after numerous flashes and rootings until I flashed this ROM this morning, and that seems to have cleared it up.

Anyway, my impressions on the Galaxy Nexus...

This puppy is huge! I'm charging the battery on my digital camera to try to get some comparisons of the Nexus One and Galaxy Nexus, but if you want a good idea of the size, it's almost the exact same size as a dollar bill, except a little shorter.

You ever go to a cell phone store and look at the flip phones and think "awww, such cute little screens, but I don't know how you could get anything done on that tiny little window." I felt that way when picking up the N1 after 20 minutes with the GNex.

The N1 had a habit of turning in my pocket, the GNex stands tall and it's thinner, so although it's much larger, it rides in my pocket better than the N1.

There are some things I don't really like.

The phone has very few features and it's easy to pull it out of your pocket and try to use it upside down. The earplug is on the bottom, which may or may not be a good thing, I'm not really sure yet.

The battery cover is a cheap piece of plastic that snaps in place instead of sliding. It's not what I would have designed, but it does raise the possibility of easy replacement, so there may be some cool looking battery covers showing up soon.

There are no hardware buttons for "back" "menu" "home" and "search", instead there are software buttons for "back" "home" and "recent apps". Three small dots are used for settings, and they may be at the top or the bottom of an app. I miss being able to always find them in one place.

And no trackball. Oh, how I miss that, but no other phones have them either. I've really been dreading the loss of the trackball, but I'll have to adapt.

With the launcher, you can't add widgets by long pressing the home screen, you have to do it from the app drawer. The app drawer has tabs for apps and widgets, and everything side scrolls now, which takes some getting used to.

LauncherPro still works, so that gives you the old school feel with long press widget adds etc, but it hasn't had an update in forever so it will surely stop working one of these days and old fogies like me will be dragged kicking and screaming into the future.

I really do love the phone. My gosh, when I pull that thing out it feels like I'm using a tablet. I have a lot of setup to do to get things working the way I want, so that means a lot of playing with this cool phone!

Monday, December 12, 2011

Android blues... and cheers.

The bad.

My Nexus One is dying. About a month ago, I was having problems like my favorite keyboard kept being reset to the Android default and my email sync kept turning off for no reason. So I upgraded to the newest Cyanogen and had even more problems. First it took several attempts to install, then a couple more wipes and attempts and some tweaking, hacking and tricking to get the Market to work, and I've been having random reboots and lock-ups since.

When you have a broken power button, a random lock up means you have to plug it into a charger then pull and insert the battery a couple of times to trick the sucker into booting.

I'm pretty sure there is something wrong with the phone's hardware somewhere. The upside is that it gives me an excuse to get the new Galaxy Nexus. The downside is that Verizon is dragging their feet about putting the darn thing on sale, so I'm stuck with a dying N1 for the time being.

There's nothing cooler than having to leave a party to go outside and plug my phone into the car charger to tease it into a hard reboot when it suddenly locks up in the middle of a conversation.

The Good.

If you haven't been to the web version of the Android Market lately, they've added some handy filters to search results, and they're also having 10 cent app sales to celebrate their 10 billionth download. The downloads have been changing daily and there are quite a few worth picking up. I've grabbed a bunch because, although I don't really want them now, I may have a use for them in the future.

Sunday, October 30, 2011

Run Tasker task from command line

I have been looking for an alternative to Notify My Android in order to send myself notifications to my phone when I'm at home. NMA notifications work fine, but you have to open the app to clear them and I just wanted a vibration or sound that didn't leave anything else on the phone for when a job finished at the computer or something.

I first looked at playing a media file with the following command:

am start -n com.android.music/com.android.music.MediaPlaybackActivity -d /sdcard/foo.mp3

That sorta works. It opens the media app and plays the file then immediately goes to the next song. Adding && sleep 1 && pkill com.android.music makes it work more like I wanted, but that's too ugly.

I ran across this post in the Tasker forum about invoking a task from the command line, but the consensus was that it wouldn't work unless the command line app has the right permissions.

But then I discovered that this works:

am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name YOUR_TASK_NAME

The only difference being the "-e" option instead of "-es."

So I made a simple script called "task" for the phone.
#! /system/bin/sh
am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name "$*"
Now I can bounce the command off the phone via ssh and run any Tasker task I want.

Wednesday, October 19, 2011

The Pogoplug is taking over my life

The $50 Pogoplug that I bought to goof around with is now my main server.



The Pogoplug is about the size of a small, thick book. To the right is an Edge DiskGo network attached storage drive. That's where I keep all my media to be played on the TV via the Roku and the MyMedia Server Roku app. The Pogoplug is running a small python server that acts as the companion to the Mymedia app and I simply mounted the drive over the network because I didn't have any USB cables to plug it in directly, so it acts as if it is serving the files from it's own drive.

Debian is installed on the USB stick in the front of it. The white cable in the back is the power cord, and there's a cat5 plugged into the back which you can't see, and the two black cords are USB cords running to my CM11A and W800RF32A, which are an X10 controller and wireless receiver respectively.

It's not only serving media and running the automation, but other scripts to check weather, watch my IP address, back up files from my phone when I connect to my home wifi, etc. Everything installed and runs just as easily as it would on any desktop Linux. The only hard part was getting accustomed to Debian, but it's not so different from Slackware and at least it's not Ubuntu.

That's the beauty of Linux, very small programs requiring very little resources can do as much, if not more, than some $100 program you'd have to buy for a Windows computer, and they can do it in the background without you having to be there to point and click, and they can do it on very minimal hardware.

Thursday, October 13, 2011

remote ssh to multiple hosts on same network in Android

I have four devices running ssh at home. Since they're all attached to my router, they all have the same IP address to the outside world, but ssh runs on different ports on each device. In theory, you can ssh into each one by specifying the correct port. In practice, however, it's not always that simple, especially with Android.

In order to prevent a man-in-the-middle attack, when ssh makes a connection, it saves the computer's IP and host key in the ~/.ssh/known_hosts file and the next time you try to connect, it checks the IP in that file to make sure the host key is the same.

Let me illustrate. Let's say my home IP address is 123.45.54.321. I have 2 devices, comp1 and comp2 running ssh on port 111 and 222, respectively. And let's just say their host keys are AAA and BBB (the keys are actually much, much longer). If I ssh into 123.45.54.321 port 111, then this gets entered into the known_hosts file: 123.45.54.321 AAA.

Now, if I try to ssh into comp2 at 123.45.54.321 port 222, it gets the host key BBB from the computer and looks in the known_hosts file and says, "whoa, I expected AAA from the computer at 123.45.54.321, something is wrong" then the connection fails.

There are normally a couple of solutions for this. First, you can sometimes connect to comp1, copy the key from known_hosts then remove it from the file and connect to comp2. Now put the comp1 key back in known hosts. I've never done this and heard that it doesn't always work, but sometimes ssh will keep trying entries in known_hosts until it gets one right.

The better solution is to set up ssh config file like so:

Host comp1
Hostname comp1.somedomain.com
Port 111
HostKeyAlias = comp1
CheckHostIP = no

Host comp2
Hostname comp2.somedomain.com
Port 222
HostKeyAlias = comp2
CheckHostIP = no


Then you can connect with the command ssh comp1 or ssh comp2.

Unfortunately, that doesn't work with Android because it doesn't have an ssh config file. I'm not entirely sure you can do anything about it with the normal Android ssh program. I deleted it long ago and use the ssh binary from Better Terminal Emulator Pro (see this post) and there is a workaround with it.

The first trick doesn't work with the BTEP ssh binary, and neither does the second trick because it doesn't seem to use a config file. As often is the case with Android, the ugliest solution is the only solution.

BTEP looks for the known_hosts file in /data/data/com.magicandroidapps.bettertermpro/home/.ssh (sorry, I originally posted the wrong directory. Fixed now!). You can use the first trick to get a copy of the host keys, then write a script to overwrite known_hosts depending on which computer you want to connect to.
#! /system/bin/sh

case "$1" in

comp1)
echo "$(hip) ssh-rsa AAA==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts
ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT;;

comp2)
echo "$(hip) ssh-rsa BBB==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts
ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT;;

esac
You would fill in your user, path to the ssh key and port number. You can also fill in the IP address, but that's what the $(hip) part does. hip is a script that tells me my home computer's IP address which I've blogged about here and here. Essentially, I keep my home IP address in a file and the hip command just displays that file. That way, I don't need to hard code my IP in any scripts. If my IP changes, I can just update it in that file and not worry about changing the scripts.

I named the script above simply "s". So, if I run s comp2, it will write 123.45.54.321 ssh-rsa BBB== to known_hosts then connect to comp2.

Incidentally, this also takes care of another problem- IP changes. The first time you connect to a host, ssh asks if you really want to connect and you have to type yes or no.

If you normally have 123.45.54.321 ssh-rsa BBB== in your known_hosts file and your home IP changes for some reason, the new IP won't be in the file and your scripts will break until you manually log in and tell ssh yes or no. But now that no longer matters because we are controlling known_hosts and filling it with the correct up-to-date IP and associated key.

The other solutions are better for computers that are running the real OpenSSH, but this is the only solution I could figure out for Android and it's funky programs.

Tuesday, October 11, 2011

Pogoplug

I was in Best Buy today and noticed that they sell Pogoplugs for $50 so I picked one up. I believe it is the first generation without wifi, but I don't care about that, I prefer using network cable when available over wifi anyway. The downside to Pogoplugs is that they have very little space available on them, but you can install Linux on an external hard drive plugged into them via USB. I didn't have an external drive, per se. I have a NAS network drive, and that may work, but I didn't have a USB cord to attach it, so I installed Linux on a USB stick for the time being.

Using this guide, it only took a few minutes to have a very minimalistic version of Debian running on it, and after installing the gcc compiler and other tools, I was able to install Heyu. Then I plugged my CM11A X10 controller into the Pogoplug and was a little surprised that the darn thing actually worked. Awesome!

The NAS drive is what I use to store videos for streaming to the Roku. I tried to install the server program on the Pogoplug using the USB stick just to see if it would work, but python threw socket errors for some reason. I'm going to investigate whether I can use the NAS with the Pogoplug. If not, I'll probably get an external drive and use it to serve videos, control the home automation, and various other things I have a computer doing now. I'm not entirely certain I want to turn over everything to a little box like this, but I want to do it to see for myself that it can be done, then change back to the computer if I prefer it.

I think it's pretty amazing that, for $50, you can get a computer the size of a book that can do all this. Then again, the Raspberry Pi.org/ is only going to be $25, so maybe I got ripped off!

Followers