Sunday, 6 February 2011

Sleeping CPUs and lazy Llamas

A new version of Llama is now on the Android market. This has an experimental feature which may help some of you that have been experiencing a minor problem. Some people have reported that Llama doesn't run event actions until they've turned their screen on. I'll try and explain what's going on.

It happens because when the screen is off, the phone puts its CPU to sleep. This saves a considerable amount of battery life; if the screen is off, there's probably nothing going on, so the CPU is turned off. The phone will wake the CPU when a phone call comes in or a message arrives. Applications can also request that the CPU wakes every 15 minutes, so they can check your email.

Previously, Llama was different: Llama only asked Android to tell it when the cell changed. If the cell changed when the CPU was turned off, Llama wouldn't be able to process the change. However, when a phone call or messaged arrived (or you turned the screen on) Llama would spring into action and catch up with the cell changes then run whatever actions were necessary (such as turning the volume down before the phone rings).

Normally, this is exactly what you want, and for most event actions this works fine. However, some people wanted Llama to turn on their Bluetooth when they left home. Since they never turned the screen on manually, the CPU never woke up to turn on their Bluetooth. This brings me onto the most recent change in Llama: Cell Polling. It's now possible to check every minute or so to see if the current cell has changed. It's an experimental feature at the moment, so I'd like to hear if you think it helps.

If you enable Cell Polling, you'll be asking the operating system to wake up the CPU for a short period of time so that Llama can check the cell ID. This uses Android's partial wake locks. I left this running overnight for about 8 hours, and Android's hidden battery history screen* showed the Llama only held onto a partial wake lock for 2 seconds in total. I doubt this will have any major affect on battery life if you turn it on, but as I said, the majority of you won't need it :)

Now for some non-phone-geeky stuff. The new version now lets you reboot your phone if you are rooted, which may be helpful if you want to reboot once a week in the middle of the night. Be careful with your event conditions; you don't want your phone rebooting every time you get home. I've tried to prevent any horribleness by requiring that your phone has been on for at least 5 minutes, so that Llama can't trigger a reboot immediately after your phone has just rebooted. This should give you plenty of time to delete an event that's incorrectly configured.

There's also Bluetooth connection and disconnection events, so you can now easily change profiles when your Bluetooth headset is connected, and there's also a 'Not in area' condition to give your events a bit more power. You can now view what events happened and what caused them in the Event History log. To view it, go to the Events tab then press Menu and Event History.

Finally, for anyone that's interested in how free apps perform on the Android market, here's some stats. Hopefully you'll find this useful if you want to put any apps on the Market. I couldn't find stats like this when I was deciding to release Llama:

Days on market:
9
Downloads:
 about 4000
Active installs:
about 2000
Support emails:
24
Donations:
14



* to view Android's battery history, type *#*#4636#*#* in the phone dialer, then choose battery history and Partial Wake Usage. (more info here)

Recent changes in version 1.2011.02.06.1300
  • Event History Log (go to Events tab and press Menu)
  • Reboot action (requires root)
  • Bluetooth device connect/disconnect condition
  • Car mode condition
  • Not in area condition
  • Optional cell polling to wake the CPU every 2-3 minutes, to catch every cell change. This might affect battery life a tiny bit if it's enabled.
  • Fixed a whole load of stuff to do with how the service works