GeekFor.Me is long overdue for a post explaining awake time and when you should and shouldn’t worry about it, and I actually worry that this post could bring that whole debate back up, but I wanted to get this information out there.

The official Facebook application for Android was just updated to version 1.3. Soon after there were many reports of people’s phones not sleeping, including this one and this one just as examples. I’m not a big Facebook user but I do have experience in tracking down phone sleeping issues so I decided to take a quick look. I will mention that in my testing I did not have Facebook syncing my contacts but that’s the only setting I changed from the default setup.

First I’ll give a quick explanation on what a wake lock is. Certain applications may find a reason to need to keep your phone awake. This is most common with something like a game so that your screen doesn’t turn off while you are in thewakelock-table middle of playing it. There are actually 4 different types of wake locks. The bottom 3 in the chart will all keep your screen on but will still allow your phone to sleep if you do turn off your screen. Despite it’s name a partial wake lock is actually the “worst”. It will allow your screen to turn off both automatically and by you doing it yourself, however the CPU and your phone itself will still stay “awake.” From the Android Developer site:

Device battery life will be significantly affected by the use of this API. Do not acquire WakeLocks unless you really need them, use the minimum levels possible, and be sure to release it as soon as you can.

If you hold a partial wakelock, the CPU will continue to run, irrespective of any timers and even after the user presses the power button.

Just having Facebook installed on your phone isn’t going to cause the Wake Lock. It isn’t getting set until you actually run the application and log in. From there on your phone isn’t going to sleep properly until you restart your phone or until Android kills the task. Here is an application state dump:

    Apk com.facebook.katana:
      7 wakeup alarms
      Service com.facebook.katana.platform.FacebookSyncAdapterService:
        Created for: 0ms  uptime
        Starts: 0, launches: 1
      Service com.facebook.katana.service.FacebookService:
        Created for: 31m 53s 635ms  uptime
        Starts: 5, launches: 3
      Service com.facebook.katana.service.LoggingService:
        Created for: 11s 672ms  uptime
        Starts: 1, launches: 1

  #10013:
    Wake lock FacebookService: 27m 53s 107ms partial (1 times) realtime
    Proc com.facebook.katana:
      CPU: 2s 580ms usr + 620ms krn
      1 proc starts
    Apk com.facebook.katana:
      3 wakeup alarms
      Service com.facebook.katana.service.FacebookService:
        Created for: 28m 3s 255ms  uptime
        Starts: 1, launches: 1
      Service com.facebook.katana.service.LoggingService:
        Created for: 11s 672ms  uptime
        Starts: 1, launches: 1

mLocks.size=1:
  PARTIAL_WAKE_LOCK  'FacebookService' activated (minState=0, uid=10013, pid=260)3

Now it’s not any type of secret that the Facebook application is capable of creating a wake lock. For security purposes, every application in Android must request and be granted permission for what it wants to do when you install it. facebook-permission This is the main point of the step where you click OK during an application install.

As you can see in this picture the application asks for permission to be able to prevent the phone from sleeping, and that’s exactly what it does. The problem is that this application isn’t properly releasing this wake lock when it should. Now I don’t develop for Facebook and I can’t tell you why they create the lock in the first place or how long it should be running, but I can tell you that it will cause horrible battery life.

At this point the only workarounds are to not use it, to downgrade back to Facebook 1.2, or to wait until the Facebook team fixes the issue. If you are a Fresh Evo user and you are looking for a way to downgrade back to 1.2 then just hold out until tomorrow and I’ll get a patch up on Fresh Updater for you. If you haven’t gotten the latest update from Facebook yet then don’t worry, you’re safe! If you are super impatient and can’t wait then simply uninstall Facebook 1.3 and re-flash Fresh Evo. No wipe is required and no data will be lost (unless you installed a theme) but it will put Facebook 1.2 back on your phone since that’s what was included originally. Just make sure to uninstall 1.3 first.

This post is a bit long and wordy… I could have gotten by with just tweeting “your phone won’t sleep with Facebook 1.3” but really digging in to this stuff is what I love and I figured I would share it with all of you. :) If you are wondering if your phone is affected by this, there is a quick test. Go to Settings < About Phone < Battery and you will see your awake time. WITH YOUR PHONE UNPLUGGED, turn the screen off and wait about 1 minute. Now turn it back on. Your awake time should have only gone up by about 10-15 seconds. If it went up a full minute (or your up time and awake time already match each other) then your phone isn’t sleeping. Keep in mind that this isn’t going to affect you if you aren’t using Facebook 1.3 or if the application is no longer running in the background because it’s already been killed off by Android.

For the techies in the group I’ve attached a few screenshots of the app and device state dumps showing the wake locks and Facebook’s permissions. Thanks for reading! As a side note: this is my first ever post from Windows Live Writer. Assuming everything publishes properly then it will definitely be my new composer.


device-state katana-permissions wakelock-2 awake