Wednesday, March 7, 2012

Battery Optimization Guide

Updated June 2nd, 2012
This guide gives recommendations on Epic 4G batteries, explains the many options you can customize to improve battery life and how to diagnose battery drain problems on CM9 for the Samsung Epic 4G.  Some of this advice is based upon our current understanding of bugs in CM9 and how to best workaround causes of battery drain until the developers are able to fix their causes.  We will update this guide as we learn more.  If you have suggestions for further improve this guide, please reply in the comments below.

Battery Quality

CM9 beta0 with Samsung 1800mah Battery
  • OEM Samsung batteries have the highest quality and have capacities near their stated ratings.
    • The default battery of the Samsung Epic 4G is rated at 1500mah.
    • *RECOMMENDED* Samsung Epic Touch battery rated at 1800mah works in the Epic 4G.
  • Counterfeit Samsung batteries are very cheap from eBay.  Most of them are low price (like $5 each), have different colors or markings, and often lack serial numbers.  They do work, but exhibit strange problems like the battery going dead immediately after reporting 45% full.  Battery capacity is known to be poor, and these batteries exhibit strange behaviors like random % capacity changes during runtime or reboot a lot more often.  It is recommended that you avoid these batteries.
  • Other brands of high capacity batteries have mixed reputations.  Many claim to have capacities higher than the 1500mah or 1800mah of Samsung OEM batteries, however independent tests have indicated they often are well below their claimed ratings.  Many additionally lose capacity rapidly within weeks or months at a faster rate than Samsung OEM batteries.
    • One Epic CM developer tried the Hyperion 1800mah battery from Amazon.  It fits within the Epic 4G with the standard cover, however it is a little fatter, causing the snap-on Body Glove case no longer lock into the back.  Months later it is still going strong.  Not bad for the price.
    • Even larger capacity like 3800mah batteries work in the Epic.  They usually come with replacement back covers that are necessary because the larger battery needs more room.  They make your phone much heavier, but some people like the extra battery life.  The usual warnings about non-OEM brand batteries apply here.
Power Saving Options
  • Google Talk is logged in by default.
    • You probably did not want this?  Go into the Talk app, hit Menu button and Sign Out. 
  • Turn off haptic feedback and touch sounds
    • By default the phone vibrates when you touch menu options or type on the onscreen keyboard.  Vibration uses a lot of power.  Sounds when you touch the screen also use a little power.
    • Settings > Sound > scroll down to System
      • Dial pad touch tones - many users like it, others turn it off so it is silent when dialing the phone to avoid bothering other people.
      • Touch sounds - default touch sound is very subtle so many choose to keep it.  You can save a little power if you turn it off.
      • Screen lock sound - also subtle, I personally keep it.
      • Vibrate on touch - strongly recommend to turn this off if you want to maximize battery life.
    • Settings > Language & input > Android keyboard > toggles to the right of it
      • Vibrate on keypress - turn this off to maximize battery.
      • Alternatively, you can make the vibration much smaller in Advanced settings near the bottom.  Keypress vibration duration settings of 5ms is nice.  It is a tiny reaction you can feel from pressing an onscreen keyboard button.
  • Turn off LED Notifications
    • Settings > Display > Pulse notification light
      • Blinking LED notifications are nice.  Unfortunately, the Epic CPU is unable to sleep while blinking the LED because it relies on software timers.  For this reason, it is strongly recommended that you turn off LED notifications entirely if you wish to maximize battery life.  As measured by CPU Spy, maximum CPU deep sleep can jump from 65% to over 95% with this option turned off.  You can still hear the notification chime and vibration when you have an incoming message.
    • Settings > Display > Pulse low battery light
      • You may also want to turn this off for the same reason.  If you do not, the battery will drain even faster when the battery is already low.
  • Put Wifi to Sleep while phone is sleeping
    • Settings > Wifi (touch the icon on the left) > Menu button > Advanced > Keep Wi-fi on during sleep
      • Strongly recommended to choose Only when plugged in.  The behavior of this option is different from Gingerbread. Rather than turning off the wifi, CM9 instead seems to put it into a semi-sleep state.  Data is turned off, but it can recover very quickly when needed.  If you want Wifi to turn off entirely, Juice Defender Plus or Ultimate edition is capable of controlling Wifi sleep states while the screen is off.  It is uncertain if Juice Defender disabled Wifi really uses less power than semi-sleeping Wifi as set by CM9.
  • No Signal?  Use Airplane mode
    • Settings > Battery > Cell standby
      • If your Time without signal is a high percentage, then your phone's radio is using extra power trying to find a cell tower that does not exist.  If you are in rural areas with weak or no cell signal, your phone uses significantly more power as it tries to find a cell tower.  Enable airplane mode in order to conserve your battery until you return to civilization.
  • Turn off Facebook Notifications and Background Data
    • In the Facebook app, hit Menu > Settings.  Uncheck Notifications, and it also turns off background data refresh.  This allows Facebook to fully close instead of always running in the background draining your battery and using some previous RAM.
    • If you want Facebook and its background service to die completely, use this procedure.
      • Settings > Developer options > Kill app back button > Enable
      • From now on, when you are done using Facebook, hold down the Back button.  This will completely kill Facebook until you run it again.
  • Turn off Data and Sync when you do not need it.
    • Different types of users
    • Why should your phone be busy while the screen is off?
    • Juice Defender - understanding the benefits and drawbacks
  • Reduce the number of applications that start automatically.
  • Autostarts screenshot
    • Apps you install will sometimes (and in most cases) have triggering events to start those applications in the background when certain events are triggered.  In most cases, it is safe to disable that app from automatically triggering and instead launch that app when you want it as you normally would.  By reducing the starting of applications, I have found that I also save battery because, well, my phone is doing less work and less work equals more battery.
    • I have seen some apps autostart even though you have disabled autostart events for that app (unclear yet why that's happening).  If you find that is the case, and you want to stop it from running, try moving that app to the SD card using a program such as DroidSail along with disabling events.  Why? Apps on SD cards at present do not receive the on_boot_complete event.  Please note, this may break some functionality such as widgets.
    • In order to decide what to disable, you need to understand how you will use the app and whether you need it to run in the background.  You can use an app such as Autostarts to control the startup on Android (At the writing of this it costs $1.03 USD).
    • When selecting apps to disable autostarting in Autostarts, stay clear of ones highlighted in Yellow as they are system apps.
    • Look for these key events:
      • After Startup
      • Connectivity Changed
      • Other events can also be disabled but remember, by disabling events that start apps, you can be breaking the functionality that the app gives you.  For example, disabling ‘after startup’ on an app such as AdAway will render the webserver that runs as part of that application to not run on boot.  Be smart, but disable what makes sense.
      • If something doesn’t work right and you are not sure what you disabled for that app, simply uninstall it and reinstall it.
  • Stop syncing things that you don’t use regularly.
    • You can always manually sync them when you need them.
    • Access the menu here:  Menu  -> System Settings ->  Accounts and Sync
    • For example, I use Gmail, Google Contacts, Google Calendar, and Google Browser regularly so I let that sync.  I disable Google Currents, Google Docs, and Google Chrome Beta because I rarely use them.  When I want to use them (once every couple weeks), I start the app and sync them manually.


    Myths and Misconceptions
    • mmc_delayed_work is often falsely blamed as the cause of wakelocks preventing your CPU from sleeping.  It seems certain other kernel-level sources of wakelocks have blame erroneously assigned to mmc_delayed_work.  For example, the LED notifications prior to CM9 alpha4 would add wakelock blame to mmc_delayed_work.
    • Battery blame percentages in Settings > Battery are not accurate.  This is a bug in Epic CM9.
    Known causes of Battery Drain
    • 4G drains battery very quickly.  It is recommended that you stick with 3G data while on battery, and switch to 4G only temporarily for big downloads or if you are plugged into AC power.
    • Dropbox sync is known to prevent the CPU from sleeping.  Turn it off in Settings > Accounts & sync.  Dropbox is still useful as without sync, you can still easily choose photos/files to upload directly to your chosen folder.
    • App bugs sometimes erroneously leave GPS and Camera devices enabled even after the devices are no longer needed.  This is akin to leaving the lights on after you have left the room.  If you notice your battery is draining quickly after using one of these devices, for the moment your only option is to reboot the phone to stop the power drain.  The Epic CM developers are investigating this issue to fix in a future release.
      • Google Talk is known to erroneously leave a camera enabled when you switch between front and back camera.
      • Camera has been known to sometimes leave the camera device on even after the app is no longer running.  It might be if you turn off the screen while the camera is in preview mode.  This might be the reason why Samsung camera does not allow you to turn off the screen while the camera app is running.
      • Google Maps uses the GPS device to find its location.  It has been seen to leave the GPS device enabled after it is no longer needed.  It is unclear if manually disabling GPS turns it off.
    • Minimum 100mhz CPU scaling is broken in Bug #14 if you have ever modified the CPU scaling options in CM9 in the past.  If you want 100mhz to return, use your favorite root-capable file manager to delete the /data/system/throttle directory then reboot.  It is strongly recommended that you do not change the CPU scaling options for now.  Contrary to popular belief, it is possible to achieve maximum battery life without changing these settings.  It is far more important to kill the causes of wakelocks than to screw with your CPU settings.
    • Rare Bug: Media scan uses 100% CPU for many minutes.  You can use SystemPanel Lite as described below to determine if this is the cause of your CPU drain.  This rarely happens on phones that have many thousands of files on the sdcard.  It is uncertain why it happens to some people and not others, as media scanning takes only a few seconds with for other users with thousands of files.  In any case, if SystemPanel Lite identifies android.process.media as using many minutes of CPU, you have two options.
      • Add .nomedia files to most of your directories in sdcard, especially those containing CWM backups.  This makes the media scanning faster as it skips directories with many files that you do not consider to be media.
      • Copy your files to your computer, format your sdcard and reboot  Does this solve the problem? If not, you might need to buy a new sdcard.  They do fail every once in a while.  This sdcard from Amazon seems to be highly rated.
    How to Diagnose Battery Drain on your Phone
    The key to preventing power drain on Android devices is to detect the causes of wakelocks that prevent the processor from sleeping.  These tools can help.
    • CPU Spy
      • This app allows you to see the deep sleep % since boot or timer reset, but not the cause of wakelocks.  Maximized battery with Juice Defender and sync turned off in most apps is capable of achieving > 90% deep sleep and ~30 hour battery life with a 1500mah OEM Samsung battery.  Your goal is to adjust system and apps settings to maximize the deep sleep percentage.
      • After you are done charging, hit Menu > Reset Timers so measurement on battery will be accurate.  The Epic is not capable of deep sleep while charging because software is needed by the charging regulator chip. 
    • SystemPanel Lite
      • This app can show you processes and how much CPU they have used.  You need to modify the settings to allow it to show hidden system processes like android.process.media that are sometimes the cause of excessive CPU usage.
      • Launch SystemPanel Lite.  From the main screen, tap the Menu icon or hit the menu button. Then tap Settings.  Check "System processes" for internal system processes to show up with the rest of the processes. Also enable "Show App CPU time" to display total CPU time on the main list of processes.
      • How to interpret results: The main screen shows you all processes active and cached.  The main screen also shows current memory usage and total CPU time used since the process was started (if you enabled that option in the settings).
        • The first thing to notice is the bar to the left of each entry showing current cpu usage.  If you notice any processes using a high amount of CPU cycles then you will need to investigate that process further to ensure it is desired behavior or a problem exists with a process using more resources than it should.  The less you tax your CPU the longer your battery will last.  If you have a process with high CPU usage then consider ending, disabling, or uninstalling the offending application or service.
        • The next bit of information to look through is CPU time for high usage.  High CPU usage can be a helpful indicator of a process or application that is causing significant battery drain.  If you tap on the process, take a peek at "Average Consumption" and if it is high then consider ending, disabling, or uninstalling the offending application or service.
        • The third bit to browse is memory usage.  While high memory processes do not directly relate to battery drain, high memory usage can slow other processes down and cause them to utilize the CPU and other resources in longer intervals, thus affecting overall battery life.  If you have a process with high memory usage then consider ending, disabling, or uninstalling the offending application or service.
        • Keep in mind some processes and applications are required for your device to operate correctly.  Most of those processes should not be taxing your system that much.  If you end a process and it causes undesired results, simple reboot your device to relaunch that process.
    • Better Battery Stats
      • Warning!  While this app is useful as a battery diagnostic, having it installed causes your battery to drain at a rapid pace.  Uninstall it when you are not actively using it to diagnose other issues. [NOTE: I believe this is not directly BBS's fault.  The battery drain occurs when the phone is woken up very frequently from sleep something BBS is doing with mmc storage causes the phone to not be able to return to sleep as quickly as mmc detection is very slow causing larger mmc_delayed_work time.  Under normal circumstances BBS would not cause this issue as the phone would not wakeup from sleep so frequently -Troy Smith]
      • This app will let you do two things.
        • It will let you identify what is keeping your phone from deep sleep.
        • Help you identify what applications are using CPU which translates to battery drain.
      • Deep Sleep: In the app, select "Process" from the drop down.  You will see a list of Android processes sorted by CPU usage.  Your goal is to review that list and identify applications that are using CPU.  You will either need to uninstall the apps that are causing the most drain, disable them from autostarting, or disable their sync/notifications.
      • Partial Wakelocks: This screen will sort all the processes on your phone that caused a wakelock.  You can review this list and either disable those processes, uninstall abusing apps, or reduce sync intervals, etc.
    Discuss the Battery Optimization Guide in this XDA Forum thread.