Transcript
Page 1: Understanding, debugging and fixing power bugs

Understanding, Debugging and Fixing

Power Bugs

Aditya & Satyam

Page 2: Understanding, debugging and fixing power bugs

Power Bugs

Apps are to blame the most for bad battery life

Page 3: Understanding, debugging and fixing power bugs

Power Bugs

• Bad coding patterns cause power bugs

• Specific behaviors of the Android Platform

• App inter-dependencies!

• Special Attention must be paid to optimize for power!

Page 4: Understanding, debugging and fixing power bugs

Users Hate Power Bugs

Page 5: Understanding, debugging and fixing power bugs

Understanding Common Power Bugs

Page 6: Understanding, debugging and fixing power bugs

Common Power Bugs 1. Not Sleeping Properly

Page 7: Understanding, debugging and fixing power bugs

Common Power Bugs 2. Un-necessary Animations

Page 8: Understanding, debugging and fixing power bugs

Common Power Bugs 3. Updating the Screen

Page 9: Understanding, debugging and fixing power bugs

Common Power Bugs 4. Handling Display-Off

Page 10: Understanding, debugging and fixing power bugs

Common Power Bugs 5. Waking up to notifications

Page 11: Understanding, debugging and fixing power bugs

More Types Of Power Bugs

• Registering for un-necessary events

• Waking up the system causes everyone to be woken up

• Register for “active” notifications (instead of passive ones)

• Handset-specific problems

Page 12: Understanding, debugging and fixing power bugs

Best Practices(or how to avoid the dreaded battery drain)

Page 13: Understanding, debugging and fixing power bugs

Power Consumption is Complex and Inter-dependent among components

Jeff Sharkey at Google IO

Page 14: Understanding, debugging and fixing power bugs

Best Practices - Network

• prefetch data

– to avoid switching states frequently, try and read as much data as possible

– trade-off between too much pre-fetch and battery drain

– google recommends pre-fetching data that you will initiate in the next 2 to 5 minutes, and in the order of 1-5 MB size

• batch data

– do data send/receive in batches rather than on-demand

– eg: batch analytics information, rather than sending them as they are collected

Page 15: Understanding, debugging and fixing power bugs

Best Practices - Network

• using inexact timers

– AlarmManager.setInexactRepeating()

– use ELAPSED_REALTIME instead of ELAPSED_REALTIME_WAKEUP

• detect network connection

– avoid connection attempts if no network is active

• avoid polling and use GCM when possible

– avoids multiple connections

– reduces the number of device state changes

Page 16: Understanding, debugging and fixing power bugs

Best Practices - Screen

• color matters!

– esp on OLED screens

– darker the color, lesser the consumption

• brightness levels have more impact

– refer to - http://stackoverflow.com/questions/5032588/cant-apply-system-screen-brightness-programmatically-in-android

Page 17: Understanding, debugging and fixing power bugs

Best Practices - Screen

• programmatically reduce brightness if its suits your app/activity

• Use “night mode” for reading Apps

• Think about your color scheme

Page 18: Understanding, debugging and fixing power bugs

Best Practices - CPU

• wakelocks are your friend, but your users worst nightmare!

• use them only if really needed and ensure they are removed as soon as possible

• Use ‘android:keepScreenOn’ property in your manifest instead of doing it programmatically

Page 19: Understanding, debugging and fixing power bugs

Best Practices - CPU

• if possible, spread out your computationally intensive job

• gpu typically consumes more power than cpu

– avoid floating point math where possible

• use algorithms that consume less CPU cycle

– O(n log n) vs O(n 2) algorithms

Page 20: Understanding, debugging and fixing power bugs

Identifying power bugs with little eye

Demo

Page 21: Understanding, debugging and fixing power bugs

Optimized Apps = Better User Experience

Thank You

www.littleeye.co

[email protected]@littleeye.co


Top Related